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:
Alekhya 2020-07-07 15:00:17 -07:00 committed by GitHub
parent 8d72bc0ea4
commit a314106b7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 46 additions and 27 deletions

View File

@ -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_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_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_path">Path</system:String>

View File

@ -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_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_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_path">Path</system:String>
</ResourceDictionary>

View File

@ -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_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_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_path">Path</system:String>

View File

@ -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_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_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_path">Path</system:String>

View File

@ -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_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_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_path">Path</system:String>

View File

@ -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_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_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_path">Path</system:String>

View File

@ -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_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_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_path">Path</system:String>

View File

@ -9,6 +9,7 @@ namespace Microsoft.Plugin.Program.Programs
Result Result(string query, IPublicAPI api);
string UniqueIdentifier { get; set; }
string Name { get; }
string Description { get; set; }
string Location { get; }
}
}

View File

@ -262,13 +262,20 @@ namespace Microsoft.Plugin.Program.Programs
public string LogoPath { get; set; }
public UWP Package { get; set; }
// Function to calculate the score of a result
private int Score(string query)
{
var displayNameMatch = StringMatcher.FuzzySearch(query, DisplayName);
var descriptionMatch = StringMatcher.FuzzySearch(query, Description);
var score = new[] { displayNameMatch.Score, descriptionMatch.Score/2 }.Max();
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)
{
@ -280,7 +287,7 @@ namespace Microsoft.Plugin.Program.Programs
var result = new Result
{
SubTitle = "Packaged application",
SubTitle = SetSubtitle(api),
Icon = Logo,
Score = score,
ContextData = this,
@ -291,17 +298,10 @@ namespace Microsoft.Plugin.Program.Programs
}
};
if (Description.Length >= DisplayName.Length &&
Description.Substring(0, DisplayName.Length) == DisplayName)
{
result.Title = Description;
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Description).MatchData;
}
else
{
result.Title = DisplayName;
result.TitleHighlightData = StringMatcher.FuzzySearch(query, DisplayName).MatchData;
}
// To set the title to always be the displayname of the packaged application
result.Title = DisplayName;
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"), Package.Location);

View File

@ -52,6 +52,7 @@ namespace Microsoft.Plugin.Program.Programs
RUN_COMMAND = 3
}
// Function to calculate the score of a result
private int Score(string query)
{
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
public string SetSubtitle(uint AppType, IPublicAPI api)
private string SetSubtitle(IPublicAPI api)
{
if(AppType == (uint)ApplicationTypes.WIN32_APPLICATION)
{
@ -168,7 +169,7 @@ namespace Microsoft.Plugin.Program.Programs
var result = new Result
{
SubTitle = SetSubtitle(AppType, api),
SubTitle = SetSubtitle(api),
IcoPath = IcoPath,
Score = score,
ContextData = this,
@ -187,17 +188,9 @@ namespace Microsoft.Plugin.Program.Programs
}
};
if (Description.Length >= Name.Length &&
Description.Substring(0, Name.Length) == Name)
{
result.Title = Description;
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Description).MatchData;
}
else
{
result.Title = Name;
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Name).MatchData;
}
// To set the title for the result to always be the name of the application
result.Title = Name;
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);

View File

@ -12,7 +12,7 @@ using System.IO;
namespace Wox.Test.Plugins
{
[TestFixture]
public class ProgramPluginTest
public class Win32Tests
{
Win32 notepad_appdata = new Win32
{
@ -138,6 +138,7 @@ namespace Wox.Test.Plugins
Win32 cmder_run_command = new Win32
{
Name = "Cmder",
Description = "Cmder: Lovely Console Emulator",
ExecutableName = "Cmder.exe",
FullPath = "c:\\tools\\cmder\\cmder.exe",
LnkResolvedPath = null,
@ -333,5 +334,21 @@ namespace Wox.Test.Plugins
// the query matches the name (cmd) and is therefore not filtered (case-insensitive)
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));
}
}
}