This commit is contained in:
qianlifeng 2015-01-23 18:28:14 +08:00
parent 17bc9c35a7
commit 672abbcaad
2 changed files with 75 additions and 0 deletions

View File

@ -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]);
}
}
}

View File

@ -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;