Merge branch 'dev'

This commit is contained in:
rmterra
2016-02-23 23:07:35 -03:00
9 changed files with 232 additions and 347 deletions

View File

@@ -53,42 +53,42 @@ namespace Wox
WindowIntelopHelper.DisableControlBox(this); WindowIntelopHelper.DisableControlBox(this);
CheckUpdate(); CheckUpdate();
var vm = this.DataContext as MainViewModel; var vm = DataContext as MainViewModel;
vm.PropertyChanged += (o, eve) => vm.PropertyChanged += (o, eve) =>
{ {
if(eve.PropertyName == "SelectAllText") if(eve.PropertyName == "SelectAllText")
{ {
if (vm.SelectAllText) if (vm.SelectAllText)
{ {
this.tbQuery.SelectAll(); tbQuery.SelectAll();
} }
} }
else if(eve.PropertyName == "CaretIndex") else if(eve.PropertyName == "CaretIndex")
{ {
this.tbQuery.CaretIndex = vm.CaretIndex; tbQuery.CaretIndex = vm.CaretIndex;
} }
else if(eve.PropertyName == "Left") else if(eve.PropertyName == "Left")
{ {
this.Left = vm.Left; Left = vm.Left;
} }
else if(eve.PropertyName == "Top") else if(eve.PropertyName == "Top")
{ {
this.Top = vm.Top; Top = vm.Top;
} }
else if(eve.PropertyName == "IsVisible") else if(eve.PropertyName == "IsVisible")
{ {
if (vm.WindowVisibility.IsVisible()) if (vm.WindowVisibility.IsVisible())
{ {
this.tbQuery.Focus(); tbQuery.Focus();
} }
} }
}; };
vm.Left = GetWindowsLeft(); vm.Left = GetWindowsLeft();
vm.Top = GetWindowsTop(); vm.Top = GetWindowsTop();
this.Activate(); Activate();
this.Focus(); Focus();
this.tbQuery.Focus(); tbQuery.Focus();
} }
private double GetWindowsLeft() private double GetWindowsLeft()
@@ -160,7 +160,7 @@ namespace Wox
private void Window_PreviewKeyDown(object sender, KeyEventArgs e) private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
{ {
var vm = this.DataContext as MainViewModel; var vm = DataContext as MainViewModel;
if (null == vm) return; if (null == vm) return;
//when alt is pressed, the real key should be e.SystemKey //when alt is pressed, the real key should be e.SystemKey

View File

@@ -17,22 +17,22 @@ namespace Wox
public NotifyIconManager(IPublicAPI api) public NotifyIconManager(IPublicAPI api)
{ {
this.InitialTray(); InitialTray();
this._api = api; _api = api;
} }
private void InitialTray() private void InitialTray()
{ {
notifyIcon = new NotifyIcon { Text = "Wox", Icon = Properties.Resources.app, Visible = true }; notifyIcon = new NotifyIcon { Text = "Wox", Icon = Properties.Resources.app, Visible = true };
notifyIcon.Click += (o, e) => this._api.ShowApp(); notifyIcon.Click += (o, e) => _api.ShowApp();
var open = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTrayOpen")); var open = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTrayOpen"));
open.Click += (o, e) => this._api.ShowApp(); open.Click += (o, e) => _api.ShowApp();
var setting = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTraySettings")); var setting = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTraySettings"));
setting.Click += (o, e) => this._api.OpenSettingDialog(); setting.Click += (o, e) => _api.OpenSettingDialog();
var about = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTrayAbout")); var about = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTrayAbout"));
about.Click += (o, e) => this._api.OpenSettingDialog("about"); about.Click += (o, e) => _api.OpenSettingDialog("about");
var exit = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTrayExit")); var exit = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTrayExit"));
exit.Click += (o, e) => this._api.CloseApp(); exit.Click += (o, e) => _api.CloseApp();
MenuItem[] childen = { open, setting, about, exit }; MenuItem[] childen = { open, setting, about, exit };
notifyIcon.ContextMenu = new ContextMenu(childen); notifyIcon.ContextMenu = new ContextMenu(childen);
} }

View File

@@ -29,7 +29,7 @@ namespace Wox
public PublicAPIInstance(MainViewModel mainVM) public PublicAPIInstance(MainViewModel mainVM)
{ {
this.MainVM = mainVM; MainVM = mainVM;
GlobalHotkey.Instance.hookedKeyboardCallback += KListener_hookedKeyboardCallback; GlobalHotkey.Instance.hookedKeyboardCallback += KListener_hookedKeyboardCallback;
@@ -38,15 +38,15 @@ namespace Wox
SetHotkey(UserSettingStorage.Instance.Hotkey, OnHotkey); SetHotkey(UserSettingStorage.Instance.Hotkey, OnHotkey);
SetCustomPluginHotkey(); SetCustomPluginHotkey();
this.MainVM.ListeningKeyPressed += (o, e) => { MainVM.ListeningKeyPressed += (o, e) => {
if(e.KeyEventArgs.Key == Key.Back) if(e.KeyEventArgs.Key == Key.Back)
{ {
if (null != this.BackKeyDownEvent) if (null != BackKeyDownEvent)
{ {
BackKeyDownEvent(new WoxKeyDownEventArgs BackKeyDownEvent(new WoxKeyDownEventArgs
{ {
Query = this.MainVM.QueryText, Query = MainVM.QueryText,
keyEventArgs = e.KeyEventArgs keyEventArgs = e.KeyEventArgs
}); });
} }
@@ -71,15 +71,15 @@ namespace Wox
public void ChangeQuery(string query, bool requery = false) public void ChangeQuery(string query, bool requery = false)
{ {
this.MainVM.QueryText = query; MainVM.QueryText = query;
this.MainVM.CaretIndex = this.MainVM.QueryText.Length; MainVM.CaretIndex = MainVM.QueryText.Length;
} }
public void ChangeQueryText(string query, bool selectAll = false) public void ChangeQueryText(string query, bool selectAll = false)
{ {
this.MainVM.QueryText = query; MainVM.QueryText = query;
this.MainVM.SelectAllText = true; MainVM.SelectAllText = true;
} }
public void CloseApp() public void CloseApp()
@@ -128,12 +128,12 @@ namespace Wox
public void StartLoadingBar() public void StartLoadingBar()
{ {
this.MainVM.ProgressBarVisibility = Visibility.Visible; MainVM.ProgressBarVisibility = Visibility.Visible;
} }
public void StopLoadingBar() public void StopLoadingBar()
{ {
this.MainVM.ProgressBarVisibility = Visibility.Collapsed; MainVM.ProgressBarVisibility = Visibility.Collapsed;
} }
public void InstallPlugin(string path) public void InstallPlugin(string path)
@@ -168,7 +168,7 @@ namespace Wox
o.PluginID = plugin.ID; o.PluginID = plugin.ID;
o.OriginQuery = query; o.OriginQuery = query;
}); });
this.MainVM.UpdateResultView(results, plugin, query); MainVM.UpdateResultView(results, plugin, query);
} }
public void ShowContextMenu(PluginMetadata plugin, List<Result> results) public void ShowContextMenu(PluginMetadata plugin, List<Result> results)
@@ -181,7 +181,7 @@ namespace Wox
o.PluginID = plugin.ID; o.PluginID = plugin.ID;
}); });
this.MainVM.ShowContextMenu(results, plugin.ID); MainVM.ShowContextMenu(results, plugin.ID);
} }
} }
@@ -200,16 +200,16 @@ namespace Wox
private void HideWox() private void HideWox()
{ {
UserSettingStorage.Instance.WindowLeft = this.MainVM.Left; UserSettingStorage.Instance.WindowLeft = MainVM.Left;
UserSettingStorage.Instance.WindowTop = this.MainVM.Top; UserSettingStorage.Instance.WindowTop = MainVM.Top;
this.MainVM.WindowVisibility = Visibility.Collapsed; MainVM.WindowVisibility = Visibility.Collapsed;
} }
private void ShowWox(bool selectAll = true) private void ShowWox(bool selectAll = true)
{ {
UserSettingStorage.Instance.IncreaseActivateTimes(); UserSettingStorage.Instance.IncreaseActivateTimes();
this.MainVM.WindowVisibility = Visibility.Visible; MainVM.WindowVisibility = Visibility.Visible;
this.MainVM.SelectAllText = true; MainVM.SelectAllText = true;
} }
public void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action) public void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action)

View File

@@ -19,7 +19,7 @@ namespace Wox
{ {
public void AddResults(List<Result> newResults, string resultId) public void AddResults(List<Result> newResults, string resultId)
{ {
var vm = this.DataContext as ResultsViewModel; var vm = DataContext as ResultsViewModel;
vm.AddResults(newResults, resultId); vm.AddResults(newResults, resultId);
} }

View File

@@ -35,9 +35,9 @@ namespace Wox
public SettingWindow(IPublicAPI api) public SettingWindow(IPublicAPI api)
{ {
this._api = api; _api = api;
InitializeComponent(); InitializeComponent();
this.ResultListBoxPreview.DataContext = new ResultsViewModel(); ResultListBoxPreview.DataContext = new ResultsViewModel();
Loaded += Setting_Loaded; Loaded += Setting_Loaded;
} }
@@ -259,11 +259,11 @@ namespace Wox
{ {
if (!App.Window.IsVisible) if (!App.Window.IsVisible)
{ {
this._api.ShowApp(); _api.ShowApp();
} }
else else
{ {
this._api.HideApp(); _api.HideApp();
} }
}); });
RemoveHotkey(UserSettingStorage.Instance.Hotkey); RemoveHotkey(UserSettingStorage.Instance.Hotkey);

View File

@@ -11,11 +11,11 @@ namespace Wox.ViewModel
public class BaseViewModel : INotifyPropertyChanged public class BaseViewModel : INotifyPropertyChanged
{ {
protected virtual void OnPropertyChanged(string propertyName) protected void OnPropertyChanged(string propertyName)
{ {
if (null != this.PropertyChanged) if (null != PropertyChanged)
{ {
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
} }
} }
@@ -29,7 +29,7 @@ namespace Wox.ViewModel
public RelayCommand(Action<object> action) public RelayCommand(Action<object> action)
{ {
this._action = action; _action = action;
} }
public virtual bool CanExecute(object parameter) public virtual bool CanExecute(object parameter)
@@ -41,9 +41,9 @@ namespace Wox.ViewModel
public virtual void Execute(object parameter) public virtual void Execute(object parameter)
{ {
if (null != this._action) if (null != _action)
{ {
this._action(parameter); _action(parameter);
} }
} }
} }

View File

@@ -47,11 +47,11 @@ namespace Wox.ViewModel
public MainViewModel() public MainViewModel()
{ {
this.InitializeResultListBox(); InitializeResultListBox();
this.InitializeContextMenu(); InitializeContextMenu();
this.InitializeKeyCommands(); InitializeKeyCommands();
this._queryHasReturn = false; _queryHasReturn = false;
} }
#endregion #endregion
@@ -66,14 +66,14 @@ namespace Wox.ViewModel
{ {
get get
{ {
return this._queryText; return _queryText;
} }
set set
{ {
this._queryText = value; _queryText = value;
OnPropertyChanged("QueryText"); OnPropertyChanged("QueryText");
this.HandleQueryTextUpdated(); HandleQueryTextUpdated();
} }
} }
@@ -81,11 +81,11 @@ namespace Wox.ViewModel
{ {
get get
{ {
return this._selectAllText; return _selectAllText;
} }
set set
{ {
this._selectAllText = value; _selectAllText = value;
OnPropertyChanged("SelectAllText"); OnPropertyChanged("SelectAllText");
} }
} }
@@ -94,11 +94,11 @@ namespace Wox.ViewModel
{ {
get get
{ {
return this._caretIndex; return _caretIndex;
} }
set set
{ {
this._caretIndex = value; _caretIndex = value;
OnPropertyChanged("CaretIndex"); OnPropertyChanged("CaretIndex");
} }
} }
@@ -107,11 +107,11 @@ namespace Wox.ViewModel
{ {
get get
{ {
return this._isProgressBarTooltipVisible; return _isProgressBarTooltipVisible;
} }
set set
{ {
this._isProgressBarTooltipVisible = value; _isProgressBarTooltipVisible = value;
OnPropertyChanged("IsProgressBarTooltipVisible"); OnPropertyChanged("IsProgressBarTooltipVisible");
} }
} }
@@ -120,11 +120,11 @@ namespace Wox.ViewModel
{ {
get get
{ {
return this._left; return _left;
} }
set set
{ {
this._left = value; _left = value;
OnPropertyChanged("Left"); OnPropertyChanged("Left");
} }
} }
@@ -133,11 +133,11 @@ namespace Wox.ViewModel
{ {
get get
{ {
return this._top; return _top;
} }
set set
{ {
this._top = value; _top = value;
OnPropertyChanged("Top"); OnPropertyChanged("Top");
} }
} }
@@ -146,11 +146,11 @@ namespace Wox.ViewModel
{ {
get get
{ {
return this._contextMenuVisibility; return _contextMenuVisibility;
} }
set set
{ {
this._contextMenuVisibility = value; _contextMenuVisibility = value;
OnPropertyChanged("ContextMenuVisibility"); OnPropertyChanged("ContextMenuVisibility");
} }
} }
@@ -159,11 +159,11 @@ namespace Wox.ViewModel
{ {
get get
{ {
return this._progressBarVisibility; return _progressBarVisibility;
} }
set set
{ {
this._progressBarVisibility = value; _progressBarVisibility = value;
OnPropertyChanged("ProgressBarVisibility"); OnPropertyChanged("ProgressBarVisibility");
} }
} }
@@ -172,11 +172,11 @@ namespace Wox.ViewModel
{ {
get get
{ {
return this._resultListBoxVisibility; return _resultListBoxVisibility;
} }
set set
{ {
this._resultListBoxVisibility = value; _resultListBoxVisibility = value;
OnPropertyChanged("ResultListBoxVisibility"); OnPropertyChanged("ResultListBoxVisibility");
} }
} }
@@ -185,154 +185,102 @@ namespace Wox.ViewModel
{ {
get get
{ {
return this._windowVisibility; return _windowVisibility;
} }
set set
{ {
this._windowVisibility = value; _windowVisibility = value;
OnPropertyChanged("WindowVisibility"); OnPropertyChanged("WindowVisibility");
if (value.IsNotVisible() && this.ContextMenuVisibility.IsVisible()) if (value.IsNotVisible() && ContextMenuVisibility.IsVisible())
{ {
this.BackToSearchMode(); BackToSearchMode();
} }
} }
} }
public ICommand EscCommand public ICommand EscCommand { get; set; }
{
get;
set;
}
public ICommand SelectNextItemCommand public ICommand SelectNextItemCommand { get; set; }
{
get;
set;
}
public ICommand SelectPrevItemCommand public ICommand SelectPrevItemCommand { get; set; }
{
get;
set;
}
public ICommand CtrlOCommand public ICommand CtrlOCommand { get; set; }
{
get;
set;
}
public ICommand DisplayNextQueryCommand public ICommand DisplayNextQueryCommand { get; set; }
{
get;
set;
}
public ICommand DisplayPrevQueryCommand public ICommand DisplayPrevQueryCommand { get; set; }
{
get;
set;
}
public ICommand SelectNextPageCommand public ICommand SelectNextPageCommand { get; set; }
{
get;
set;
}
public ICommand SelectPrevPageCommand public ICommand SelectPrevPageCommand { get; set; }
{
get;
set;
}
public ICommand StartHelpCommand
{
get;
set;
}
public ICommand ShiftEnterCommand
{
get;
set;
}
public ICommand OpenResultCommand
{
get;
set;
}
public ICommand BackCommand
{
get;
set;
}
public ICommand StartHelpCommand { get; set; }
public ICommand ShiftEnterCommand { get; set; }
public ICommand OpenResultCommand { get; set; }
public ICommand BackCommand { get; set; }
#endregion #endregion
#region Private Methods #region Private Methods
private void InitializeKeyCommands() private void InitializeKeyCommands()
{ {
this.EscCommand = new RelayCommand((parameter) => EscCommand = new RelayCommand((parameter) =>
{ {
if (this.ContextMenuVisibility.IsVisible()) if (ContextMenuVisibility.IsVisible())
{
this.BackToSearchMode();
}
else
{
this.WindowVisibility = Visibility.Collapsed;
}
});
this.SelectNextItemCommand = new RelayCommand((parameter) =>
{
if (this.ContextMenuVisibility.IsVisible())
{
this.ContextMenu.SelectNextResult();
}
else
{
this.Results.SelectNextResult();
}
});
this.SelectPrevItemCommand = new RelayCommand((parameter) =>
{
if (this.ContextMenuVisibility.IsVisible())
{
this.ContextMenu.SelectPrevResult();
}
else
{
this.Results.SelectPrevResult();
}
});
this.CtrlOCommand = new RelayCommand((parameter) =>
{
if (this.ContextMenuVisibility.IsVisible())
{ {
BackToSearchMode(); BackToSearchMode();
} }
else else
{ {
ShowContextMenu(this.Results.SelectedResult.RawResult); WindowVisibility = Visibility.Collapsed;
}
});
SelectNextItemCommand = new RelayCommand((parameter) =>
{
if (ContextMenuVisibility.IsVisible())
{
ContextMenu.SelectNextResult();
}
else
{
Results.SelectNextResult();
}
});
SelectPrevItemCommand = new RelayCommand((parameter) =>
{
if (ContextMenuVisibility.IsVisible())
{
ContextMenu.SelectPrevResult();
}
else
{
Results.SelectPrevResult();
}
});
CtrlOCommand = new RelayCommand((parameter) =>
{
if (ContextMenuVisibility.IsVisible())
{
BackToSearchMode();
}
else
{
ShowContextMenu(Results.SelectedResult.RawResult);
} }
}); });
this.DisplayNextQueryCommand = new RelayCommand((parameter) => DisplayNextQueryCommand = new RelayCommand((parameter) =>
{ {
var nextQuery = QueryHistoryStorage.Instance.Next(); var nextQuery = QueryHistoryStorage.Instance.Next();
@@ -340,7 +288,7 @@ namespace Wox.ViewModel
}); });
this.DisplayPrevQueryCommand = new RelayCommand((parameter) => DisplayPrevQueryCommand = new RelayCommand((parameter) =>
{ {
var prev = QueryHistoryStorage.Instance.Previous(); var prev = QueryHistoryStorage.Instance.Previous();
@@ -348,55 +296,55 @@ namespace Wox.ViewModel
}); });
this.SelectNextPageCommand = new RelayCommand((parameter) => SelectNextPageCommand = new RelayCommand((parameter) =>
{ {
this.Results.SelectNextPage(); Results.SelectNextPage();
}); });
this.SelectPrevPageCommand = new RelayCommand((parameter) => SelectPrevPageCommand = new RelayCommand((parameter) =>
{ {
this.Results.SelectPrevPage(); Results.SelectPrevPage();
}); });
this.StartHelpCommand = new RelayCommand((parameter) => StartHelpCommand = new RelayCommand((parameter) =>
{ {
Process.Start("http://doc.getwox.com"); Process.Start("http://doc.getwox.com");
}); });
this.ShiftEnterCommand = new RelayCommand((parameter) => ShiftEnterCommand = new RelayCommand((parameter) =>
{ {
if (this.ContextMenuVisibility.IsNotVisible() && null != this.Results.SelectedResult) if (ContextMenuVisibility.IsNotVisible() && null != Results.SelectedResult)
{ {
this.ShowContextMenu(this.Results.SelectedResult.RawResult); ShowContextMenu(Results.SelectedResult.RawResult);
} }
}); });
this.OpenResultCommand = new RelayCommand((parameter) => OpenResultCommand = new RelayCommand((parameter) =>
{ {
if (null != parameter) if (null != parameter)
{ {
var index = int.Parse(parameter.ToString()); var index = int.Parse(parameter.ToString());
this.Results.SelectResult(index); Results.SelectResult(index);
} }
if (null != this.Results.SelectedResult) if (null != Results.SelectedResult)
{ {
this.Results.SelectedResult.OpenResultListBoxItemCommand.Execute(null); Results.SelectedResult.OpenResultListBoxItemCommand.Execute(null);
} }
}); });
this.BackCommand = new RelayCommand((parameter) => BackCommand = new RelayCommand((parameter) =>
{ {
if (null != ListeningKeyPressed) if (null != ListeningKeyPressed)
{ {
this.ListeningKeyPressed(this, new ListeningKeyPressedEventArgs(parameter as System.Windows.Input.KeyEventArgs)); ListeningKeyPressed(this, new ListeningKeyPressedEventArgs(parameter as System.Windows.Input.KeyEventArgs));
} }
}); });
@@ -404,14 +352,14 @@ namespace Wox.ViewModel
private void InitializeResultListBox() private void InitializeResultListBox()
{ {
this.Results = new ResultsViewModel(); Results = new ResultsViewModel();
this.ResultListBoxVisibility = Visibility.Collapsed; ResultListBoxVisibility = Visibility.Collapsed;
} }
private void ShowContextMenu(Result result) private void ShowContextMenu(Result result)
{ {
if (result == null) return; if (result == null) return;
this.ShowContextMenu(result, PluginManager.GetContextMenusForPlugin(result)); ShowContextMenu(result, PluginManager.GetContextMenusForPlugin(result));
} }
private void ShowContextMenu(Result result, List<Result> actions) private void ShowContextMenu(Result result, List<Result> actions)
@@ -425,21 +373,21 @@ namespace Wox.ViewModel
actions.Add(GetTopMostContextMenu(result)); actions.Add(GetTopMostContextMenu(result));
this.DisplayContextMenu(actions, result.PluginID); DisplayContextMenu(actions, result.PluginID);
} }
private void DisplayContextMenu(List<Result> actions, string pluginID) private void DisplayContextMenu(List<Result> actions, string pluginID)
{ {
_textBeforeEnterContextMenuMode = this.QueryText; _textBeforeEnterContextMenuMode = QueryText;
this.ContextMenu.Clear(); ContextMenu.Clear();
this.ContextMenu.AddResults(actions, pluginID); ContextMenu.AddResults(actions, pluginID);
CurrentContextMenus = actions; CurrentContextMenus = actions;
this.ContextMenuVisibility = Visibility.Visible; ContextMenuVisibility = Visibility.Visible;
this.ResultListBoxVisibility = Visibility.Collapsed; ResultListBoxVisibility = Visibility.Collapsed;
this.QueryText = ""; QueryText = "";
} }
private Result GetTopMostContextMenu(Result result) private Result GetTopMostContextMenu(Result result)
@@ -474,22 +422,22 @@ namespace Wox.ViewModel
private void InitializeContextMenu() private void InitializeContextMenu()
{ {
this.ContextMenu = new ResultsViewModel(); ContextMenu = new ResultsViewModel();
this.ContextMenuVisibility = Visibility.Collapsed; ContextMenuVisibility = Visibility.Collapsed;
} }
private void HandleQueryTextUpdated() private void HandleQueryTextUpdated()
{ {
if (_ignoreTextChange) { _ignoreTextChange = false; return; } if (_ignoreTextChange) { _ignoreTextChange = false; return; }
this.IsProgressBarTooltipVisible = false; IsProgressBarTooltipVisible = false;
if (this.ContextMenuVisibility.IsVisible()) if (ContextMenuVisibility.IsVisible())
{ {
QueryContextMenu(); QueryContextMenu();
} }
else else
{ {
string query = this.QueryText.Trim(); string query = QueryText.Trim();
if (!string.IsNullOrEmpty(query)) if (!string.IsNullOrEmpty(query))
{ {
Query(query); Query(query);
@@ -498,7 +446,7 @@ namespace Wox.ViewModel
} }
else else
{ {
this.Results.Clear(); Results.Clear();
} }
} }
} }
@@ -506,11 +454,11 @@ namespace Wox.ViewModel
private void QueryContextMenu() private void QueryContextMenu()
{ {
var contextMenuId = "Context Menu Id"; var contextMenuId = "Context Menu Id";
this.ContextMenu.Clear(); ContextMenu.Clear();
var query = this.QueryText.ToLower(); var query = QueryText.ToLower();
if (string.IsNullOrEmpty(query)) if (string.IsNullOrEmpty(query))
{ {
this.ContextMenu.AddResults(CurrentContextMenus, contextMenuId); ContextMenu.AddResults(CurrentContextMenus, contextMenuId);
} }
else else
{ {
@@ -523,7 +471,7 @@ namespace Wox.ViewModel
filterResults.Add(contextMenu); filterResults.Add(contextMenu);
} }
} }
this.ContextMenu.AddResults(filterResults, contextMenuId); ContextMenu.AddResults(filterResults, contextMenuId);
} }
} }
@@ -540,18 +488,18 @@ namespace Wox.ViewModel
{ {
if (!string.IsNullOrEmpty(keyword)) if (!string.IsNullOrEmpty(keyword))
{ {
this.Results.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata); Results.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata);
} }
} }
else else
{ {
if (string.IsNullOrEmpty(keyword)) if (string.IsNullOrEmpty(keyword))
{ {
this.Results.RemoveResultsFor(PluginManager.NonGlobalPlugins[lastKeyword].Metadata); Results.RemoveResultsFor(PluginManager.NonGlobalPlugins[lastKeyword].Metadata);
} }
else if (lastKeyword != keyword) else if (lastKeyword != keyword)
{ {
this.Results.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata); Results.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata);
} }
} }
_lastQuery = query; _lastQuery = query;
@@ -561,7 +509,7 @@ namespace Wox.ViewModel
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)
{ {
this.IsProgressBarTooltipVisible = true; IsProgressBarTooltipVisible = true;
} }
}); });
action.Invoke(); action.Invoke();
@@ -577,27 +525,27 @@ namespace Wox.ViewModel
PluginManager.QueryForAllPlugins(query); PluginManager.QueryForAllPlugins(query);
} }
this.IsProgressBarTooltipVisible = false; IsProgressBarTooltipVisible = false;
} }
private void ResetQueryHistoryIndex() private void ResetQueryHistoryIndex()
{ {
this.Results.RemoveResultsFor(QueryHistoryStorage.MetaData); Results.RemoveResultsFor(QueryHistoryStorage.MetaData);
QueryHistoryStorage.Instance.Reset(); QueryHistoryStorage.Instance.Reset();
} }
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}", Infrastructure.Stopwatch.Normal($"UI update cost for {metadata.Name}",
() => { this.Results.AddResults(list, metadata.ID); }); () => { Results.AddResults(list, metadata.ID); });
} }
private void BackToSearchMode() private void BackToSearchMode()
{ {
this.QueryText = _textBeforeEnterContextMenuMode; QueryText = _textBeforeEnterContextMenuMode;
this.ContextMenuVisibility = Visibility.Collapsed; ContextMenuVisibility = Visibility.Collapsed;
this.ResultListBoxVisibility = Visibility.Visible; ResultListBoxVisibility = Visibility.Visible;
this.CaretIndex = this.QueryText.Length; CaretIndex = QueryText.Length;
} }
private void DisplayQueryHistory(HistoryItem history) private void DisplayQueryHistory(HistoryItem history)
@@ -606,12 +554,12 @@ namespace Wox.ViewModel
{ {
var historyMetadata = QueryHistoryStorage.MetaData; var historyMetadata = QueryHistoryStorage.MetaData;
this.QueryText = history.Query; QueryText = history.Query;
this.SelectAllText = true; SelectAllText = true;
var executeQueryHistoryTitle = InternationalizationManager.Instance.GetTranslation("executeQuery"); var executeQueryHistoryTitle = InternationalizationManager.Instance.GetTranslation("executeQuery");
var lastExecuteTime = InternationalizationManager.Instance.GetTranslation("lastExecuteTime"); var lastExecuteTime = InternationalizationManager.Instance.GetTranslation("lastExecuteTime");
this.Results.RemoveResultsExcept(historyMetadata); Results.RemoveResultsExcept(historyMetadata);
UpdateResultViewInternal(new List<Result> UpdateResultViewInternal(new List<Result>
{ {
new Result new Result
@@ -622,8 +570,8 @@ namespace Wox.ViewModel
PluginDirectory = WoxDirectroy.Executable, PluginDirectory = WoxDirectroy.Executable,
Action = _ =>{ Action = _ =>{
this.QueryText = history.Query; QueryText = history.Query;
this.SelectAllText = true; SelectAllText = true;
return false; return false;
} }
@@ -639,7 +587,7 @@ namespace Wox.ViewModel
public void UpdateResultView(List<Result> list, PluginMetadata metadata, Query originQuery) public void UpdateResultView(List<Result> list, PluginMetadata metadata, Query originQuery)
{ {
_queryHasReturn = true; _queryHasReturn = true;
this.IsProgressBarTooltipVisible = false; IsProgressBarTooltipVisible = false;
list.ForEach(o => list.ForEach(o =>
{ {
@@ -655,13 +603,13 @@ namespace Wox.ViewModel
if (list.Count > 0) if (list.Count > 0)
{ {
this.ResultListBoxVisibility = Visibility.Visible; ResultListBoxVisibility = Visibility.Visible;
} }
} }
public void ShowContextMenu(List<Result> actions, string pluginID) public void ShowContextMenu(List<Result> actions, string pluginID)
{ {
this.DisplayContextMenu(actions, pluginID); DisplayContextMenu(actions, pluginID);
} }
#endregion #endregion
@@ -681,7 +629,7 @@ namespace Wox.ViewModel
public ListeningKeyPressedEventArgs(System.Windows.Input.KeyEventArgs keyEventArgs) public ListeningKeyPressedEventArgs(System.Windows.Input.KeyEventArgs keyEventArgs)
{ {
this.KeyEventArgs = keyEventArgs; KeyEventArgs = keyEventArgs;
} }
} }

View File

@@ -1,9 +1,4 @@
using System; using Wox.Core.Plugin;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wox.Core.Plugin;
using Wox.Core.Resource; using Wox.Core.Resource;
using Wox.Infrastructure; using Wox.Infrastructure;
using Wox.Infrastructure.Hotkey; using Wox.Infrastructure.Hotkey;
@@ -16,7 +11,6 @@ namespace Wox.ViewModel
{ {
#region Private Fields #region Private Fields
private Result _result;
private bool _isSelected; private bool _isSelected;
#endregion #endregion
@@ -27,9 +21,9 @@ namespace Wox.ViewModel
{ {
if (null != result) if (null != result)
{ {
this._result = result; RawResult = result;
this.OpenResultListBoxItemCommand = new RelayCommand((parameter) => OpenResultListBoxItemCommand = new RelayCommand(_ =>
{ {
bool hideWindow = result.Action(new ActionContext bool hideWindow = result.Action(new ActionContext
@@ -40,12 +34,12 @@ namespace Wox.ViewModel
if (hideWindow) if (hideWindow)
{ {
App.API.HideApp(); App.API.HideApp();
UserSelectedRecordStorage.Instance.Add(this._result); UserSelectedRecordStorage.Instance.Add(RawResult);
QueryHistoryStorage.Instance.Add(this._result.OriginQuery.RawQuery); QueryHistoryStorage.Instance.Add(RawResult.OriginQuery.RawQuery);
} }
}); });
this.OpenContextMenuItemCommand = new RelayCommand((parameter) => OpenContextMenuItemCommand = new RelayCommand(_ =>
{ {
var actions = PluginManager.GetContextMenusForPlugin(result); var actions = PluginManager.GetContextMenusForPlugin(result);
@@ -71,29 +65,11 @@ namespace Wox.ViewModel
#region ViewModel Properties #region ViewModel Properties
public string Title public string Title => RawResult.Title;
{
get
{
return this._result.Title;
}
}
public string SubTitle public string SubTitle => RawResult.SubTitle;
{
get
{
return this._result.SubTitle;
}
}
public string FullIcoPath public string FullIcoPath => RawResult.FullIcoPath;
{
get
{
return this._result.FullIcoPath;
}
}
public bool IsSelected public bool IsSelected
{ {
@@ -113,13 +89,7 @@ namespace Wox.ViewModel
#region Properties #region Properties
public Result RawResult public Result RawResult { get; }
{
get
{
return this._result;
}
}
#endregion #endregion
@@ -163,7 +133,7 @@ namespace Wox.ViewModel
ResultViewModel r = obj as ResultViewModel; ResultViewModel r = obj as ResultViewModel;
if (r != null) if (r != null)
{ {
return _result.Equals(r.RawResult); return RawResult.Equals(r.RawResult);
} }
return false; return false;
@@ -171,12 +141,12 @@ namespace Wox.ViewModel
public override int GetHashCode() public override int GetHashCode()
{ {
return _result.GetHashCode(); return RawResult.GetHashCode();
} }
public override string ToString() public override string ToString()
{ {
return _result.ToString(); return RawResult.ToString();
} }
} }

View File

@@ -18,46 +18,22 @@ namespace Wox.ViewModel
#region Private Fields #region Private Fields
private ResultViewModel _selectedResult; private ResultViewModel _selectedResult;
private ResultCollection _results; public ResultCollection Results { get; } = new ResultCollection();
private bool _isVisible;
private Thickness _margin; private Thickness _margin;
private readonly object _resultsUpdateLock = new object(); private readonly object _resultsUpdateLock = new object();
#endregion #endregion
#region Constructor
public ResultsViewModel()
{
this._results = new ResultCollection();
}
#endregion
#region ViewModel Properties #region ViewModel Properties
public int MaxHeight public int MaxHeight => UserSettingStorage.Instance.MaxResultsToShow * 50;
{
get
{
return UserSettingStorage.Instance.MaxResultsToShow * 50;
}
}
public ResultCollection Results
{
get
{
return this._results;
}
}
public ResultViewModel SelectedResult public ResultViewModel SelectedResult
{ {
get get
{ {
return this._selectedResult; return _selectedResult;
} }
set set
{ {
@@ -86,11 +62,11 @@ namespace Wox.ViewModel
{ {
get get
{ {
return this._margin; return _margin;
} }
set set
{ {
this._margin = value; _margin = value;
OnPropertyChanged("Margin"); OnPropertyChanged("Margin");
} }
} }
@@ -124,78 +100,78 @@ namespace Wox.ViewModel
public void SelectResult(int index) public void SelectResult(int index)
{ {
if(index <= this.Results.Count - 1) if (index <= Results.Count - 1)
{ {
this.SelectedResult = this.Results[index]; SelectedResult = Results[index];
} }
} }
public void SelectNextResult() public void SelectNextResult()
{ {
if (null != this.SelectedResult) if (null != SelectedResult)
{ {
var index = this.Results.IndexOf(this.SelectedResult); var index = Results.IndexOf(SelectedResult);
if(index == this.Results.Count - 1) if (index == Results.Count - 1)
{ {
index = -1; index = -1;
} }
this.SelectedResult = this.Results.ElementAt(index + 1); SelectedResult = Results.ElementAt(index + 1);
} }
} }
public void SelectPrevResult() public void SelectPrevResult()
{ {
if (null != this.SelectedResult) if (null != SelectedResult)
{ {
var index = this.Results.IndexOf(this.SelectedResult); var index = Results.IndexOf(SelectedResult);
if (index == 0) if (index == 0)
{ {
index = this.Results.Count; index = Results.Count;
} }
this.SelectedResult = this.Results.ElementAt(index - 1); SelectedResult = Results.ElementAt(index - 1);
} }
} }
public void SelectNextPage() public void SelectNextPage()
{ {
var index = 0; var index = 0;
if (null != this.SelectedResult) if (null != SelectedResult)
{ {
index = this.Results.IndexOf(this.SelectedResult); index = Results.IndexOf(SelectedResult);
} }
index += 5; index += 5;
if (index > this.Results.Count - 1) if (index > Results.Count - 1)
{ {
index = this.Results.Count - 1; index = Results.Count - 1;
} }
this.SelectedResult = this.Results.ElementAt(index); SelectedResult = Results.ElementAt(index);
} }
public void SelectPrevPage() public void SelectPrevPage()
{ {
var index = 0; var index = 0;
if (null != this.SelectedResult) if (null != SelectedResult)
{ {
index = this.Results.IndexOf(this.SelectedResult); index = Results.IndexOf(SelectedResult);
} }
index -= 5; index -= 5;
if (index < 0) if (index < 0)
{ {
index = 0; index = 0;
} }
this.SelectedResult = this.Results.ElementAt(index); SelectedResult = Results.ElementAt(index);
} }
public void Clear() public void Clear()
{ {
this._results.Clear(); Results.Clear();
} }
public void RemoveResultsExcept(PluginMetadata metadata) public void RemoveResultsExcept(PluginMetadata metadata)
{ {
lock (_resultsUpdateLock) lock (_resultsUpdateLock)
{ {
_results.RemoveAll(r => r.RawResult.PluginID != metadata.ID); Results.RemoveAll(r => r.RawResult.PluginID != metadata.ID);
} }
} }
@@ -203,7 +179,7 @@ namespace Wox.ViewModel
{ {
lock (_resultsUpdateLock) lock (_resultsUpdateLock)
{ {
_results.RemoveAll(r => r.RawResult.PluginID == metadata.ID); Results.RemoveAll(r => r.RawResult.PluginID == metadata.ID);
} }
} }
@@ -214,7 +190,7 @@ namespace Wox.ViewModel
var newResults = new List<ResultViewModel>(); var newResults = new List<ResultViewModel>();
newRawResults.ForEach((re) => { newResults.Add(new ResultViewModel(re)); }); newRawResults.ForEach((re) => { newResults.Add(new ResultViewModel(re)); });
// todo use async to do new result calculation // todo use async to do new result calculation
var resultsCopy = _results.ToList(); var resultsCopy = Results.ToList();
var oldResults = resultsCopy.Where(r => r.RawResult.PluginID == resultId).ToList(); var oldResults = resultsCopy.Where(r => r.RawResult.PluginID == resultId).ToList();
// intersection of A (old results) and B (new newResults) // intersection of A (old results) and B (new newResults)
var intersection = oldResults.Intersect(newResults).ToList(); var intersection = oldResults.Intersect(newResults).ToList();
@@ -258,16 +234,16 @@ namespace Wox.ViewModel
} }
// update UI in one run, so it can avoid UI flickering // update UI in one run, so it can avoid UI flickering
_results.Update(resultsCopy); Results.Update(resultsCopy);
if(this._results.Count > 0) if (Results.Count > 0)
{ {
this.Margin = new Thickness { Top = 8 }; Margin = new Thickness { Top = 8 };
this.SelectedResult = this._results[0]; SelectedResult = Results[0];
} }
else else
{ {
this.Margin = new Thickness { Top = 0 }; Margin = new Thickness { Top = 0 };
} }
} }
} }
@@ -278,10 +254,6 @@ namespace Wox.ViewModel
public class ResultCollection : ObservableCollection<ResultViewModel> public class ResultCollection : ObservableCollection<ResultViewModel>
{ {
public ResultCollection()
{
}
public void RemoveAll(Predicate<ResultViewModel> predicate) public void RemoveAll(Predicate<ResultViewModel> predicate)
{ {
CheckReentrancy(); CheckReentrancy();
@@ -289,12 +261,7 @@ namespace Wox.ViewModel
List<ResultViewModel> itemsToRemove = Items.Where(x => predicate(x)).ToList(); List<ResultViewModel> itemsToRemove = Items.Where(x => predicate(x)).ToList();
if (itemsToRemove.Count > 0) if (itemsToRemove.Count > 0)
{ {
itemsToRemove.ForEach(item => { Items.Remove(item); });
itemsToRemove.ForEach(item => {
Items.Remove(item);
});
OnPropertyChanged(new PropertyChangedEventArgs("Count")); OnPropertyChanged(new PropertyChangedEventArgs("Count"));
OnPropertyChanged(new PropertyChangedEventArgs("Item[]")); OnPropertyChanged(new PropertyChangedEventArgs("Item[]"));
@@ -347,5 +314,5 @@ namespace Wox.ViewModel
} }
} }
} }