mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-14 11:39:16 +08:00
Implement #202
This commit is contained in:
parent
17bc9c35a7
commit
672abbcaad
@ -541,6 +541,44 @@ namespace Wox
|
||||
}
|
||||
e.Handled = true;
|
||||
break;
|
||||
|
||||
case Key.D1:
|
||||
SelectItem(1);
|
||||
break;
|
||||
|
||||
case Key.D2:
|
||||
SelectItem(2);
|
||||
break;
|
||||
|
||||
case Key.D3:
|
||||
SelectItem(3);
|
||||
break;
|
||||
|
||||
case Key.D4:
|
||||
SelectItem(4);
|
||||
break;
|
||||
|
||||
case Key.D5:
|
||||
SelectItem(5);
|
||||
break;
|
||||
case Key.D6:
|
||||
SelectItem(6);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectItem(int index)
|
||||
{
|
||||
int zeroBasedIndex = index - 1;
|
||||
SpecialKeyState keyState = GlobalHotkey.Instance.CheckModifiers();
|
||||
if (keyState.AltPressed || keyState.CtrlPressed)
|
||||
{
|
||||
List<Result> visibleResults = pnlResult.GetVisibleResults();
|
||||
if (zeroBasedIndex < visibleResults.Count)
|
||||
{
|
||||
SelectResult(visibleResults[zeroBasedIndex]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,6 +110,43 @@ namespace Wox
|
||||
}
|
||||
}
|
||||
|
||||
public List<Result> GetVisibleResults()
|
||||
{
|
||||
var theStackPanel = GetInnerStackPanel(lbResults);
|
||||
List<Result> visibleElements = new List<Result>();
|
||||
|
||||
for (int i = 0; i < theStackPanel.Children.Count; i++)
|
||||
{
|
||||
|
||||
if (i >= theStackPanel.VerticalOffset && i <= theStackPanel.VerticalOffset + theStackPanel.ViewportHeight)
|
||||
{
|
||||
FrameworkElement element = theStackPanel.Children[i] as FrameworkElement;
|
||||
visibleElements.Add(element.DataContext as Result);
|
||||
}
|
||||
}
|
||||
return visibleElements;
|
||||
}
|
||||
|
||||
private VirtualizingStackPanel GetInnerStackPanel(FrameworkElement element)
|
||||
{
|
||||
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(element); i++)
|
||||
{
|
||||
var child = VisualTreeHelper.GetChild(element, i) as FrameworkElement;
|
||||
|
||||
if (child == null) continue;
|
||||
|
||||
if (child is VirtualizingStackPanel) return child as VirtualizingStackPanel;
|
||||
|
||||
var panel = GetInnerStackPanel(child);
|
||||
|
||||
if (panel != null)
|
||||
return panel;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public Result GetActiveResult()
|
||||
{
|
||||
int index = lbResults.SelectedIndex;
|
||||
|
Loading…
Reference in New Issue
Block a user