diff --git a/Plugins/Wox.Plugin.PluginIndicator/Wox.Plugin.PluginIndicator.csproj b/Plugins/Wox.Plugin.PluginIndicator/Wox.Plugin.PluginIndicator.csproj index f8670040db..e9c867eada 100644 --- a/Plugins/Wox.Plugin.PluginIndicator/Wox.Plugin.PluginIndicator.csproj +++ b/Plugins/Wox.Plugin.PluginIndicator/Wox.Plugin.PluginIndicator.csproj @@ -38,6 +38,7 @@ True + diff --git a/Wox.Core/UserSettings/PluginHotkey.cs b/Wox.Core/UserSettings/PluginHotkey.cs index 02b607b11a..3f2e7be979 100644 --- a/Wox.Core/UserSettings/PluginHotkey.cs +++ b/Wox.Core/UserSettings/PluginHotkey.cs @@ -1,10 +1,8 @@ -using System; -using PropertyChanged; +using Wox.Plugin; namespace Wox.Core.UserSettings { - [ImplementPropertyChanged] - public class CustomPluginHotkey + public class CustomPluginHotkey : BaseModel { public string Hotkey { get; set; } public string ActionKeyword { get; set; } diff --git a/Wox.Core/UserSettings/PluginSettings.cs b/Wox.Core/UserSettings/PluginSettings.cs index 0d9430325b..158054c4e3 100644 --- a/Wox.Core/UserSettings/PluginSettings.cs +++ b/Wox.Core/UserSettings/PluginSettings.cs @@ -1,13 +1,9 @@ using System.Collections.Generic; -using System.Linq; -using PropertyChanged; -using Wox.Core.Plugin; using Wox.Plugin; namespace Wox.Core.UserSettings { - [ImplementPropertyChanged] - public class PluginsSettings + public class PluginsSettings : BaseModel { public string PythonDirectory { get; set; } public Dictionary Plugins { get; set; } = new Dictionary(); diff --git a/Wox.Core/UserSettings/Settings.cs b/Wox.Core/UserSettings/Settings.cs index 3ca977abfd..ca58e2fe72 100644 --- a/Wox.Core/UserSettings/Settings.cs +++ b/Wox.Core/UserSettings/Settings.cs @@ -3,12 +3,11 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Drawing; using Newtonsoft.Json; -using PropertyChanged; +using Wox.Plugin; namespace Wox.Core.UserSettings { - [ImplementPropertyChanged] - public class Settings + public class Settings : BaseModel { public string Hotkey { get; set; } = "Alt + Space"; public string Language { get; set; } = "en"; @@ -55,6 +54,7 @@ namespace Wox.Core.UserSettings public int ProxyPort { get; set; } public string ProxyUserName { get; set; } public string ProxyPassword { get; set; } + } [Obsolete] diff --git a/Wox.Infrastructure/Logger/Log.cs b/Wox.Infrastructure/Logger/Log.cs index 56870be676..e793dfd599 100644 --- a/Wox.Infrastructure/Logger/Log.cs +++ b/Wox.Infrastructure/Logger/Log.cs @@ -3,7 +3,6 @@ using System.IO; using NLog; using NLog.Config; using NLog.Targets; -using Wox.Infrastructure.Exception; namespace Wox.Infrastructure.Logger { diff --git a/Wox.Plugin/BaseModel.cs b/Wox.Plugin/BaseModel.cs new file mode 100644 index 0000000000..1beae5cb42 --- /dev/null +++ b/Wox.Plugin/BaseModel.cs @@ -0,0 +1,19 @@ +using System.ComponentModel; +using System.Runtime.CompilerServices; +using JetBrains.Annotations; +using PropertyChanged; + +namespace Wox.Plugin +{ + [ImplementPropertyChanged] + public class BaseModel : INotifyPropertyChanged + { + public event PropertyChangedEventHandler PropertyChanged; + + [NotifyPropertyChangedInvocator] + protected void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +} \ No newline at end of file diff --git a/Wox.Plugin/PluginMetadata.cs b/Wox.Plugin/PluginMetadata.cs index 6a8341cf00..55981e6454 100644 --- a/Wox.Plugin/PluginMetadata.cs +++ b/Wox.Plugin/PluginMetadata.cs @@ -5,9 +5,8 @@ using Newtonsoft.Json; using PropertyChanged; namespace Wox.Plugin { - [ImplementPropertyChanged] [JsonObject(MemberSerialization.OptOut)] - public class PluginMetadata + public class PluginMetadata : BaseModel { private string _pluginDirectory; public string ID { get; set; } diff --git a/Wox.Plugin/Wox.Plugin.csproj b/Wox.Plugin/Wox.Plugin.csproj index 2aec1a0258..3a2a19c1a6 100644 --- a/Wox.Plugin/Wox.Plugin.csproj +++ b/Wox.Plugin/Wox.Plugin.csproj @@ -60,6 +60,7 @@ Properties\SolutionAssemblyInfo.cs + diff --git a/Wox/SettingWindow.xaml b/Wox/SettingWindow.xaml index e6598b2e2d..b50c17531d 100644 --- a/Wox/SettingWindow.xaml +++ b/Wox/SettingWindow.xaml @@ -349,7 +349,7 @@ - + diff --git a/Wox/ViewModel/BaseViewModel.cs b/Wox/ViewModel/BaseViewModel.cs index daa6976e00..ff5fbf9f7a 100644 --- a/Wox/ViewModel/BaseViewModel.cs +++ b/Wox/ViewModel/BaseViewModel.cs @@ -1,21 +1,9 @@ using System; -using System.ComponentModel; -using System.Runtime.CompilerServices; using System.Windows.Input; namespace Wox.ViewModel { - public class BaseViewModel : INotifyPropertyChanged - { - - protected void OnPropertyChanged([CallerMemberName] string propertyName = null) - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } - - public event PropertyChangedEventHandler PropertyChanged; - } - + //todo rename file public class RelayCommand : ICommand { diff --git a/Wox/ViewModel/MainViewModel.cs b/Wox/ViewModel/MainViewModel.cs index cb8493f718..f102eb4fd1 100644 --- a/Wox/ViewModel/MainViewModel.cs +++ b/Wox/ViewModel/MainViewModel.cs @@ -20,7 +20,7 @@ using Wox.Storage; namespace Wox.ViewModel { - public class MainViewModel : BaseViewModel, ISavable + public class MainViewModel : BaseModel, ISavable { #region Private Fields @@ -231,15 +231,15 @@ namespace Wox.ViewModel } private void InitializeResultListBox() - { - Results = new ResultsViewModel(_settings.MaxResultsToShow); + { + Results = new ResultsViewModel(_settings); ResultListBoxVisibility = Visibility.Collapsed; } private void InitializeContextMenu() { - ContextMenu = new ResultsViewModel(_settings.MaxResultsToShow); + ContextMenu = new ResultsViewModel(_settings); ContextMenuVisibility = Visibility.Collapsed; } diff --git a/Wox/ViewModel/PluginViewModel.cs b/Wox/ViewModel/PluginViewModel.cs index cc2414ef16..16cbaa24bb 100644 --- a/Wox/ViewModel/PluginViewModel.cs +++ b/Wox/ViewModel/PluginViewModel.cs @@ -1,14 +1,12 @@ 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 class PluginViewModel : BaseModel { public PluginPair PluginPair { get; set; } public PluginMetadata Metadata { get; set; } diff --git a/Wox/ViewModel/ResultViewModel.cs b/Wox/ViewModel/ResultViewModel.cs index 0e97976724..d7fd9365c1 100644 --- a/Wox/ViewModel/ResultViewModel.cs +++ b/Wox/ViewModel/ResultViewModel.cs @@ -7,7 +7,7 @@ using Wox.Plugin; namespace Wox.ViewModel { - public class ResultViewModel : BaseViewModel + public class ResultViewModel : BaseModel { #region Private Fields diff --git a/Wox/ViewModel/ResultsViewModel.cs b/Wox/ViewModel/ResultsViewModel.cs index 288e4098bc..21c362f9b1 100644 --- a/Wox/ViewModel/ResultsViewModel.cs +++ b/Wox/ViewModel/ResultsViewModel.cs @@ -6,10 +6,11 @@ using System.Windows; using System.Windows.Data; using Wox.Core.UserSettings; using Wox.Plugin; +using PropertyChanged; namespace Wox.ViewModel { - public class ResultsViewModel : BaseViewModel + public class ResultsViewModel : BaseModel { #region Private Fields @@ -19,16 +20,24 @@ namespace Wox.ViewModel private readonly object _addResultsLock = new object(); private readonly object _collectionLock = new object(); - public int MaxResults = 6; + private readonly Settings _settings; + private int MaxResults => _settings?.MaxResultsToShow ?? 6; public ResultsViewModel() { Results = new ResultCollection(); BindingOperations.EnableCollectionSynchronization(Results, _collectionLock); } - public ResultsViewModel(int maxResults) : this() + public ResultsViewModel(Settings settings) : this() { - MaxResults = maxResults; + _settings = settings; + _settings.PropertyChanged += (s, e) => + { + if (e.PropertyName == nameof(_settings.MaxResultsToShow)) + { + OnPropertyChanged(nameof(MaxHeight)); + } + }; } #endregion diff --git a/Wox/ViewModel/SettingWindowViewModel.cs b/Wox/ViewModel/SettingWindowViewModel.cs index 4a9c1b1a71..1a1ef4f295 100644 --- a/Wox/ViewModel/SettingWindowViewModel.cs +++ b/Wox/ViewModel/SettingWindowViewModel.cs @@ -4,10 +4,8 @@ using System.IO; using System.Linq; using System.Windows; using System.Windows.Controls; -using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; -using PropertyChanged; using Wox.Core.Plugin; using Wox.Core.Resource; using Wox.Core.UserSettings; @@ -15,12 +13,10 @@ using Wox.Helper; using Wox.Infrastructure; using Wox.Infrastructure.Storage; using Wox.Plugin; -using static System.String; namespace Wox.ViewModel { - [ImplementPropertyChanged] - public class SettingWindowViewModel + public class SettingWindowViewModel : BaseModel { private readonly JsonStrorage _storage; @@ -28,6 +24,13 @@ namespace Wox.ViewModel { _storage = new JsonStrorage(); Settings = _storage.Load(); + Settings.PropertyChanged += (s, e) => + { + if (e.PropertyName == nameof(Settings.ActivateTimes)) + { + OnPropertyChanged(nameof(ActivatedTimes)); + } + }; } public Settings Settings { get; set; } @@ -63,7 +66,7 @@ namespace Wox.ViewModel var d2 = settings[b.Metadata.ID].Disabled; if (d1 == d2) { - return Compare(a.Metadata.Name, b.Metadata.Name, StringComparison.CurrentCulture); + return string.Compare(a.Metadata.Name, b.Metadata.Name, StringComparison.CurrentCulture); } else { @@ -145,7 +148,7 @@ namespace Wox.ViewModel bitmap.BeginInit(); bitmap.StreamSource = memStream; bitmap.EndInit(); - var brush = new ImageBrush(bitmap) {Stretch = Stretch.UniformToFill}; + var brush = new ImageBrush(bitmap) { Stretch = Stretch.UniformToFill }; return brush; } else @@ -194,7 +197,7 @@ namespace Wox.ViewModel SubTitle = "Please star it!" } }; - var vm = new ResultsViewModel(6); + var vm = new ResultsViewModel(); vm.AddResults(results, "PREVIEW"); return vm; } @@ -303,15 +306,14 @@ namespace Wox.ViewModel public static string Github => Constant.Github; public static string ReleaseNotes => @"https://github.com/Wox-launcher/Wox/releases/latest"; public static string Version => Constant.Version; - public string ActivatedTimes - => Format(_translater.GetTranslation("about_activate_times"), Settings.ActivateTimes); + public string ActivatedTimes => string.Format(_translater.GetTranslation("about_activate_times"), Settings.ActivateTimes); private string _newVersionTips; public string NewVersionTips { get { return _newVersionTips; } set { - _newVersionTips = Format(_translater.GetTranslation("newVersionTips"), value); + _newVersionTips = string.Format(_translater.GetTranslation("newVersionTips"), value); NewVersionTipsVisibility = Visibility.Visible; } }