Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fxcop] Fixes for Wox.Plugin (1of3) #7457

Merged
merged 31 commits into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
504f076
Merge pull request #1 from microsoft/master
avneet-kr Oct 9, 2020
daa3342
Merge pull request #2 from microsoft/master
avneet-kr Oct 15, 2020
e23d846
Merge branch 'master' of github.com:avneet-kr/PowerToys into master
avneet-kr Oct 16, 2020
48b7b2e
Merge branch 'master' of github.com:avneet-kr/PowerToys into master
avneet-kr Oct 19, 2020
da924fc
Merge branch 'master' of github.com:avneet-kr/PowerToys into master
avneet-kr Oct 20, 2020
2eb2191
Merge branch 'master' of github.com:avneet-kr/PowerToys into master
avneet-kr Oct 20, 2020
0506145
Merge branch 'master' of github.com:avneet-kr/PowerToys into master
avneet-kr Oct 22, 2020
0744d2f
Merge branch 'master' of github.com:avneet-kr/PowerToys into master
avneet-kr Oct 22, 2020
06053a4
Enabled FxCopAnalyzer for Wox.Plugin
avneet-kr Oct 19, 2020
6554c01
Added CultureInfo (CA1307: Specify StringComparison for clarity / CA1…
avneet-kr Oct 20, 2020
6124591
Check arguments and throw ArgumentNullException (CA1062: Validate arg…
avneet-kr Oct 20, 2020
556c6b4
Changed url parameter from string to System.Uri and added null checks…
avneet-kr Oct 20, 2020
58a91dd
Rethrow exception without specifying the exception explicitly (CA2200…
avneet-kr Oct 20, 2020
5723f6e
Changed from Collection property to methods for PluginMetadata::Actio…
avneet-kr Oct 20, 2020
8a55369
Changed from Collection property to methods for Result::GetTitleHighl…
avneet-kr Oct 20, 2020
3ee0980
Made Collection property read-only and added parameter in constructor…
avneet-kr Oct 20, 2020
cb4c580
Made Collection property read only and added parameter in constructor…
avneet-kr Oct 20, 2020
7f6c3a5
CA1507: Use nameof in place of string
avneet-kr Oct 20, 2020
64dc964
Removed initialization for ThemeManager::_disposed (CA1805: Do not in…
avneet-kr Oct 20, 2020
014841b
Changed Query::Terms array property to ReadOnlyCollection and added p…
avneet-kr Oct 22, 2020
7a7185f
CA1060: Move P/Invokes to NativeMethods class
avneet-kr Oct 21, 2020
10fe6c6
CA1806: Do not ignore method results
avneet-kr Oct 21, 2020
704e177
CA2101: Specify marshaling for P/Invoke string arguments
avneet-kr Oct 21, 2020
a683a43
Removed unnecessary empty interface IFeatures (CA1040: Avoid empty in…
avneet-kr Oct 21, 2020
731d71e
Added comments for CultureInfo (CA1307: Specify StringComparison for …
avneet-kr Oct 21, 2020
fe7aad3
Reverted "Enabled FxCopAnalyzer for Wox.Plugin"
avneet-kr Oct 22, 2020
b9ab10d
Merge branch 'master' of github.com:avneet-kr/PowerToys into master
avneet-kr Oct 22, 2020
94eab4e
Merge branch 'master' of github.com:avneet-kr/PowerToys into master
avneet-kr Oct 23, 2020
68f9cc6
Merge branch 'master' of github.com:avneet-kr/PowerToys into master
avneet-kr Oct 23, 2020
4540b43
Merge branch 'master' into FxCopAnalyzer_WoxPlugin
avneet-kr Oct 23, 2020
26e333b
Added localization for Wox.Plugin and localized strings in FilesFolde…
avneet-kr Oct 26, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ public class FileItemResult : IItemResult

public Wox.Plugin.Result Create(IPublicAPI contextApi)
{
var result = new Wox.Plugin.Result
var result = new Wox.Plugin.Result(StringMatcher.FuzzySearch(Search, Path.GetFileName(FilePath)).MatchData)
{
Title = Title,
SubTitle = string.Format(CultureInfo.CurrentCulture, Properties.Resources.wox_plugin_folder_select_file_result_subtitle, FilePath),
IcoPath = FilePath,
TitleHighlightData = StringMatcher.FuzzySearch(Search, Path.GetFileName(FilePath)).MatchData,
Action = c => ShellAction.Execute(FilePath, contextApi),
ContextData = new SearchResult { Type = ResultType.File, FullPath = FilePath },
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ public FolderItemResult(DisplayFileInfo fileSystemInfo)

public Wox.Plugin.Result Create(IPublicAPI contextApi)
{
return new Wox.Plugin.Result
return new Wox.Plugin.Result(StringMatcher.FuzzySearch(Search, Title).MatchData)
{
Title = Title,
IcoPath = Path,
SubTitle = string.Format(CultureInfo.CurrentCulture, Properties.Resources.wox_plugin_folder_select_folder_result_subtitle, Subtitle),
QueryTextDisplay = Path,
TitleHighlightData = StringMatcher.FuzzySearch(Search, Title).MatchData,
ContextData = new SearchResult { Type = ResultType.Folder, FullPath = Path },
Action = c => ShellAction.Execute(Path, contextApi),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ public class UserFolderResult : IItemResult

public Result Create(IPublicAPI contextApi)
{
return new Result
return new Result(StringMatcher.FuzzySearch(Search, Title).MatchData)
{
Title = Title,
IcoPath = Path,
SubTitle = string.Format(CultureInfo.CurrentCulture, Properties.Resources.wox_plugin_folder_select_folder_result_subtitle, Subtitle),
QueryTextDisplay = Path,
TitleHighlightData = StringMatcher.FuzzySearch(Search, Title).MatchData,
ContextData = new SearchResult { Type = ResultType.Folder, FullPath = Path },
Action = c => _shellAction.Execute(Path, contextApi),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using Microsoft.Plugin.Program.ProgramArgumentParser;
using Mono.Collections.Generic;
using NUnit.Framework;
using Wox.Plugin;

Expand Down Expand Up @@ -34,7 +35,7 @@ public void ProgramArgumentParserTestsCanParseQuery(string inputQuery, string ex
// basic version of the Quey parser which can be found at Wox.Core.Plugin.QueryBuilder but did not want to create a project reference
var splittedSearchString = inputQuery?.Split(Query.TermSeparator, System.StringSplitOptions.RemoveEmptyEntries);
var cleanQuery = string.Join(Query.TermSeparator, splittedSearchString);
var query = new Query(cleanQuery, cleanQuery, splittedSearchString, string.Empty);
var query = new Query(cleanQuery, cleanQuery, new ReadOnlyCollection<string>(splittedSearchString), string.Empty);

// Act
string program = null, programArguments = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public bool TryParse(Query query, out string program, out string programArgument
if (!string.IsNullOrEmpty(query?.Search))
{
// First Argument is always (part of) the program, 2nd term is possibly a Program Argument
if (query.Terms.Length > 1)
if (query.Terms.Count > 1)
{
for (var i = 1; i < query.Terms.Length; i++)
for (var i = 1; i < query.Terms.Count; i++)
{
if (!string.Equals(query.Terms[i], DoubleDash, StringComparison.Ordinal))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public bool TryParse(Query query, out string program, out string programArgument
if (!string.IsNullOrEmpty(query?.Search))
{
// First Argument is always (part of) the program, 2nd term is possibly a Program Argument
if (query.Terms.Length > 1)
if (query.Terms.Count > 1)
{
for (var i = 1; i < query.Terms.Length; i++)
for (var i = 1; i < query.Terms.Count; i++)
{
if (!ArgumentPrefixRegex.IsMatch(query.Terms[i]))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public Result Result(string query, string queryArguments, IPublicAPI api)

// To set the title to always be the displayname of the packaged application
result.Title = DisplayName;
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Name).MatchData;
result.SetTitleHighlightData(StringMatcher.FuzzySearch(query, Name).MatchData);

var toolTipTitle = string.Format(CultureInfo.CurrentCulture, "{0}: {1}", Properties.Resources.powertoys_run_plugin_program_file_name, result.Title);
var toolTipText = string.Format(CultureInfo.CurrentCulture, "{0}: {1}", Properties.Resources.powertoys_run_plugin_program_file_path, Package.Location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public Result Result(string query, string queryArguments, IPublicAPI api)

// 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;
result.SetTitleHighlightData(StringMatcher.FuzzySearch(query, Name).MatchData);

var toolTipTitle = string.Format(CultureInfo.CurrentCulture, "{0}: {1}", Properties.Resources.powertoys_run_plugin_program_file_name, result.Title);
var toolTipText = string.Format(CultureInfo.CurrentCulture, "{0}: {1}", Properties.Resources.powertoys_run_plugin_program_file_path, FullPath);
Expand Down
4 changes: 2 additions & 2 deletions src/modules/launcher/Wox.Core/Plugin/PluginConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ private static PluginMetadata GetPluginMetadata(string pluginDirectory)
metadata.PluginDirectory = pluginDirectory;

// for plugins which doesn't has ActionKeywords key
metadata.ActionKeywords = metadata.ActionKeywords ?? new List<string> { metadata.ActionKeyword };
metadata.SetActionKeywords(metadata.GetActionKeywords() ?? new List<string> { metadata.ActionKeyword });

// for plugin still use old ActionKeyword
metadata.ActionKeyword = metadata.ActionKeywords?[0];
metadata.ActionKeyword = metadata.GetActionKeywords()?[0];
}
catch (Exception e)
{
Expand Down
11 changes: 5 additions & 6 deletions src/modules/launcher/Wox.Core/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public static void InitializePlugins(IPublicAPI api)
}

// Plugins may have multiple ActionKeywords, eg. WebSearch
plugin.Metadata.ActionKeywords.Where(x => x != Query.GlobalPluginWildcardSign)
plugin.Metadata.GetActionKeywords().Where(x => x != Query.GlobalPluginWildcardSign)
.ToList()
.ForEach(x => NonGlobalPlugins[x] = plugin);
}
Expand Down Expand Up @@ -244,7 +244,7 @@ public static void UpdatePluginMetadata(List<Result> results, PluginMetadata met

private static bool IsGlobalPlugin(PluginMetadata metadata)
{
return metadata.ActionKeywords.Contains(Query.GlobalPluginWildcardSign);
return metadata.GetActionKeywords().Contains(Query.GlobalPluginWildcardSign);
}

/// <summary>
Expand All @@ -258,7 +258,6 @@ public static PluginPair GetPluginForId(string id)
}

public static IEnumerable<PluginPair> GetPluginsForInterface<T>()
where T : IFeatures
{
return AllPlugins.Where(p => p.Plugin is T);
}
Expand Down Expand Up @@ -320,7 +319,7 @@ public static void AddActionKeyword(string id, string newActionKeyword)
NonGlobalPlugins[newActionKeyword] = plugin;
}

plugin.Metadata.ActionKeywords.Add(newActionKeyword);
plugin.Metadata.GetActionKeywords().Add(newActionKeyword);
}

/// <summary>
Expand All @@ -332,7 +331,7 @@ public static void RemoveActionKeyword(string id, string oldActionkeyword)
var plugin = GetPluginForId(id);
if (oldActionkeyword == Query.GlobalPluginWildcardSign
&& // Plugins may have multiple ActionKeywords that are global, eg. WebSearch
plugin.Metadata.ActionKeywords
plugin.Metadata.GetActionKeywords()
.Where(x => x == Query.GlobalPluginWildcardSign)
.ToList()
.Count == 1)
Expand All @@ -345,7 +344,7 @@ public static void RemoveActionKeyword(string id, string oldActionkeyword)
NonGlobalPlugins.Remove(oldActionkeyword);
}

plugin.Metadata.ActionKeywords.Remove(oldActionkeyword);
plugin.Metadata.GetActionKeywords().Remove(oldActionkeyword);
}

public static void ReplaceActionKeyword(string id, string oldActionKeyword, string newActionKeyword)
Expand Down
5 changes: 3 additions & 2 deletions src/modules/launcher/Wox.Core/Plugin/QueryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Mono.Collections.Generic;
using Wox.Plugin;

namespace Wox.Core.Plugin
Expand Down Expand Up @@ -63,7 +64,7 @@ public static Dictionary<PluginPair, Query> Build(ref string text, Dictionary<st
}

// A new query is constructed for each plugin as they have different action keywords
var query = new Query(rawQuery, search, terms, pluginActionKeyword);
var query = new Query(rawQuery, search, new ReadOnlyCollection<string>(terms), pluginActionKeyword);

pluginQueryPair.TryAdd(pluginPair, query);
}
Expand All @@ -80,7 +81,7 @@ public static Dictionary<PluginPair, Query> Build(ref string text, Dictionary<st
{
if (!pluginQueryPair.ContainsKey(globalPlugin))
{
var query = new Query(rawQuery, rawQuery, terms, string.Empty);
var query = new Query(rawQuery, rawQuery, new ReadOnlyCollection<string>(terms), string.Empty);
pluginQueryPair.Add(globalPlugin, query);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void UpdatePluginSettings(List<PluginMetadata> metadatas)
var settings = Plugins[metadata.ID];
if (settings.ActionKeywords?.Count > 0)
{
metadata.ActionKeywords = settings.ActionKeywords;
metadata.SetActionKeywords(settings.ActionKeywords);
metadata.ActionKeyword = settings.ActionKeywords[0];
}

Expand All @@ -32,7 +32,7 @@ public void UpdatePluginSettings(List<PluginMetadata> metadatas)
{
ID = metadata.ID,
Name = metadata.Name,
ActionKeywords = metadata.ActionKeywords,
ActionKeywords = metadata.GetActionKeywords(),
Disabled = metadata.Disabled,
};
}
Expand Down
13 changes: 11 additions & 2 deletions src/modules/launcher/Wox.Plugin/AllowedLanguage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Globalization;

namespace Wox.Plugin
{
public static class AllowedLanguage
Expand All @@ -18,8 +21,14 @@ public static string Executable

public static bool IsAllowed(string language)
{
return language.ToUpper() == CSharp.ToUpper()
|| language.ToUpper() == Executable.ToUpper();
if (language == null)
{
throw new ArgumentNullException(nameof(language));
}

// Using InvariantCulture since this is a command line arg
return language.ToUpper(CultureInfo.InvariantCulture) == CSharp.ToUpper(CultureInfo.InvariantCulture)
|| language.ToUpper(CultureInfo.InvariantCulture) == Executable.ToUpper(CultureInfo.InvariantCulture);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,22 @@

namespace Wox.Plugin
{
public interface IFeatures
{
}

public interface IContextMenu : IFeatures
public interface IContextMenu
{
List<ContextMenuResult> LoadContextMenus(Result selectedResult);
}

/// <summary>
/// Represent plugins that support internationalization
/// </summary>
public interface IPluginI18n : IFeatures
public interface IPluginI18n
{
string GetTranslatedPluginTitle();

string GetTranslatedPluginDescription();
}

public interface IResultUpdated : IFeatures
public interface IResultUpdated
{
event ResultUpdatedEventHandler ResultsUpdated;
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/launcher/Wox.Plugin/IDelayedExecutionPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Wox.Plugin
{
public interface IDelayedExecutionPlugin : IFeatures
public interface IDelayedExecutionPlugin
{
List<Result> Query(Query query, bool delayedExecution);
}
Expand Down
14 changes: 14 additions & 0 deletions src/modules/launcher/Wox.Plugin/LocProject.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Projects": [
{
"LanguageSet": "Azure_Languages",
"LocItems": [
{
"SourceFile": "src\\modules\\launcher\\Wox.Plugin\\Properties\\Resources.resx",
"CopyOption": "LangIDOnName",
"OutputPath": "src\\modules\\launcher\\Wox.Plugin\\Properties"
}
]
}
]
}
17 changes: 16 additions & 1 deletion src/modules/launcher/Wox.Plugin/PluginMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ public class PluginMetadata : BaseModel
{
private string _pluginDirectory;

private List<string> _actionKeywords;

public PluginMetadata(List<string> actionKeywords = null)
{
_actionKeywords = actionKeywords;
}

public string ID { get; set; }

public string Name { get; set; }
Expand Down Expand Up @@ -51,7 +58,15 @@ internal set

public string ActionKeyword { get; set; }

public List<string> ActionKeywords { get; set; }
public List<string> GetActionKeywords()
{
return _actionKeywords;
}

public void SetActionKeywords(List<string> value)
{
_actionKeywords = value;
}

public string IcoPath { get; set; }

Expand Down
8 changes: 6 additions & 2 deletions src/modules/launcher/Wox.Plugin/PluginPair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;

namespace Wox.Plugin
{
public class PluginPair
Expand All @@ -19,7 +21,8 @@ public override bool Equals(object obj)
{
if (obj is PluginPair r)
{
return string.Equals(r.Metadata.ID, Metadata.ID);
// Using Ordinal since this is used internally
return string.Equals(r.Metadata.ID, Metadata.ID, StringComparison.Ordinal);
}
else
{
Expand All @@ -29,7 +32,8 @@ public override bool Equals(object obj)

public override int GetHashCode()
{
var hashcode = Metadata.ID?.GetHashCode() ?? 0;
// Using Ordinal since this is used internally
var hashcode = Metadata.ID?.GetHashCode(StringComparison.Ordinal) ?? 0;
return hashcode;
}
}
Expand Down
Loading