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:
@@ -11,6 +11,7 @@ namespace Wox
|
||||
{
|
||||
private PluginPair _plugin;
|
||||
private Settings _settings;
|
||||
private readonly Internationalization _translater = InternationalizationManager.Instance;
|
||||
|
||||
public ActionKeywords(string pluginId, Settings settings)
|
||||
{
|
||||
@@ -19,7 +20,7 @@ namespace Wox
|
||||
_settings = settings;
|
||||
if (_plugin == null)
|
||||
{
|
||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("cannotFindSpecifiedPlugin"));
|
||||
MessageBox.Show(_translater.GetTranslation("cannotFindSpecifiedPlugin"));
|
||||
Close();
|
||||
}
|
||||
}
|
||||
@@ -39,21 +40,18 @@ namespace Wox
|
||||
{
|
||||
var oldActionKeyword = _plugin.Metadata.ActionKeywords[0];
|
||||
var newActionKeyword = tbAction.Text.Trim();
|
||||
try
|
||||
if (!PluginManager.ActionKeywordRegistered(newActionKeyword))
|
||||
{
|
||||
// update in-memory data
|
||||
PluginManager.UpdateActionKeywordForPlugin(_plugin, oldActionKeyword, newActionKeyword);
|
||||
var id = _plugin.Metadata.ID;
|
||||
PluginManager.ReplaceActionKeyword(id, oldActionKeyword, newActionKeyword);
|
||||
MessageBox.Show(_translater.GetTranslation("succeed"));
|
||||
Close();
|
||||
}
|
||||
catch (WoxPluginException e)
|
||||
else
|
||||
{
|
||||
MessageBox.Show(e.Message);
|
||||
return;
|
||||
string msg = _translater.GetTranslation("newActionKeywordsHasBeenAssigned");
|
||||
MessageBox.Show(msg);
|
||||
}
|
||||
// update persistant data
|
||||
_settings.PluginSettings.UpdateActionKeyword(_plugin.Metadata);
|
||||
|
||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed"));
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,10 +83,10 @@
|
||||
<Image Source="{Binding Image, IsAsync=True}"
|
||||
Width="32" Height="32" />
|
||||
<StackPanel Margin="3 0 3 0">
|
||||
<TextBlock Text="{Binding Metadata.Name}"
|
||||
ToolTip="{Binding Metadata.Name}" />
|
||||
<TextBlock Text="{Binding Metadata.Description}"
|
||||
ToolTip="{Binding Metadata.Description}"
|
||||
<TextBlock Text="{Binding PluginPair.Metadata.Name}"
|
||||
ToolTip="{Binding PluginPair.Metadata.Name}" />
|
||||
<TextBlock Text="{Binding PluginPair.Metadata.Description}"
|
||||
ToolTip="{Binding PluginPair.Metadata.Description}"
|
||||
Opacity="0.5" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
@@ -119,8 +119,8 @@
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{Binding Metadata.Name}"
|
||||
ToolTip="{Binding Metadata.Name}"
|
||||
<TextBlock Text="{Binding PluginPair.Metadata.Name}"
|
||||
ToolTip="{Binding PluginPair.Metadata.Name}"
|
||||
Grid.Column="0"
|
||||
Cursor="Hand" MouseUp="OnPluginNameClick" FontSize="24"
|
||||
HorizontalAlignment="Left" />
|
||||
@@ -128,14 +128,14 @@
|
||||
VerticalAlignment="Bottom" Opacity="0.5">
|
||||
<TextBlock Text="{DynamicResource author}" />
|
||||
<TextBlock Text=": " />
|
||||
<TextBlock Text="{Binding Metadata.Author}" ToolTip="{Binding Metadata.Author}" />
|
||||
<TextBlock Text="{Binding PluginPair.Metadata.Author}" ToolTip="{Binding PluginPair.Metadata.Author}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<TextBlock Text="{Binding Metadata.Description}"
|
||||
ToolTip="{Binding Metadata.Description}"
|
||||
<TextBlock Text="{Binding PluginPair.Metadata.Description}"
|
||||
ToolTip="{Binding PluginPair.Metadata.Description}"
|
||||
Grid.Row="1" Opacity="0.5" />
|
||||
<DockPanel Grid.Row="2" Margin="0 10 0 8">
|
||||
<CheckBox IsChecked="{Binding Metadata.Disabled}" Checked="OnPluginToggled"
|
||||
<CheckBox IsChecked="{Binding PluginPair.Metadata.Disabled}" Checked="OnPluginToggled"
|
||||
Unchecked="OnPluginToggled">
|
||||
<TextBlock Text="{DynamicResource disable}" />
|
||||
</CheckBox>
|
||||
|
||||
@@ -214,15 +214,15 @@ namespace Wox
|
||||
|
||||
private void OnPluginToggled(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var id = _viewModel.SelectedPlugin.Metadata.ID;
|
||||
_settings.PluginSettings.Plugins[id].Disabled = _viewModel.SelectedPlugin.Metadata.Disabled;
|
||||
var id = _viewModel.SelectedPlugin.PluginPair.Metadata.ID;
|
||||
_settings.PluginSettings.Plugins[id].Disabled = _viewModel.SelectedPlugin.PluginPair.Metadata.Disabled;
|
||||
}
|
||||
|
||||
private void OnPluginActionKeywordsClick(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.ChangedButton == MouseButton.Left)
|
||||
{
|
||||
var id = _viewModel.SelectedPlugin.Metadata.ID;
|
||||
var id = _viewModel.SelectedPlugin.PluginPair.Metadata.ID;
|
||||
ActionKeywords changeKeywordsWindow = new ActionKeywords(id, _settings);
|
||||
changeKeywordsWindow.ShowDialog();
|
||||
}
|
||||
@@ -234,7 +234,7 @@ namespace Wox
|
||||
{
|
||||
if (e.ChangedButton == MouseButton.Left)
|
||||
{
|
||||
var website = _viewModel.SelectedPlugin.Metadata.Website;
|
||||
var website = _viewModel.SelectedPlugin.PluginPair.Metadata.Website;
|
||||
if (!string.IsNullOrEmpty(website))
|
||||
{
|
||||
var uri = new Uri(website);
|
||||
@@ -251,7 +251,7 @@ namespace Wox
|
||||
{
|
||||
if (e.ChangedButton == MouseButton.Left)
|
||||
{
|
||||
var directory = _viewModel.SelectedPlugin.Metadata.PluginDirectory;
|
||||
var directory = _viewModel.SelectedPlugin.PluginPair.Metadata.PluginDirectory;
|
||||
if (!string.IsNullOrEmpty(directory) && Directory.Exists(directory))
|
||||
{
|
||||
Process.Start(directory);
|
||||
|
||||
@@ -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