mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
MVVM refactoring for web search plugin, part 1
1. #486 2. fix #778 #763 #742 3. MVVM refactoring 4. remove IMultipleActionKeywords interface, use PluginManager directly
This commit is contained in:
@@ -9,15 +9,13 @@ namespace Wox.ViewModel
|
||||
public class PluginViewModel : BaseModel
|
||||
{
|
||||
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 => string.Join(Query.ActionKeywordSeperater, Metadata.ActionKeywords);
|
||||
public ImageSource Image => ImageLoader.Load(PluginPair.Metadata.IcoPath);
|
||||
public Visibility ActionKeywordsVisibility => PluginPair.Metadata.ActionKeywords.Count > 1 ? Visibility.Collapsed : Visibility.Visible;
|
||||
public string InitilizaTime => string.Format(_translator.GetTranslation("plugin_init_time"), PluginPair.Metadata.InitTime);
|
||||
public string QueryTime => string.Format(_translator.GetTranslation("plugin_query_time"), PluginPair.Metadata.AvgQueryTime);
|
||||
public string ActionKeywordsText => string.Join(Query.ActionKeywordSeperater, PluginPair.Metadata.ActionKeywords);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,14 +36,7 @@ namespace Wox.ViewModel
|
||||
|
||||
public string PluginID => RawResult.PluginID;
|
||||
|
||||
public ImageSource Image
|
||||
{
|
||||
get
|
||||
{
|
||||
var image = ImageLoader.Load(RawResult.IcoPath);
|
||||
return image;
|
||||
}
|
||||
}
|
||||
public ImageSource Image => ImageLoader.Load(RawResult.IcoPath);
|
||||
|
||||
public int Score
|
||||
{
|
||||
|
||||
@@ -84,8 +84,6 @@ namespace Wox.ViewModel
|
||||
var metadatas = plugins.Select(p => new PluginViewModel
|
||||
{
|
||||
PluginPair = p,
|
||||
Metadata = p.Metadata,
|
||||
Plugin = p.Plugin
|
||||
}).ToList();
|
||||
return metadatas;
|
||||
}
|
||||
@@ -95,23 +93,9 @@ namespace Wox.ViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
var settingProvider = SelectedPlugin.Plugin as ISettingProvider;
|
||||
var settingProvider = SelectedPlugin.PluginPair.Plugin as ISettingProvider;
|
||||
if (settingProvider != null)
|
||||
{
|
||||
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(_translater.GetTranslation("succeed"));
|
||||
};
|
||||
}
|
||||
var control = settingProvider.CreateSettingPanel();
|
||||
control.HorizontalAlignment = HorizontalAlignment.Stretch;
|
||||
control.VerticalAlignment = VerticalAlignment.Stretch;
|
||||
@@ -124,6 +108,8 @@ namespace Wox.ViewModel
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region theme
|
||||
|
||||
Reference in New Issue
Block a user