Skip to content

Commit

Permalink
feat: 🚧 change query
Browse files Browse the repository at this point in the history
  • Loading branch information
Daydreamer-riri committed Mar 17, 2024
1 parent 8a289d2 commit f7c3e09
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ foreach ($platform in "ARM64", "x64")
{
Remove-Item -Path "$PSScriptRoot\Community.PowerToys.Run.Plugin.WebSearchShortcut\bin\*" -Recurse
}
if (Test-Path -Path "$PSScriptRoot\WebSearchShortcut-$version-$platform.zip")
{
Remove-Item -Path "$PSScriptRoot\WebSearchShortcut-$version-$platform.zip"
}

dotnet build $PSScriptRoot\PowerToys-Run-WebSearchShortcut.sln -c Release /p:Platform=$platform

Expand Down
37 changes: 35 additions & 2 deletions Community.PowerToys.Run.Plugin.WebSearchShortcut/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,33 @@ public List<Result> Query(Query query)
return WebSearchShortcutStorage.GetRecords().Select(GetResultForGetRecord).ToList();
}

return WebSearchShortcutStorage.GetRecords(args).Select(GetResultForGetRecord).ToList() ?? [];

var tokens = args.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries);
if (tokens.Length == 1)
{
return WebSearchShortcutStorage.GetRecords(args).Select(GetResultForGetRecord).ToList() ?? [];
}

var item = WebSearchShortcutStorage.GetRecords(tokens[0]).ToList()[0];
if (item is null)
{
return [];
}
return [
new Result
{
QueryTextDisplay = args,
IcoPath = IconPath,
Title = $"{item.Name}: {tokens[1]}",
SubTitle = $"Search for {item.Name} with {tokens[1]}",
// Action = _ =>
// {
// Context!.API.ChangeQuery(item.Url);
// return false;
// },
Score = 1000,
ContextData = item,
}
];

Result GetResultForGetRecord(Item record) => new()
{
Expand All @@ -114,6 +139,14 @@ Result GetResultForGetRecord(Item record) => new()
Title = record.Name,
SubTitle = record.Url,
// ToolTipData = new ToolTipData("Get", $"Key: {record.Key}\nValue: {record.Value}\nCreated: {record.Created}\nUpdated: {record.Updated}"),
Action = _ =>
{
var newQuery = string.IsNullOrWhiteSpace(query.ActionKeyword)
? $"{record.Name} "
: $"{query.ActionKeyword} {record.Name} ";
Context!.API.ChangeQuery(newQuery, true);
return false;
},
ContextData = record,
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"ID": "B5E595872B8068104D5AD6BBE39A6664",
"Disabled": false,
"ActionKeyword": ":?",
"ActionKeyword": "??",
"IsGlobal": false,
"Name": "Web Search Shortcut",
"Author": "Daydreamer-riri",
Expand Down
Binary file modified WebSearchShortcut-0.0.1-ARM64.zip
Binary file not shown.
Binary file modified WebSearchShortcut-0.0.1-x64.zip
Binary file not shown.

0 comments on commit f7c3e09

Please sign in to comment.