mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
[PowerToys Run] Keyboard shows command tooltips (#12720)
* [PowerToys Run] Keyboard shows command tooltips * Fix spellchecker error * Another try at fixing the spellcheck error
This commit is contained in:
@@ -176,6 +176,7 @@
|
|||||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||||
SelectionMode="Single"
|
SelectionMode="Single"
|
||||||
SelectedIndex="{Binding Results.SelectedIndex, Mode=TwoWay}"
|
SelectedIndex="{Binding Results.SelectedIndex, Mode=TwoWay}"
|
||||||
|
SelectionChanged="SuggestionsListView_SelectionChanged"
|
||||||
ItemContainerStyle="{StaticResource ResultsListViewItemContainerStyle}"
|
ItemContainerStyle="{StaticResource ResultsListViewItemContainerStyle}"
|
||||||
AutomationProperties.Name="{x:Static p:Resources.Results}">
|
AutomationProperties.Name="{x:Static p:Resources.Results}">
|
||||||
|
|
||||||
@@ -208,7 +209,7 @@
|
|||||||
<RowDefinition Height="*"/>
|
<RowDefinition Height="*"/>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<Grid.ToolTip>
|
<Grid.ToolTip>
|
||||||
<ToolTip Visibility="{Binding Result.ToolTipVisibility}">
|
<ToolTip Visibility="{Binding Result.ToolTipVisibility}" Opened="ToolTip_Opened">
|
||||||
<StackPanel>
|
<StackPanel>
|
||||||
<TextBlock
|
<TextBlock
|
||||||
Style="{DynamicResource CollapsableTextblock}"
|
Style="{DynamicResource CollapsableTextblock}"
|
||||||
@@ -270,6 +271,7 @@
|
|||||||
SelectionMode="Single"
|
SelectionMode="Single"
|
||||||
Margin="0,0,-8,0"
|
Margin="0,0,-8,0"
|
||||||
SelectedIndex="{Binding ContextMenuSelectedIndex}"
|
SelectedIndex="{Binding ContextMenuSelectedIndex}"
|
||||||
|
SelectionChanged="ContextMenuListView_SelectionChanged"
|
||||||
Visibility="{Binding AreContextButtonsActive, Converter={StaticResource BooleanToVisibilityConverter}}"
|
Visibility="{Binding AreContextButtonsActive, Converter={StaticResource BooleanToVisibilityConverter}}"
|
||||||
ItemContainerStyle="{StaticResource CommandButtonListViewItemContainerStyle}">
|
ItemContainerStyle="{StaticResource CommandButtonListViewItemContainerStyle}">
|
||||||
<ItemsControl.ItemsPanel>
|
<ItemsControl.ItemsPanel>
|
||||||
@@ -288,9 +290,10 @@
|
|||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Height="42"
|
Height="42"
|
||||||
Width="42"
|
Width="42"
|
||||||
|
Name="commandButton"
|
||||||
BorderThickness="1" >
|
BorderThickness="1" >
|
||||||
<ToolTipService.ToolTip>
|
<ToolTipService.ToolTip>
|
||||||
<ToolTip >
|
<ToolTip Opened="ToolTip_Opened">
|
||||||
<TextBlock
|
<TextBlock
|
||||||
AutomationProperties.Name="{x:Static p:Resources.ContextMenuItemAdditionalInformation}"
|
AutomationProperties.Name="{x:Static p:Resources.ContextMenuItemAdditionalInformation}"
|
||||||
Text="{Binding Title}"/>
|
Text="{Binding Title}"/>
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Media;
|
||||||
|
|
||||||
namespace PowerLauncher
|
namespace PowerLauncher
|
||||||
{
|
{
|
||||||
@@ -15,5 +17,73 @@ namespace PowerLauncher
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ToolTip _previouslyOpenedToolTip;
|
||||||
|
|
||||||
|
// From https://docs.microsoft.com/en-us/dotnet/desktop/wpf/data/how-to-find-datatemplate-generated-elements
|
||||||
|
private TypeChildItem FindVisualChild<TypeChildItem>(DependencyObject obj)
|
||||||
|
where TypeChildItem : DependencyObject
|
||||||
|
{
|
||||||
|
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
|
||||||
|
{
|
||||||
|
DependencyObject child = VisualTreeHelper.GetChild(obj, i);
|
||||||
|
if (child != null && child is TypeChildItem)
|
||||||
|
{
|
||||||
|
return (TypeChildItem)child;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TypeChildItem childOfChild = FindVisualChild<TypeChildItem>(child);
|
||||||
|
if (childOfChild != null)
|
||||||
|
{
|
||||||
|
return childOfChild;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HideCurrentToolTip()
|
||||||
|
{
|
||||||
|
if (_previouslyOpenedToolTip != null)
|
||||||
|
{
|
||||||
|
_previouslyOpenedToolTip.IsOpen = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ContextMenuListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
var listView = sender as ListView;
|
||||||
|
if (listView.SelectedItem != null)
|
||||||
|
{
|
||||||
|
ListBoxItem listBoxItem = (ListBoxItem)listView.ItemContainerGenerator.ContainerFromItem(listView.SelectedItem);
|
||||||
|
ContentPresenter contentPresenter = FindVisualChild<ContentPresenter>(listBoxItem);
|
||||||
|
DataTemplate dataTemplate = contentPresenter.ContentTemplate;
|
||||||
|
Button button = (Button)dataTemplate.FindName("commandButton", contentPresenter);
|
||||||
|
ToolTip tooltip = button.ToolTip as ToolTip;
|
||||||
|
tooltip.PlacementTarget = button;
|
||||||
|
tooltip.Placement = System.Windows.Controls.Primitives.PlacementMode.Right;
|
||||||
|
tooltip.PlacementRectangle = new Rect(0, button.Height, 0, 0);
|
||||||
|
tooltip.IsOpen = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ToolTip_Opened(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (string.Equals(sender.GetType().FullName, "System.Windows.Controls.ToolTip", System.StringComparison.InvariantCulture))
|
||||||
|
{
|
||||||
|
HideCurrentToolTip();
|
||||||
|
_previouslyOpenedToolTip = (ToolTip)sender;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SuggestionsListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (string.Equals(((ListView)e.OriginalSource).Name, "SuggestionsList", System.StringComparison.InvariantCulture))
|
||||||
|
{
|
||||||
|
HideCurrentToolTip();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user