mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 04:37:30 +02:00
Add Context menu
This commit is contained in:
@@ -17,16 +17,17 @@ namespace Wox.Commands
|
||||
|
||||
public override void Dispatch(Query query)
|
||||
{
|
||||
var queryPlugins = allSytemPlugins;
|
||||
if (UserSettingStorage.Instance.WebSearches.Exists(o => o.ActionWord == query.ActionName && o.Enabled))
|
||||
{
|
||||
//websearch mode
|
||||
allSytemPlugins = new List<PluginPair>()
|
||||
queryPlugins = new List<PluginPair>()
|
||||
{
|
||||
allSytemPlugins.First(o => ((ISystemPlugin)o.Plugin).ID == "565B73353DBF4806919830B9202EE3BF")
|
||||
};
|
||||
}
|
||||
|
||||
foreach (PluginPair pair in allSytemPlugins)
|
||||
foreach (PluginPair pair in queryPlugins)
|
||||
{
|
||||
PluginPair pair1 = pair;
|
||||
ThreadPool.QueueUserWorkItem(state =>
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
<StackPanel Orientation="Vertical">
|
||||
<TextBox Style="{DynamicResource QueryBoxStyle}" PreviewDragOver="TbQuery_OnPreviewDragOver" AllowDrop="True" Grid.Row="0" x:Name="tbQuery" PreviewKeyDown="TbQuery_OnPreviewKeyDown" TextChanged="TextBoxBase_OnTextChanged" />
|
||||
<Line Style="{DynamicResource PendingLineStyle}" x:Name="progressBar" Y1="0" Y2="0" X2="100" Grid.Row="1" Height="2" StrokeThickness="1"></Line>
|
||||
<wox:ResultPanel x:Name="resultCtrl" />
|
||||
<wox:ResultPanel x:Name="pnlResult" />
|
||||
<wox:ResultPanel x:Name="pnlContextMenu" Visibility="Collapsed" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Window>
|
||||
@@ -141,6 +141,13 @@ namespace Wox
|
||||
results.ForEach(o =>
|
||||
{
|
||||
o.PluginDirectory = plugin.PluginDirectory;
|
||||
if (o.ContextMenu != null)
|
||||
{
|
||||
o.ContextMenu.ForEach(t =>
|
||||
{
|
||||
t.PluginDirectory = plugin.PluginDirectory;
|
||||
});
|
||||
}
|
||||
o.OriginQuery = query;
|
||||
});
|
||||
OnUpdateResultView(results);
|
||||
@@ -148,7 +155,6 @@ namespace Wox
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -160,7 +166,9 @@ namespace Wox
|
||||
|
||||
progressBar.ToolTip = toolTip;
|
||||
InitialTray();
|
||||
resultCtrl.OnMouseClickItem += AcceptSelect;
|
||||
pnlResult.LeftMouseClickEvent += SelectResult;
|
||||
pnlContextMenu.LeftMouseClickEvent += SelectResult;
|
||||
pnlResult.RightMouseClickEvent += pnlResult_RightMouseClickEvent;
|
||||
|
||||
ThreadPool.SetMaxThreads(30, 10);
|
||||
try
|
||||
@@ -180,6 +188,11 @@ namespace Wox
|
||||
this.Closing += MainWindow_Closing;
|
||||
}
|
||||
|
||||
void pnlResult_RightMouseClickEvent(Result result)
|
||||
{
|
||||
ShowContextMenu(result);
|
||||
}
|
||||
|
||||
void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
UserSettingStorage.Instance.WindowLeft = Left;
|
||||
@@ -300,21 +313,22 @@ namespace Wox
|
||||
|
||||
lastQuery = tbQuery.Text;
|
||||
toolTip.IsOpen = false;
|
||||
resultCtrl.Dirty = true;
|
||||
pnlResult.Dirty = true;
|
||||
Dispatcher.DelayInvoke("UpdateSearch",
|
||||
o =>
|
||||
{
|
||||
Dispatcher.DelayInvoke("ClearResults", i =>
|
||||
{
|
||||
// first try to use clear method inside resultCtrl, which is more closer to the add new results
|
||||
// first try to use clear method inside pnlResult, which is more closer to the add new results
|
||||
// and this will not bring splash issues.After waiting 30ms, if there still no results added, we
|
||||
// must clear the result. otherwise, it will be confused why the query changed, but the results
|
||||
// didn't.
|
||||
if (resultCtrl.Dirty) resultCtrl.Clear();
|
||||
if (pnlResult.Dirty) pnlResult.Clear();
|
||||
}, TimeSpan.FromMilliseconds(100), null);
|
||||
queryHasReturn = false;
|
||||
var q = new Query(lastQuery);
|
||||
CommandFactory.DispatchCommand(q);
|
||||
BackToResultMode();
|
||||
if (Plugins.HitThirdpartyKeyword(q))
|
||||
{
|
||||
Dispatcher.DelayInvoke("ShowProgressbar", originQuery =>
|
||||
@@ -328,6 +342,12 @@ namespace Wox
|
||||
}, TimeSpan.FromMilliseconds(ShouldNotDelayQuery ? 0 : 150));
|
||||
}
|
||||
|
||||
private void BackToResultMode()
|
||||
{
|
||||
pnlResult.Visibility = Visibility.Visible;
|
||||
pnlContextMenu.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
private bool ShouldNotDelayQuery
|
||||
{
|
||||
get
|
||||
@@ -463,7 +483,7 @@ namespace Wox
|
||||
ShowWox(false);
|
||||
if (!tbQuery.Text.StartsWith(">"))
|
||||
{
|
||||
resultCtrl.Clear();
|
||||
pnlResult.Clear();
|
||||
ChangeQuery(">");
|
||||
}
|
||||
tbQuery.CaretIndex = tbQuery.Text.Length;
|
||||
@@ -473,7 +493,7 @@ namespace Wox
|
||||
|
||||
private void updateCmdMode()
|
||||
{
|
||||
var currentSelectedItem = resultCtrl.GetActiveResult();
|
||||
var currentSelectedItem = pnlResult.GetActiveResult();
|
||||
if (currentSelectedItem != null)
|
||||
{
|
||||
ignoreTextChange = true;
|
||||
@@ -489,7 +509,14 @@ namespace Wox
|
||||
switch (key)
|
||||
{
|
||||
case Key.Escape:
|
||||
HideWox();
|
||||
if (IsInContextMenuMode)
|
||||
{
|
||||
BackToResultMode();
|
||||
}
|
||||
else
|
||||
{
|
||||
HideWox();
|
||||
}
|
||||
e.Handled = true;
|
||||
break;
|
||||
|
||||
@@ -516,14 +543,14 @@ namespace Wox
|
||||
break;
|
||||
|
||||
case Key.PageDown:
|
||||
resultCtrl.SelectNextPage();
|
||||
pnlResult.SelectNextPage();
|
||||
if (IsCMDMode) updateCmdMode();
|
||||
toolTip.IsOpen = false;
|
||||
e.Handled = true;
|
||||
break;
|
||||
|
||||
case Key.PageUp:
|
||||
resultCtrl.SelectPrevPage();
|
||||
pnlResult.SelectPrevPage();
|
||||
if (IsCMDMode) updateCmdMode();
|
||||
toolTip.IsOpen = false;
|
||||
e.Handled = true;
|
||||
@@ -545,29 +572,68 @@ namespace Wox
|
||||
break;
|
||||
|
||||
case Key.Enter:
|
||||
AcceptSelect(resultCtrl.GetActiveResult());
|
||||
Result activeResult = GetActiveResult();
|
||||
if (globalHotkey.CheckModifiers().ShiftPressed)
|
||||
{
|
||||
ShowContextMenu(activeResult);
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectResult(activeResult);
|
||||
}
|
||||
e.Handled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsInContextMenuMode
|
||||
{
|
||||
get { return pnlContextMenu.Visibility == Visibility.Visible; }
|
||||
}
|
||||
|
||||
private Result GetActiveResult()
|
||||
{
|
||||
if (IsInContextMenuMode)
|
||||
{
|
||||
return pnlContextMenu.GetActiveResult();
|
||||
}
|
||||
else
|
||||
{
|
||||
return pnlResult.GetActiveResult();
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectPrevItem()
|
||||
{
|
||||
resultCtrl.SelectPrev();
|
||||
if (IsCMDMode) updateCmdMode();
|
||||
if (IsInContextMenuMode)
|
||||
{
|
||||
pnlContextMenu.SelectPrev();
|
||||
}
|
||||
else
|
||||
{
|
||||
pnlResult.SelectPrev();
|
||||
if (IsCMDMode) updateCmdMode();
|
||||
}
|
||||
toolTip.IsOpen = false;
|
||||
}
|
||||
|
||||
private void SelectNextItem()
|
||||
{
|
||||
resultCtrl.SelectNext();
|
||||
if (IsCMDMode) updateCmdMode();
|
||||
if (IsInContextMenuMode)
|
||||
{
|
||||
pnlContextMenu.SelectNext();
|
||||
}
|
||||
else
|
||||
{
|
||||
pnlResult.SelectNext();
|
||||
if (IsCMDMode) updateCmdMode();
|
||||
}
|
||||
toolTip.IsOpen = false;
|
||||
}
|
||||
|
||||
private void AcceptSelect(Result result)
|
||||
private void SelectResult(Result result)
|
||||
{
|
||||
if (!resultCtrl.Dirty && result != null)
|
||||
if (result != null)
|
||||
{
|
||||
if (result.Action != null)
|
||||
{
|
||||
@@ -599,7 +665,20 @@ namespace Wox
|
||||
if (o.AutoAjustScore) o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o);
|
||||
});
|
||||
List<Result> l = list.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == lastQuery).ToList();
|
||||
Dispatcher.Invoke(new Action(() => resultCtrl.AddResults(l)));
|
||||
Dispatcher.Invoke(new Action(() =>
|
||||
pnlResult.AddResults(l))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowContextMenu(Result result)
|
||||
{
|
||||
if (result.ContextMenu != null && result.ContextMenu.Count > 0)
|
||||
{
|
||||
pnlContextMenu.Clear();
|
||||
pnlContextMenu.AddResults(result.ContextMenu);
|
||||
pnlContextMenu.Visibility = Visibility.Visible;
|
||||
pnlResult.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<!-- a result item height is 50 including margin -->
|
||||
<Grid HorizontalAlignment="Stretch" Height="40" VerticalAlignment="Stretch" Margin="5" Cursor="Hand">
|
||||
<Grid HorizontalAlignment="Stretch" Height="40" VerticalAlignment="Stretch" Margin="5" Cursor="Hand">
|
||||
<Grid.Resources>
|
||||
<converters:ImagePathConverter x:Key="ImageConverter" />
|
||||
</Grid.Resources>
|
||||
|
||||
@@ -14,11 +14,18 @@ namespace Wox
|
||||
{
|
||||
public partial class ResultPanel : UserControl
|
||||
{
|
||||
public event Action<Result> OnMouseClickItem;
|
||||
public event Action<Result> LeftMouseClickEvent;
|
||||
public event Action<Result> RightMouseClickEvent;
|
||||
|
||||
protected virtual void OnOnMouseClickItem(Result result)
|
||||
protected virtual void OnRightMouseClick(Result result)
|
||||
{
|
||||
Action<Result> handler = OnMouseClickItem;
|
||||
Action<Result> handler = RightMouseClickEvent;
|
||||
if (handler != null) handler(result);
|
||||
}
|
||||
|
||||
protected virtual void OnLeftMouseClick(Result result)
|
||||
{
|
||||
Action<Result> handler = LeftMouseClickEvent;
|
||||
if (handler != null) handler(result);
|
||||
}
|
||||
|
||||
@@ -133,9 +140,13 @@ namespace Wox
|
||||
private void LbResults_OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
var item = ItemsControl.ContainerFromElement(lbResults, e.OriginalSource as DependencyObject) as ListBoxItem;
|
||||
if (item != null)
|
||||
if (item != null && e.ChangedButton == MouseButton.Left)
|
||||
{
|
||||
OnOnMouseClickItem(item.DataContext as Result);
|
||||
OnLeftMouseClick(item.DataContext as Result);
|
||||
}
|
||||
if (item != null && e.ChangedButton == MouseButton.Right)
|
||||
{
|
||||
OnRightMouseClick(item.DataContext as Result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user