Skip to content

Commit 23723e6

Browse files
authored
New HotKeys for GUI (#2470)
1 parent 41c4296 commit 23723e6

File tree

2 files changed

+77
-19
lines changed

2 files changed

+77
-19
lines changed

MetaMorpheus/GUI/MainWindow.xaml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
mc:Ignorable="d"
88
Drop="Window_Drop" AllowDrop="true" Background="{StaticResource BackgroundColor}" WindowStartupLocation="CenterScreen" MinHeight="400"
99
MinWidth="800" Height="550" Width="1000"
10-
Loaded="MyWindow_Loaded">
10+
Loaded="MyWindow_Loaded"
11+
PreviewKeyDown="Window_PreviewKeyDown">
1112

1213
<Window.Resources>
1314
<ResourceDictionary>
@@ -426,7 +427,7 @@
426427

427428
<!--The list of databases-->
428429
<DataGrid Name="dataGridProteinDatabases" Grid.Row="3" Grid.ColumnSpan="4" ItemsSource="{Binding}" Style="{StaticResource x:DataGridStyle}"
429-
ColumnHeaderStyle="{StaticResource DataGridColumnHeaderStyle}" PreviewKeyDown="Window_PreviewKeyDown" >
430+
ColumnHeaderStyle="{StaticResource DataGridColumnHeaderStyle}" PreviewKeyDown="BoxWithList_PreviewKeyDown" >
430431
<DataGrid.RowStyle>
431432
<Style TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource DatabaseDataGridItemStyle}" />
432433
</DataGrid.RowStyle>
@@ -475,7 +476,7 @@
475476

476477
<!--The list of spectra files-->
477478
<DataGrid Name="dataGridSpectraFiles" ItemsSource="{Binding}" Grid.Row="3" Style="{StaticResource x:DataGridStyle}"
478-
ColumnHeaderStyle="{StaticResource DataGridColumnHeaderStyle}" PreviewKeyDown="Window_PreviewKeyDown">
479+
ColumnHeaderStyle="{StaticResource DataGridColumnHeaderStyle}" PreviewKeyDown="BoxWithList_PreviewKeyDown">
479480
<DataGrid.RowStyle>
480481
<Style TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource SpectraFileDataGridItemStyle}" />
481482
</DataGrid.RowStyle>
@@ -537,7 +538,7 @@
537538

538539
<!--List of tasks-->
539540
<TreeView x:Name="tasksTreeView" Grid.Row="3" ItemsSource="{Binding}" MouseDoubleClick="TasksTreeView_MouseDoubleClick"
540-
Margin="10,0,10,10" BorderBrush="{StaticResource BorderColor}" PreviewKeyDown="Window_PreviewKeyDown">
541+
Margin="10,0,10,10" BorderBrush="{StaticResource BorderColor}" PreviewKeyDown="BoxWithList_PreviewKeyDown">
541542
</TreeView>
542543
</Grid>
543544
</TabItem>
@@ -570,7 +571,7 @@
570571

571572
<!--Protein DB Summary-->
572573
<DataGrid Name="proteinDbSummaryDataGrid" ItemsSource="{Binding}" Grid.Row="0" Margin="20,10,0,0"
573-
Style="{StaticResource x:DataGridStyle}" ColumnHeaderStyle="{StaticResource DataGridColumnHeaderStyle}" PreviewKeyDown="Window_PreviewKeyDown">
574+
Style="{StaticResource x:DataGridStyle}" ColumnHeaderStyle="{StaticResource DataGridColumnHeaderStyle}" PreviewKeyDown="BoxWithList_PreviewKeyDown">
574575
<DataGrid.RowStyle>
575576
<Style TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource DatabaseDataGridItemStyle}" >
576577
<Setter Property="FontSize" Value="11" />
@@ -598,7 +599,7 @@
598599

599600
<!--Spectra file Summary-->
600601
<DataGrid Name="spectraFileSummaryDataGrid" ItemsSource="{Binding}" Grid.Row="2" Margin="20,0,0,10"
601-
Style="{StaticResource x:DataGridStyle}" ColumnHeaderStyle="{StaticResource DataGridColumnHeaderStyle}" PreviewKeyDown="Window_PreviewKeyDown">
602+
Style="{StaticResource x:DataGridStyle}" ColumnHeaderStyle="{StaticResource DataGridColumnHeaderStyle}" PreviewKeyDown="BoxWithList_PreviewKeyDown">
602603
<DataGrid.RowStyle>
603604
<Style TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource SpectraFileDataGridItemStyle}">
604605
<Setter Property="FontSize" Value="11" />
@@ -627,7 +628,7 @@
627628

628629
<!--Task Summary-->
629630
<TreeView Name="taskSummary" ItemsSource="{Binding}" Grid.Column="2" Margin="0,10,20,10" MouseDoubleClick="TasksTreeView_MouseDoubleClick"
630-
PreviewKeyDown="Window_PreviewKeyDown">
631+
PreviewKeyDown="BoxWithList_PreviewKeyDown">
631632
<TreeView.ItemContainerStyle>
632633
<Style TargetType="{x:Type TreeViewItem}">
633634
<Setter Property="FontSize" Value="13" />

MetaMorpheus/GUI/MainWindow.xaml.cs

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using Microsoft.Win32;
44
using MzLibUtil;
55
using Nett;
6-
using Proteomics;
76
using System;
87
using System.Collections.Generic;
98
using System.Collections.ObjectModel;
@@ -14,6 +13,7 @@
1413
using System.Threading.Tasks;
1514
using System.Windows;
1615
using System.Windows.Controls;
16+
using System.Windows.Controls.Primitives;
1717
using System.Windows.Documents;
1818
using System.Windows.Input;
1919
using System.Windows.Navigation;
@@ -1058,34 +1058,91 @@ private void OpenOutputFolder_Click(object sender, RoutedEventArgs e)
10581058
OpenFolder(outputFolder);
10591059
}
10601060

1061+
1062+
1063+
// This is designed for the entire window
1064+
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
1065+
{
1066+
if (!RunTasksButton.IsEnabled) return;
1067+
switch (e.Key)
1068+
{
1069+
// run all tasks
1070+
case Key.Enter when (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control:
1071+
RunTasksButton.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
1072+
e.Handled = true;
1073+
break;
1074+
1075+
default:
1076+
e.Handled = false; break;
1077+
}
1078+
}
1079+
1080+
private MetaMorpheusTask? _clipboard;
1081+
10611082
/// <summary>
10621083
/// Handles keyboard input.
1084+
/// Note: This is designed for all boxes which contain lists of items such as database, tasks, or spectra files.
10631085
/// Note: Window_KeyDown is NOT used because it does not seem to capture keyboard input from a DataGrid.
10641086
/// </summary>
1065-
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
1087+
private void BoxWithList_PreviewKeyDown(object sender, KeyEventArgs e)
10661088
{
1067-
if (RunTasksButton.IsEnabled)
1089+
if (!RunTasksButton.IsEnabled) return;
1090+
1091+
switch (e.Key)
10681092
{
10691093
// delete selected task/db/spectra
1070-
if (e.Key == Key.Delete || e.Key == Key.Back)
1071-
{
1094+
case Key.Delete:
1095+
case Key.Back:
10721096
Delete_Click(sender, e);
10731097
e.Handled = true;
1074-
}
1098+
break;
10751099

10761100
// move task down
1077-
if (e.Key == Key.Add || e.Key == Key.OemPlus)
1078-
{
1101+
case Key.Add:
1102+
case Key.OemPlus:
10791103
MoveSelectedTask_Click(sender, e, false);
10801104
e.Handled = true;
1081-
}
1105+
break;
10821106

10831107
// move task up
1084-
if (e.Key == Key.Subtract || e.Key == Key.OemMinus)
1085-
{
1108+
case Key.Subtract:
1109+
case Key.OemMinus:
10861110
MoveSelectedTask_Click(sender, e, true);
10871111
e.Handled = true;
1088-
}
1112+
break;
1113+
1114+
// copy selected task
1115+
case Key.C when (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control:
1116+
if (sender is TreeView { SelectedItem: PreRunTask preRunTask })
1117+
{
1118+
_clipboard = preRunTask.metaMorpheusTask;
1119+
}
1120+
e.Handled = true;
1121+
1122+
break;
1123+
1124+
// paste selected task
1125+
case Key.V when (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control:
1126+
if (sender is TreeView && _clipboard != null)
1127+
{
1128+
PreRunTasks.Add(new PreRunTask(_clipboard));
1129+
UpdateGuiOnPreRunChange();
1130+
}
1131+
e.Handled = true;
1132+
break;
1133+
1134+
// Duplicate Selected Task
1135+
case Key.D when (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control:
1136+
if (sender is TreeView { SelectedItem: PreRunTask task })
1137+
{
1138+
PreRunTasks.Add(task);
1139+
UpdateGuiOnPreRunChange();
1140+
}
1141+
e.Handled = true;
1142+
break;
1143+
1144+
default:
1145+
e.Handled = false; break;
10891146
}
10901147
}
10911148

0 commit comments

Comments
 (0)