From 37867e008bb390fee00a2d09415fc6d1c0591800 Mon Sep 17 00:00:00 2001 From: Davide Giacometti Date: Fri, 16 Feb 2024 15:26:48 +0100 Subject: [PATCH] [PTRun]Fix tooltip closing and improve Registry tooltip spacing (#31361) --- .../Helper/ResultHelper.cs | 10 +++++----- .../launcher/PowerLauncher/ResultList.xaml | 2 ++ .../launcher/PowerLauncher/ResultList.xaml.cs | 16 +++++++++------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry/Helper/ResultHelper.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry/Helper/ResultHelper.cs index 2714d6e47086..77a7f55be74b 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry/Helper/ResultHelper.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry/Helper/ResultHelper.cs @@ -58,7 +58,7 @@ internal static List GetResultList(in IEnumerable list, i result.Action = (_) => ContextMenuHelper.TryToOpenInRegistryEditor(entry); result.ContextData = entry; - result.ToolTipData = new ToolTipData(Resources.RegistryKey, $"{Resources.KeyName}\t{result.Title}"); + result.ToolTipData = new ToolTipData(Resources.RegistryKey, $"{Resources.KeyName} {result.Title}"); resultList.Add(result); } @@ -198,10 +198,10 @@ internal static string GetTruncatedText(string text, in int maxLength, TruncateS /// A tool-tip text private static string GetToolTipTextForRegistryValue(RegistryKey key, KeyValuePair valueEntry) { - return $"{Resources.KeyName}\t{key.Name}{Environment.NewLine}" - + $"{Resources.Name}\t{valueEntry.Key}{Environment.NewLine}" - + $"{Resources.Type}\t{ValueHelper.GetType(key, valueEntry.Key)}{Environment.NewLine}" - + $"{Resources.Value}\t{ValueHelper.GetValue(key, valueEntry.Key)}"; + return $"{Resources.KeyName} {key.Name}{Environment.NewLine}" + + $"{Resources.Name} {valueEntry.Key}{Environment.NewLine}" + + $"{Resources.Type} {ValueHelper.GetType(key, valueEntry.Key)}{Environment.NewLine}" + + $"{Resources.Value} {ValueHelper.GetValue(key, valueEntry.Key)}"; } /// diff --git a/src/modules/launcher/PowerLauncher/ResultList.xaml b/src/modules/launcher/PowerLauncher/ResultList.xaml index 0c8f69b21ef7..7eda85a709fd 100644 --- a/src/modules/launcher/PowerLauncher/ResultList.xaml +++ b/src/modules/launcher/PowerLauncher/ResultList.xaml @@ -85,12 +85,14 @@ FontWeight="SemiBold" Style="{DynamicResource CollapsableTextblock}" Text="{Binding Result.ToolTipData.Title}" + TextAlignment="Left" TextWrapping="Wrap" /> diff --git a/src/modules/launcher/PowerLauncher/ResultList.xaml.cs b/src/modules/launcher/PowerLauncher/ResultList.xaml.cs index 9cc6d8e1aa2b..020cf919fb03 100644 --- a/src/modules/launcher/PowerLauncher/ResultList.xaml.cs +++ b/src/modules/launcher/PowerLauncher/ResultList.xaml.cs @@ -22,7 +22,7 @@ public ResultList() // From https://learn.microsoft.com/dotnet/desktop/wpf/data/how-to-find-datatemplate-generated-elements private TypeChildItem FindVisualChild(DependencyObject obj) - where TypeChildItem : DependencyObject + where TypeChildItem : DependencyObject { for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++) { @@ -80,20 +80,22 @@ private void ContextMenuListView_SelectionChanged(object sender, SelectionChange } } - [System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1309:Use ordinal string comparison", Justification = "Using StringComparison.InvariantCulture since this is user facing")] private void ToolTip_Opened(object sender, RoutedEventArgs e) { - if (string.Equals(sender.GetType().FullName, "System.Windows.Controls.ToolTip", System.StringComparison.InvariantCulture)) + if (string.Equals(sender.GetType().FullName, "System.Windows.Controls.ToolTip", System.StringComparison.Ordinal)) { - HideCurrentToolTip(); - _previouslyOpenedToolTip = (ToolTip)sender; + var openedToolTip = (ToolTip)sender; + if (_previouslyOpenedToolTip != openedToolTip) + { + HideCurrentToolTip(); + _previouslyOpenedToolTip = openedToolTip; + } } } - [System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1309:Use ordinal string comparison", Justification = "Using StringComparison.InvariantCulture since this is user facing")] private void SuggestionsListView_SelectionChanged(object sender, SelectionChangedEventArgs e) { - if (string.Equals(((ListView)e.OriginalSource).Name, "SuggestionsList", System.StringComparison.InvariantCulture)) + if (string.Equals(((ListView)e.OriginalSource).Name, "SuggestionsList", System.StringComparison.Ordinal)) { HideCurrentToolTip(); }