Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Flow.Launcher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ public MainWindow()

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))
{
_viewModel.ResultCopy(QueryTextBox.SelectedText);
System.Windows.Clipboard.SetText(QueryTextBox.SelectedText);
Comment on lines -69 to +71
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using this Clipboard method and not the viewmodel one?

Copy link
Contributor

@VictoriousRaptor VictoriousRaptor Jun 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy selected text raises a notification, which is quite unnecessary. Maybe the right way is to remove notification for copy texts?

And BTW does this PR affects clipboard manager plugins like ClipboardR?

Copy link
Member Author

@Garulf Garulf Jun 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way avoids wasting time parsing if the text is a file and doesn't send a notification.

I don't think anyone just copying text from the query text box wants or needs this.

Copy link
Member

@jjw24 jjw24 Jun 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy selected text raises a notification, which is quite unnecessary. Maybe the right way is to remove notification for copy texts?

Yes agree no need for notification. I missed the method being ResultCopy where this is copying query test.

And BTW does this PR affects clipboard manager plugins like ClipboardR?

I haven't used the plugin, does it just access copied data or does it also do copy?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And BTW does this PR affects clipboard manager plugins like ClipboardR?

I created an issue to let the author know about this change.

}
}

Expand Down
2 changes: 1 addition & 1 deletion Flow.Launcher/PublicAPIInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void ShellRun(string cmd, string filename = "cmd.exe")

public void CopyToClipboard(string text)
{
Clipboard.SetDataObject(text);
_mainVM.ResultCopy(text);
}

public void StartLoadingBar() => _mainVM.ProgressBarVisibility = Visibility.Visible;
Expand Down
58 changes: 25 additions & 33 deletions Flow.Launcher/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,47 +1104,39 @@ public void UpdateResultView(IEnumerable<ResultsForUpdate> resultsForUpdates)
}

/// <summary>
/// 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.
/// </summary>
/// <param name="stringToCopy">The file or folder path, or text to copy to the clipboard.</param>
/// <returns>Nothing.</returns>
public void ResultCopy(string stringToCopy)
{
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
Expand Down