update copy calls to use API CopyToClipboard method

This commit is contained in:
Jeremy Wu 2023-06-08 22:46:37 +10:00
parent 936d2b7e34
commit 1ff328be03
7 changed files with 11 additions and 29 deletions

View file

@ -40,7 +40,8 @@ namespace Flow.Launcher.Plugin
void ShellRun(string cmd, string filename = "cmd.exe");
/// <summary>
/// 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.
/// </summary>
/// <param name="text">Text to save on clipboard</param>
public void CopyToClipboard(string text);

View file

@ -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);
}
}

View file

@ -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"));

View file

@ -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;
}

View file

@ -95,7 +95,7 @@ namespace Flow.Launcher.Plugin.Caculator
{
try
{
Clipboard.SetDataObject(newResult);
Context.API.CopyToClipboard(newResult);
return true;
}
catch (ExternalException)

View file

@ -124,7 +124,7 @@ namespace Flow.Launcher.Plugin.Explorer
{
try
{
Clipboard.SetText(record.FullPath);
Clipboard.SetDataObject(record.FullPath);
return true;
}
catch (Exception e)

View file

@ -22,26 +22,6 @@ namespace Flow.Launcher.Plugin.WindowsSettings.Helper
internal static List<Result> GetContextMenu(in Result result, in string assemblyName)
{
return new List<Result>(0);
}
/// <summary>
/// Copy the given text to the clipboard
/// </summary>
/// <param name="text">The text to copy to the clipboard</param>
/// <returns><see langword="true"/>The text successful copy to the clipboard, otherwise <see langword="false"/></returns>
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;
}
}
}
}
}