Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New HotKeys for GUI #2470

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions MetaMorpheus/GUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
mc:Ignorable="d"
Drop="Window_Drop" AllowDrop="true" Background="{StaticResource BackgroundColor}" WindowStartupLocation="CenterScreen" MinHeight="400"
MinWidth="800" Height="550" Width="1000"
Loaded="MyWindow_Loaded">
Loaded="MyWindow_Loaded"
PreviewKeyDown="Window_PreviewKeyDown">

<Window.Resources>
<ResourceDictionary>
Expand Down Expand Up @@ -426,7 +427,7 @@

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

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

<!--List of tasks-->
<TreeView x:Name="tasksTreeView" Grid.Row="3" ItemsSource="{Binding}" MouseDoubleClick="TasksTreeView_MouseDoubleClick"
Margin="10,0,10,10" BorderBrush="{StaticResource BorderColor}" PreviewKeyDown="Window_PreviewKeyDown">
Margin="10,0,10,10" BorderBrush="{StaticResource BorderColor}" PreviewKeyDown="BoxWithList_PreviewKeyDown">
</TreeView>
</Grid>
</TabItem>
Expand Down Expand Up @@ -570,7 +571,7 @@

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

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

<!--Task Summary-->
<TreeView Name="taskSummary" ItemsSource="{Binding}" Grid.Column="2" Margin="0,10,20,10" MouseDoubleClick="TasksTreeView_MouseDoubleClick"
PreviewKeyDown="Window_PreviewKeyDown">
PreviewKeyDown="BoxWithList_PreviewKeyDown">
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="FontSize" Value="13" />
Expand Down
81 changes: 69 additions & 12 deletions MetaMorpheus/GUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Microsoft.Win32;
using MzLibUtil;
using Nett;
using Proteomics;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand All @@ -14,6 +13,7 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Navigation;
Expand Down Expand Up @@ -1058,34 +1058,91 @@
OpenFolder(outputFolder);
}



// This is designed for the entire window
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (!RunTasksButton.IsEnabled) return;
switch (e.Key)
{
// run all tasks
case Key.Enter when (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control:
RunTasksButton.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
e.Handled = true;
break;

default:
e.Handled = false; break;
}
}

private MetaMorpheusTask? _clipboard;

Check warning on line 1080 in MetaMorpheus/GUI/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / windows-latest

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 1080 in MetaMorpheus/GUI/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / windows-latest

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 1080 in MetaMorpheus/GUI/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / windows-latest

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 1080 in MetaMorpheus/GUI/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / windows-latest

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

/// <summary>
/// Handles keyboard input.
/// Note: This is designed for all boxes which contain lists of items such as database, tasks, or spectra files.
/// Note: Window_KeyDown is NOT used because it does not seem to capture keyboard input from a DataGrid.
/// </summary>
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
private void BoxWithList_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (RunTasksButton.IsEnabled)
if (!RunTasksButton.IsEnabled) return;

switch (e.Key)
{
// delete selected task/db/spectra
if (e.Key == Key.Delete || e.Key == Key.Back)
{
case Key.Delete:
case Key.Back:
Delete_Click(sender, e);
e.Handled = true;
}
break;

// move task down
if (e.Key == Key.Add || e.Key == Key.OemPlus)
{
case Key.Add:
case Key.OemPlus:
MoveSelectedTask_Click(sender, e, false);
e.Handled = true;
}
break;

// move task up
if (e.Key == Key.Subtract || e.Key == Key.OemMinus)
{
case Key.Subtract:
case Key.OemMinus:
MoveSelectedTask_Click(sender, e, true);
e.Handled = true;
}
break;

// copy selected task
case Key.C when (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control:
if (sender is TreeView { SelectedItem: PreRunTask preRunTask })
{
_clipboard = preRunTask.metaMorpheusTask;
}
e.Handled = true;

break;

// paste selected task
case Key.V when (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control:
if (sender is TreeView && _clipboard != null)
{
PreRunTasks.Add(new PreRunTask(_clipboard));
UpdateGuiOnPreRunChange();
}
e.Handled = true;
break;

// Duplicate Selected Task
case Key.D when (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control:
if (sender is TreeView { SelectedItem: PreRunTask task })
{
PreRunTasks.Add(task);
UpdateGuiOnPreRunChange();
}
e.Handled = true;
break;

default:
e.Handled = false; break;
}
}

Expand Down
Loading