Add file path to clipboard as file if valid

This commit is contained in:
Garulf 2022-01-25 19:45:08 -05:00
parent 0f78d5176e
commit 48dbfc240b

View file

@ -20,6 +20,7 @@ using Flow.Launcher.Infrastructure;
using System.Windows.Media; using System.Windows.Media;
using Flow.Launcher.Infrastructure.Hotkey; using Flow.Launcher.Infrastructure.Hotkey;
using Flow.Launcher.Plugin.SharedCommands; using Flow.Launcher.Plugin.SharedCommands;
using System.IO;
namespace Flow.Launcher namespace Flow.Launcher
{ {
@ -59,18 +60,31 @@ namespace Flow.Launcher
{ {
var results = _viewModel.Results; var results = _viewModel.Results;
var result = results.SelectedItem?.Result; 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; string copyText = String.IsNullOrEmpty(result.CopyText) ? result.SubTitle : result.CopyText;
System.Windows.Clipboard.SetDataObject(_copyText.ToString()); 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; e.Handled = true;
} }
} }
//else if (!String.IsNullOrEmpty(QueryTextBox.Text)) else if (!String.IsNullOrEmpty(QueryTextBox.Text))
//{ {
// System.Windows.Clipboard.SetDataObject(QueryTextBox.SelectedText); System.Windows.Clipboard.SetDataObject(QueryTextBox.SelectedText);
//} }
e.Handled = false; e.Handled = false;
} }
private async void OnClosing(object sender, CancelEventArgs e) private async void OnClosing(object sender, CancelEventArgs e)