Databinding for plugin tab + faster image load

This commit is contained in:
bao-qian
2016-05-22 05:30:38 +01:00
parent 708dba6cb1
commit 7056be0870
22 changed files with 286 additions and 274 deletions

View File

@@ -38,7 +38,7 @@ namespace Wox
private void OnStartup(object sender, StartupEventArgs e)
{
Stopwatch.Debug("Startup Time", () =>
Stopwatch.Normal("Startup Time", () =>
{
RegisterDispatcherUnhandledException();

4
Wox/FodyWeavers.xml Normal file
View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Weavers>
<PropertyChanged />
</Weavers>

View File

@@ -31,16 +31,13 @@
<Button.Content>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5"
Cursor="Hand" UseLayoutRounding="False">
<Grid.Resources>
<image:ImagePathConverter x:Key="ImageConverter" />
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="32" />
<ColumnDefinition />
<ColumnDefinition Width="0" />
</Grid.ColumnDefinitions>
<Image x:Name="imgIco" Width="32" Height="32" HorizontalAlignment="Left"
Source="{Binding IcoPath,Converter={StaticResource ImageConverter},IsAsync=True}" />
Source="{Binding Image ,IsAsync=True}" />
<Grid Margin="5 0 5 0" Grid.Column="1" HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition />

View File

@@ -5,7 +5,6 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:wox="clr-namespace:Wox"
xmlns:vm="clr-namespace:Wox.ViewModel"
xmlns:woxPlugin="clr-namespace:Wox.Plugin;assembly=Wox.Plugin"
xmlns:image="clr-namespace:Wox.Infrastructure.Image;assembly=Wox.Infrastructure"
x:Class="Wox.SettingWindow"
mc:Ignorable="d"
@@ -15,11 +14,8 @@
WindowStartupLocation="CenterScreen"
Height="600" Width="800" PreviewKeyDown="Window_PreviewKeyDown"
d:DataContext="{d:DesignInstance vm:SettingWindowViewModel}">
<Window.Resources>
<image:ImagePathConverter x:Key="ImageConverter" />
</Window.Resources>
<TabControl Height="auto" SelectedIndex="{Binding SelectedTab}">
<TabItem Header="{DynamicResource general}">
<TabItem Header="{DynamicResource general}" Height="24" VerticalAlignment="Top">
<StackPanel Orientation="Vertical">
<CheckBox IsChecked="{Binding Settings.StartWoxOnSystemStartup}" Margin="10">
<TextBlock Text="{DynamicResource startWoxOnSystemStartup}" />
@@ -36,7 +32,7 @@
<CheckBox Margin="10" IsChecked="{Binding Settings.IgnoreHotkeysOnFullscreen}">
<TextBlock Text="{DynamicResource ignoreHotkeysOnFullscreen}" />
</CheckBox>
<CheckBox Margin="10" IsChecked="{Binding Settings.AutoUpdates}"
<CheckBox Margin="10" IsChecked="{Binding Settings.AutoUpdates}"
Checked="OnAutoStartupChecked" Unchecked="OnAutoStartupUncheck">
<TextBlock Text="{DynamicResource autoUpdates}" />
</CheckBox>
@@ -44,108 +40,116 @@
<TextBlock Text="{DynamicResource language}" />
<ComboBox Margin="10 0 0 0" Width="120" SelectionChanged="OnLanguageChanged"
ItemsSource="{Binding Languages}" SelectedValue="{Binding Settings.Language}"
DisplayMemberPath="Display" SelectedValuePath = "LanguageCode" />
DisplayMemberPath="Display" SelectedValuePath="LanguageCode" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="10">
<TextBlock Text="{DynamicResource maxShowResults}" />
<ComboBox Margin="10 0 0 0" Width="45" ItemsSource="{Binding MaxResultsRange}" SelectedItem="{Binding Settings.MaxResultsToShow}"/>
<ComboBox Margin="10 0 0 0" Width="45" ItemsSource="{Binding MaxResultsRange}"
SelectedItem="{Binding Settings.MaxResultsToShow}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="10" Text="{DynamicResource pythonDirectory}" />
<TextBox Width="300" Margin="10" Text="{Binding Settings.PluginSettings.PythonDirectory}"/>
<Button Margin="10" Click="OnSelectPythonDirectoryClick" Content="{DynamicResource selectPythonDirectory}" />
<TextBox Width="300" Margin="10" Text="{Binding Settings.PluginSettings.PythonDirectory}" />
<Button Margin="10" Click="OnSelectPythonDirectoryClick"
Content="{DynamicResource selectPythonDirectory}" />
</StackPanel>
</StackPanel>
</TabItem>
<TabItem Header="{DynamicResource plugin}" Selector.Selected="OnPluginTabSelected">
<TabItem Header="{DynamicResource plugin}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="39.5" />
<ColumnDefinition Width="160.5"/>
<ColumnDefinition Width="200" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<DockPanel Grid.Column="0" Grid.ColumnSpan="2">
<TextBlock DockPanel.Dock="Top" Margin="10" HorizontalAlignment="Left" Cursor="Hand"
MouseUp="tbMorePlugins_MouseUp" Foreground="Blue"
<DockPanel Grid.Column="0">
<TextBlock DockPanel.Dock="Top" Margin="10" Cursor="Hand"
MouseUp="OnMorePluginsClicked" Foreground="Blue"
Text="{DynamicResource browserMorePlugins}" />
<ListBox x:Name="PluginsListBox" Margin="10, 0, 10, 10"
SelectionChanged="OnPluginsSelectionChanged"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
ScrollViewer.HorizontalScrollBarVisibility="Disabled" Grid.IsSharedSizeScope="True">
<ListBox.Resources>
<DataTemplate DataType="{x:Type woxPlugin:PluginPair}">
<Grid Height="36" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="32" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Image Width="32" Height="32" HorizontalAlignment="Left"
Source="{Binding Metadata.IcoPath,Converter={StaticResource ImageConverter},IsAsync=True}" />
<Grid Margin="3 0 3 0" Grid.Column="1" HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock VerticalAlignment="Center" ToolTip="{Binding Metadata.Name}"
x:Name="tbTitle" Text="{Binding Metadata.Name}" />
<TextBlock ToolTip="{Binding Metadata.Description}"
Grid.Row="1" x:Name="tbSubTitle"
Text="{Binding Metadata.Description}" Opacity="0.5" />
</Grid>
</Grid>
<ListBox SelectedIndex="0" SelectedItem="{Binding SelectedPlugin}"
ItemsSource="{Binding MetadataViewModels}"
Margin="10, 0, 10, 10" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="3">
<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}"
Opacity="0.5" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.Resources>
</ListBox.ItemTemplate>
</ListBox>
</DockPanel>
<Grid Margin="0" Grid.Column="2">
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ContentControl Grid.ColumnSpan="1" Grid.Row="0" Margin="10 10 10 0">
<ContentControl DataContext="{Binding Path=SelectedPlugin}"
Grid.ColumnSpan="1" Grid.Row="0" Margin="10 10 10 0">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="48" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Image Width="48" Height="48" HorizontalAlignment="Left" VerticalAlignment="Top"
x:Name="PluginIcon" />
<Image Source="{Binding Image, IsAsync=True}"
Width="48" Height="48" HorizontalAlignment="Left" VerticalAlignment="Top" />
<Grid Margin="10,0,0,0" Grid.Column="1" HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<DockPanel Grid.Row="0">
<TextBlock x:Name="PluginTitle" Text="Plugin Title" Cursor="Hand"
MouseUp="PluginTitle_OnMouseUp"
ToolTip="{Binding Source=pluginTitle, Path=Text}" FontSize="24" />
<TextBlock Opacity="0.5" VerticalAlignment="Bottom" HorizontalAlignment="Right"
x:Name="PluginAuthor" Text="{DynamicResource author}" />
</DockPanel>
<TextBlock Grid.Row="1" x:Name="PluginSubTitle" Opacity="0.5"
ToolTip="{Binding Source=pluginSubTitle, Path=Text}" />
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Metadata.Name}"
ToolTip="{Binding Metadata.Name}"
Grid.Column="0"
Cursor="Hand" MouseUp="OnPluginNameClick" FontSize="24"
HorizontalAlignment="Left" />
<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right"
VerticalAlignment="Bottom" Opacity="0.5">
<TextBlock Text="{DynamicResource author}" />
<TextBlock Text=": " />
<TextBlock Text="{Binding Metadata.Author}" ToolTip="{Binding Metadata.Author}" />
</StackPanel>
</Grid>
<TextBlock Text="{Binding Metadata.Description}"
ToolTip="{Binding Metadata.Description}"
Grid.Row="1" Opacity="0.5" />
<DockPanel Grid.Row="2" Margin="0 10 0 8">
<CheckBox x:Name="DisablePlugin" Click="OnDisablePluginClicked">
<CheckBox IsChecked="{Binding Metadata.Disabled}" Checked="OnPluginToggled"
Unchecked="OnPluginToggled">
<TextBlock Text="{DynamicResource disable}" />
</CheckBox>
<TextBlock Margin="20 0 0 0"
x:Name="PluginActionKeywordsTitle"
Text="{DynamicResource actionKeywords}" />
<TextBlock Margin="5 0 0 0" ToolTip="Change Action Keywords" Cursor="Hand"
MouseUp="PluginActionKeywords_OnMouseUp" Foreground="Blue" Text="keys"
x:Name="PluginActionKeywords" />
<TextBlock Margin="10 0 0 0" Text="Initialize time: 0ms" x:Name="PluginInitTime" />
<TextBlock Margin="10 0 0 0" Text="Query time: 0ms" x:Name="PluginQueryTime" />
<TextBlock HorizontalAlignment="Right" Cursor="Hand"
MouseUp="tbOpenPluginDirecoty_MouseUp" Foreground="Blue"
Text="{DynamicResource pluginDirectory}" x:Name="OpenPluginDirecoty" />
<TextBlock Text="{DynamicResource actionKeywords}"
Visibility="{Binding ActionKeywordsVisibility}"
Margin="20 0 0 0" />
<TextBlock Text="{Binding ActionKeywordsText}"
Visibility="{Binding ActionKeywordsVisibility}"
ToolTip="Change Action Keywords"
Margin="5 0 0 0" Cursor="Hand" Foreground="Blue"
MouseUp="OnPluginActionKeywordsClick" />
<TextBlock Text="{Binding InitilizaTime}" Margin="10 0 0 0" />
<TextBlock Text="{Binding QueryTime}" Margin="10 0 0 0" />
<TextBlock Text="{DynamicResource pluginDirectory}"
HorizontalAlignment="Right" Cursor="Hand"
MouseUp="OnPluginDirecotyClick" Foreground="Blue" />
</DockPanel>
</Grid>
</Grid>
</ContentControl>
<ContentControl x:Name="PluginContentPanel" Grid.ColumnSpan="1" Grid.Row="1" Margin="0"
<ContentControl Content="{Binding SettingProvider}"
Grid.ColumnSpan="1" Grid.Row="1"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</Grid>
</Grid>

View File

@@ -6,7 +6,6 @@ using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
@@ -20,8 +19,6 @@ using Wox.Core.Resource;
using Wox.Core.UserSettings;
using Wox.Helper;
using Wox.Infrastructure.Hotkey;
using Wox.Infrastructure.Image;
using Wox.Infrastructure.Logger;
using Wox.Plugin;
using Wox.ViewModel;
using Stopwatch = Wox.Infrastructure.Stopwatch;
@@ -31,17 +28,19 @@ namespace Wox
public partial class SettingWindow
{
private const string StartupPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
public readonly IPublicAPI _api;
bool settingsLoaded;
private Dictionary<ISettingProvider, Control> featureControls = new Dictionary<ISettingProvider, Control>();
private bool themeTabLoaded;
private Settings _settings;
private SettingWindowViewModel _viewModel;
public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel)
{
InitializeComponent();
_settings = viewModel.Settings;
DataContext = viewModel;
_viewModel = viewModel;
_api = api;
ResultListBoxPreview.DataContext = new ResultsViewModel(_settings);
Loaded += Setting_Loaded;
@@ -448,179 +447,58 @@ namespace Wox
#region Plugin
private void OnPluginsSelectionChanged(object sender, SelectionChangedEventArgs _)
private void OnPluginToggled(object sender, RoutedEventArgs e)
{
var pair = PluginsListBox.SelectedItem as PluginPair;
string pluginId = string.Empty;
List<string> actionKeywords = null;
if (pair == null) return;
actionKeywords = pair.Metadata.ActionKeywords;
PluginAuthor.Visibility = Visibility.Visible;
PluginInitTime.Text =
string.Format(InternationalizationManager.Instance.GetTranslation("plugin_init_time"), pair.InitTime);
PluginQueryTime.Text =
string.Format(InternationalizationManager.Instance.GetTranslation("plugin_query_time"),
pair.AvgQueryTime);
if (actionKeywords.Count > 1)
{
PluginActionKeywordsTitle.Visibility = Visibility.Collapsed;
PluginActionKeywords.Visibility = Visibility.Collapsed;
}
else
{
PluginActionKeywordsTitle.Visibility = Visibility.Visible;
PluginActionKeywords.Visibility = Visibility.Visible;
}
OpenPluginDirecoty.Visibility = Visibility.Visible;
PluginTitle.Text = pair.Metadata.Name;
PluginTitle.Cursor = Cursors.Hand;
PluginActionKeywords.Text = string.Join(Query.ActionKeywordSeperater, actionKeywords.ToArray());
PluginAuthor.Text = InternationalizationManager.Instance.GetTranslation("author") + ": " +
pair.Metadata.Author;
PluginSubTitle.Text = pair.Metadata.Description;
pluginId = pair.Metadata.ID;
PluginIcon.Source = ImageLoader.Load(pair.Metadata.IcoPath);
var customizedPluginConfig = _settings.PluginSettings.Plugins[pluginId];
DisablePlugin.IsChecked = customizedPluginConfig != null && customizedPluginConfig.Disabled;
PluginContentPanel.Content = null;
var settingProvider = pair.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(pair, e.OldActionKeyword, e.NewActionKeyword);
// update persistant data
_settings.PluginSettings.UpdateActionKeyword(pair.Metadata);
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed"));
};
}
featureControls.Add(settingProvider, control = settingProvider.CreateSettingPanel());
}
PluginContentPanel.Content = control;
control.HorizontalAlignment = HorizontalAlignment.Stretch;
control.VerticalAlignment = VerticalAlignment.Stretch;
control.Width = Double.NaN;
control.Height = Double.NaN;
}
var id = _viewModel.SelectedPlugin.Metadata.ID;
_settings.PluginSettings.Plugins[id].Disabled = _viewModel.SelectedPlugin.Metadata.Disabled;
}
private void OnDisablePluginClicked(object sender, RoutedEventArgs e)
{
var checkBox = (CheckBox)e.Source;
var pair = (PluginPair)PluginsListBox.SelectedItem;
var id = pair.Metadata.ID;
if (checkBox.IsChecked != null)
{
var disabled = (bool)checkBox.IsChecked;
_settings.PluginSettings.Plugins[id].Disabled = disabled;
}
else
{
Log.Warn($"IsChecked for checkbox is null for plugin: {pair.Metadata.Name}");
}
}
private void PluginActionKeywords_OnMouseUp(object sender, MouseButtonEventArgs e)
private void OnPluginActionKeywordsClick(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
{
var pair = PluginsListBox.SelectedItem as PluginPair;
if (pair != null)
{
//third-party plugin
string id = pair.Metadata.ID;
ActionKeywords changeKeywordsWindow = new ActionKeywords(id, _settings);
changeKeywordsWindow.ShowDialog();
PluginPair plugin = PluginManager.GetPluginForId(id);
if (plugin != null)
PluginActionKeywords.Text = string.Join(Query.ActionKeywordSeperater,
pair.Metadata.ActionKeywords.ToArray());
}
var id = _viewModel.SelectedPlugin.Metadata.ID;
ActionKeywords changeKeywordsWindow = new ActionKeywords(id, _settings);
changeKeywordsWindow.ShowDialog();
}
}
private void PluginTitle_OnMouseUp(object sender, MouseButtonEventArgs e)
private void OnPluginNameClick(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
{
var pair = PluginsListBox.SelectedItem as PluginPair;
if (pair != null)
if (e.ChangedButton == MouseButton.Left)
{
//third-party plugin
if (!string.IsNullOrEmpty(pair.Metadata.Website))
var website = _viewModel.SelectedPlugin.Metadata.Website;
if (!string.IsNullOrEmpty(website))
{
try
{
Process.Start(pair.Metadata.Website);
}
catch
var uri = new Uri(website);
if (Uri.CheckSchemeName(uri.Scheme))
{
Process.Start(website);
}
}
}
}
}
private void tbOpenPluginDirecoty_MouseUp(object sender, MouseButtonEventArgs e)
private void OnPluginDirecotyClick(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
{
var pair = PluginsListBox.SelectedItem as PluginPair;
if (pair != null)
var directory = _viewModel.SelectedPlugin.Metadata.PluginDirectory;
if (!string.IsNullOrEmpty(directory) && Directory.Exists(directory))
{
//third-party plugin
if (!string.IsNullOrEmpty(pair.Metadata.Website))
{
try
{
Process.Start(pair.Metadata.PluginDirectory);
}
catch
{
}
}
Process.Start(directory);
}
}
}
private void tbMorePlugins_MouseUp(object sender, MouseButtonEventArgs e)
private void OnMorePluginsClicked(object sender, MouseButtonEventArgs e)
{
Process.Start("http://www.getwox.com/plugin");
}
public void OnPluginTabSelected(object sender, RoutedEventArgs e)
{
var plugins = PluginManager.AllPlugins;
//move all disabled to bottom
plugins.Sort(delegate (PluginPair a, PluginPair b)
{
int res = _settings.PluginSettings.Plugins[a.Metadata.ID].Disabled ? 1 : 0;
res += _settings.PluginSettings.Plugins[b.Metadata.ID].Disabled ? -1 : 0;
return res;
});
PluginsListBox.ItemsSource = new CompositeCollection
{
new CollectionContainer
{
Collection = plugins
}
}; ;
PluginsListBox.SelectedIndex = 0;
}
#endregion
#region Proxy
@@ -738,5 +616,6 @@ namespace Wox
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
e.Handled = true;
}
}
}

View 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;
}
}
}
}

View File

@@ -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
{

View File

@@ -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();

View File

@@ -118,6 +118,10 @@
<Private>True</Private>
</Reference>
<Reference Include="PresentationUI, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="PropertyChanged, Version=1.51.0.0, Culture=neutral, PublicKeyToken=ee3ee20bcf148ddd, processorArchitecture=MSIL">
<HintPath>..\packages\PropertyChanged.Fody.1.51.0\lib\dotnet\PropertyChanged.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ReachFramework" />
<Reference Include="Splat, Version=1.6.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Splat.1.6.2\lib\Net45\Splat.dll</HintPath>
@@ -167,6 +171,7 @@
<Compile Include="Storage\UserSelectedRecord.cs" />
<Compile Include="ViewModel\BaseViewModel.cs" />
<Compile Include="ViewModel\MainViewModel.cs" />
<Compile Include="ViewModel\PluginViewModel.cs" />
<Compile Include="ViewModel\ResultViewModel.cs" />
<Compile Include="ViewModel\ResultsViewModel.cs" />
<Compile Include="ViewModel\SettingWindowViewModel.cs" />
@@ -228,6 +233,7 @@
<Resource Include="Images\app_error.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="FodyWeavers.xml" />
<Content Include="Languages\en.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -442,4 +448,11 @@ cd "$(TargetDir)" &amp; del /s /q *.xml
</Target>
<Target Name="AfterBuild">
</Target>
<Import Project="..\packages\Fody.1.29.2\build\dotnet\Fody.targets" Condition="Exists('..\packages\Fody.1.29.2\build\dotnet\Fody.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Fody.1.29.2\build\dotnet\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.1.29.2\build\dotnet\Fody.targets'))" />
</Target>
</Project>

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DeltaCompressionDotNet" version="1.0.0" targetFramework="net452" />
<package id="Fody" version="1.29.2" targetFramework="net452" developmentDependency="true" />
<package id="InputSimulator" version="1.0.4.0" targetFramework="net452" />
<package id="JetBrains.Annotations" version="10.1.4" targetFramework="net452" />
<package id="Mono.Cecil" version="0.9.6.1" targetFramework="net452" />
@@ -8,6 +9,7 @@
<package id="NHotkey" version="1.2.1" targetFramework="net452" />
<package id="NHotkey.Wpf" version="1.2.1" targetFramework="net452" />
<package id="NuGet.CommandLine" version="3.4.3" targetFramework="net452" developmentDependency="true" />
<package id="PropertyChanged.Fody" version="1.51.0" targetFramework="net452" developmentDependency="true" />
<package id="SharpZipLib" version="0.86.0" targetFramework="net452" />
<package id="Splat" version="1.6.2" targetFramework="net452" />
<package id="squirrel.windows" version="1.4.0" targetFramework="net452" />