Remove redundant code

This commit is contained in:
bao-qian 2016-02-22 21:43:37 +00:00
parent 1a489652ff
commit 43bfeff2be
15 changed files with 40 additions and 116 deletions

View File

@ -14,7 +14,6 @@ using Wox.Plugin;
using Wox.ViewModel; using Wox.ViewModel;
using Stopwatch = Wox.Infrastructure.Stopwatch; using Stopwatch = Wox.Infrastructure.Stopwatch;
namespace Wox namespace Wox
{ {
public partial class App : Application, ISingleInstanceApp public partial class App : Application, ISingleInstanceApp

View File

@ -1,11 +1,6 @@
using System; using System;
using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Data;
namespace Wox.Converters namespace Wox.Converters
{ {

View File

@ -1,9 +1,9 @@
using NHotkey; using System;
using NHotkey.Wpf;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using NHotkey;
using NHotkey.Wpf;
using Wox.Core.Resource; using Wox.Core.Resource;
using Wox.Core.UserSettings; using Wox.Core.UserSettings;
using Wox.Infrastructure.Hotkey; using Wox.Infrastructure.Hotkey;

View File

@ -1,8 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using Wox.Infrastructure.Storage; using Wox.Infrastructure.Storage;
namespace Wox.ImageLoader namespace Wox.ImageLoader

View File

@ -10,12 +10,11 @@ using Wox.Core.Updater;
using Wox.Core.UserSettings; using Wox.Core.UserSettings;
using Wox.Helper; using Wox.Helper;
using Wox.Infrastructure.Hotkey; using Wox.Infrastructure.Hotkey;
using Wox.ViewModel;
using DataFormats = System.Windows.DataFormats; using DataFormats = System.Windows.DataFormats;
using DragEventArgs = System.Windows.DragEventArgs; using DragEventArgs = System.Windows.DragEventArgs;
using KeyEventArgs = System.Windows.Input.KeyEventArgs; using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using MessageBox = System.Windows.MessageBox; using MessageBox = System.Windows.MessageBox;
using Wox.ViewModel;
using Wox.Plugin;
namespace Wox namespace Wox
{ {

View File

@ -1,9 +1,4 @@
using System; using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Wox.Core.Resource; using Wox.Core.Resource;
using Wox.Plugin; using Wox.Plugin;

View File

@ -1,16 +1,12 @@
using NHotkey; using System;
using NHotkey.Wpf;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Threading; using NHotkey;
using NHotkey.Wpf;
using Wox.Core.Plugin; using Wox.Core.Plugin;
using Wox.Core.Resource; using Wox.Core.Resource;
using Wox.Core.UserSettings; using Wox.Core.UserSettings;

View File

@ -1,15 +1,7 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Contexts; using System.Runtime.Remoting.Contexts;
using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using Wox.Core.UserSettings;
using Wox.Helper;
using Wox.Plugin; using Wox.Plugin;
using Wox.Storage;
using Wox.ViewModel; using Wox.ViewModel;
namespace Wox namespace Wox

View File

@ -11,18 +11,18 @@ using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using Microsoft.Win32; using Microsoft.Win32;
using NHotkey;
using NHotkey.Wpf;
using Wox.Core.Plugin; using Wox.Core.Plugin;
using Wox.Core.Resource; using Wox.Core.Resource;
using Wox.Core.Updater; using Wox.Core.Updater;
using Wox.Core.UserSettings; using Wox.Core.UserSettings;
using Wox.Helper; using Wox.Helper;
using Wox.Infrastructure.Hotkey;
using Wox.Plugin; using Wox.Plugin;
using Wox.ViewModel;
using Application = System.Windows.Forms.Application; using Application = System.Windows.Forms.Application;
using Stopwatch = Wox.Infrastructure.Stopwatch; using Stopwatch = Wox.Infrastructure.Stopwatch;
using Wox.Infrastructure.Hotkey;
using NHotkey.Wpf;
using NHotkey;
using Wox.ViewModel;
namespace Wox namespace Wox
{ {

View File

@ -1,8 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using Newtonsoft.Json; using Newtonsoft.Json;
using Wox.Infrastructure.Storage; using Wox.Infrastructure.Storage;
using Wox.Plugin; using Wox.Plugin;

View File

@ -1,7 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using Wox.Infrastructure.Storage; using Wox.Infrastructure.Storage;
using Wox.Plugin; using Wox.Plugin;

View File

@ -1,6 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Newtonsoft.Json; using Newtonsoft.Json;
using Wox.Infrastructure.Storage; using Wox.Infrastructure.Storage;
using Wox.Plugin; using Wox.Plugin;

View File

@ -1,9 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input; using System.Windows.Input;
namespace Wox.ViewModel namespace Wox.ViewModel

View File

@ -1,19 +1,15 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Forms;
using System.Windows.Input; using System.Windows.Input;
using Wox.Core.Plugin; using Wox.Core.Plugin;
using Wox.Core.Resource; using Wox.Core.Resource;
using Wox.Core.UserSettings;
using Wox.Infrastructure; using Wox.Infrastructure;
using Wox.Infrastructure.Hotkey;
using Wox.Plugin; using Wox.Plugin;
using Wox.Storage; using Wox.Storage;
using Stopwatch = Wox.Infrastructure.Stopwatch;
namespace Wox.ViewModel namespace Wox.ViewModel
{ {
@ -35,7 +31,7 @@ namespace Wox.ViewModel
private bool _queryHasReturn; private bool _queryHasReturn;
private Query _lastQuery = new Query(); private Query _lastQuery = new Query();
private bool _ignoreTextChange; private bool _ignoreTextChange;
private List<Result> CurrentContextMenus = new List<Result>(); private List<Result> _currentContextMenus = new List<Result>();
private string _textBeforeEnterContextMenuMode; private string _textBeforeEnterContextMenuMode;
#endregion #endregion
@ -197,21 +193,13 @@ namespace Wox.ViewModel
} }
public ICommand EscCommand { get; set; } public ICommand EscCommand { get; set; }
public ICommand SelectNextItemCommand { get; set; } public ICommand SelectNextItemCommand { get; set; }
public ICommand SelectPrevItemCommand { get; set; } public ICommand SelectPrevItemCommand { get; set; }
public ICommand CtrlOCommand { get; set; } public ICommand CtrlOCommand { get; set; }
public ICommand DisplayNextQueryCommand { get; set; } public ICommand DisplayNextQueryCommand { get; set; }
public ICommand DisplayPrevQueryCommand { get; set; } public ICommand DisplayPrevQueryCommand { get; set; }
public ICommand SelectNextPageCommand { get; set; } public ICommand SelectNextPageCommand { get; set; }
public ICommand SelectPrevPageCommand { get; set; } public ICommand SelectPrevPageCommand { get; set; }
public ICommand StartHelpCommand { get; set; } public ICommand StartHelpCommand { get; set; }
public ICommand ShiftEnterCommand { get; set; } public ICommand ShiftEnterCommand { get; set; }
public ICommand OpenResultCommand { get; set; } public ICommand OpenResultCommand { get; set; }
@ -222,9 +210,8 @@ namespace Wox.ViewModel
private void InitializeKeyCommands() private void InitializeKeyCommands()
{ {
EscCommand = new RelayCommand((parameter) => EscCommand = new RelayCommand(_ =>
{ {
if (IsContextMenuVisible) if (IsContextMenuVisible)
{ {
BackToSearchMode(); BackToSearchMode();
@ -233,12 +220,10 @@ namespace Wox.ViewModel
{ {
IsVisible = false; IsVisible = false;
} }
}); });
SelectNextItemCommand = new RelayCommand((parameter) => SelectNextItemCommand = new RelayCommand(o =>
{ {
if (IsContextMenuVisible) if (IsContextMenuVisible)
{ {
ContextMenu.SelectNextResult(); ContextMenu.SelectNextResult();
@ -247,12 +232,10 @@ namespace Wox.ViewModel
{ {
Results.SelectNextResult(); Results.SelectNextResult();
} }
}); });
SelectPrevItemCommand = new RelayCommand((parameter) => SelectPrevItemCommand = new RelayCommand(_ =>
{ {
if (IsContextMenuVisible) if (IsContextMenuVisible)
{ {
ContextMenu.SelectPrevResult(); ContextMenu.SelectPrevResult();
@ -261,12 +244,10 @@ namespace Wox.ViewModel
{ {
Results.SelectPrevResult(); Results.SelectPrevResult();
} }
}); });
CtrlOCommand = new RelayCommand((parameter) => CtrlOCommand = new RelayCommand(_ =>
{ {
if (IsContextMenuVisible) if (IsContextMenuVisible)
{ {
BackToSearchMode(); BackToSearchMode();
@ -277,73 +258,54 @@ namespace Wox.ViewModel
} }
}); });
DisplayNextQueryCommand = new RelayCommand((parameter) => DisplayNextQueryCommand = new RelayCommand(_ =>
{ {
var nextQuery = QueryHistoryStorage.Instance.Next(); var nextQuery = QueryHistoryStorage.Instance.Next();
DisplayQueryHistory(nextQuery); DisplayQueryHistory(nextQuery);
}); });
DisplayPrevQueryCommand = new RelayCommand((parameter) => DisplayPrevQueryCommand = new RelayCommand(_ =>
{ {
var prev = QueryHistoryStorage.Instance.Previous(); var prev = QueryHistoryStorage.Instance.Previous();
DisplayQueryHistory(prev); DisplayQueryHistory(prev);
}); });
SelectNextPageCommand = new RelayCommand((parameter) => SelectNextPageCommand = new RelayCommand(_ =>
{ {
Results.SelectNextPage(); Results.SelectNextPage();
}); });
SelectPrevPageCommand = new RelayCommand((parameter) => SelectPrevPageCommand = new RelayCommand(_ =>
{ {
Results.SelectPrevPage(); Results.SelectPrevPage();
}); });
StartHelpCommand = new RelayCommand((parameter) => StartHelpCommand = new RelayCommand(_ =>
{ {
Process.Start("http://doc.getwox.com"); Process.Start("http://doc.getwox.com");
}); });
ShiftEnterCommand = new RelayCommand((parameter) => ShiftEnterCommand = new RelayCommand(_ =>
{ {
if (!IsContextMenuVisible && null != Results.SelectedResult) if (!IsContextMenuVisible && null != Results.SelectedResult)
{ {
ShowContextMenu(Results.SelectedResult.RawResult); ShowContextMenu(Results.SelectedResult.RawResult);
} }
}); });
OpenResultCommand = new RelayCommand((parameter) => OpenResultCommand = new RelayCommand(o =>
{ {
if (null != o)
if (null != parameter)
{ {
var index = int.Parse(parameter.ToString()); var index = int.Parse(o.ToString());
Results.SelectResult(index); Results.SelectResult(index);
} }
Results.SelectedResult?.OpenResultListBoxItemCommand.Execute(null);
if (null != Results.SelectedResult)
{
Results.SelectedResult.OpenResultListBoxItemCommand.Execute(null);
}
}); });
BackCommand = new RelayCommand((parameter) => BackCommand = new RelayCommand(_ =>
{ {
if (null != ListeningKeyPressed) ListeningKeyPressed?.Invoke(this, new ListeningKeyPressedEventArgs(_ as KeyEventArgs));
{
ListeningKeyPressed(this, new ListeningKeyPressedEventArgs(parameter as System.Windows.Input.KeyEventArgs));
}
}); });
} }
@ -379,7 +341,7 @@ namespace Wox.ViewModel
ContextMenu.Clear(); ContextMenu.Clear();
ContextMenu.AddResults(actions, pluginID); ContextMenu.AddResults(actions, pluginID);
CurrentContextMenus = actions; _currentContextMenus = actions;
IsContextMenuVisible = true; IsContextMenuVisible = true;
IsResultListBoxVisible = false; IsResultListBoxVisible = false;
@ -455,12 +417,12 @@ namespace Wox.ViewModel
var query = QueryText.ToLower(); var query = QueryText.ToLower();
if (string.IsNullOrEmpty(query)) if (string.IsNullOrEmpty(query))
{ {
ContextMenu.AddResults(CurrentContextMenus, contextMenuId); ContextMenu.AddResults(_currentContextMenus, contextMenuId);
} }
else else
{ {
List<Result> filterResults = new List<Result>(); List<Result> filterResults = new List<Result>();
foreach (Result contextMenu in CurrentContextMenus) foreach (Result contextMenu in _currentContextMenus)
{ {
if (StringMatcher.IsMatch(contextMenu.Title, query) if (StringMatcher.IsMatch(contextMenu.Title, query)
|| StringMatcher.IsMatch(contextMenu.SubTitle, query)) || StringMatcher.IsMatch(contextMenu.SubTitle, query))
@ -501,14 +463,14 @@ namespace Wox.ViewModel
} }
_lastQuery = query; _lastQuery = query;
Action action = new Action(async () => Action action = async () =>
{ {
await Task.Delay(150); await Task.Delay(150);
if (!string.IsNullOrEmpty(query.RawQuery) && query.RawQuery == _lastQuery.RawQuery && !_queryHasReturn) if (!string.IsNullOrEmpty(query.RawQuery) && query.RawQuery == _lastQuery.RawQuery && !_queryHasReturn)
{ {
IsProgressBarTooltipVisible = true; IsProgressBarTooltipVisible = true;
} }
}); };
action.Invoke(); action.Invoke();
//Application.Current.Dispatcher.InvokeAsync(async () => //Application.Current.Dispatcher.InvokeAsync(async () =>
@ -533,7 +495,7 @@ namespace Wox.ViewModel
private void UpdateResultViewInternal(List<Result> list, PluginMetadata metadata) private void UpdateResultViewInternal(List<Result> 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); }); () => { Results.AddResults(list, metadata.ID); });
} }
@ -592,7 +554,7 @@ namespace Wox.ViewModel
}); });
if (originQuery.RawQuery == _lastQuery.RawQuery) if (originQuery.RawQuery == _lastQuery.RawQuery)
{ {
System.Windows.Application.Current.Dispatcher.Invoke(() => Application.Current.Dispatcher.Invoke(() =>
{ {
UpdateResultViewInternal(list, metadata); UpdateResultViewInternal(list, metadata);
}); });
@ -618,13 +580,13 @@ namespace Wox.ViewModel
public class ListeningKeyPressedEventArgs : EventArgs public class ListeningKeyPressedEventArgs : EventArgs
{ {
public System.Windows.Input.KeyEventArgs KeyEventArgs public KeyEventArgs KeyEventArgs
{ {
get; get;
private set; private set;
} }
public ListeningKeyPressedEventArgs(System.Windows.Input.KeyEventArgs keyEventArgs) public ListeningKeyPressedEventArgs(KeyEventArgs keyEventArgs)
{ {
KeyEventArgs = keyEventArgs; KeyEventArgs = keyEventArgs;
} }

View File

@ -4,8 +4,6 @@ using System.Collections.ObjectModel;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using Wox.Core.UserSettings; using Wox.Core.UserSettings;
using Wox.Plugin; using Wox.Plugin;