From 1ff328be031a7b18a2ce6c81b350047b48803d30 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Thu, 8 Jun 2023 22:46:37 +1000 Subject: [PATCH] update copy calls to use API CopyToClipboard method --- Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs | 3 ++- Flow.Launcher/MainWindow.xaml.cs | 2 +- Flow.Launcher/ViewModel/MainViewModel.cs | 7 +++--- .../Main.cs | 2 +- .../Flow.Launcher.Plugin.Calculator/Main.cs | 2 +- .../ContextMenu.cs | 2 +- .../Helper/ContextMenuHelper.cs | 22 +------------------ 7 files changed, 11 insertions(+), 29 deletions(-) diff --git a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs index d0fdf136b..24d4c9a73 100644 --- a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs @@ -40,7 +40,8 @@ namespace Flow.Launcher.Plugin void ShellRun(string cmd, string filename = "cmd.exe"); /// - /// Copy Text to clipboard + /// If the passed in text is the path to a file or directory, the actual file/directory will + /// be copied to clipboard. Otherwise the text itself will be copied to clipboard. /// /// Text to save on clipboard public void CopyToClipboard(string text); diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 1e7735fb2..6ee0e24c1 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -68,7 +68,7 @@ namespace Flow.Launcher } else if (!string.IsNullOrEmpty(QueryTextBox.Text)) { - System.Windows.Clipboard.SetText(QueryTextBox.SelectedText); + System.Windows.Clipboard.SetDataObject(QueryTextBox.SelectedText); } } diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 8529df7b3..354b625a4 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -1112,11 +1112,10 @@ namespace Flow.Launcher.ViewModel public void ResultCopy(string stringToCopy) { if (string.IsNullOrEmpty(stringToCopy)) - { return; - } + var isFile = File.Exists(stringToCopy); - var isFolder = Directory.Exists(stringToCopy); + var isFolder = isFile ? false : Directory.Exists(stringToCopy); // No need to eval directory exists if determined that file exists if (isFile || isFolder) { var paths = new StringCollection @@ -1125,6 +1124,7 @@ namespace Flow.Launcher.ViewModel }; Clipboard.SetFileDropList(paths); + App.API.ShowMsg( $"{App.API.GetTranslation("copy")} {(isFile ? App.API.GetTranslation("fileTitle") : App.API.GetTranslation("folderTitle"))}", App.API.GetTranslation("completedSuccessfully")); @@ -1132,6 +1132,7 @@ namespace Flow.Launcher.ViewModel else { Clipboard.SetDataObject(stringToCopy); + App.API.ShowMsg( $"{App.API.GetTranslation("copy")} {App.API.GetTranslation("textTitle")}", App.API.GetTranslation("completedSuccessfully")); diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs index d9a719272..3ac12dc2e 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs @@ -174,7 +174,7 @@ namespace Flow.Launcher.Plugin.BrowserBookmark { try { - Clipboard.SetDataObject(((BookmarkAttributes)selectedResult.ContextData).Url); + context.API.CopyToClipboard(((BookmarkAttributes)selectedResult.ContextData).Url); return true; } diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs index d5dcdacea..e2aa5860c 100644 --- a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs @@ -95,7 +95,7 @@ namespace Flow.Launcher.Plugin.Caculator { try { - Clipboard.SetDataObject(newResult); + Context.API.CopyToClipboard(newResult); return true; } catch (ExternalException) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs b/Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs index f5733bbb5..5e5cab2f5 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs @@ -124,7 +124,7 @@ namespace Flow.Launcher.Plugin.Explorer { try { - Clipboard.SetText(record.FullPath); + Clipboard.SetDataObject(record.FullPath); return true; } catch (Exception e) diff --git a/Plugins/Flow.Launcher.Plugin.WindowsSettings/Helper/ContextMenuHelper.cs b/Plugins/Flow.Launcher.Plugin.WindowsSettings/Helper/ContextMenuHelper.cs index e123e2d2f..ca09df9de 100644 --- a/Plugins/Flow.Launcher.Plugin.WindowsSettings/Helper/ContextMenuHelper.cs +++ b/Plugins/Flow.Launcher.Plugin.WindowsSettings/Helper/ContextMenuHelper.cs @@ -22,26 +22,6 @@ namespace Flow.Launcher.Plugin.WindowsSettings.Helper internal static List GetContextMenu(in Result result, in string assemblyName) { return new List(0); - } - - /// - /// Copy the given text to the clipboard - /// - /// The text to copy to the clipboard - /// The text successful copy to the clipboard, otherwise - private static bool TryToCopyToClipBoard(in string text) - { - try - { - Clipboard.Clear(); - Clipboard.SetText(text); - return true; - } - catch (Exception exception) - { - Log.Exception("Can't copy to clipboard", exception, typeof(Main)); - return false; - } - } + } } }