diff --git a/src/modules/launcher/PowerLauncher/ViewModel/ContextMenuItemViewModel.cs b/src/modules/launcher/PowerLauncher/ViewModel/ContextMenuItemViewModel.cs index 239a978a99..fc124e2ed7 100644 --- a/src/modules/launcher/PowerLauncher/ViewModel/ContextMenuItemViewModel.cs +++ b/src/modules/launcher/PowerLauncher/ViewModel/ContextMenuItemViewModel.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation +// Copyright (c) Microsoft Corporation // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -13,52 +13,13 @@ namespace PowerLauncher.ViewModel { private ICommand _command; - public string PluginName { get; set; } + public string PluginName { get; } - private string _title; + public string Title { get; } - public string Title - { - get => _title; - set - { - if (_title != value) - { - _title = value; - OnPropertyChanged(nameof(Title)); - } - } - } + public string Glyph { get; } - private string _glyph; - - public string Glyph - { - get => _glyph; - set - { - if (_glyph != value) - { - _glyph = value; - OnPropertyChanged(nameof(Glyph)); - } - } - } - - private string _fontFamily; - - public string FontFamily - { - get => _fontFamily; - set - { - if (_fontFamily != value) - { - _fontFamily = value; - OnPropertyChanged(nameof(FontFamily)); - } - } - } + public string FontFamily { get; } public ICommand Command { @@ -78,12 +39,23 @@ namespace PowerLauncher.ViewModel } } - public Key AcceleratorKey { get; set; } + public Key AcceleratorKey { get; } - public ModifierKeys AcceleratorModifiers { get; set; } + public ModifierKeys AcceleratorModifiers { get; } public bool IsAcceleratorKeyEnabled { get; set; } + public ContextMenuItemViewModel(string pluginName, string title, string glyph, string fontFamily, Key acceleratorKey, ModifierKeys acceleratorModifiers, ICommand command) + { + PluginName = pluginName; + Title = title; + Glyph = glyph; + FontFamily = fontFamily; + Command = command; + AcceleratorKey = acceleratorKey; + AcceleratorModifiers = acceleratorModifiers; + } + public void SendTelemetryEvent(LauncherResultActionEvent.TriggerType triggerType) { var eventData = new LauncherResultActionEvent() diff --git a/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs b/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs index 395080177b..2822e76566 100644 --- a/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs +++ b/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation +// Copyright (c) Microsoft Corporation // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -11,7 +11,6 @@ using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; -using System.Windows.Media; using System.Windows.Threading; using interop; using Microsoft.PowerLauncher.Telemetry; @@ -51,7 +50,7 @@ namespace PowerLauncher.ViewModel private bool _saved; private ushort _hotkeyHandle; - internal HotkeyManager HotkeyManager { get; set; } + internal HotkeyManager HotkeyManager { get; private set; } public MainViewModel(PowerToysRunSettings settings) { @@ -257,8 +256,6 @@ namespace PowerLauncher.ViewModel SelectedResults.SelectPrevPage(); }); - SelectFirstResultCommand = new RelayCommand(_ => SelectedResults.SelectFirstResult()); - OpenResultWithKeyboardCommand = new RelayCommand(index => { OpenResultsEvent(index, false); @@ -269,31 +266,6 @@ namespace PowerLauncher.ViewModel OpenResultsEvent(index, true); }); - LoadContextMenuCommand = new RelayCommand(_ => - { - if (SelectedIsFromQueryResults()) - { - SelectedResults = ContextMenu; - } - else - { - SelectedResults = Results; - } - }); - - LoadHistoryCommand = new RelayCommand(_ => - { - if (SelectedIsFromQueryResults()) - { - SelectedResults = History; - History.SelectedIndex = _history.Items.Count - 1; - } - else - { - SelectedResults = Results; - } - }); - ClearQueryCommand = new RelayCommand(_ => { if (!string.IsNullOrEmpty(QueryText)) @@ -306,10 +278,6 @@ namespace PowerLauncher.ViewModel }); } - public Brush MainWindowBackground { get; set; } - - public Brush MainWindowBorderBrush { get; set; } - private ResultsViewModel _results; public ResultsViewModel Results @@ -402,27 +370,12 @@ namespace PowerLauncher.ViewModel { Results.Visibility = Visibility.Hidden; _queryTextBeforeLeaveResults = QueryText; - - // Because of Fody's optimization - // setter won't be called when property value is not changed. - // so we need manually call Query() - // http://stackoverflow.com/posts/25895769/revisions - if (string.IsNullOrEmpty(QueryText)) - { - Query(); - } - else - { - QueryText = string.Empty; - } } _selectedResults.Visibility = Visibility.Visible; } } - public Visibility ProgressBarVisibility { get; set; } - private Visibility _visibility; public Visibility MainWindowVisibility @@ -451,37 +404,31 @@ namespace PowerLauncher.ViewModel } } - public ICommand IgnoreCommand { get; set; } + public ICommand IgnoreCommand { get; private set; } - public ICommand EscCommand { get; set; } + public ICommand EscCommand { get; private set; } - public ICommand SelectNextItemCommand { get; set; } + public ICommand SelectNextItemCommand { get; private set; } - public ICommand SelectPrevItemCommand { get; set; } + public ICommand SelectPrevItemCommand { get; private set; } - public ICommand SelectNextContextMenuItemCommand { get; set; } + public ICommand SelectNextContextMenuItemCommand { get; private set; } - public ICommand SelectPreviousContextMenuItemCommand { get; set; } + public ICommand SelectPreviousContextMenuItemCommand { get; private set; } - public ICommand SelectNextTabItemCommand { get; set; } + public ICommand SelectNextTabItemCommand { get; private set; } - public ICommand SelectPrevTabItemCommand { get; set; } + public ICommand SelectPrevTabItemCommand { get; private set; } - public ICommand SelectNextPageCommand { get; set; } + public ICommand SelectNextPageCommand { get; private set; } - public ICommand SelectPrevPageCommand { get; set; } + public ICommand SelectPrevPageCommand { get; private set; } - public ICommand SelectFirstResultCommand { get; set; } + public ICommand OpenResultWithKeyboardCommand { get; private set; } - public ICommand LoadContextMenuCommand { get; set; } + public ICommand OpenResultWithMouseCommand { get; private set; } - public ICommand LoadHistoryCommand { get; set; } - - public ICommand OpenResultWithKeyboardCommand { get; set; } - - public ICommand OpenResultWithMouseCommand { get; set; } - - public ICommand ClearQueryCommand { get; set; } + public ICommand ClearQueryCommand { get; private set; } public void Query() { diff --git a/src/modules/launcher/PowerLauncher/ViewModel/ResultViewModel.cs b/src/modules/launcher/PowerLauncher/ViewModel/ResultViewModel.cs index d9f18dc957..5355cb3032 100644 --- a/src/modules/launcher/PowerLauncher/ViewModel/ResultViewModel.cs +++ b/src/modules/launcher/PowerLauncher/ViewModel/ResultViewModel.cs @@ -24,17 +24,13 @@ namespace PowerLauncher.ViewModel public ObservableCollection ContextMenuItems { get; } = new ObservableCollection(); - public ICommand ActivateContextButtonsHoverCommand { get; set; } + public ICommand ActivateContextButtonsHoverCommand { get; } - public ICommand ActivateContextButtonsSelectionCommand { get; set; } + public ICommand DeactivateContextButtonsHoverCommand { get; } - public ICommand DeactivateContextButtonsHoverCommand { get; set; } + public bool IsSelected { get; private set; } - public ICommand DeactivateContextButtonsSelectionCommand { get; set; } - - public bool IsSelected { get; set; } - - public bool IsHovered { get; set; } + public bool IsHovered { get; private set; } private bool _areContextButtonsActive; @@ -79,9 +75,7 @@ namespace PowerLauncher.ViewModel LoadContextMenu(); ActivateContextButtonsHoverCommand = new RelayCommand(ActivateContextButtonsHoverAction); - ActivateContextButtonsSelectionCommand = new RelayCommand(ActivateContextButtonsSelectionAction); DeactivateContextButtonsHoverCommand = new RelayCommand(DeactivateContextButtonsHoverAction); - DeactivateContextButtonsSelectionCommand = new RelayCommand(DeactivateContextButtonsSelectionAction); } private void ActivateContextButtonsHoverAction(object sender) @@ -89,11 +83,6 @@ namespace PowerLauncher.ViewModel ActivateContextButtons(ActivationType.Hover); } - private void ActivateContextButtonsSelectionAction(object sender) - { - ActivateContextButtons(ActivationType.Selection); - } - public void ActivateContextButtons(ActivationType activationType) { // Result does not contain any context menu items - we don't need to show the context menu ListView at all. @@ -122,11 +111,6 @@ namespace PowerLauncher.ViewModel DeactivateContextButtons(ActivationType.Hover); } - private void DeactivateContextButtonsSelectionAction(object sender) - { - DeactivateContextButtons(ActivationType.Selection); - } - public void DeactivateContextButtons(ActivationType activationType) { if (activationType == ActivationType.Selection) @@ -156,15 +140,14 @@ namespace PowerLauncher.ViewModel ContextMenuItems.Clear(); foreach (var r in results) { - ContextMenuItems.Add(new ContextMenuItemViewModel() - { - PluginName = r.PluginName, - Title = r.Title, - Glyph = r.Glyph, - FontFamily = r.FontFamily, - AcceleratorKey = r.AcceleratorKey, - AcceleratorModifiers = r.AcceleratorModifiers, - Command = new RelayCommand(_ => + ContextMenuItems.Add(new ContextMenuItemViewModel( + r.PluginName, + r.Title, + r.Glyph, + r.FontFamily, + r.AcceleratorKey, + r.AcceleratorModifiers, + new RelayCommand(_ => { bool hideWindow = r.Action != null && @@ -179,8 +162,7 @@ namespace PowerLauncher.ViewModel // TODO - Do we hide the window // MainWindowVisibility = Visibility.Collapsed; } - }), - }); + }))); } } diff --git a/src/modules/launcher/PowerLauncher/ViewModel/ResultsViewModel.cs b/src/modules/launcher/PowerLauncher/ViewModel/ResultsViewModel.cs index eb3fe0ceb4..542aaae321 100644 --- a/src/modules/launcher/PowerLauncher/ViewModel/ResultsViewModel.cs +++ b/src/modules/launcher/PowerLauncher/ViewModel/ResultsViewModel.cs @@ -95,8 +95,6 @@ namespace PowerLauncher.ViewModel } } - public Thickness Margin { get; set; } - private Visibility _visibility = Visibility.Hidden; public Visibility Visibility diff --git a/src/modules/launcher/PowerLauncher/ViewModel/SettingWindowViewModel.cs b/src/modules/launcher/PowerLauncher/ViewModel/SettingWindowViewModel.cs index 2d8335a3c1..a86be57be6 100644 --- a/src/modules/launcher/PowerLauncher/ViewModel/SettingWindowViewModel.cs +++ b/src/modules/launcher/PowerLauncher/ViewModel/SettingWindowViewModel.cs @@ -2,7 +2,6 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Globalization; using Wox.Infrastructure.Storage; using Wox.Infrastructure.UserSettings; using Wox.Plugin; @@ -19,7 +18,7 @@ namespace PowerLauncher.ViewModel Settings = _storage.Load(); } - public PowerToysRunSettings Settings { get; set; } + public PowerToysRunSettings Settings { get; } public void Save() { diff --git a/src/modules/launcher/Wox.Plugin/Wox.Plugin.csproj b/src/modules/launcher/Wox.Plugin/Wox.Plugin.csproj index 94ed3f0e6f..6ce7a44086 100644 --- a/src/modules/launcher/Wox.Plugin/Wox.Plugin.csproj +++ b/src/modules/launcher/Wox.Plugin/Wox.Plugin.csproj @@ -62,14 +62,6 @@ - - - - - - - - diff --git a/src/modules/launcher/Wox.Test/ResultsViewModelTest.cs b/src/modules/launcher/Wox.Test/ResultsViewModelTest.cs index fae10cc511..18f3ad839b 100644 --- a/src/modules/launcher/Wox.Test/ResultsViewModelTest.cs +++ b/src/modules/launcher/Wox.Test/ResultsViewModelTest.cs @@ -2,6 +2,7 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Windows.Input; using NUnit.Framework; using PowerLauncher.ViewModel; using Wox.Plugin; @@ -18,10 +19,7 @@ namespace Wox.Test ResultsViewModel rvm = new ResultsViewModel(); Result result = new Result(); ResultViewModel selectedItem = new ResultViewModel(result); - selectedItem.ContextMenuItems.Add(new ContextMenuItemViewModel() - { - Title = "Dummy Context Menu", - }); + selectedItem.ContextMenuItems.Add(new ContextMenuItemViewModel(null, null, null, null, Key.None, ModifierKeys.None, null)); rvm.SelectedItem = selectedItem; // Assert @@ -35,10 +33,7 @@ namespace Wox.Test ResultsViewModel rvm = new ResultsViewModel(); Result result = new Result(); ResultViewModel selectedItem = new ResultViewModel(result); - selectedItem.ContextMenuItems.Add(new ContextMenuItemViewModel() - { - Title = "Dummy Context Menu", - }); + selectedItem.ContextMenuItems.Add(new ContextMenuItemViewModel(null, null, null, null, Key.None, ModifierKeys.None, null)); rvm.SelectedItem = selectedItem; // Act @@ -55,10 +50,7 @@ namespace Wox.Test ResultsViewModel rvm = new ResultsViewModel(); Result result = new Result(); ResultViewModel selectedItem = new ResultViewModel(result); - selectedItem.ContextMenuItems.Add(new ContextMenuItemViewModel() - { - Title = "Dummy Context Menu", - }); + selectedItem.ContextMenuItems.Add(new ContextMenuItemViewModel(null, null, null, null, Key.None, ModifierKeys.None, null)); rvm.SelectedItem = selectedItem; // Act @@ -75,18 +67,9 @@ namespace Wox.Test ResultsViewModel rvm = new ResultsViewModel(); Result result = new Result(); ResultViewModel selectedItem = new ResultViewModel(result); - selectedItem.ContextMenuItems.Add(new ContextMenuItemViewModel() - { - Title = "Dummy Context Menu 1", - }); - selectedItem.ContextMenuItems.Add(new ContextMenuItemViewModel() - { - Title = "Dummy Context Menu 2", - }); - selectedItem.ContextMenuItems.Add(new ContextMenuItemViewModel() - { - Title = "Dummy Context Menu 3", - }); + selectedItem.ContextMenuItems.Add(new ContextMenuItemViewModel(null, null, null, null, Key.None, ModifierKeys.None, null)); + selectedItem.ContextMenuItems.Add(new ContextMenuItemViewModel(null, null, null, null, Key.None, ModifierKeys.None, null)); + selectedItem.ContextMenuItems.Add(new ContextMenuItemViewModel(null, null, null, null, Key.None, ModifierKeys.None, null)); rvm.SelectedItem = selectedItem; // Act @@ -106,10 +89,7 @@ namespace Wox.Test ResultsViewModel rvm = new ResultsViewModel(); Result result = new Result(); ResultViewModel selectedItem = new ResultViewModel(result); - selectedItem.ContextMenuItems.Add(new ContextMenuItemViewModel() - { - Title = "Dummy Context Menu", - }); + selectedItem.ContextMenuItems.Add(new ContextMenuItemViewModel(null, null, null, null, Key.None, ModifierKeys.None, null)); rvm.SelectedItem = selectedItem; // Act @@ -127,10 +107,7 @@ namespace Wox.Test ResultsViewModel rvm = new ResultsViewModel(); Result result = new Result(); ResultViewModel selectedItem = new ResultViewModel(result); - selectedItem.ContextMenuItems.Add(new ContextMenuItemViewModel() - { - Title = "Dummy Context Menu", - }); + selectedItem.ContextMenuItems.Add(new ContextMenuItemViewModel(null, null, null, null, Key.None, ModifierKeys.None, null)); rvm.SelectedItem = selectedItem; // Act @@ -148,10 +125,7 @@ namespace Wox.Test ResultsViewModel rvm = new ResultsViewModel(); Result result = new Result(); ResultViewModel selectedItem = new ResultViewModel(result); - selectedItem.ContextMenuItems.Add(new ContextMenuItemViewModel() - { - Title = "Dummy Context Menu", - }); + selectedItem.ContextMenuItems.Add(new ContextMenuItemViewModel(null, null, null, null, Key.None, ModifierKeys.None, null)); rvm.SelectedItem = selectedItem; // Act