mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
Set the name(not the description) as the Title of the Result (#4745)
* Added tests to verify that the name is always set as the title and never the description * removed AppType as an argument * refactored code * added comments * localized strings * removed empty constructor * made setsubtitle private * removed the mock Win32 class used for unit testing * removed the UWP tests
This commit is contained in:
@@ -39,6 +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_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_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_run_command">Run command</system:String>
|
||||||
|
<system:String x:Key="powertoys_run_plugin_program_packaged_application">Packaged application</system:String>
|
||||||
<system:String x:Key="powertoys_run_plugin_program_file_name">Name</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>
|
<system:String x:Key="powertoys_run_plugin_program_file_path">Path</system:String>
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,8 @@
|
|||||||
<system:String x:Key="powertoys_run_plugin_program_internet_shortcut_application">Internet shortcut application</system:String>
|
<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_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_run_command">Run command</system:String>
|
||||||
|
<system:String x:Key="powertoys_run_plugin_program_packaged_application">Packaged application</system:String>
|
||||||
<system:String x:Key="powertoys_run_plugin_program_file_name">Name</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>
|
<system:String x:Key="powertoys_run_plugin_program_file_path">Path</system:String>
|
||||||
|
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
@@ -40,6 +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_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_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_run_command">Run command</system:String>
|
||||||
|
<system:String x:Key="powertoys_run_plugin_program_packaged_application">Packaged application</system:String>
|
||||||
<system:String x:Key="powertoys_run_plugin_program_file_name">Name</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>
|
<system:String x:Key="powertoys_run_plugin_program_file_path">Path</system:String>
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +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_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_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_run_command">Run command</system:String>
|
||||||
|
<system:String x:Key="powertoys_run_plugin_program_packaged_application">Packaged application</system:String>
|
||||||
<system:String x:Key="powertoys_run_plugin_program_file_name">Name</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>
|
<system:String x:Key="powertoys_run_plugin_program_file_path">Path</system:String>
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +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_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_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_run_command">Run command</system:String>
|
||||||
|
<system:String x:Key="powertoys_run_plugin_program_packaged_application">Packaged application</system:String>
|
||||||
<system:String x:Key="powertoys_run_plugin_program_file_name">Name</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>
|
<system:String x:Key="powertoys_run_plugin_program_file_path">Path</system:String>
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +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_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_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_run_command">Run command</system:String>
|
||||||
|
<system:String x:Key="powertoys_run_plugin_program_packaged_application">Packaged application</system:String>
|
||||||
<system:String x:Key="powertoys_run_plugin_program_file_name">Name</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>
|
<system:String x:Key="powertoys_run_plugin_program_file_path">Path</system:String>
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +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_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_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_run_command">Run command</system:String>
|
||||||
|
<system:String x:Key="powertoys_run_plugin_program_packaged_application">Packaged application</system:String>
|
||||||
<system:String x:Key="powertoys_run_plugin_program_file_name">Name</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>
|
<system:String x:Key="powertoys_run_plugin_program_file_path">Path</system:String>
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
Result Result(string query, IPublicAPI api);
|
Result Result(string query, IPublicAPI api);
|
||||||
string UniqueIdentifier { get; set; }
|
string UniqueIdentifier { get; set; }
|
||||||
string Name { get; }
|
string Name { get; }
|
||||||
|
string Description { get; set; }
|
||||||
string Location { get; }
|
string Location { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -262,6 +262,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
public string LogoPath { get; set; }
|
public string LogoPath { get; set; }
|
||||||
public UWP Package { get; set; }
|
public UWP Package { get; set; }
|
||||||
|
|
||||||
|
// Function to calculate the score of a result
|
||||||
private int Score(string query)
|
private int Score(string query)
|
||||||
{
|
{
|
||||||
var displayNameMatch = StringMatcher.FuzzySearch(query, DisplayName);
|
var displayNameMatch = StringMatcher.FuzzySearch(query, DisplayName);
|
||||||
@@ -270,6 +271,12 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to set the subtitle based on the Type of application
|
||||||
|
private string SetSubtitle(IPublicAPI api)
|
||||||
|
{
|
||||||
|
return api.GetTranslation("powertoys_run_plugin_program_packaged_application");
|
||||||
|
}
|
||||||
|
|
||||||
public Result Result(string query, IPublicAPI api)
|
public Result Result(string query, IPublicAPI api)
|
||||||
{
|
{
|
||||||
var score = Score(query);
|
var score = Score(query);
|
||||||
@@ -280,7 +287,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
|
|
||||||
var result = new Result
|
var result = new Result
|
||||||
{
|
{
|
||||||
SubTitle = "Packaged application",
|
SubTitle = SetSubtitle(api),
|
||||||
Icon = Logo,
|
Icon = Logo,
|
||||||
Score = score,
|
Score = score,
|
||||||
ContextData = this,
|
ContextData = this,
|
||||||
@@ -291,17 +298,10 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Description.Length >= DisplayName.Length &&
|
// To set the title to always be the displayname of the packaged application
|
||||||
Description.Substring(0, DisplayName.Length) == DisplayName)
|
|
||||||
{
|
|
||||||
result.Title = Description;
|
|
||||||
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Description).MatchData;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result.Title = DisplayName;
|
result.Title = DisplayName;
|
||||||
result.TitleHighlightData = StringMatcher.FuzzySearch(query, DisplayName).MatchData;
|
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Name).MatchData;
|
||||||
}
|
|
||||||
|
|
||||||
var toolTipTitle = string.Format("{0} : {1}", api.GetTranslation("powertoys_run_plugin_program_file_name"), result.Title);
|
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);
|
var toolTipText = string.Format("{0} : {1}", api.GetTranslation("powertoys_run_plugin_program_file_path"), Package.Location);
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
RUN_COMMAND = 3
|
RUN_COMMAND = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to calculate the score of a result
|
||||||
private int Score(string query)
|
private int Score(string query)
|
||||||
{
|
{
|
||||||
var nameMatch = StringMatcher.FuzzySearch(query, Name);
|
var nameMatch = StringMatcher.FuzzySearch(query, Name);
|
||||||
@@ -103,7 +104,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Function to set the subtitle based on the Type of application
|
// Function to set the subtitle based on the Type of application
|
||||||
public string SetSubtitle(uint AppType, IPublicAPI api)
|
private string SetSubtitle(IPublicAPI api)
|
||||||
{
|
{
|
||||||
if(AppType == (uint)ApplicationTypes.WIN32_APPLICATION)
|
if(AppType == (uint)ApplicationTypes.WIN32_APPLICATION)
|
||||||
{
|
{
|
||||||
@@ -168,7 +169,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
|
|
||||||
var result = new Result
|
var result = new Result
|
||||||
{
|
{
|
||||||
SubTitle = SetSubtitle(AppType, api),
|
SubTitle = SetSubtitle(api),
|
||||||
IcoPath = IcoPath,
|
IcoPath = IcoPath,
|
||||||
Score = score,
|
Score = score,
|
||||||
ContextData = this,
|
ContextData = this,
|
||||||
@@ -187,17 +188,9 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Description.Length >= Name.Length &&
|
// To set the title for the result to always be the name of the application
|
||||||
Description.Substring(0, Name.Length) == Name)
|
|
||||||
{
|
|
||||||
result.Title = Description;
|
|
||||||
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Description).MatchData;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result.Title = Name;
|
result.Title = Name;
|
||||||
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Name).MatchData;
|
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Name).MatchData;
|
||||||
}
|
|
||||||
|
|
||||||
var toolTipTitle = string.Format("{0} : {1}", api.GetTranslation("powertoys_run_plugin_program_file_name"), result.Title);
|
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);
|
var toolTipText = string.Format("{0} : {1}", api.GetTranslation("powertoys_run_plugin_program_file_path"), FullPath);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ using System.IO;
|
|||||||
namespace Wox.Test.Plugins
|
namespace Wox.Test.Plugins
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class ProgramPluginTest
|
public class Win32Tests
|
||||||
{
|
{
|
||||||
Win32 notepad_appdata = new Win32
|
Win32 notepad_appdata = new Win32
|
||||||
{
|
{
|
||||||
@@ -138,6 +138,7 @@ namespace Wox.Test.Plugins
|
|||||||
Win32 cmder_run_command = new Win32
|
Win32 cmder_run_command = new Win32
|
||||||
{
|
{
|
||||||
Name = "Cmder",
|
Name = "Cmder",
|
||||||
|
Description = "Cmder: Lovely Console Emulator",
|
||||||
ExecutableName = "Cmder.exe",
|
ExecutableName = "Cmder.exe",
|
||||||
FullPath = "c:\\tools\\cmder\\cmder.exe",
|
FullPath = "c:\\tools\\cmder\\cmder.exe",
|
||||||
LnkResolvedPath = null,
|
LnkResolvedPath = null,
|
||||||
@@ -333,5 +334,21 @@ namespace Wox.Test.Plugins
|
|||||||
// the query matches the name (cmd) and is therefore not filtered (case-insensitive)
|
// the query matches the name (cmd) and is therefore not filtered (case-insensitive)
|
||||||
Assert.IsTrue(cmd_run_command.QueryEqualsNameForRunCommands(query));
|
Assert.IsTrue(cmd_run_command.QueryEqualsNameForRunCommands(query));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Win32Apps_ShouldSetNameAsTitle_WhileCreatingResult()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var mock = new Mock<IPublicAPI>();
|
||||||
|
mock.Setup(x => x.GetTranslation(It.IsAny<string>())).Returns(It.IsAny<string>());
|
||||||
|
StringMatcher.Instance = new StringMatcher();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = cmder_run_command.Result("cmder", mock.Object);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.IsTrue(result.Title.Equals(cmder_run_command.Name));
|
||||||
|
Assert.IsFalse(result.Title.Equals(cmder_run_command.Description));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user