Skip to content

Commit 6f556a4

Browse files
committed
Hook copy command
1 parent 9d94507 commit 6f556a4

File tree

3 files changed

+13
-26
lines changed

3 files changed

+13
-26
lines changed

Flow.Launcher/MainWindow.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@
178178
Style="{DynamicResource QueryBoxStyle}"
179179
Text="{Binding QueryText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
180180
Visibility="Visible">
181+
<TextBox.CommandBindings>
182+
<CommandBinding Command="ApplicationCommands.Copy" Executed="OnCopy" />
183+
</TextBox.CommandBindings>
181184
<TextBox.ContextMenu>
182185
<ContextMenu>
183186
<MenuItem Command="ApplicationCommands.Cut" />

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,17 @@ public MainWindow()
4747
{
4848
InitializeComponent();
4949
}
50+
private void OnCopy(object sender, ExecutedRoutedEventArgs e)
51+
{
52+
var results = _viewModel.Results;
53+
var result = results.SelectedItem?.Result;
54+
if (result != null) // SelectedItem returns null if selection is empty.
55+
{
5056

57+
System.Windows.Clipboard.SetDataObject(result.Title.ToString());
58+
}
59+
e.Handled = true;
60+
}
5161
private async void OnClosing(object sender, CancelEventArgs e)
5262
{
5363
_settings.WindowTop = Top;

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -189,32 +189,6 @@ private void InitializeKeyCommands()
189189

190190
SelectFirstResultCommand = new RelayCommand(_ => SelectedResults.SelectFirstResult());
191191

192-
CopyToClipboard = new RelayCommand(index =>
193-
{
194-
var results = SelectedResults;
195-
196-
if (index != null)
197-
{
198-
results.SelectedIndex = int.Parse(index.ToString());
199-
}
200-
201-
var result = results.SelectedItem?.Result;
202-
if (result != null) // SelectedItem returns null if selection is empty.
203-
{
204-
bool hideWindow = result.Action != null && result.Action(new ActionContext
205-
{
206-
SpecialKeyState = GlobalHotkey.Instance.CheckModifiers()
207-
});
208-
Clipboard.SetText(result.Title.ToString());
209-
if (hideWindow)
210-
{
211-
Hide();
212-
}
213-
214-
215-
}
216-
});
217-
218192
StartHelpCommand = new RelayCommand(_ =>
219193
{
220194
SearchWeb.NewTabInBrowser("https://github.com/Flow-Launcher/Flow.Launcher/wiki/Flow-Launcher/");

0 commit comments

Comments
 (0)