Skip to content

Commit 48dbfc2

Browse files
committed
Add file path to clipboard as file if valid
1 parent 0f78d51 commit 48dbfc2

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using System.Windows.Media;
2121
using Flow.Launcher.Infrastructure.Hotkey;
2222
using Flow.Launcher.Plugin.SharedCommands;
23+
using System.IO;
2324

2425
namespace Flow.Launcher
2526
{
@@ -59,18 +60,31 @@ private void OnCopy(object sender, ExecutedRoutedEventArgs e)
5960
{
6061
var results = _viewModel.Results;
6162
var result = results.SelectedItem?.Result;
62-
if (result != null) // SelectedItem returns null if selection is empty.
63+
if (result != null)
6364
{
64-
string _copyText = String.IsNullOrEmpty(result.CopyText) ? result.Title : result.CopyText;
65-
System.Windows.Clipboard.SetDataObject(_copyText.ToString());
65+
string copyText = String.IsNullOrEmpty(result.CopyText) ? result.SubTitle : result.CopyText;
66+
if (File.Exists(copyText) || Directory.Exists(copyText))
67+
{
68+
69+
System.Collections.Specialized.StringCollection paths = new System.Collections.Specialized.StringCollection();
70+
paths.Add(copyText);
71+
72+
System.Windows.Clipboard.SetFileDropList(paths);
73+
74+
}
75+
else
76+
{
77+
System.Windows.Clipboard.SetDataObject(copyText.ToString());
78+
}
79+
6680
e.Handled = true;
6781
}
6882

6983
}
70-
//else if (!String.IsNullOrEmpty(QueryTextBox.Text))
71-
//{
72-
// System.Windows.Clipboard.SetDataObject(QueryTextBox.SelectedText);
73-
//}
84+
else if (!String.IsNullOrEmpty(QueryTextBox.Text))
85+
{
86+
System.Windows.Clipboard.SetDataObject(QueryTextBox.SelectedText);
87+
}
7488
e.Handled = false;
7589
}
7690
private async void OnClosing(object sender, CancelEventArgs e)

0 commit comments

Comments
 (0)