Tooltip for indexer and program plugin (#4589)

* Fix multiline title issue

* Added code to display tooltip for program and indexer plugin

* Added tests for Result class

* Theme based color for tooltip

* Added colors for tooltip

* Added string tags to tooltip

* Add initial show delay

* Seperated textbox for title and path
This commit is contained in:
Divyansh Srivastava 2020-07-07 13:02:39 -07:00 committed by GitHub
parent 1533c9315f
commit 8d72bc0ea4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 207 additions and 7 deletions

View File

@ -4,5 +4,7 @@
<system:String x:Key="Microsoft_plugin_indexer_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_name">Name</system:String>
<system:String x:Key="Microsoft_plugin_indexer_path">Path</system:String>
</ResourceDictionary>

View File

@ -4,5 +4,7 @@
<system:String x:Key="Microsoft_plugin_indexer_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_name">Name</system:String>
<system:String x:Key="Microsoft_plugin_indexer_path">Path</system:String>
</ResourceDictionary>

View File

@ -4,5 +4,7 @@
<system:String x:Key="Microsoft_plugin_indexer_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_name">Name</system:String>
<system:String x:Key="Microsoft_plugin_indexer_path">Path</system:String>
</ResourceDictionary>

View File

@ -4,5 +4,7 @@
<system:String x:Key="Microsoft_plugin_indexer_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_name">Name</system:String>
<system:String x:Key="Microsoft_plugin_indexer_path">Path</system:String>
</ResourceDictionary>

View File

@ -4,5 +4,7 @@
<system:String x:Key="Microsoft_plugin_indexer_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_name">Name</system:String>
<system:String x:Key="Microsoft_plugin_indexer_path">Path</system:String>
</ResourceDictionary>

View File

@ -4,5 +4,7 @@
<system:String x:Key="Microsoft_plugin_indexer_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_name">Name</system:String>
<system:String x:Key="Microsoft_plugin_indexer_path">Path</system:String>
</ResourceDictionary>

View File

@ -4,5 +4,7 @@
<system:String x:Key="Microsoft_plugin_indexer_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_name">Name</system:String>
<system:String x:Key="Microsoft_plugin_indexer_path">Path</system:String>
</ResourceDictionary>

View File

@ -65,7 +65,8 @@ namespace Microsoft.Plugin.Indexer
foreach (var searchResult in searchResultsList)
{
var path = searchResult.Path;
var toolTipTitle = string.Format("{0} : {1}", _context.API.GetTranslation("Microsoft_plugin_indexer_name"), searchResult.Title);
var toolTipText = string.Format("{0} : {1}", _context.API.GetTranslation("Microsoft_plugin_indexer_path"), path);
string workingDir = null;
if (_settings.UseLocationAsWorkingDir)
workingDir = Path.GetDirectoryName(path);
@ -74,6 +75,7 @@ namespace Microsoft.Plugin.Indexer
r.Title = searchResult.Title;
r.SubTitle = "Search: " + path;
r.IcoPath = path;
r.ToolTipData = new ToolTipData(toolTipTitle, toolTipText);
r.Action = c =>
{
bool hide;

View File

@ -39,5 +39,7 @@
<system:String x:Key="powertoys_run_plugin_program_internet_shortcut_application">Weblink-Anwendung</system:String>
<system:String x:Key="powertoys_run_plugin_program_web_application">Web-Anwendung</system:String>
<system:String x:Key="powertoys_run_plugin_program_run_command">Run command</system:String>
<system:String x:Key="powertoys_run_plugin_program_file_name">Name</system:String>
<system:String x:Key="powertoys_run_plugin_program_file_path">Path</system:String>
</ResourceDictionary>

View File

@ -50,4 +50,6 @@
<system:String x:Key="powertoys_run_plugin_program_internet_shortcut_application">Internet shortcut application</system:String>
<system:String x:Key="powertoys_run_plugin_program_web_application">Web application</system:String>
<system:String x:Key="powertoys_run_plugin_program_run_command">Run command</system:String>
<system:String x:Key="powertoys_run_plugin_program_file_name">Name</system:String>
<system:String x:Key="powertoys_run_plugin_program_file_path">Path</system:String>
</ResourceDictionary>

View File

@ -40,5 +40,7 @@
<system:String x:Key="powertoys_run_plugin_program_internet_shortcut_application">Internet shortcut application</system:String>
<system:String x:Key="powertoys_run_plugin_program_web_application">Web application</system:String>
<system:String x:Key="powertoys_run_plugin_program_run_command">Run command</system:String>
<system:String x:Key="powertoys_run_plugin_program_file_name">Name</system:String>
<system:String x:Key="powertoys_run_plugin_program_file_path">Path</system:String>
</ResourceDictionary>

View File

@ -39,5 +39,7 @@
<system:String x:Key="powertoys_run_plugin_program_internet_shortcut_application">Internet shortcut application</system:String>
<system:String x:Key="powertoys_run_plugin_program_web_application">Web application</system:String>
<system:String x:Key="powertoys_run_plugin_program_run_command">Run command</system:String>
<system:String x:Key="powertoys_run_plugin_program_file_name">Name</system:String>
<system:String x:Key="powertoys_run_plugin_program_file_path">Path</system:String>
</ResourceDictionary>

View File

@ -41,5 +41,7 @@
<system:String x:Key="powertoys_run_plugin_program_internet_shortcut_application">Internet shortcut application</system:String>
<system:String x:Key="powertoys_run_plugin_program_web_application">Web application</system:String>
<system:String x:Key="powertoys_run_plugin_program_run_command">Run command</system:String>
<system:String x:Key="powertoys_run_plugin_program_file_name">Name</system:String>
<system:String x:Key="powertoys_run_plugin_program_file_path">Path</system:String>
</ResourceDictionary>

View File

@ -41,5 +41,7 @@
<system:String x:Key="powertoys_run_plugin_program_internet_shortcut_application">Internet shortcut application</system:String>
<system:String x:Key="powertoys_run_plugin_program_web_application">Web application</system:String>
<system:String x:Key="powertoys_run_plugin_program_run_command">Run command</system:String>
<system:String x:Key="powertoys_run_plugin_program_file_name">Name</system:String>
<system:String x:Key="powertoys_run_plugin_program_file_path">Path</system:String>
</ResourceDictionary>

View File

@ -39,5 +39,7 @@
<system:String x:Key="powertoys_run_plugin_program_internet_shortcut_application">Internet shortcut application</system:String>
<system:String x:Key="powertoys_run_plugin_program_web_application">Web application</system:String>
<system:String x:Key="powertoys_run_plugin_program_run_command">Run command</system:String>
<system:String x:Key="powertoys_run_plugin_program_file_name">Name</system:String>
<system:String x:Key="powertoys_run_plugin_program_file_path">Path</system:String>
</ResourceDictionary>

View File

@ -301,7 +301,12 @@ namespace Microsoft.Plugin.Program.Programs
{
result.Title = DisplayName;
result.TitleHighlightData = StringMatcher.FuzzySearch(query, DisplayName).MatchData;
}
}
var toolTipTitle = string.Format("{0} : {1}", api.GetTranslation("powertoys_run_plugin_program_file_name"), result.Title);
var toolTipText = string.Format("{0} : {1}", api.GetTranslation("powertoys_run_plugin_program_file_path"), Package.Location);
result.ToolTipData = new ToolTipData(toolTipTitle, toolTipText);
return result;
}

View File

@ -199,6 +199,10 @@ namespace Microsoft.Plugin.Program.Programs
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Name).MatchData;
}
var toolTipTitle = string.Format("{0} : {1}", api.GetTranslation("powertoys_run_plugin_program_file_name"), result.Title);
var toolTipText = string.Format("{0} : {1}", api.GetTranslation("powertoys_run_plugin_program_file_path"), FullPath);
result.ToolTipData = new ToolTipData(toolTipTitle, toolTipText);
return result;
}

View File

@ -113,6 +113,13 @@
</Setter.Value>
</Setter>
</Style>
<Style x:Key="CollapsableTextblock" TargetType="TextBlock">
<Style.Triggers>
<Trigger Property="Text" Value="">
<Setter Property="Visibility" Value="Collapsed"/>
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
</UserControl.Resources>
@ -137,7 +144,13 @@
<!--Style="{StaticResource ListViewNoAnimations}"-->
<ListView.ItemTemplate>
<DataTemplate >
<Grid Height="72" Width="642" Background="Transparent" >
<Grid
Height="72"
Width="642"
Background="Transparent"
ToolTipService.BetweenShowDelay="0"
ToolTipService.InitialShowDelay="1000"
>
<Behaviors:Interaction.Triggers>
<Behaviors:EventTrigger EventName="MouseEnter">
<Behaviors:InvokeCommandAction Command="{Binding ActivateContextButtonsHoverCommand}"/>
@ -155,6 +168,26 @@
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ToolTip>
<ToolTip
Visibility="{Binding Result.ToolTipVisibility}"
BorderThickness="1"
BorderBrush="{DynamicResource ToolTipBorderBrushKey}"
Background="{DynamicResource ToolTipBackgroundBrushKey}">
<StackPanel>
<TextBlock
Style="{DynamicResource CollapsableTextblock}"
Text="{Binding Result.ToolTipData.Title}"
Foreground="{DynamicResource ToolTipForegroundBrushKey}"
TextWrapping="Wrap" />
<TextBlock
Style="{DynamicResource CollapsableTextblock}"
Text="{Binding Result.ToolTipData.Text}"
Foreground="{DynamicResource ToolTipForegroundBrushKey}"
TextWrapping="Wrap" />
</StackPanel>
</ToolTip>
</Grid.ToolTip>
<Image x:Name="AppIcon" Height="36" MaxWidth="56" Grid.RowSpan="2" Margin="-6,-2,0,0" HorizontalAlignment="Center" Source="{Binding Image}" />
<TextBlock x:Name="Title" Grid.Column="1" Text="{Binding Result.Title}" FontWeight="SemiBold" FontSize="20" Margin="0,0,0,-2" VerticalAlignment="Bottom"/>
<TextBlock x:Name="Path" Grid.Column="1" Text= "{Binding Result.SubTitle}" Grid.Row="1" Foreground="{DynamicResource SecondaryTextForeground}" Margin="0,2,0,0" VerticalAlignment="Top"/>

View File

@ -43,4 +43,8 @@
<SolidColorBrush x:Key="ScrollBarLineButtonBackground" Color="Transparent"/>
<Color x:Key="ScrollBarLineButtonBackgroundPointerOver">#FF313131</Color>
<Color x:Key="ScrollBarLineButtonBackgroundPointerPressed">#FFa4a4a4</Color>
<SolidColorBrush x:Key="ToolTipBorderBrushKey" Color="#FFFFFFFF" />
<SolidColorBrush x:Key="ToolTipForegroundBrushKey" Color="#FFFFFFFF" />
<SolidColorBrush x:Key="ToolTipBackgroundBrushKey" Color="#FF171717" />
</ResourceDictionary>

View File

@ -43,4 +43,8 @@
<SolidColorBrush x:Key="ScrollBarLineButtonBackground" Color="Black"/>
<Color x:Key="ScrollBarLineButtonBackgroundPointerOver">#FF000000</Color>
<Color x:Key="ScrollBarLineButtonBackgroundPointerPressed">#FF000000</Color>
<SolidColorBrush x:Key="ToolTipBorderBrushKey" Color="#FFFFFFFF" />
<SolidColorBrush x:Key="ToolTipForegroundBrushKey" Color="#FFFFFFFF" />
<SolidColorBrush x:Key="ToolTipBackgroundBrushKey" Color="#FF171717" />
</ResourceDictionary>

View File

@ -43,4 +43,8 @@
<SolidColorBrush x:Key="ScrollBarLineButtonBackground" Color="Transparent"/>
<Color x:Key="ScrollBarLineButtonBackgroundPointerOver">#FF000000</Color>
<Color x:Key="ScrollBarLineButtonBackgroundPointerPressed">#FF000000</Color>
<SolidColorBrush x:Key="ToolTipBorderBrushKey" Color="#FFFFFFFF" />
<SolidColorBrush x:Key="ToolTipForegroundBrushKey" Color="#FFFFFFFF" />
<SolidColorBrush x:Key="ToolTipBackgroundBrushKey" Color="#FF171717" />
</ResourceDictionary>

View File

@ -42,5 +42,8 @@
<SolidColorBrush x:Key="ScrollBarLineButtonBackground" Color="Transparent"/>
<Color x:Key="ScrollBarLineButtonBackgroundPointerOver">#FF000000</Color>
<Color x:Key="ScrollBarLineButtonBackgroundPointerPressed">#FF000000</Color>
<SolidColorBrush x:Key="ToolTipBorderBrushKey" Color="#FFFFFFFF" />
<SolidColorBrush x:Key="ToolTipForegroundBrushKey" Color="#FFFFFFFF" />
<SolidColorBrush x:Key="ToolTipBackgroundBrushKey" Color="#FF171717" />
</ResourceDictionary>

View File

@ -42,4 +42,8 @@
<SolidColorBrush x:Key="ScrollBarLineButtonBackground" Color="Transparent"/>
<Color x:Key="ScrollBarLineButtonBackgroundPointerOver">#FF000000</Color>
<Color x:Key="ScrollBarLineButtonBackgroundPointerPressed">#FF000000</Color>
<SolidColorBrush x:Key="ToolTipBorderBrushKey" Color="#FF000000" />
<SolidColorBrush x:Key="ToolTipForegroundBrushKey" Color="#FF000000" />
<SolidColorBrush x:Key="ToolTipBackgroundBrushKey" Color="#FFF2F2F2" />
</ResourceDictionary>

View File

@ -42,4 +42,8 @@
<SolidColorBrush x:Key="ScrollBarLineButtonBackground" Color="Transparent"/>
<Color x:Key="ScrollBarLineButtonBackgroundPointerOver">#FFd2d2d2</Color>
<Color x:Key="ScrollBarLineButtonBackgroundPointerPressed">#FF5d5d5d</Color>
<SolidColorBrush x:Key="ToolTipBorderBrushKey" Color="#FF000000" />
<SolidColorBrush x:Key="ToolTipForegroundBrushKey" Color="#FF000000" />
<SolidColorBrush x:Key="ToolTipBackgroundBrushKey" Color="#FFF2F2F2" />
</ResourceDictionary>

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Windows.Media;
using System.Windows;
namespace Wox.Plugin
{
@ -9,14 +10,37 @@ namespace Wox.Plugin
public class Result
{
private string _title;
private ToolTipData _toolTipData;
private string _pluginDirectory;
private string _icoPath;
public string Title { get; set; }
public string Title {
get { return _title; }
set
{
_title = value.Replace("\n", " ");
}
}
public string SubTitle { get; set; }
public string Glyph { get; set; }
public string FontFamily { get; set; }
public string FontFamily { get; set; }
public Visibility ToolTipVisibility { get; set; } = Visibility.Collapsed;
public ToolTipData ToolTipData
{
get
{
return _toolTipData;
}
set
{
_toolTipData = value;
ToolTipVisibility = Visibility.Visible;
}
}
/// <summary>
/// The text that will get displayed in the Search text box, when this item is selected in the result list.

View File

@ -0,0 +1,21 @@
using System;
namespace Wox.Plugin
{
public class ToolTipData
{
public string Title { get; private set; }
public string Text { get; private set; }
public ToolTipData(string title, string text)
{
if(string.IsNullOrEmpty(title))
{
throw new ArgumentException("title cannot be null or empty", "title");
}
Title = title;
Text = text;
}
}
}

View File

@ -0,0 +1,37 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using Wox.Plugin;
namespace Wox.Test.Plugins
{
[TestFixture]
class ResultTest
{
[Test]
public void Result_UpdatesToolTipVisibilityToVisible_WhenToolTipDataIsSet()
{
// Arrange
Result res = new Result();
string toolTipText = "ToolTipText";
// Act
res.ToolTipData = new ToolTipData(toolTipText, string.Empty);
// Assert
Assert.AreEqual(res.ToolTipVisibility, Visibility.Visible);
}
[Test]
public void Result_UpdatesToolTipVisibilityToCollapsed_WhenToolTipDataIsNotSet()
{
// Act
Result res = new Result();
// Assert
Assert.AreEqual(res.ToolTipVisibility, Visibility.Collapsed);
}
}
}

View File

@ -0,0 +1,23 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Text;
using Wox.Plugin;
namespace Wox.Test.Plugins
{
[TestFixture]
class ToolTipDataTest
{
[Test]
public void Constructor_ThrowsNullArgumentException_WhenToolTipTitleIsNull()
{
// Arrange
string title = null;
string text = "text";
// Assert
var ex = Assert.Throws<ArgumentException>(() => new ToolTipData(title, text));
}
}
}