From 48dbfc240b9abbc2fca81607a00a2ca654bc698e Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Tue, 25 Jan 2022 19:45:08 -0500 Subject: [PATCH] Add file path to clipboard as file if valid --- Flow.Launcher/MainWindow.xaml.cs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index eaaac452c..6625a6d89 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -20,6 +20,7 @@ using Flow.Launcher.Infrastructure; using System.Windows.Media; using Flow.Launcher.Infrastructure.Hotkey; using Flow.Launcher.Plugin.SharedCommands; +using System.IO; namespace Flow.Launcher { @@ -59,18 +60,31 @@ namespace Flow.Launcher { var results = _viewModel.Results; var result = results.SelectedItem?.Result; - if (result != null) // SelectedItem returns null if selection is empty. + if (result != null) { - string _copyText = String.IsNullOrEmpty(result.CopyText) ? result.Title : result.CopyText; - System.Windows.Clipboard.SetDataObject(_copyText.ToString()); + string copyText = String.IsNullOrEmpty(result.CopyText) ? result.SubTitle : result.CopyText; + if (File.Exists(copyText) || Directory.Exists(copyText)) + { + + System.Collections.Specialized.StringCollection paths = new System.Collections.Specialized.StringCollection(); + paths.Add(copyText); + + System.Windows.Clipboard.SetFileDropList(paths); + + } + else + { + System.Windows.Clipboard.SetDataObject(copyText.ToString()); + } + e.Handled = true; } } - //else if (!String.IsNullOrEmpty(QueryTextBox.Text)) - //{ - // System.Windows.Clipboard.SetDataObject(QueryTextBox.SelectedText); - //} + else if (!String.IsNullOrEmpty(QueryTextBox.Text)) + { + System.Windows.Clipboard.SetDataObject(QueryTextBox.SelectedText); + } e.Handled = false; } private async void OnClosing(object sender, CancelEventArgs e)