add IPathSelected interface for query window hotkey path capture

This commit is contained in:
Jeremy 2022-02-08 20:03:52 +11:00
parent 11f1f402b2
commit 7faa4bb0f4
5 changed files with 61 additions and 3 deletions

View file

@ -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<List<Result>> QueryForPluginAsync(PluginPair pair, Query query, CancellationToken token)
{
var results = new List<Result>();

View file

@ -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);
}
}

View file

@ -39,7 +39,7 @@
</Window.Resources>
<Window.InputBindings>
<KeyBinding Key="Escape" Command="{Binding EscCommand}" />
<KeyBinding Key="F1" Command="{Binding StartHelpCommand}" />
<KeyBinding Key="F1" Command="{Binding F1SelectedCommand}" />
<KeyBinding Key="F5" Command="{Binding ReloadPluginDataCommand}" />
<KeyBinding Key="Tab" Command="{Binding AutocompleteQueryCommand}" />
<KeyBinding

View file

@ -187,6 +187,33 @@ namespace Flow.Launcher.ViewModel
SelectPrevPageCommand = new RelayCommand(_ => { 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;

View file

@ -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;