Hook copy command

This commit is contained in:
Garulf 2021-12-02 03:55:47 -05:00
parent 9d94507e16
commit 6f556a47b5
3 changed files with 13 additions and 26 deletions

View file

@ -178,6 +178,9 @@
Style="{DynamicResource QueryBoxStyle}"
Text="{Binding QueryText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Visibility="Visible">
<TextBox.CommandBindings>
<CommandBinding Command="ApplicationCommands.Copy" Executed="OnCopy" />
</TextBox.CommandBindings>
<TextBox.ContextMenu>
<ContextMenu>
<MenuItem Command="ApplicationCommands.Cut" />

View file

@ -47,7 +47,17 @@ namespace Flow.Launcher
{
InitializeComponent();
}
private void OnCopy(object sender, ExecutedRoutedEventArgs e)
{
var results = _viewModel.Results;
var result = results.SelectedItem?.Result;
if (result != null) // SelectedItem returns null if selection is empty.
{
System.Windows.Clipboard.SetDataObject(result.Title.ToString());
}
e.Handled = true;
}
private async void OnClosing(object sender, CancelEventArgs e)
{
_settings.WindowTop = Top;

View file

@ -189,32 +189,6 @@ namespace Flow.Launcher.ViewModel
SelectFirstResultCommand = new RelayCommand(_ => SelectedResults.SelectFirstResult());
CopyToClipboard = new RelayCommand(index =>
{
var results = SelectedResults;
if (index != null)
{
results.SelectedIndex = int.Parse(index.ToString());
}
var result = results.SelectedItem?.Result;
if (result != null) // SelectedItem returns null if selection is empty.
{
bool hideWindow = result.Action != null && result.Action(new ActionContext
{
SpecialKeyState = GlobalHotkey.Instance.CheckModifiers()
});
Clipboard.SetText(result.Title.ToString());
if (hideWindow)
{
Hide();
}
}
});
StartHelpCommand = new RelayCommand(_ =>
{
SearchWeb.NewTabInBrowser("https://github.com/Flow-Launcher/Flow.Launcher/wiki/Flow-Launcher/");