diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index 110faad2bc..9da4a20397 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -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 visibleResults = pnlResult.GetVisibleResults(); + if (zeroBasedIndex < visibleResults.Count) + { + SelectResult(visibleResults[zeroBasedIndex]); + } } } diff --git a/Wox/ResultPanel.xaml.cs b/Wox/ResultPanel.xaml.cs index 736d5d262c..7274a8c544 100644 --- a/Wox/ResultPanel.xaml.cs +++ b/Wox/ResultPanel.xaml.cs @@ -110,6 +110,43 @@ namespace Wox } } + public List GetVisibleResults() + { + var theStackPanel = GetInnerStackPanel(lbResults); + List visibleElements = new List(); + + 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;