Skip to content

Commit 1ff328b

Browse files
committed
update copy calls to use API CopyToClipboard method
1 parent 936d2b7 commit 1ff328b

File tree

7 files changed

+11
-29
lines changed

7 files changed

+11
-29
lines changed

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public interface IPublicAPI
4040
void ShellRun(string cmd, string filename = "cmd.exe");
4141

4242
/// <summary>
43-
/// Copy Text to clipboard
43+
/// If the passed in text is the path to a file or directory, the actual file/directory will
44+
/// be copied to clipboard. Otherwise the text itself will be copied to clipboard.
4445
/// </summary>
4546
/// <param name="text">Text to save on clipboard</param>
4647
public void CopyToClipboard(string text);

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private void OnCopy(object sender, ExecutedRoutedEventArgs e)
6868
}
6969
else if (!string.IsNullOrEmpty(QueryTextBox.Text))
7070
{
71-
System.Windows.Clipboard.SetText(QueryTextBox.SelectedText);
71+
System.Windows.Clipboard.SetDataObject(QueryTextBox.SelectedText);
7272
}
7373
}
7474

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,11 +1112,10 @@ public void UpdateResultView(IEnumerable<ResultsForUpdate> resultsForUpdates)
11121112
public void ResultCopy(string stringToCopy)
11131113
{
11141114
if (string.IsNullOrEmpty(stringToCopy))
1115-
{
11161115
return;
1117-
}
1116+
11181117
var isFile = File.Exists(stringToCopy);
1119-
var isFolder = Directory.Exists(stringToCopy);
1118+
var isFolder = isFile ? false : Directory.Exists(stringToCopy); // No need to eval directory exists if determined that file exists
11201119
if (isFile || isFolder)
11211120
{
11221121
var paths = new StringCollection
@@ -1125,13 +1124,15 @@ public void ResultCopy(string stringToCopy)
11251124
};
11261125

11271126
Clipboard.SetFileDropList(paths);
1127+
11281128
App.API.ShowMsg(
11291129
$"{App.API.GetTranslation("copy")} {(isFile ? App.API.GetTranslation("fileTitle") : App.API.GetTranslation("folderTitle"))}",
11301130
App.API.GetTranslation("completedSuccessfully"));
11311131
}
11321132
else
11331133
{
11341134
Clipboard.SetDataObject(stringToCopy);
1135+
11351136
App.API.ShowMsg(
11361137
$"{App.API.GetTranslation("copy")} {App.API.GetTranslation("textTitle")}",
11371138
App.API.GetTranslation("completedSuccessfully"));

Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public List<Result> LoadContextMenus(Result selectedResult)
174174
{
175175
try
176176
{
177-
Clipboard.SetDataObject(((BookmarkAttributes)selectedResult.ContextData).Url);
177+
context.API.CopyToClipboard(((BookmarkAttributes)selectedResult.ContextData).Url);
178178

179179
return true;
180180
}

Plugins/Flow.Launcher.Plugin.Calculator/Main.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public List<Result> Query(Query query)
9595
{
9696
try
9797
{
98-
Clipboard.SetDataObject(newResult);
98+
Context.API.CopyToClipboard(newResult);
9999
return true;
100100
}
101101
catch (ExternalException)

Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public List<Result> LoadContextMenus(Result selectedResult)
124124
{
125125
try
126126
{
127-
Clipboard.SetText(record.FullPath);
127+
Clipboard.SetDataObject(record.FullPath);
128128
return true;
129129
}
130130
catch (Exception e)

Plugins/Flow.Launcher.Plugin.WindowsSettings/Helper/ContextMenuHelper.cs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,6 @@ internal static class ContextMenuHelper
2222
internal static List<Result> GetContextMenu(in Result result, in string assemblyName)
2323
{
2424
return new List<Result>(0);
25-
}
26-
27-
/// <summary>
28-
/// Copy the given text to the clipboard
29-
/// </summary>
30-
/// <param name="text">The text to copy to the clipboard</param>
31-
/// <returns><see langword="true"/>The text successful copy to the clipboard, otherwise <see langword="false"/></returns>
32-
private static bool TryToCopyToClipBoard(in string text)
33-
{
34-
try
35-
{
36-
Clipboard.Clear();
37-
Clipboard.SetText(text);
38-
return true;
39-
}
40-
catch (Exception exception)
41-
{
42-
Log.Exception("Can't copy to clipboard", exception, typeof(Main));
43-
return false;
44-
}
45-
}
25+
}
4626
}
4727
}

0 commit comments

Comments
 (0)