diff --git a/Build.ps1 b/Build.ps1 index 811b099..cb0b135 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -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 diff --git a/Community.PowerToys.Run.Plugin.WebSearchShortcut/Main.cs b/Community.PowerToys.Run.Plugin.WebSearchShortcut/Main.cs index c7c97d9..f02a2a2 100644 --- a/Community.PowerToys.Run.Plugin.WebSearchShortcut/Main.cs +++ b/Community.PowerToys.Run.Plugin.WebSearchShortcut/Main.cs @@ -104,8 +104,33 @@ public List 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() { @@ -114,6 +139,14 @@ public List Query(Query query) 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, }; } diff --git a/Community.PowerToys.Run.Plugin.WebSearchShortcut/plugin.json b/Community.PowerToys.Run.Plugin.WebSearchShortcut/plugin.json index 701aeef..3c0a236 100644 --- a/Community.PowerToys.Run.Plugin.WebSearchShortcut/plugin.json +++ b/Community.PowerToys.Run.Plugin.WebSearchShortcut/plugin.json @@ -1,7 +1,7 @@ { "ID": "B5E595872B8068104D5AD6BBE39A6664", "Disabled": false, - "ActionKeyword": ":?", + "ActionKeyword": "??", "IsGlobal": false, "Name": "Web Search Shortcut", "Author": "Daydreamer-riri", diff --git a/WebSearchShortcut-0.0.1-ARM64.zip b/WebSearchShortcut-0.0.1-ARM64.zip index 3f88018..e454795 100644 Binary files a/WebSearchShortcut-0.0.1-ARM64.zip and b/WebSearchShortcut-0.0.1-ARM64.zip differ diff --git a/WebSearchShortcut-0.0.1-x64.zip b/WebSearchShortcut-0.0.1-x64.zip index e1a9697..8548e6f 100644 Binary files a/WebSearchShortcut-0.0.1-x64.zip and b/WebSearchShortcut-0.0.1-x64.zip differ