From 69158b9777a6a77e812eacce36eaa79dd6243f55 Mon Sep 17 00:00:00 2001 From: Grzegorz Dziedzic Date: Mon, 4 May 2020 20:58:37 +0200 Subject: [PATCH] Limit no of hotkeys displayed for mod+num launching --- .../OpenResultHotkeyVisibilityConverter.cs | 31 +++++++++++++++++++ Flow.Launcher/ResultListBox.xaml | 22 ++++++++----- 2 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 Flow.Launcher/Converters/OpenResultHotkeyVisibilityConverter.cs diff --git a/Flow.Launcher/Converters/OpenResultHotkeyVisibilityConverter.cs b/Flow.Launcher/Converters/OpenResultHotkeyVisibilityConverter.cs new file mode 100644 index 000000000..7de5af79a --- /dev/null +++ b/Flow.Launcher/Converters/OpenResultHotkeyVisibilityConverter.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; + +namespace Flow.Launcher.Converters +{ + [ValueConversion(typeof(bool), typeof(Visibility))] + public class OpenResultHotkeyVisibilityConverter : IValueConverter + { + private const int MaxVisibleHotkeys = 9; + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var hotkeyNumber = int.MaxValue; + + if (value is ListBoxItem listBoxItem) + { + ListBox listBox = ItemsControl.ItemsControlFromItemContainer(listBoxItem) as ListBox; + hotkeyNumber = listBox.ItemContainerGenerator.IndexFromContainer(listBoxItem) + 1; + } + + return hotkeyNumber <= MaxVisibleHotkeys ? Visibility.Visible : Visibility.Collapsed; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new System.InvalidOperationException(); + } +} diff --git a/Flow.Launcher/ResultListBox.xaml b/Flow.Launcher/ResultListBox.xaml index 6f1c7e613..d21c014d6 100644 --- a/Flow.Launcher/ResultListBox.xaml +++ b/Flow.Launcher/ResultListBox.xaml @@ -34,6 +34,7 @@ + @@ -47,14 +48,19 @@ - - - - - - - - + + + + + + + + + + + + +