Skip to content

Commit

Permalink
feat: remove /w- prefix command to ContextMenuResult
Browse files Browse the repository at this point in the history
  • Loading branch information
CCcat8059 committed Mar 17, 2024
1 parent 123404e commit 18638df
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
23 changes: 7 additions & 16 deletions Classes/DataHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,25 +153,16 @@ public Result AddWebData(List<string> terms)
}
};
}
public List<Result> GetRemovableList(string keyword)
public bool RemoveKeyword(string keyword)
{
List<Result> results = GetMatchingKeywords(keyword[1..].Trim());
foreach (Result result in results)
WebDatas.RemoveAll(w => w.Keyword == keyword);
if (!Main.IsPluginDirectoryValid)
{
result.IcoPath = Main.IconPath["DeleteKeyword"];
result.Action = _ =>
{
WebDatas.RemoveAll(w => w.Keyword == result.Title);
if (!Main.IsPluginDirectoryValid)
{
Log.Error($"Plugin: {PR.plugin_name}\nplugin path not found", typeof(WebData));
return false;
}
DumpWebDatasToJSON();
return true;
};
Log.Error($"Plugin: {PR.plugin_name}\nplugin path not found", typeof(WebData));
return false;
}
return results;
DumpWebDatasToJSON();
return true;
}
}
}
Expand Down
Binary file removed Images/DeleteKeyword.dark.png
Binary file not shown.
Binary file removed Images/DeleteKeyword.light.png
Binary file not shown.
17 changes: 13 additions & 4 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ public List<Result> Query(Query query)
{
results.Add(DH.AddWebData(new(query.Terms)));
}
else if (query.Search.StartsWith("-"))
{
return DH.GetRemovableList(query.Search);
}

results.AddRange(DH.GetMatchingKeywords(query.Search));
return results;
Expand Down Expand Up @@ -174,6 +170,19 @@ protected virtual void Dispose(bool disposing)

public List<ContextMenuResult> LoadContextMenus(Result selectedResult) => new List<ContextMenuResult>()
{
new ContextMenuResult()
{
PluginName = PR.plugin_name,
Title = "Remove this keyword",
Glyph = "\xE74D",
FontFamily = "Segoe Fluent Icons, Segoe MDL2 Assets",
AcceleratorKey = System.Windows.Input.Key.D,
AcceleratorModifiers = System.Windows.Input.ModifierKeys.Control,
Action = _ =>
{
return DH.RemoveKeyword(selectedResult.Title);
}
},
new ContextMenuResult()
{
PluginName = PR.plugin_name,
Expand Down

0 comments on commit 18638df

Please sign in to comment.