mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
move logic to view model
This commit is contained in:
parent
48dbfc240b
commit
c5be5b89cb
3 changed files with 47 additions and 28 deletions
|
|
@ -29,8 +29,12 @@ namespace Flow.Launcher.Plugin
|
|||
/// </summary>
|
||||
public string ActionKeywordAssigned { get; set; }
|
||||
|
||||
public string CopyText { get; set; } = String.Empty;
|
||||
public string FileCopy { get; set; } = String.Empty;
|
||||
/// <summary>
|
||||
/// This holds the text which can be provided by plugin to be copied to the
|
||||
/// user's clipboard when Ctrl + C is pressed on a result. If the text is a file/directory path
|
||||
/// flow will copy the actual file/folder instead of just the path text.
|
||||
/// </summary>
|
||||
public string CopyText { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// This holds the text which can be provided by plugin to help Flow autocomplete text
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ using Flow.Launcher.Infrastructure;
|
|||
using System.Windows.Media;
|
||||
using Flow.Launcher.Infrastructure.Hotkey;
|
||||
using Flow.Launcher.Plugin.SharedCommands;
|
||||
using System.IO;
|
||||
|
||||
namespace Flow.Launcher
|
||||
{
|
||||
|
|
@ -55,37 +54,15 @@ namespace Flow.Launcher
|
|||
}
|
||||
private void OnCopy(object sender, ExecutedRoutedEventArgs e)
|
||||
{
|
||||
|
||||
if (QueryTextBox.SelectionLength == 0)
|
||||
{
|
||||
var results = _viewModel.Results;
|
||||
var result = results.SelectedItem?.Result;
|
||||
if (result != null)
|
||||
{
|
||||
string copyText = String.IsNullOrEmpty(result.CopyText) ? result.SubTitle : result.CopyText;
|
||||
if (File.Exists(copyText) || Directory.Exists(copyText))
|
||||
{
|
||||
|
||||
System.Collections.Specialized.StringCollection paths = new System.Collections.Specialized.StringCollection();
|
||||
paths.Add(copyText);
|
||||
|
||||
System.Windows.Clipboard.SetFileDropList(paths);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Windows.Clipboard.SetDataObject(copyText.ToString());
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
_viewModel.ResultCopy(string.Empty);
|
||||
|
||||
}
|
||||
else if (!String.IsNullOrEmpty(QueryTextBox.Text))
|
||||
else if (!string.IsNullOrEmpty(QueryTextBox.Text))
|
||||
{
|
||||
System.Windows.Clipboard.SetDataObject(QueryTextBox.SelectedText);
|
||||
_viewModel.ResultCopy(QueryTextBox.SelectedText);
|
||||
}
|
||||
e.Handled = false;
|
||||
}
|
||||
private async void OnClosing(object sender, CancelEventArgs e)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ using Flow.Launcher.Infrastructure.Logger;
|
|||
using Microsoft.VisualStudio.Threading;
|
||||
using System.Threading.Channels;
|
||||
using ISavable = Flow.Launcher.Plugin.ISavable;
|
||||
using System.IO;
|
||||
using System.Collections.Specialized;
|
||||
|
||||
namespace Flow.Launcher.ViewModel
|
||||
{
|
||||
|
|
@ -873,6 +875,42 @@ namespace Flow.Launcher.ViewModel
|
|||
Results.AddResults(resultsForUpdates, token);
|
||||
}
|
||||
|
||||
/// <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
|
||||
/// </summary>
|
||||
public void ResultCopy(string stringToCopy)
|
||||
{
|
||||
if (string.IsNullOrEmpty(stringToCopy))
|
||||
{
|
||||
var result = Results.SelectedItem?.Result;
|
||||
if (result != null)
|
||||
{
|
||||
string copyText = string.IsNullOrEmpty(result.CopyText) ? result.SubTitle : result.CopyText;
|
||||
if (File.Exists(copyText) || Directory.Exists(copyText))
|
||||
{
|
||||
|
||||
var paths = new StringCollection();
|
||||
paths.Add(copyText);
|
||||
|
||||
Clipboard.SetFileDropList(paths);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Clipboard.SetDataObject(copyText.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Clipboard.SetDataObject(stringToCopy);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue