mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Make CopyToClipboard generic
This commit is contained in:
parent
1ff328be03
commit
2b862f702a
7 changed files with 39 additions and 52 deletions
|
|
@ -40,11 +40,13 @@ namespace Flow.Launcher.Plugin
|
||||||
void ShellRun(string cmd, string filename = "cmd.exe");
|
void ShellRun(string cmd, string filename = "cmd.exe");
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If the passed in text is the path to a file or directory, the actual file/directory will
|
/// Copies the passed in text and shows a message indicating whether the operation was completed successfully.
|
||||||
/// be copied to clipboard. Otherwise the text itself will be copied to clipboard.
|
/// When directCopy is set to true and 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 still be copied to clipboard.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text">Text to save on clipboard</param>
|
/// <param name="text">Text to save on clipboard</param>
|
||||||
public void CopyToClipboard(string text);
|
/// <param name="directCopy">When true it will directly copy the file/folder from the path specified in text</param>
|
||||||
|
public void CopyToClipboard(string text, bool directCopy = false);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Save everything, all of Flow Launcher and plugins' data and settings
|
/// Save everything, all of Flow Launcher and plugins' data and settings
|
||||||
|
|
|
||||||
|
|
@ -63,8 +63,7 @@ namespace Flow.Launcher
|
||||||
if (QueryTextBox.SelectionLength == 0 && result != null)
|
if (QueryTextBox.SelectionLength == 0 && result != null)
|
||||||
{
|
{
|
||||||
string copyText = result.CopyText;
|
string copyText = result.CopyText;
|
||||||
_viewModel.ResultCopy(copyText);
|
App.API.CopyToClipboard(copyText, directCopy: true);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (!string.IsNullOrEmpty(QueryTextBox.Text))
|
else if (!string.IsNullOrEmpty(QueryTextBox.Text))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ using Flow.Launcher.Infrastructure.Logger;
|
||||||
using Flow.Launcher.Infrastructure.Storage;
|
using Flow.Launcher.Infrastructure.Storage;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Collections.Specialized;
|
||||||
|
|
||||||
namespace Flow.Launcher
|
namespace Flow.Launcher
|
||||||
{
|
{
|
||||||
|
|
@ -116,11 +117,36 @@ namespace Flow.Launcher
|
||||||
ShellCommand.Execute(startInfo);
|
ShellCommand.Execute(startInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CopyToClipboard(string text)
|
public void CopyToClipboard(string stringToCopy, bool directCopy = false)
|
||||||
{
|
{
|
||||||
_mainVM.ResultCopy(text);
|
if (string.IsNullOrEmpty(stringToCopy))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var isFile = File.Exists(stringToCopy);
|
||||||
|
if (directCopy && (isFile || Directory.Exists(stringToCopy)))
|
||||||
|
{
|
||||||
|
var paths = new StringCollection
|
||||||
|
{
|
||||||
|
stringToCopy
|
||||||
|
};
|
||||||
|
|
||||||
|
Clipboard.SetFileDropList(paths);
|
||||||
|
|
||||||
|
ShowMsg(
|
||||||
|
$"{GetTranslation("copy")} {(isFile ? GetTranslation("fileTitle") : GetTranslation("folderTitle"))}",
|
||||||
|
GetTranslation("completedSuccessfully"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Clipboard.SetDataObject(stringToCopy);
|
||||||
|
|
||||||
|
ShowMsg(
|
||||||
|
$"{GetTranslation("copy")} {GetTranslation("textTitle")}",
|
||||||
|
GetTranslation("completedSuccessfully"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void StartLoadingBar() => _mainVM.ProgressBarVisibility = Visibility.Visible;
|
public void StartLoadingBar() => _mainVM.ProgressBarVisibility = Visibility.Visible;
|
||||||
|
|
||||||
public void StopLoadingBar() => _mainVM.ProgressBarVisibility = Visibility.Collapsed;
|
public void StopLoadingBar() => _mainVM.ProgressBarVisibility = Visibility.Collapsed;
|
||||||
|
|
|
||||||
|
|
@ -1103,43 +1103,6 @@ namespace Flow.Launcher.ViewModel
|
||||||
Results.AddResults(resultsForUpdates, token);
|
Results.AddResults(resultsForUpdates, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 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))
|
|
||||||
return;
|
|
||||||
|
|
||||||
var isFile = File.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
|
|
||||||
{
|
|
||||||
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
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ namespace Flow.Launcher.Plugin.Explorer
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Clipboard.SetDataObject(record.FullPath);
|
Context.API.CopyToClipboard(record.FullPath);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
@ -147,10 +147,7 @@ namespace Flow.Launcher.Plugin.Explorer
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Clipboard.SetFileDropList(new System.Collections.Specialized.StringCollection
|
Context.API.CopyToClipboard(record.FullPath, directCopy: true);
|
||||||
{
|
|
||||||
record.FullPath
|
|
||||||
});
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ namespace Flow.Launcher.Plugin.Explorer
|
||||||
? action
|
? action
|
||||||
: _ =>
|
: _ =>
|
||||||
{
|
{
|
||||||
Clipboard.SetDataObject(e.ToString());
|
Context.API.CopyToClipboard(e.ToString());
|
||||||
return new ValueTask<bool>(true);
|
return new ValueTask<bool>(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -406,7 +406,7 @@ namespace Flow.Launcher.Plugin.Shell
|
||||||
Title = context.API.GetTranslation("flowlauncher_plugin_cmd_copy"),
|
Title = context.API.GetTranslation("flowlauncher_plugin_cmd_copy"),
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
Clipboard.SetDataObject(selectedResult.Title);
|
context.API.CopyToClipboard(selectedResult.Title);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
IcoPath = "Images/copy.png",
|
IcoPath = "Images/copy.png",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue