Skip to content

Commit fa2c894

Browse files
authored
Merge pull request #2143 from Flow-Launcher/expand-resultcopy
Consistent handling of clipboard copying
2 parents 22dd59e + c631895 commit fa2c894

File tree

3 files changed

+31
-37
lines changed

3 files changed

+31
-37
lines changed

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,16 @@ public MainWindow()
5959

6060
private void OnCopy(object sender, ExecutedRoutedEventArgs e)
6161
{
62-
if (QueryTextBox.SelectionLength == 0)
62+
var result = _viewModel.Results.SelectedItem?.Result;
63+
if (QueryTextBox.SelectionLength == 0 && result != null)
6364
{
64-
_viewModel.ResultCopy(string.Empty);
65+
string copyText = result.CopyText;
66+
_viewModel.ResultCopy(copyText);
6567

6668
}
6769
else if (!string.IsNullOrEmpty(QueryTextBox.Text))
6870
{
69-
_viewModel.ResultCopy(QueryTextBox.SelectedText);
71+
System.Windows.Clipboard.SetText(QueryTextBox.SelectedText);
7072
}
7173
}
7274

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public void ShellRun(string cmd, string filename = "cmd.exe")
118118

119119
public void CopyToClipboard(string text)
120120
{
121-
Clipboard.SetDataObject(text);
121+
_mainVM.ResultCopy(text);
122122
}
123123

124124
public void StartLoadingBar() => _mainVM.ProgressBarVisibility = Visibility.Visible;

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,47 +1104,39 @@ public void UpdateResultView(IEnumerable<ResultsForUpdate> resultsForUpdates)
11041104
}
11051105

11061106
/// <summary>
1107-
/// This is the global copy method for an individual result. If no text is passed,
1108-
/// the method will work out what is to be copied based on the result, so plugin can offer the text
1109-
/// to be copied via the result model. If the text is a directory/file path,
1110-
/// then actual file/folder will be copied instead.
1111-
/// The result's subtitle text is the default text to be copied
1107+
/// Copies the specified file or folder path to the clipboard, or the specified text if it is not a valid file or folder path.
1108+
/// Shows a message indicating whether the operation was completed successfully.
11121109
/// </summary>
1110+
/// <param name="stringToCopy">The file or folder path, or text to copy to the clipboard.</param>
1111+
/// <returns>Nothing.</returns>
11131112
public void ResultCopy(string stringToCopy)
11141113
{
11151114
if (string.IsNullOrEmpty(stringToCopy))
11161115
{
1117-
var result = Results.SelectedItem?.Result;
1118-
if (result != null)
1119-
{
1120-
string copyText = result.CopyText;
1121-
var isFile = File.Exists(copyText);
1122-
var isFolder = Directory.Exists(copyText);
1123-
if (isFile || isFolder)
1124-
{
1125-
var paths = new StringCollection
1126-
{
1127-
copyText
1128-
};
1129-
1130-
Clipboard.SetFileDropList(paths);
1131-
App.API.ShowMsg(
1132-
$"{App.API.GetTranslation("copy")} {(isFile ? App.API.GetTranslation("fileTitle") : App.API.GetTranslation("folderTitle"))}",
1133-
App.API.GetTranslation("completedSuccessfully"));
1134-
}
1135-
else
1136-
{
1137-
Clipboard.SetDataObject(copyText);
1138-
App.API.ShowMsg(
1139-
$"{App.API.GetTranslation("copy")} {App.API.GetTranslation("textTitle")}",
1140-
App.API.GetTranslation("completedSuccessfully"));
1141-
}
1142-
}
1143-
11441116
return;
11451117
}
1118+
var isFile = File.Exists(stringToCopy);
1119+
var isFolder = Directory.Exists(stringToCopy);
1120+
if (isFile || isFolder)
1121+
{
1122+
var paths = new StringCollection
1123+
{
1124+
stringToCopy
1125+
};
11461126

1147-
Clipboard.SetDataObject(stringToCopy);
1127+
Clipboard.SetFileDropList(paths);
1128+
App.API.ShowMsg(
1129+
$"{App.API.GetTranslation("copy")} {(isFile ? App.API.GetTranslation("fileTitle") : App.API.GetTranslation("folderTitle"))}",
1130+
App.API.GetTranslation("completedSuccessfully"));
1131+
}
1132+
else
1133+
{
1134+
Clipboard.SetDataObject(stringToCopy);
1135+
App.API.ShowMsg(
1136+
$"{App.API.GetTranslation("copy")} {App.API.GetTranslation("textTitle")}",
1137+
App.API.GetTranslation("completedSuccessfully"));
1138+
}
1139+
return;
11481140
}
11491141

11501142
#endregion

0 commit comments

Comments
 (0)