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

[WebSearch] Add copy URL to menu #3082

Merged
merged 2 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion Plugins/Flow.Launcher.Plugin.WebSearch/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
Thus, the generic formula for a search on Netflix is https://www.netflix.com/search?q={q}
</system:String>


<system:String x:Key="flowlauncher_plugin_websearch_copyurl_title">Copy URL</system:String>
<system:String x:Key="flowlauncher_plugin_websearch_copyurl_subtitle">Copy search URL to clipboard</system:String>

<!-- web search edit -->
<system:String x:Key="flowlauncher_plugin_websearch_title">Title</system:String>
Expand Down
3 changes: 2 additions & 1 deletion Plugins/Flow.Launcher.Plugin.WebSearch/Languages/ru.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
Thus, the generic formula for a search on Netflix is https://www.netflix.com/search?q={q}
</system:String>


<system:String x:Key="flowlauncher_plugin_websearch_copyurl_title">Скопировать URL-адрес</system:String>
<system:String x:Key="flowlauncher_plugin_websearch_copyurl_subtitle">Скопировать URL поиска в буфер обмена</system:String>

<!-- web search edit -->
<system:String x:Key="flowlauncher_plugin_websearch_title">Title</system:String>
Expand Down
27 changes: 24 additions & 3 deletions Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Flow.Launcher.Plugin.WebSearch
{
public class Main : IAsyncPlugin, ISettingProvider, IPluginI18n, IResultUpdated
public class Main : IAsyncPlugin, ISettingProvider, IPluginI18n, IResultUpdated, IContextMenu
{
private PluginInitContext _context;

Expand Down Expand Up @@ -76,7 +76,8 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
_context.API.OpenUrl(searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)));

return true;
}
},
ContextData = searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)),
};

results.Add(result);
Expand Down Expand Up @@ -139,11 +140,31 @@ private async Task<IEnumerable<Result>> SuggestionsAsync(string keyword, string
_context.API.OpenUrl(searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)));

return true;
}
},
ContextData = searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)),
});
return resultsFromSuggestion;
}

public List<Result> LoadContextMenus(Result selected)
{
if (selected?.ContextData == null || selected.ContextData is not string) return new List<Result>();
return new List<Result>() {
new Result
{
Title = _context.API.GetTranslation("flowlauncher_plugin_websearch_copyurl_title"),
SubTitle = _context.API.GetTranslation("flowlauncher_plugin_websearch_copyurl_subtitle"),
IcoPath = "Images/copylink.png",
Action = c =>
{
_context.API.CopyToClipboard(selected.ContextData as string);

return true;
}
},
};
}

public Task InitAsync(PluginInitContext context)
{
return Task.Run(Init);
Expand Down
Loading