From f019bb22845ed0635c637f7ec4cd13ebfa11b701 Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Fri, 19 May 2023 00:55:41 -0400 Subject: [PATCH 1/5] Remove result logic so this method can be reused --- Flow.Launcher/ViewModel/MainViewModel.cs | 49 ++++++++++-------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 27809f67b..5486b41fb 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -1114,37 +1114,30 @@ namespace Flow.Launcher.ViewModel { if (string.IsNullOrEmpty(stringToCopy)) { - var result = Results.SelectedItem?.Result; - if (result != null) - { - string copyText = result.CopyText; - var isFile = File.Exists(copyText); - var isFolder = Directory.Exists(copyText); - if (isFile || isFolder) - { - var paths = new StringCollection - { - copyText - }; - - Clipboard.SetFileDropList(paths); - App.API.ShowMsg( - $"{App.API.GetTranslation("copy")} {(isFile ? App.API.GetTranslation("fileTitle") : App.API.GetTranslation("folderTitle"))}", - App.API.GetTranslation("completedSuccessfully")); - } - else - { - Clipboard.SetDataObject(copyText); - App.API.ShowMsg( - $"{App.API.GetTranslation("copy")} {App.API.GetTranslation("textTitle")}", - App.API.GetTranslation("completedSuccessfully")); - } - } - return; } + var isFile = File.Exists(stringToCopy); + var isFolder = Directory.Exists(stringToCopy); + if (isFile || isFolder) + { + var paths = new StringCollection + { + stringToCopy + }; - Clipboard.SetDataObject(stringToCopy); + Clipboard.SetFileDropList(paths); + App.API.ShowMsg( + $"{App.API.GetTranslation("copy")} {(isFile ? App.API.GetTranslation("fileTitle") : App.API.GetTranslation("folderTitle"))}", + App.API.GetTranslation("completedSuccessfully")); + } + else + { + Clipboard.SetDataObject(stringToCopy); + App.API.ShowMsg( + $"{App.API.GetTranslation("copy")} {App.API.GetTranslation("textTitle")}", + App.API.GetTranslation("completedSuccessfully")); + } + return; } #endregion From f992729147b2a415a82526d9479e9fb875c8aa61 Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Fri, 19 May 2023 00:56:33 -0400 Subject: [PATCH 2/5] Provide CopyText field instead of empty string --- Flow.Launcher/MainWindow.xaml.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 43bd9fd35..b334dd0fd 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -59,9 +59,11 @@ namespace Flow.Launcher private void OnCopy(object sender, ExecutedRoutedEventArgs e) { - if (QueryTextBox.SelectionLength == 0) + var result = _viewModel.Results.SelectedItem?.Result; + if (QueryTextBox.SelectionLength == 0 && result != null) { - _viewModel.ResultCopy(string.Empty); + string copyText = result.CopyText; + _viewModel.ResultCopy(copyText); } else if (!string.IsNullOrEmpty(QueryTextBox.Text)) From ed11cc2b22c0b6eaccfa74cef246e17b8289b9d1 Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Fri, 19 May 2023 00:57:02 -0400 Subject: [PATCH 3/5] Use ResultCopy to support files --- Flow.Launcher/PublicAPIInstance.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 800115bfa..b61e22d5e 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -118,7 +118,7 @@ namespace Flow.Launcher public void CopyToClipboard(string text) { - Clipboard.SetDataObject(text); + _mainVM.ResultCopy(text); } public void StartLoadingBar() => _mainVM.ProgressBarVisibility = Visibility.Visible; From 488c8e81b8541b48c973c4dc923148fb0d17e23e Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Sun, 4 Jun 2023 17:13:48 -0400 Subject: [PATCH 4/5] Update docstring --- Flow.Launcher/ViewModel/MainViewModel.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 5486b41fb..8529df7b3 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -1104,12 +1104,11 @@ namespace Flow.Launcher.ViewModel } /// - /// This is the global copy method for an individual result. If no text is passed, - /// the method will work out what is to be copied based on the result, so plugin can offer the text - /// to be copied via the result model. If the text is a directory/file path, - /// then actual file/folder will be copied instead. - /// The result's subtitle text is the default text to be copied + /// Copies the specified file or folder path to the clipboard, or the specified text if it is not a valid file or folder path. + /// Shows a message indicating whether the operation was completed successfully. /// + /// The file or folder path, or text to copy to the clipboard. + /// Nothing. public void ResultCopy(string stringToCopy) { if (string.IsNullOrEmpty(stringToCopy)) From c6318952111bbadf32b20bbeb70ba236f7336d50 Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Sun, 4 Jun 2023 17:22:49 -0400 Subject: [PATCH 5/5] Copy selected query text if there is a selection --- Flow.Launcher/MainWindow.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index b334dd0fd..1e7735fb2 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)) { - _viewModel.ResultCopy(QueryTextBox.SelectedText); + System.Windows.Clipboard.SetText(QueryTextBox.SelectedText); } }