mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 04:07:40 +02:00
Allow searches in context menu
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
@@ -11,7 +12,6 @@ using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media.Animation;
|
||||
using NHotkey;
|
||||
using NHotkey.Wpf;
|
||||
@@ -25,18 +25,14 @@ using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Hotkey;
|
||||
using Wox.Plugin;
|
||||
using Wox.Storage;
|
||||
using Brushes = System.Windows.Media.Brushes;
|
||||
using Color = System.Windows.Media.Color;
|
||||
using ContextMenu = System.Windows.Forms.ContextMenu;
|
||||
using DataFormats = System.Windows.DataFormats;
|
||||
using DragEventArgs = System.Windows.DragEventArgs;
|
||||
using IDataObject = System.Windows.IDataObject;
|
||||
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
||||
using MenuItem = System.Windows.Forms.MenuItem;
|
||||
using MessageBox = System.Windows.MessageBox;
|
||||
using ToolTip = System.Windows.Controls.ToolTip;
|
||||
using Wox.Infrastructure.Logger;
|
||||
using IDataObject = System.Windows.IDataObject;
|
||||
using System.IO;
|
||||
|
||||
namespace Wox
|
||||
{
|
||||
@@ -52,6 +48,8 @@ namespace Wox
|
||||
private ToolTip toolTip = new ToolTip();
|
||||
|
||||
private bool ignoreTextChange = false;
|
||||
private List<Result> CurrentContextMenus = new List<Result>();
|
||||
private string textBeforeEnterContextMenuMode;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -70,6 +68,16 @@ namespace Wox
|
||||
}));
|
||||
}
|
||||
|
||||
public void ChangeQueryText(string query)
|
||||
{
|
||||
Dispatcher.Invoke(new Action(() =>
|
||||
{
|
||||
ignoreTextChange = true;
|
||||
tbQuery.Text = query;
|
||||
tbQuery.CaretIndex = tbQuery.Text.Length;
|
||||
}));
|
||||
}
|
||||
|
||||
public void CloseApp()
|
||||
{
|
||||
Dispatcher.Invoke(new Action(() =>
|
||||
@@ -380,13 +388,43 @@ namespace Wox
|
||||
notifyIcon.ContextMenu = new ContextMenu(childen);
|
||||
}
|
||||
|
||||
private void QueryContextMenu()
|
||||
{
|
||||
pnlContextMenu.Clear();
|
||||
var query = tbQuery.Text.ToLower();
|
||||
if (string.IsNullOrEmpty(query))
|
||||
{
|
||||
pnlContextMenu.AddResults(CurrentContextMenus);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<Result> filterResults = new List<Result>();
|
||||
foreach (Result contextMenu in CurrentContextMenus)
|
||||
{
|
||||
if (StringMatcher.IsMatch(contextMenu.Title, query)
|
||||
|| StringMatcher.IsMatch(contextMenu.SubTitle, query))
|
||||
{
|
||||
filterResults.Add(contextMenu);
|
||||
}
|
||||
}
|
||||
pnlContextMenu.AddResults(filterResults);
|
||||
}
|
||||
}
|
||||
|
||||
private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
if (ignoreTextChange) { ignoreTextChange = false; return; }
|
||||
|
||||
lastQuery = tbQuery.Text;
|
||||
toolTip.IsOpen = false;
|
||||
pnlResult.Dirty = true;
|
||||
|
||||
if (IsInContextMenuMode)
|
||||
{
|
||||
QueryContextMenu();
|
||||
return;
|
||||
}
|
||||
|
||||
lastQuery = tbQuery.Text;
|
||||
int searchDelay = GetSearchDelay(lastQuery);
|
||||
|
||||
Dispatcher.DelayInvoke("UpdateSearch",
|
||||
@@ -464,11 +502,11 @@ namespace Wox
|
||||
{
|
||||
PluginManager.Query(q);
|
||||
StopProgress();
|
||||
BackToResultMode();
|
||||
}
|
||||
|
||||
private void BackToResultMode()
|
||||
{
|
||||
ChangeQueryText(textBeforeEnterContextMenuMode);
|
||||
pnlResult.Visibility = Visibility.Visible;
|
||||
pnlContextMenu.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
@@ -490,6 +528,7 @@ namespace Wox
|
||||
|
||||
private void HideWox()
|
||||
{
|
||||
BackToResultMode();
|
||||
Hide();
|
||||
}
|
||||
|
||||
@@ -553,7 +592,7 @@ namespace Wox
|
||||
|
||||
case Key.N:
|
||||
case Key.J:
|
||||
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
|
||||
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
||||
{
|
||||
SelectNextItem();
|
||||
}
|
||||
@@ -561,14 +600,14 @@ namespace Wox
|
||||
|
||||
case Key.P:
|
||||
case Key.K:
|
||||
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
|
||||
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
||||
{
|
||||
SelectPrevItem();
|
||||
}
|
||||
break;
|
||||
|
||||
case Key.O:
|
||||
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
|
||||
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
||||
{
|
||||
if (IsInContextMenuMode)
|
||||
{
|
||||
@@ -592,7 +631,7 @@ namespace Wox
|
||||
break;
|
||||
|
||||
case Key.D:
|
||||
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
|
||||
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
||||
{
|
||||
pnlResult.SelectNextPage();
|
||||
}
|
||||
@@ -604,7 +643,7 @@ namespace Wox
|
||||
break;
|
||||
|
||||
case Key.U:
|
||||
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
|
||||
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
||||
{
|
||||
pnlResult.SelectPrevPage();
|
||||
}
|
||||
@@ -774,7 +813,7 @@ namespace Wox
|
||||
{
|
||||
if (TopMostRecordStorage.Instance.IsTopMost(result))
|
||||
{
|
||||
result.ContextMenu.Add(new Result("Remove top most in this query", "Images\\topmost.png")
|
||||
result.ContextMenu.Add(new Result(GetTranslation("cancelTopMostInThisQuery"), "Images\\down.png")
|
||||
{
|
||||
PluginDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
|
||||
Action = _ =>
|
||||
@@ -787,7 +826,7 @@ namespace Wox
|
||||
}
|
||||
else
|
||||
{
|
||||
result.ContextMenu.Add(new Result("Set as top most in this query", "Images\\topmost.png")
|
||||
result.ContextMenu.Add(new Result(GetTranslation("setAsTopMostInThisQuery"), "Images\\up.png")
|
||||
{
|
||||
PluginDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
|
||||
Action = _ =>
|
||||
@@ -804,8 +843,11 @@ namespace Wox
|
||||
{
|
||||
if (result.ContextMenu != null && result.ContextMenu.Count > 0)
|
||||
{
|
||||
textBeforeEnterContextMenuMode = tbQuery.Text;
|
||||
ChangeQueryText("");
|
||||
pnlContextMenu.Clear();
|
||||
pnlContextMenu.AddResults(result.ContextMenu);
|
||||
CurrentContextMenus = result.ContextMenu;
|
||||
pnlContextMenu.Visibility = Visibility.Visible;
|
||||
pnlResult.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user