Skip to content

Commit 69158b9

Browse files
committed
Limit no of hotkeys displayed for mod+num launching
1 parent 6bc0ae6 commit 69158b9

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.Text;
5+
using System.Windows;
6+
using System.Windows.Controls;
7+
using System.Windows.Data;
8+
9+
namespace Flow.Launcher.Converters
10+
{
11+
[ValueConversion(typeof(bool), typeof(Visibility))]
12+
public class OpenResultHotkeyVisibilityConverter : IValueConverter
13+
{
14+
private const int MaxVisibleHotkeys = 9;
15+
16+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
17+
{
18+
var hotkeyNumber = int.MaxValue;
19+
20+
if (value is ListBoxItem listBoxItem)
21+
{
22+
ListBox listBox = ItemsControl.ItemsControlFromItemContainer(listBoxItem) as ListBox;
23+
hotkeyNumber = listBox.ItemContainerGenerator.IndexFromContainer(listBoxItem) + 1;
24+
}
25+
26+
return hotkeyNumber <= MaxVisibleHotkeys ? Visibility.Visible : Visibility.Collapsed;
27+
}
28+
29+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new System.InvalidOperationException();
30+
}
31+
}

Flow.Launcher/ResultListBox.xaml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<Grid.Resources>
3535
<converter:HighlightTextConverter x:Key="HighlightTextConverter"/>
3636
<converter:OrdinalConverter x:Key="OrdinalConverter" />
37+
<converter:OpenResultHotkeyVisibilityConverter x:Key="OpenResultHotkeyVisibilityConverter" />
3738
</Grid.Resources>
3839
<Grid.ColumnDefinitions>
3940
<ColumnDefinition Width="32" />
@@ -47,14 +48,19 @@
4748
<RowDefinition />
4849
<RowDefinition Height="Auto" x:Name="SubTitleRowDefinition" />
4950
</Grid.RowDefinitions>
50-
<TextBlock Margin="0 5 5 0" Visibility="{Binding ShowOpenResultHotkey}" Style="{DynamicResource ItemSubTitleStyle}" HorizontalAlignment="Right" Opacity="0.8" >
51-
<TextBlock.Text>
52-
<MultiBinding StringFormat="{}{0}+{1}">
53-
<Binding Path="OpenResultModifiers" />
54-
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ListBoxItem}" Converter="{StaticResource ResourceKey=OrdinalConverter}"/>
55-
</MultiBinding>
56-
</TextBlock.Text>
57-
</TextBlock>
51+
<StackPanel Visibility="{Binding ShowOpenResultHotkey}">
52+
<TextBlock Margin="0 5 5 0" Style="{DynamicResource ItemSubTitleStyle}" HorizontalAlignment="Right" Opacity="0.8" >
53+
<TextBlock.Visibility>
54+
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ListBoxItem}" Converter="{StaticResource ResourceKey=OpenResultHotkeyVisibilityConverter}" />
55+
</TextBlock.Visibility>
56+
<TextBlock.Text>
57+
<MultiBinding StringFormat="{}{0}+{1}">
58+
<Binding Path="OpenResultModifiers" />
59+
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ListBoxItem}" Converter="{StaticResource ResourceKey=OrdinalConverter}" />
60+
</MultiBinding>
61+
</TextBlock.Text>
62+
</TextBlock>
63+
</StackPanel>
5864
<TextBlock Style="{DynamicResource ItemTitleStyle}" DockPanel.Dock="Left"
5965
VerticalAlignment="Center" ToolTip="{Binding Result.Title}" x:Name="Title"
6066
Text="{Binding Result.Title}">

0 commit comments

Comments
 (0)