From 7faa4bb0f4e0dbcf105f86db09dbd052ca4ddfb2 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 8 Feb 2022 20:03:52 +1100 Subject: [PATCH] add IPathSelected interface for query window hotkey path capture --- Flow.Launcher.Core/Plugin/PluginManager.cs | 11 ++++++- .../Interfaces/IPathSelected.cs | 13 +++++++++ Flow.Launcher/MainWindow.xaml | 2 +- Flow.Launcher/ViewModel/MainViewModel.cs | 29 +++++++++++++++++++ Plugins/Flow.Launcher.Plugin.Explorer/Main.cs | 9 +++++- 5 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 Flow.Launcher.Plugin/Interfaces/IPathSelected.cs diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index 134c3c002..7c0727b66 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; @@ -179,6 +179,15 @@ namespace Flow.Launcher.Core.Plugin } } + public static async Task PublishPathSelectedFromResult(string selectedPath, string hotkey) + { + await Task.WhenAll(AllPlugins.Select(plugin => plugin.Plugin switch + { + IPathSelected p => p.PathSelected(selectedPath, hotkey), + _ => Task.CompletedTask, + })); + } + public static async Task> QueryForPluginAsync(PluginPair pair, Query query, CancellationToken token) { var results = new List(); diff --git a/Flow.Launcher.Plugin/Interfaces/IPathSelected.cs b/Flow.Launcher.Plugin/Interfaces/IPathSelected.cs new file mode 100644 index 000000000..bb7ad6ddc --- /dev/null +++ b/Flow.Launcher.Plugin/Interfaces/IPathSelected.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Flow.Launcher.Plugin +{ + public interface IPathSelected : IFeatures + { + Task PathSelected(string path, string hotkey); + } +} diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index 714fcc53f..ec2d28ebf 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -39,7 +39,7 @@ - + { SelectedResults.SelectPrevPage(); }); + F1SelectedCommand = new RelayCommand(_ => + { + var results = SelectedResults; + var result = results.SelectedItem?.Result; + + if (result is null) + return; + + var selectedPath = string.Empty; + + if (File.Exists(result.Title) || Directory.Exists(result.Title)) + { + selectedPath = result.Title; + } + else if (File.Exists(result.SubTitle) || Directory.Exists(result.SubTitle)) + { + selectedPath = result.SubTitle; + } + else if (!string.IsNullOrEmpty(result.IcoPath)) + { + selectedPath = result.IcoPath; + } + + PluginManager.PublishPathSelectedFromResult(selectedPath, "f1"); + + }); + SelectFirstResultCommand = new RelayCommand(_ => SelectedResults.SelectFirstResult()); StartHelpCommand = new RelayCommand(_ => @@ -430,6 +457,8 @@ namespace Flow.Launcher.ViewModel public ICommand AutocompleteQueryCommand { get; set; } + public ICommand F1SelectedCommand { get; set; } + public string OpenResultCommandModifiers { get; private set; } public string Image => Constant.QueryTextBoxIconImagePath; diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs index 60208759e..8133eba6a 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs @@ -11,7 +11,7 @@ using System.Windows.Controls; namespace Flow.Launcher.Plugin.Explorer { - public class Main : ISettingProvider, IAsyncPlugin, IContextMenu, IPluginI18n + public class Main : ISettingProvider, IAsyncPlugin, IContextMenu, IPluginI18n, IPathSelected { internal PluginInitContext Context { get; set; } @@ -28,6 +28,13 @@ namespace Flow.Launcher.Plugin.Explorer return new ExplorerSettings(viewModel); } + public Task PathSelected(string filePath, string hotkey) + { + //checked the hotkey if is ctrl+c, then + //copy file to clipboard. + return Task.CompletedTask; + } + public Task InitAsync(PluginInitContext context) { Context = context;