mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
Merge branch 'dev'
This commit is contained in:
@@ -11,11 +11,11 @@ namespace Wox.ViewModel
|
||||
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)
|
||||
{
|
||||
this._action = action;
|
||||
_action = action;
|
||||
}
|
||||
|
||||
public virtual bool CanExecute(object parameter)
|
||||
@@ -41,9 +41,9 @@ namespace Wox.ViewModel
|
||||
|
||||
public virtual void Execute(object parameter)
|
||||
{
|
||||
if (null != this._action)
|
||||
if (null != _action)
|
||||
{
|
||||
this._action(parameter);
|
||||
_action(parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,11 +47,11 @@ namespace Wox.ViewModel
|
||||
|
||||
public MainViewModel()
|
||||
{
|
||||
this.InitializeResultListBox();
|
||||
this.InitializeContextMenu();
|
||||
this.InitializeKeyCommands();
|
||||
InitializeResultListBox();
|
||||
InitializeContextMenu();
|
||||
InitializeKeyCommands();
|
||||
|
||||
this._queryHasReturn = false;
|
||||
_queryHasReturn = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -66,14 +66,14 @@ namespace Wox.ViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._queryText;
|
||||
return _queryText;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._queryText = value;
|
||||
_queryText = value;
|
||||
OnPropertyChanged("QueryText");
|
||||
|
||||
this.HandleQueryTextUpdated();
|
||||
HandleQueryTextUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,11 +81,11 @@ namespace Wox.ViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._selectAllText;
|
||||
return _selectAllText;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._selectAllText = value;
|
||||
_selectAllText = value;
|
||||
OnPropertyChanged("SelectAllText");
|
||||
}
|
||||
}
|
||||
@@ -94,11 +94,11 @@ namespace Wox.ViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._caretIndex;
|
||||
return _caretIndex;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._caretIndex = value;
|
||||
_caretIndex = value;
|
||||
OnPropertyChanged("CaretIndex");
|
||||
}
|
||||
}
|
||||
@@ -107,11 +107,11 @@ namespace Wox.ViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._isProgressBarTooltipVisible;
|
||||
return _isProgressBarTooltipVisible;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._isProgressBarTooltipVisible = value;
|
||||
_isProgressBarTooltipVisible = value;
|
||||
OnPropertyChanged("IsProgressBarTooltipVisible");
|
||||
}
|
||||
}
|
||||
@@ -120,11 +120,11 @@ namespace Wox.ViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._left;
|
||||
return _left;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._left = value;
|
||||
_left = value;
|
||||
OnPropertyChanged("Left");
|
||||
}
|
||||
}
|
||||
@@ -133,11 +133,11 @@ namespace Wox.ViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._top;
|
||||
return _top;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._top = value;
|
||||
_top = value;
|
||||
OnPropertyChanged("Top");
|
||||
}
|
||||
}
|
||||
@@ -146,11 +146,11 @@ namespace Wox.ViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._contextMenuVisibility;
|
||||
return _contextMenuVisibility;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._contextMenuVisibility = value;
|
||||
_contextMenuVisibility = value;
|
||||
OnPropertyChanged("ContextMenuVisibility");
|
||||
}
|
||||
}
|
||||
@@ -159,11 +159,11 @@ namespace Wox.ViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._progressBarVisibility;
|
||||
return _progressBarVisibility;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._progressBarVisibility = value;
|
||||
_progressBarVisibility = value;
|
||||
OnPropertyChanged("ProgressBarVisibility");
|
||||
}
|
||||
}
|
||||
@@ -172,11 +172,11 @@ namespace Wox.ViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._resultListBoxVisibility;
|
||||
return _resultListBoxVisibility;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._resultListBoxVisibility = value;
|
||||
_resultListBoxVisibility = value;
|
||||
OnPropertyChanged("ResultListBoxVisibility");
|
||||
}
|
||||
}
|
||||
@@ -185,154 +185,102 @@ namespace Wox.ViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._windowVisibility;
|
||||
return _windowVisibility;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._windowVisibility = value;
|
||||
_windowVisibility = value;
|
||||
OnPropertyChanged("WindowVisibility");
|
||||
|
||||
if (value.IsNotVisible() && this.ContextMenuVisibility.IsVisible())
|
||||
if (value.IsNotVisible() && ContextMenuVisibility.IsVisible())
|
||||
{
|
||||
this.BackToSearchMode();
|
||||
BackToSearchMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 StartHelpCommand
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public ICommand ShiftEnterCommand
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public ICommand OpenResultCommand
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public ICommand BackCommand
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public ICommand SelectPrevPageCommand { get; set; }
|
||||
|
||||
public ICommand StartHelpCommand { get; set; }
|
||||
public ICommand ShiftEnterCommand { get; set; }
|
||||
public ICommand OpenResultCommand { get; set; }
|
||||
public ICommand BackCommand { get; set; }
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private void InitializeKeyCommands()
|
||||
{
|
||||
this.EscCommand = new RelayCommand((parameter) =>
|
||||
EscCommand = new RelayCommand((parameter) =>
|
||||
{
|
||||
|
||||
if (this.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())
|
||||
if (ContextMenuVisibility.IsVisible())
|
||||
{
|
||||
BackToSearchMode();
|
||||
}
|
||||
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();
|
||||
@@ -340,7 +288,7 @@ namespace Wox.ViewModel
|
||||
|
||||
});
|
||||
|
||||
this.DisplayPrevQueryCommand = new RelayCommand((parameter) =>
|
||||
DisplayPrevQueryCommand = new RelayCommand((parameter) =>
|
||||
{
|
||||
|
||||
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");
|
||||
});
|
||||
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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()
|
||||
{
|
||||
this.Results = new ResultsViewModel();
|
||||
this.ResultListBoxVisibility = Visibility.Collapsed;
|
||||
Results = new ResultsViewModel();
|
||||
ResultListBoxVisibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
private void ShowContextMenu(Result result)
|
||||
{
|
||||
if (result == null) return;
|
||||
this.ShowContextMenu(result, PluginManager.GetContextMenusForPlugin(result));
|
||||
ShowContextMenu(result, PluginManager.GetContextMenusForPlugin(result));
|
||||
}
|
||||
|
||||
private void ShowContextMenu(Result result, List<Result> actions)
|
||||
@@ -425,21 +373,21 @@ namespace Wox.ViewModel
|
||||
|
||||
actions.Add(GetTopMostContextMenu(result));
|
||||
|
||||
this.DisplayContextMenu(actions, result.PluginID);
|
||||
DisplayContextMenu(actions, result.PluginID);
|
||||
}
|
||||
|
||||
private void DisplayContextMenu(List<Result> actions, string pluginID)
|
||||
{
|
||||
_textBeforeEnterContextMenuMode = this.QueryText;
|
||||
_textBeforeEnterContextMenuMode = QueryText;
|
||||
|
||||
this.ContextMenu.Clear();
|
||||
this.ContextMenu.AddResults(actions, pluginID);
|
||||
ContextMenu.Clear();
|
||||
ContextMenu.AddResults(actions, pluginID);
|
||||
CurrentContextMenus = actions;
|
||||
|
||||
this.ContextMenuVisibility = Visibility.Visible;
|
||||
this.ResultListBoxVisibility = Visibility.Collapsed;
|
||||
ContextMenuVisibility = Visibility.Visible;
|
||||
ResultListBoxVisibility = Visibility.Collapsed;
|
||||
|
||||
this.QueryText = "";
|
||||
QueryText = "";
|
||||
}
|
||||
|
||||
private Result GetTopMostContextMenu(Result result)
|
||||
@@ -474,22 +422,22 @@ namespace Wox.ViewModel
|
||||
|
||||
private void InitializeContextMenu()
|
||||
{
|
||||
this.ContextMenu = new ResultsViewModel();
|
||||
this.ContextMenuVisibility = Visibility.Collapsed;
|
||||
ContextMenu = new ResultsViewModel();
|
||||
ContextMenuVisibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
private void HandleQueryTextUpdated()
|
||||
{
|
||||
if (_ignoreTextChange) { _ignoreTextChange = false; return; }
|
||||
|
||||
this.IsProgressBarTooltipVisible = false;
|
||||
if (this.ContextMenuVisibility.IsVisible())
|
||||
IsProgressBarTooltipVisible = false;
|
||||
if (ContextMenuVisibility.IsVisible())
|
||||
{
|
||||
QueryContextMenu();
|
||||
}
|
||||
else
|
||||
{
|
||||
string query = this.QueryText.Trim();
|
||||
string query = QueryText.Trim();
|
||||
if (!string.IsNullOrEmpty(query))
|
||||
{
|
||||
Query(query);
|
||||
@@ -498,7 +446,7 @@ namespace Wox.ViewModel
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Results.Clear();
|
||||
Results.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -506,11 +454,11 @@ namespace Wox.ViewModel
|
||||
private void QueryContextMenu()
|
||||
{
|
||||
var contextMenuId = "Context Menu Id";
|
||||
this.ContextMenu.Clear();
|
||||
var query = this.QueryText.ToLower();
|
||||
ContextMenu.Clear();
|
||||
var query = QueryText.ToLower();
|
||||
if (string.IsNullOrEmpty(query))
|
||||
{
|
||||
this.ContextMenu.AddResults(CurrentContextMenus, contextMenuId);
|
||||
ContextMenu.AddResults(CurrentContextMenus, contextMenuId);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -523,7 +471,7 @@ namespace Wox.ViewModel
|
||||
filterResults.Add(contextMenu);
|
||||
}
|
||||
}
|
||||
this.ContextMenu.AddResults(filterResults, contextMenuId);
|
||||
ContextMenu.AddResults(filterResults, contextMenuId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -540,18 +488,18 @@ namespace Wox.ViewModel
|
||||
{
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
this.Results.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata);
|
||||
Results.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
this.Results.RemoveResultsFor(PluginManager.NonGlobalPlugins[lastKeyword].Metadata);
|
||||
Results.RemoveResultsFor(PluginManager.NonGlobalPlugins[lastKeyword].Metadata);
|
||||
}
|
||||
else if (lastKeyword != keyword)
|
||||
{
|
||||
this.Results.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata);
|
||||
Results.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata);
|
||||
}
|
||||
}
|
||||
_lastQuery = query;
|
||||
@@ -561,7 +509,7 @@ namespace Wox.ViewModel
|
||||
await Task.Delay(150);
|
||||
if (!string.IsNullOrEmpty(query.RawQuery) && query.RawQuery == _lastQuery.RawQuery && !_queryHasReturn)
|
||||
{
|
||||
this.IsProgressBarTooltipVisible = true;
|
||||
IsProgressBarTooltipVisible = true;
|
||||
}
|
||||
});
|
||||
action.Invoke();
|
||||
@@ -577,27 +525,27 @@ namespace Wox.ViewModel
|
||||
PluginManager.QueryForAllPlugins(query);
|
||||
}
|
||||
|
||||
this.IsProgressBarTooltipVisible = false;
|
||||
IsProgressBarTooltipVisible = false;
|
||||
}
|
||||
|
||||
private void ResetQueryHistoryIndex()
|
||||
{
|
||||
this.Results.RemoveResultsFor(QueryHistoryStorage.MetaData);
|
||||
Results.RemoveResultsFor(QueryHistoryStorage.MetaData);
|
||||
QueryHistoryStorage.Instance.Reset();
|
||||
}
|
||||
|
||||
private void UpdateResultViewInternal(List<Result> list, PluginMetadata metadata)
|
||||
{
|
||||
Infrastructure.Stopwatch.Normal($"UI update cost for {metadata.Name}",
|
||||
() => { this.Results.AddResults(list, metadata.ID); });
|
||||
() => { Results.AddResults(list, metadata.ID); });
|
||||
}
|
||||
|
||||
private void BackToSearchMode()
|
||||
{
|
||||
this.QueryText = _textBeforeEnterContextMenuMode;
|
||||
this.ContextMenuVisibility = Visibility.Collapsed;
|
||||
this.ResultListBoxVisibility = Visibility.Visible;
|
||||
this.CaretIndex = this.QueryText.Length;
|
||||
QueryText = _textBeforeEnterContextMenuMode;
|
||||
ContextMenuVisibility = Visibility.Collapsed;
|
||||
ResultListBoxVisibility = Visibility.Visible;
|
||||
CaretIndex = QueryText.Length;
|
||||
}
|
||||
|
||||
private void DisplayQueryHistory(HistoryItem history)
|
||||
@@ -606,12 +554,12 @@ namespace Wox.ViewModel
|
||||
{
|
||||
var historyMetadata = QueryHistoryStorage.MetaData;
|
||||
|
||||
this.QueryText = history.Query;
|
||||
this.SelectAllText = true;
|
||||
QueryText = history.Query;
|
||||
SelectAllText = true;
|
||||
|
||||
var executeQueryHistoryTitle = InternationalizationManager.Instance.GetTranslation("executeQuery");
|
||||
var lastExecuteTime = InternationalizationManager.Instance.GetTranslation("lastExecuteTime");
|
||||
this.Results.RemoveResultsExcept(historyMetadata);
|
||||
Results.RemoveResultsExcept(historyMetadata);
|
||||
UpdateResultViewInternal(new List<Result>
|
||||
{
|
||||
new Result
|
||||
@@ -622,8 +570,8 @@ namespace Wox.ViewModel
|
||||
PluginDirectory = WoxDirectroy.Executable,
|
||||
Action = _ =>{
|
||||
|
||||
this.QueryText = history.Query;
|
||||
this.SelectAllText = true;
|
||||
QueryText = history.Query;
|
||||
SelectAllText = true;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -639,7 +587,7 @@ namespace Wox.ViewModel
|
||||
public void UpdateResultView(List<Result> list, PluginMetadata metadata, Query originQuery)
|
||||
{
|
||||
_queryHasReturn = true;
|
||||
this.IsProgressBarTooltipVisible = false;
|
||||
IsProgressBarTooltipVisible = false;
|
||||
|
||||
list.ForEach(o =>
|
||||
{
|
||||
@@ -655,13 +603,13 @@ namespace Wox.ViewModel
|
||||
|
||||
if (list.Count > 0)
|
||||
{
|
||||
this.ResultListBoxVisibility = Visibility.Visible;
|
||||
ResultListBoxVisibility = Visibility.Visible;
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowContextMenu(List<Result> actions, string pluginID)
|
||||
{
|
||||
this.DisplayContextMenu(actions, pluginID);
|
||||
DisplayContextMenu(actions, pluginID);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -681,7 +629,7 @@ namespace Wox.ViewModel
|
||||
|
||||
public ListeningKeyPressedEventArgs(System.Windows.Input.KeyEventArgs keyEventArgs)
|
||||
{
|
||||
this.KeyEventArgs = keyEventArgs;
|
||||
KeyEventArgs = keyEventArgs;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Core.Resource;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Hotkey;
|
||||
@@ -16,7 +11,6 @@ namespace Wox.ViewModel
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private Result _result;
|
||||
private bool _isSelected;
|
||||
|
||||
#endregion
|
||||
@@ -27,9 +21,9 @@ namespace Wox.ViewModel
|
||||
{
|
||||
if (null != result)
|
||||
{
|
||||
this._result = result;
|
||||
RawResult = result;
|
||||
|
||||
this.OpenResultListBoxItemCommand = new RelayCommand((parameter) =>
|
||||
OpenResultListBoxItemCommand = new RelayCommand(_ =>
|
||||
{
|
||||
|
||||
bool hideWindow = result.Action(new ActionContext
|
||||
@@ -40,12 +34,12 @@ namespace Wox.ViewModel
|
||||
if (hideWindow)
|
||||
{
|
||||
App.API.HideApp();
|
||||
UserSelectedRecordStorage.Instance.Add(this._result);
|
||||
QueryHistoryStorage.Instance.Add(this._result.OriginQuery.RawQuery);
|
||||
UserSelectedRecordStorage.Instance.Add(RawResult);
|
||||
QueryHistoryStorage.Instance.Add(RawResult.OriginQuery.RawQuery);
|
||||
}
|
||||
});
|
||||
|
||||
this.OpenContextMenuItemCommand = new RelayCommand((parameter) =>
|
||||
OpenContextMenuItemCommand = new RelayCommand(_ =>
|
||||
{
|
||||
|
||||
var actions = PluginManager.GetContextMenusForPlugin(result);
|
||||
@@ -71,29 +65,11 @@ namespace Wox.ViewModel
|
||||
|
||||
#region ViewModel Properties
|
||||
|
||||
public string Title
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._result.Title;
|
||||
}
|
||||
}
|
||||
public string Title => RawResult.Title;
|
||||
|
||||
public string SubTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._result.SubTitle;
|
||||
}
|
||||
}
|
||||
public string SubTitle => RawResult.SubTitle;
|
||||
|
||||
public string FullIcoPath
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._result.FullIcoPath;
|
||||
}
|
||||
}
|
||||
public string FullIcoPath => RawResult.FullIcoPath;
|
||||
|
||||
public bool IsSelected
|
||||
{
|
||||
@@ -113,13 +89,7 @@ namespace Wox.ViewModel
|
||||
|
||||
#region Properties
|
||||
|
||||
public Result RawResult
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._result;
|
||||
}
|
||||
}
|
||||
public Result RawResult { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -163,7 +133,7 @@ namespace Wox.ViewModel
|
||||
ResultViewModel r = obj as ResultViewModel;
|
||||
if (r != null)
|
||||
{
|
||||
return _result.Equals(r.RawResult);
|
||||
return RawResult.Equals(r.RawResult);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -171,12 +141,12 @@ namespace Wox.ViewModel
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return _result.GetHashCode();
|
||||
return RawResult.GetHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return _result.ToString();
|
||||
return RawResult.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,46 +18,22 @@ namespace Wox.ViewModel
|
||||
#region Private Fields
|
||||
|
||||
private ResultViewModel _selectedResult;
|
||||
private ResultCollection _results;
|
||||
private bool _isVisible;
|
||||
public ResultCollection Results { get; } = new ResultCollection();
|
||||
private Thickness _margin;
|
||||
|
||||
private readonly object _resultsUpdateLock = new object();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
public ResultsViewModel()
|
||||
{
|
||||
this._results = new ResultCollection();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ViewModel Properties
|
||||
|
||||
public int MaxHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return UserSettingStorage.Instance.MaxResultsToShow * 50;
|
||||
}
|
||||
}
|
||||
|
||||
public ResultCollection Results
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._results;
|
||||
}
|
||||
}
|
||||
public int MaxHeight => UserSettingStorage.Instance.MaxResultsToShow * 50;
|
||||
|
||||
public ResultViewModel SelectedResult
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._selectedResult;
|
||||
return _selectedResult;
|
||||
}
|
||||
set
|
||||
{
|
||||
@@ -86,11 +62,11 @@ namespace Wox.ViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._margin;
|
||||
return _margin;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._margin = value;
|
||||
_margin = value;
|
||||
OnPropertyChanged("Margin");
|
||||
}
|
||||
}
|
||||
@@ -124,78 +100,78 @@ namespace Wox.ViewModel
|
||||
|
||||
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()
|
||||
{
|
||||
if (null != this.SelectedResult)
|
||||
if (null != SelectedResult)
|
||||
{
|
||||
var index = this.Results.IndexOf(this.SelectedResult);
|
||||
if(index == this.Results.Count - 1)
|
||||
var index = Results.IndexOf(SelectedResult);
|
||||
if (index == Results.Count - 1)
|
||||
{
|
||||
index = -1;
|
||||
}
|
||||
this.SelectedResult = this.Results.ElementAt(index + 1);
|
||||
SelectedResult = Results.ElementAt(index + 1);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
index = this.Results.Count;
|
||||
index = Results.Count;
|
||||
}
|
||||
this.SelectedResult = this.Results.ElementAt(index - 1);
|
||||
SelectedResult = Results.ElementAt(index - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void SelectNextPage()
|
||||
{
|
||||
var index = 0;
|
||||
if (null != this.SelectedResult)
|
||||
if (null != SelectedResult)
|
||||
{
|
||||
index = this.Results.IndexOf(this.SelectedResult);
|
||||
index = Results.IndexOf(SelectedResult);
|
||||
}
|
||||
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()
|
||||
{
|
||||
var index = 0;
|
||||
if (null != this.SelectedResult)
|
||||
if (null != SelectedResult)
|
||||
{
|
||||
index = this.Results.IndexOf(this.SelectedResult);
|
||||
index = Results.IndexOf(SelectedResult);
|
||||
}
|
||||
index -= 5;
|
||||
if (index < 0)
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
this.SelectedResult = this.Results.ElementAt(index);
|
||||
SelectedResult = Results.ElementAt(index);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
this._results.Clear();
|
||||
Results.Clear();
|
||||
}
|
||||
|
||||
public void RemoveResultsExcept(PluginMetadata metadata)
|
||||
{
|
||||
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)
|
||||
{
|
||||
_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>();
|
||||
newRawResults.ForEach((re) => { newResults.Add(new ResultViewModel(re)); });
|
||||
// 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();
|
||||
// intersection of A (old results) and B (new newResults)
|
||||
var intersection = oldResults.Intersect(newResults).ToList();
|
||||
@@ -258,16 +234,16 @@ namespace Wox.ViewModel
|
||||
}
|
||||
|
||||
// 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 };
|
||||
this.SelectedResult = this._results[0];
|
||||
Margin = new Thickness { Top = 8 };
|
||||
SelectedResult = Results[0];
|
||||
}
|
||||
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 ResultCollection()
|
||||
{
|
||||
}
|
||||
|
||||
public void RemoveAll(Predicate<ResultViewModel> predicate)
|
||||
{
|
||||
CheckReentrancy();
|
||||
@@ -289,12 +261,7 @@ namespace Wox.ViewModel
|
||||
List<ResultViewModel> itemsToRemove = Items.Where(x => predicate(x)).ToList();
|
||||
if (itemsToRemove.Count > 0)
|
||||
{
|
||||
|
||||
itemsToRemove.ForEach(item => {
|
||||
|
||||
Items.Remove(item);
|
||||
|
||||
});
|
||||
itemsToRemove.ForEach(item => { Items.Remove(item); });
|
||||
|
||||
OnPropertyChanged(new PropertyChangedEventArgs("Count"));
|
||||
OnPropertyChanged(new PropertyChangedEventArgs("Item[]"));
|
||||
@@ -347,5 +314,5 @@ namespace Wox.ViewModel
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user