mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
Databinding for plugin tab + faster image load
This commit is contained in:
34
Wox/ViewModel/PluginViewModel.cs
Normal file
34
Wox/ViewModel/PluginViewModel.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using Wox.Plugin;
|
||||
using PropertyChanged;
|
||||
using Wox.Core.Resource;
|
||||
using Wox.Infrastructure.Image;
|
||||
|
||||
namespace Wox.ViewModel
|
||||
{
|
||||
[ImplementPropertyChanged]
|
||||
public class PluginViewModel
|
||||
{
|
||||
public PluginPair PluginPair { get; set; }
|
||||
public PluginMetadata Metadata { get; set; }
|
||||
public IPlugin Plugin { get; set; }
|
||||
|
||||
private readonly Internationalization _translator = InternationalizationManager.Instance;
|
||||
|
||||
public ImageSource Image => ImageLoader.Load(Metadata.IcoPath);
|
||||
public Visibility ActionKeywordsVisibility => Metadata.ActionKeywords.Count > 1 ? Visibility.Collapsed : Visibility.Visible;
|
||||
public string InitilizaTime => string.Format(_translator.GetTranslation("plugin_init_time"), Metadata.InitTime);
|
||||
public string QueryTime => string.Format(_translator.GetTranslation("plugin_query_time"), Metadata.AvgQueryTime);
|
||||
public string ActionKeywordsText
|
||||
{
|
||||
get
|
||||
{
|
||||
var text = string.Join(Query.ActionKeywordSeperater, Metadata.ActionKeywords);
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
using System;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Core.Resource;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Hotkey;
|
||||
using System.Windows.Media;
|
||||
using System.Windows;
|
||||
using Wox.Infrastructure.Image;
|
||||
using Wox.Plugin;
|
||||
using Wox.Storage;
|
||||
|
||||
|
||||
namespace Wox.ViewModel
|
||||
{
|
||||
@@ -37,7 +36,14 @@ namespace Wox.ViewModel
|
||||
|
||||
public string PluginID => RawResult.PluginID;
|
||||
|
||||
public string IcoPath => RawResult.IcoPath;
|
||||
public ImageSource Image
|
||||
{
|
||||
get
|
||||
{
|
||||
var image = ImageLoader.Load(RawResult.IcoPath);
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
||||
public int Score
|
||||
{
|
||||
|
||||
@@ -1,28 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Microsoft.Win32;
|
||||
using PropertyChanged;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Core.Resource;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Plugin;
|
||||
using static System.String;
|
||||
|
||||
namespace Wox.ViewModel
|
||||
{
|
||||
[ImplementPropertyChanged]
|
||||
public class SettingWindowViewModel
|
||||
{
|
||||
private const string StartupPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
|
||||
public Settings Settings { get; set; }
|
||||
|
||||
private readonly JsonStrorage<Settings> _storage;
|
||||
public Settings Settings { get; set; }
|
||||
private readonly Dictionary<ISettingProvider, Control> _featureControls = new Dictionary<ISettingProvider, Control>();
|
||||
|
||||
public List<Language> Languages => InternationalizationManager.Instance.LoadAvailableLanguages();
|
||||
public IEnumerable<int> MaxResultsRange => Enumerable.Range(2, 16);
|
||||
public Tab SelectedTab { get; set; } = Tab.General;
|
||||
public PluginViewModel SelectedPlugin { get; set; }
|
||||
|
||||
public IList<PluginViewModel> MetadataViewModels
|
||||
{
|
||||
get
|
||||
{
|
||||
var plugins = PluginManager.AllPlugins;
|
||||
var settings = Settings.PluginSettings.Plugins;
|
||||
plugins.Sort((a, b) =>
|
||||
{
|
||||
var d1 = settings[a.Metadata.ID].Disabled;
|
||||
var d2 = settings[b.Metadata.ID].Disabled;
|
||||
if (d1 == d2)
|
||||
{
|
||||
return Compare(a.Metadata.Name, b.Metadata.Name, StringComparison.CurrentCulture);
|
||||
}
|
||||
else
|
||||
{
|
||||
return d1.CompareTo(d2);
|
||||
}
|
||||
});
|
||||
|
||||
var metadatas = plugins.Select(p => new PluginViewModel
|
||||
{
|
||||
PluginPair = p,
|
||||
Metadata = p.Metadata,
|
||||
Plugin = p.Plugin
|
||||
}).ToList();
|
||||
return metadatas;
|
||||
}
|
||||
}
|
||||
|
||||
public SettingWindowViewModel()
|
||||
{
|
||||
@@ -30,6 +62,45 @@ namespace Wox.ViewModel
|
||||
Settings = _storage.Load();
|
||||
}
|
||||
|
||||
public Control SettingProvider
|
||||
{
|
||||
get
|
||||
{
|
||||
var settingProvider = SelectedPlugin.Plugin as ISettingProvider;
|
||||
if (settingProvider != null)
|
||||
{
|
||||
Control control;
|
||||
if (!_featureControls.TryGetValue(settingProvider, out control))
|
||||
{
|
||||
var multipleActionKeywordsProvider = settingProvider as IMultipleActionKeywords;
|
||||
if (multipleActionKeywordsProvider != null)
|
||||
{
|
||||
multipleActionKeywordsProvider.ActionKeywordsChanged += (o, e) =>
|
||||
{
|
||||
// update in-memory data
|
||||
PluginManager.UpdateActionKeywordForPlugin(SelectedPlugin.PluginPair, e.OldActionKeyword,
|
||||
e.NewActionKeyword);
|
||||
// update persistant data
|
||||
Settings.PluginSettings.UpdateActionKeyword(SelectedPlugin.Metadata);
|
||||
|
||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed"));
|
||||
};
|
||||
}
|
||||
|
||||
_featureControls.Add(settingProvider, control = settingProvider.CreateSettingPanel());
|
||||
}
|
||||
control.HorizontalAlignment = HorizontalAlignment.Stretch;
|
||||
control.VerticalAlignment = VerticalAlignment.Stretch;
|
||||
return control;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Control();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Save()
|
||||
{
|
||||
_storage.Save();
|
||||
|
||||
Reference in New Issue
Block a user