From 43bfeff2bee78b60430289a7b124077364915555 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Mon, 22 Feb 2016 21:43:37 +0000 Subject: [PATCH] Remove redundant code --- Wox/App.xaml.cs | 1 - Wox/Converters/VisibilityConverter.cs | 5 -- Wox/CustomQueryHotkeySetting.xaml.cs | 6 +- Wox/ImageLoader/ImageCacheStroage.cs | 2 - Wox/MainWindow.xaml.cs | 3 +- Wox/NotifyIconManager.cs | 7 +- Wox/PublicAPIInstance.cs | 10 +-- Wox/ResultListBox.xaml.cs | 10 +-- Wox/SettingWindow.xaml.cs | 8 +-- Wox/Storage/QueryHistoryStorage.cs | 2 - Wox/Storage/TopMostRecordStorage.cs | 2 - Wox/Storage/UserSelectedRecordStorage.cs | 2 - Wox/ViewModel/BaseViewModel.cs | 4 -- Wox/ViewModel/MainViewModel.cs | 92 +++++++----------------- Wox/ViewModel/ResultsViewModel.cs | 2 - 15 files changed, 40 insertions(+), 116 deletions(-) diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs index 3e39447d35..a7d98d7348 100644 --- a/Wox/App.xaml.cs +++ b/Wox/App.xaml.cs @@ -14,7 +14,6 @@ using Wox.Plugin; using Wox.ViewModel; using Stopwatch = Wox.Infrastructure.Stopwatch; - namespace Wox { public partial class App : Application, ISingleInstanceApp diff --git a/Wox/Converters/VisibilityConverter.cs b/Wox/Converters/VisibilityConverter.cs index 46488bde37..5cb52dbda1 100644 --- a/Wox/Converters/VisibilityConverter.cs +++ b/Wox/Converters/VisibilityConverter.cs @@ -1,11 +1,6 @@ using System; -using System.Collections.Generic; using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; -using System.Windows.Data; namespace Wox.Converters { diff --git a/Wox/CustomQueryHotkeySetting.xaml.cs b/Wox/CustomQueryHotkeySetting.xaml.cs index 8c29324509..b28addc655 100644 --- a/Wox/CustomQueryHotkeySetting.xaml.cs +++ b/Wox/CustomQueryHotkeySetting.xaml.cs @@ -1,9 +1,9 @@ -using NHotkey; -using NHotkey.Wpf; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Windows; +using NHotkey; +using NHotkey.Wpf; using Wox.Core.Resource; using Wox.Core.UserSettings; using Wox.Infrastructure.Hotkey; diff --git a/Wox/ImageLoader/ImageCacheStroage.cs b/Wox/ImageLoader/ImageCacheStroage.cs index 18b441d9ec..bc032f8d03 100644 --- a/Wox/ImageLoader/ImageCacheStroage.cs +++ b/Wox/ImageLoader/ImageCacheStroage.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; -using System.Reflection; using Wox.Infrastructure.Storage; namespace Wox.ImageLoader diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index 8d10d5b8b3..5b1a887240 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -10,12 +10,11 @@ using Wox.Core.Updater; using Wox.Core.UserSettings; using Wox.Helper; using Wox.Infrastructure.Hotkey; +using Wox.ViewModel; using DataFormats = System.Windows.DataFormats; using DragEventArgs = System.Windows.DragEventArgs; using KeyEventArgs = System.Windows.Input.KeyEventArgs; using MessageBox = System.Windows.MessageBox; -using Wox.ViewModel; -using Wox.Plugin; namespace Wox { diff --git a/Wox/NotifyIconManager.cs b/Wox/NotifyIconManager.cs index c618466446..bba0663fd1 100644 --- a/Wox/NotifyIconManager.cs +++ b/Wox/NotifyIconManager.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; +using System.Windows.Forms; using Wox.Core.Resource; using Wox.Plugin; diff --git a/Wox/PublicAPIInstance.cs b/Wox/PublicAPIInstance.cs index e4f0393006..0bb7621c2d 100644 --- a/Wox/PublicAPIInstance.cs +++ b/Wox/PublicAPIInstance.cs @@ -1,16 +1,12 @@ -using NHotkey; -using NHotkey.Wpf; -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Net; -using System.Text; -using System.Threading; -using System.Threading.Tasks; using System.Windows; using System.Windows.Input; -using System.Windows.Threading; +using NHotkey; +using NHotkey.Wpf; using Wox.Core.Plugin; using Wox.Core.Resource; using Wox.Core.UserSettings; diff --git a/Wox/ResultListBox.xaml.cs b/Wox/ResultListBox.xaml.cs index 376ff3ae18..93f540fc76 100644 --- a/Wox/ResultListBox.xaml.cs +++ b/Wox/ResultListBox.xaml.cs @@ -1,15 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Collections.Generic; using System.Runtime.Remoting.Contexts; -using System.Windows; using System.Windows.Controls; -using System.Windows.Input; -using System.Windows.Media; -using Wox.Core.UserSettings; -using Wox.Helper; using Wox.Plugin; -using Wox.Storage; using Wox.ViewModel; namespace Wox diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index 152d828b94..312060e406 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -11,18 +11,18 @@ using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using Microsoft.Win32; +using NHotkey; +using NHotkey.Wpf; using Wox.Core.Plugin; using Wox.Core.Resource; using Wox.Core.Updater; using Wox.Core.UserSettings; using Wox.Helper; +using Wox.Infrastructure.Hotkey; using Wox.Plugin; +using Wox.ViewModel; using Application = System.Windows.Forms.Application; using Stopwatch = Wox.Infrastructure.Stopwatch; -using Wox.Infrastructure.Hotkey; -using NHotkey.Wpf; -using NHotkey; -using Wox.ViewModel; namespace Wox { diff --git a/Wox/Storage/QueryHistoryStorage.cs b/Wox/Storage/QueryHistoryStorage.cs index 6fec79789a..74ca3f1aa4 100644 --- a/Wox/Storage/QueryHistoryStorage.cs +++ b/Wox/Storage/QueryHistoryStorage.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; -using System.Reflection; using Newtonsoft.Json; using Wox.Infrastructure.Storage; using Wox.Plugin; diff --git a/Wox/Storage/TopMostRecordStorage.cs b/Wox/Storage/TopMostRecordStorage.cs index 2ccbe86e58..aebaf54798 100644 --- a/Wox/Storage/TopMostRecordStorage.cs +++ b/Wox/Storage/TopMostRecordStorage.cs @@ -1,7 +1,5 @@ using System.Collections.Generic; -using System.IO; using System.Linq; -using System.Reflection; using Wox.Infrastructure.Storage; using Wox.Plugin; diff --git a/Wox/Storage/UserSelectedRecordStorage.cs b/Wox/Storage/UserSelectedRecordStorage.cs index ea0289943e..0d12826e4c 100644 --- a/Wox/Storage/UserSelectedRecordStorage.cs +++ b/Wox/Storage/UserSelectedRecordStorage.cs @@ -1,6 +1,4 @@ using System.Collections.Generic; -using System.IO; -using System.Reflection; using Newtonsoft.Json; using Wox.Infrastructure.Storage; using Wox.Plugin; diff --git a/Wox/ViewModel/BaseViewModel.cs b/Wox/ViewModel/BaseViewModel.cs index 4b0edf84a9..24757b0617 100644 --- a/Wox/ViewModel/BaseViewModel.cs +++ b/Wox/ViewModel/BaseViewModel.cs @@ -1,9 +1,5 @@ using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Input; namespace Wox.ViewModel diff --git a/Wox/ViewModel/MainViewModel.cs b/Wox/ViewModel/MainViewModel.cs index 407adce9ff..6d6c8cd1ea 100644 --- a/Wox/ViewModel/MainViewModel.cs +++ b/Wox/ViewModel/MainViewModel.cs @@ -1,19 +1,15 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Linq; -using System.Text; using System.Threading.Tasks; using System.Windows; -using System.Windows.Forms; using System.Windows.Input; using Wox.Core.Plugin; using Wox.Core.Resource; -using Wox.Core.UserSettings; using Wox.Infrastructure; -using Wox.Infrastructure.Hotkey; using Wox.Plugin; using Wox.Storage; +using Stopwatch = Wox.Infrastructure.Stopwatch; namespace Wox.ViewModel { @@ -35,7 +31,7 @@ namespace Wox.ViewModel private bool _queryHasReturn; private Query _lastQuery = new Query(); private bool _ignoreTextChange; - private List CurrentContextMenus = new List(); + private List _currentContextMenus = new List(); private string _textBeforeEnterContextMenuMode; #endregion @@ -197,21 +193,13 @@ namespace Wox.ViewModel } public ICommand EscCommand { get; set; } - public ICommand SelectNextItemCommand { get; set; } - public ICommand SelectPrevItemCommand { get; set; } - public ICommand CtrlOCommand { get; set; } - public ICommand DisplayNextQueryCommand { get; set; } - public ICommand DisplayPrevQueryCommand { get; set; } - public ICommand SelectNextPageCommand { get; set; } - public ICommand SelectPrevPageCommand { get; set; } - public ICommand StartHelpCommand { get; set; } public ICommand ShiftEnterCommand { get; set; } public ICommand OpenResultCommand { get; set; } @@ -222,9 +210,8 @@ namespace Wox.ViewModel private void InitializeKeyCommands() { - EscCommand = new RelayCommand((parameter) => + EscCommand = new RelayCommand(_ => { - if (IsContextMenuVisible) { BackToSearchMode(); @@ -233,12 +220,10 @@ namespace Wox.ViewModel { IsVisible = false; } - }); - SelectNextItemCommand = new RelayCommand((parameter) => + SelectNextItemCommand = new RelayCommand(o => { - if (IsContextMenuVisible) { ContextMenu.SelectNextResult(); @@ -247,12 +232,10 @@ namespace Wox.ViewModel { Results.SelectNextResult(); } - }); - SelectPrevItemCommand = new RelayCommand((parameter) => + SelectPrevItemCommand = new RelayCommand(_ => { - if (IsContextMenuVisible) { ContextMenu.SelectPrevResult(); @@ -261,12 +244,10 @@ namespace Wox.ViewModel { Results.SelectPrevResult(); } - }); - CtrlOCommand = new RelayCommand((parameter) => + CtrlOCommand = new RelayCommand(_ => { - if (IsContextMenuVisible) { BackToSearchMode(); @@ -277,73 +258,54 @@ namespace Wox.ViewModel } }); - DisplayNextQueryCommand = new RelayCommand((parameter) => + DisplayNextQueryCommand = new RelayCommand(_ => { - var nextQuery = QueryHistoryStorage.Instance.Next(); DisplayQueryHistory(nextQuery); - }); - DisplayPrevQueryCommand = new RelayCommand((parameter) => + DisplayPrevQueryCommand = new RelayCommand(_ => { - var prev = QueryHistoryStorage.Instance.Previous(); DisplayQueryHistory(prev); - }); - SelectNextPageCommand = new RelayCommand((parameter) => + SelectNextPageCommand = new RelayCommand(_ => { - Results.SelectNextPage(); - }); - SelectPrevPageCommand = new RelayCommand((parameter) => + SelectPrevPageCommand = new RelayCommand(_ => { - Results.SelectPrevPage(); - }); - StartHelpCommand = new RelayCommand((parameter) => + StartHelpCommand = new RelayCommand(_ => { Process.Start("http://doc.getwox.com"); }); - ShiftEnterCommand = new RelayCommand((parameter) => + ShiftEnterCommand = new RelayCommand(_ => { - if (!IsContextMenuVisible && null != Results.SelectedResult) { ShowContextMenu(Results.SelectedResult.RawResult); } - }); - OpenResultCommand = new RelayCommand((parameter) => + OpenResultCommand = new RelayCommand(o => { - - if (null != parameter) + if (null != o) { - var index = int.Parse(parameter.ToString()); + var index = int.Parse(o.ToString()); Results.SelectResult(index); } - - if (null != Results.SelectedResult) - { - Results.SelectedResult.OpenResultListBoxItemCommand.Execute(null); - } + Results.SelectedResult?.OpenResultListBoxItemCommand.Execute(null); }); - BackCommand = new RelayCommand((parameter) => + BackCommand = new RelayCommand(_ => { - if (null != ListeningKeyPressed) - { - ListeningKeyPressed(this, new ListeningKeyPressedEventArgs(parameter as System.Windows.Input.KeyEventArgs)); - } - + ListeningKeyPressed?.Invoke(this, new ListeningKeyPressedEventArgs(_ as KeyEventArgs)); }); } @@ -379,7 +341,7 @@ namespace Wox.ViewModel ContextMenu.Clear(); ContextMenu.AddResults(actions, pluginID); - CurrentContextMenus = actions; + _currentContextMenus = actions; IsContextMenuVisible = true; IsResultListBoxVisible = false; @@ -455,12 +417,12 @@ namespace Wox.ViewModel var query = QueryText.ToLower(); if (string.IsNullOrEmpty(query)) { - ContextMenu.AddResults(CurrentContextMenus, contextMenuId); + ContextMenu.AddResults(_currentContextMenus, contextMenuId); } else { List filterResults = new List(); - foreach (Result contextMenu in CurrentContextMenus) + foreach (Result contextMenu in _currentContextMenus) { if (StringMatcher.IsMatch(contextMenu.Title, query) || StringMatcher.IsMatch(contextMenu.SubTitle, query)) @@ -501,14 +463,14 @@ namespace Wox.ViewModel } _lastQuery = query; - Action action = new Action(async () => + Action action = async () => { await Task.Delay(150); if (!string.IsNullOrEmpty(query.RawQuery) && query.RawQuery == _lastQuery.RawQuery && !_queryHasReturn) { IsProgressBarTooltipVisible = true; } - }); + }; action.Invoke(); //Application.Current.Dispatcher.InvokeAsync(async () => @@ -533,7 +495,7 @@ namespace Wox.ViewModel private void UpdateResultViewInternal(List list, PluginMetadata metadata) { - Infrastructure.Stopwatch.Normal($"UI update cost for {metadata.Name}", + Stopwatch.Normal($"UI update cost for {metadata.Name}", () => { Results.AddResults(list, metadata.ID); }); } @@ -592,7 +554,7 @@ namespace Wox.ViewModel }); if (originQuery.RawQuery == _lastQuery.RawQuery) { - System.Windows.Application.Current.Dispatcher.Invoke(() => + Application.Current.Dispatcher.Invoke(() => { UpdateResultViewInternal(list, metadata); }); @@ -618,13 +580,13 @@ namespace Wox.ViewModel public class ListeningKeyPressedEventArgs : EventArgs { - public System.Windows.Input.KeyEventArgs KeyEventArgs + public KeyEventArgs KeyEventArgs { get; private set; } - public ListeningKeyPressedEventArgs(System.Windows.Input.KeyEventArgs keyEventArgs) + public ListeningKeyPressedEventArgs(KeyEventArgs keyEventArgs) { KeyEventArgs = keyEventArgs; } diff --git a/Wox/ViewModel/ResultsViewModel.cs b/Wox/ViewModel/ResultsViewModel.cs index 41fd9dd487..77d89b5341 100644 --- a/Wox/ViewModel/ResultsViewModel.cs +++ b/Wox/ViewModel/ResultsViewModel.cs @@ -4,8 +4,6 @@ using System.Collections.ObjectModel; using System.Collections.Specialized; using System.ComponentModel; using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; using Wox.Core.UserSettings; using Wox.Plugin;