Skip to content

Commit

Permalink
Set the name(not the description) as the Title of the Result (#4745)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
alekhyareddy28 committed Jul 7, 2020
1 parent 8d72bc0 commit a314106
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public interface IProgram
Result Result(string query, IPublicAPI api);
string UniqueIdentifier { get; set; }
string Name { get; }
string Description { get; set; }
string Location { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,20 @@ public class Application : IProgram
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)
{
Expand All @@ -280,7 +287,7 @@ public Result Result(string query, IPublicAPI api)

var result = new Result
{
SubTitle = "Packaged application",
SubTitle = SetSubtitle(api),
Icon = Logo,
Score = score,
ContextData = this,
Expand All @@ -291,17 +298,10 @@ public Result Result(string query, IPublicAPI api)
}
};

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ private enum ApplicationTypes
RUN_COMMAND = 3
}

// Function to calculate the score of a result
private int Score(string query)
{
var nameMatch = StringMatcher.FuzzySearch(query, Name);
Expand Down Expand Up @@ -103,7 +104,7 @@ public bool FilterWebApplication(string query)
}

// 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)
{
Expand Down Expand Up @@ -168,7 +169,7 @@ public Result Result(string query, IPublicAPI api)

var result = new Result
{
SubTitle = SetSubtitle(AppType, api),
SubTitle = SetSubtitle(api),
IcoPath = IcoPath,
Score = score,
ContextData = this,
Expand All @@ -187,17 +188,9 @@ public Result Result(string query, IPublicAPI api)
}
};

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Wox.Test.Plugins
{
[TestFixture]
public class ProgramPluginTest
public class Win32Tests
{
Win32 notepad_appdata = new Win32
{
Expand Down Expand Up @@ -138,6 +138,7 @@ public class ProgramPluginTest
Win32 cmder_run_command = new Win32
{
Name = "Cmder",
Description = "Cmder: Lovely Console Emulator",
ExecutableName = "Cmder.exe",
FullPath = "c:\\tools\\cmder\\cmder.exe",
LnkResolvedPath = null,
Expand Down Expand Up @@ -333,5 +334,21 @@ public void RunCommands_ShouldNotBeFiltered_OnExactMatch(string query)
// 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));
}
}
}

0 comments on commit a314106

Please sign in to comment.