mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
Implement the support for shortcut key
This commit is contained in:
@@ -25,9 +25,9 @@ namespace Wox.ViewModel
|
||||
public class RelayCommand : ICommand
|
||||
{
|
||||
|
||||
private Action _action;
|
||||
private Action<object> _action;
|
||||
|
||||
public RelayCommand(Action action)
|
||||
public RelayCommand(Action<object> action)
|
||||
{
|
||||
this._action = action;
|
||||
}
|
||||
@@ -43,7 +43,7 @@ namespace Wox.ViewModel
|
||||
{
|
||||
if (null != this._action)
|
||||
{
|
||||
this._action();
|
||||
this._action(parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -185,13 +186,73 @@ namespace Wox.ViewModel
|
||||
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;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private void InitializeKeyCommands()
|
||||
{
|
||||
this.EscCommand = new RelayCommand(() => {
|
||||
this.EscCommand = new RelayCommand((parameter) => {
|
||||
|
||||
if (this.IsActionPanelVisible)
|
||||
{
|
||||
@@ -203,6 +264,97 @@ namespace Wox.ViewModel
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
this.SelectNextItemCommand = new RelayCommand((parameter) => {
|
||||
|
||||
if (this.IsActionPanelVisible)
|
||||
{
|
||||
this._actionPanel.SelectNextResult();
|
||||
}
|
||||
else
|
||||
{
|
||||
this._searchResultPanel.SelectNextResult();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
this.SelectPrevItemCommand = new RelayCommand((parameter) => {
|
||||
|
||||
if (this.IsActionPanelVisible)
|
||||
{
|
||||
this._actionPanel.SelectPrevResult();
|
||||
}
|
||||
else
|
||||
{
|
||||
this._searchResultPanel.SelectPrevResult();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
this.CtrlOCommand = new RelayCommand((parameter) => {
|
||||
|
||||
if (this.IsActionPanelVisible)
|
||||
{
|
||||
BackToSearchMode();
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowActionPanel(this._searchResultPanel.SelectedResult.RawResult);
|
||||
}
|
||||
});
|
||||
|
||||
this.DisplayNextQueryCommand = new RelayCommand((parameter) => {
|
||||
|
||||
var nextQuery = QueryHistoryStorage.Instance.Next();
|
||||
DisplayQueryHistory(nextQuery);
|
||||
|
||||
});
|
||||
|
||||
this.DisplayPrevQueryCommand = new RelayCommand((parameter) => {
|
||||
|
||||
var prev = QueryHistoryStorage.Instance.Previous();
|
||||
DisplayQueryHistory(prev);
|
||||
|
||||
});
|
||||
|
||||
this.SelectNextPageCommand = new RelayCommand((parameter) => {
|
||||
|
||||
this._searchResultPanel.SelectNextPage();
|
||||
|
||||
});
|
||||
|
||||
this.SelectPrevPageCommand = new RelayCommand((parameter) => {
|
||||
|
||||
this._searchResultPanel.SelectPrevPage();
|
||||
|
||||
});
|
||||
|
||||
this.StartHelpCommand = new RelayCommand((parameter) => {
|
||||
Process.Start("http://doc.getwox.com");
|
||||
});
|
||||
|
||||
this.ShiftEnterCommand = new RelayCommand((parameter) => {
|
||||
|
||||
if (!this.IsActionPanelVisible && null != this._searchResultPanel.SelectedResult)
|
||||
{
|
||||
this.ShowActionPanel(this._searchResultPanel.SelectedResult.RawResult);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
this.OpenResultCommand = new RelayCommand((parameter) => {
|
||||
|
||||
if(null != parameter)
|
||||
{
|
||||
var index = int.Parse(parameter.ToString());
|
||||
this._searchResultPanel.SelectResult(index);
|
||||
}
|
||||
|
||||
if (null != this._searchResultPanel.SelectedResult)
|
||||
{
|
||||
this._searchResultPanel.SelectedResult.OpenResultCommand.Execute(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void InitializeResultPanel()
|
||||
@@ -406,7 +558,7 @@ namespace Wox.ViewModel
|
||||
|
||||
private void UpdateResultViewInternal(List<Result> list, PluginMetadata metadata)
|
||||
{
|
||||
Stopwatch.Normal($"UI update cost for {metadata.Name}",
|
||||
Infrastructure.Stopwatch.Normal($"UI update cost for {metadata.Name}",
|
||||
() => { this._searchResultPanel.AddResults(list, metadata.ID); });
|
||||
}
|
||||
|
||||
@@ -417,6 +569,38 @@ namespace Wox.ViewModel
|
||||
this.IsSearchResultPanelVisible = true;
|
||||
}
|
||||
|
||||
private void DisplayQueryHistory(HistoryItem history)
|
||||
{
|
||||
if (history != null)
|
||||
{
|
||||
var historyMetadata = QueryHistoryStorage.MetaData;
|
||||
|
||||
this.QueryText = history.Query;
|
||||
//TODO: Need to select all text
|
||||
|
||||
var executeQueryHistoryTitle = InternationalizationManager.Instance.GetTranslation("executeQuery");
|
||||
var lastExecuteTime = InternationalizationManager.Instance.GetTranslation("lastExecuteTime");
|
||||
this._searchResultPanel.RemoveResultsExcept(historyMetadata);
|
||||
UpdateResultViewInternal(new List<Result>
|
||||
{
|
||||
new Result
|
||||
{
|
||||
Title = string.Format(executeQueryHistoryTitle,history.Query),
|
||||
SubTitle = string.Format(lastExecuteTime,history.ExecutedDateTime),
|
||||
IcoPath = "Images\\history.png",
|
||||
PluginDirectory = WoxDirectroy.Executable,
|
||||
Action = _ =>{
|
||||
|
||||
this.QueryText = history.Query;
|
||||
//TODO: Need to select all text
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}, historyMetadata);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Wox.ViewModel
|
||||
{
|
||||
this._result = result;
|
||||
|
||||
this.OpenResultCommand = new RelayCommand(() => {
|
||||
this.OpenResultCommand = new RelayCommand((parameter) => {
|
||||
|
||||
bool hideWindow = result.Action(new ActionContext
|
||||
{
|
||||
@@ -38,7 +38,7 @@ namespace Wox.ViewModel
|
||||
}
|
||||
});
|
||||
|
||||
this.OpenResultActionPanelCommand = new RelayCommand(()=> {
|
||||
this.OpenResultActionPanelCommand = new RelayCommand((parameter) => {
|
||||
|
||||
if(null!= ResultActionPanelOpened)
|
||||
{
|
||||
|
||||
@@ -124,6 +124,70 @@ namespace Wox.ViewModel
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void SelectResult(int index)
|
||||
{
|
||||
if(index <= this.Results.Count - 1)
|
||||
{
|
||||
this.SelectedResult = this.Results[index];
|
||||
}
|
||||
}
|
||||
|
||||
public void SelectNextResult()
|
||||
{
|
||||
if (null != this.SelectedResult)
|
||||
{
|
||||
var index = this.Results.IndexOf(this.SelectedResult);
|
||||
if(index == this.Results.Count - 1)
|
||||
{
|
||||
index = -1;
|
||||
}
|
||||
this.SelectedResult = this.Results.ElementAt(index + 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void SelectPrevResult()
|
||||
{
|
||||
if (null != this.SelectedResult)
|
||||
{
|
||||
var index = this.Results.IndexOf(this.SelectedResult);
|
||||
if (index == 0)
|
||||
{
|
||||
index = this.Results.Count;
|
||||
}
|
||||
this.SelectedResult = this.Results.ElementAt(index - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void SelectNextPage()
|
||||
{
|
||||
var index = 0;
|
||||
if (null != this.SelectedResult)
|
||||
{
|
||||
index = this.Results.IndexOf(this.SelectedResult);
|
||||
}
|
||||
index += 5;
|
||||
if (index > this.Results.Count - 1)
|
||||
{
|
||||
index = this.Results.Count - 1;
|
||||
}
|
||||
this.SelectedResult = this.Results.ElementAt(index);
|
||||
}
|
||||
|
||||
public void SelectPrevPage()
|
||||
{
|
||||
var index = 0;
|
||||
if (null != this.SelectedResult)
|
||||
{
|
||||
index = this.Results.IndexOf(this.SelectedResult);
|
||||
}
|
||||
index -= 5;
|
||||
if (index < 0)
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
this.SelectedResult = this.Results.ElementAt(index);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
this._results.Clear();
|
||||
|
||||
Reference in New Issue
Block a user