From b98cfad0c0a2410dfbf0258c6d7b80032b65dd07 Mon Sep 17 00:00:00 2001 From: Nic Bollis Date: Mon, 4 Nov 2024 11:44:11 -0600 Subject: [PATCH] Update Numerical Inputs (#2433) * Updated to MzLib 1.0.548 and fixed custom ions in search tasks * reverted calibration task change * merged in master bbbyy * Spectral Library from Command Line (#2386) * Updated to MzLib 1.0.548 and fixed custom ions in search tasks * reverted calibration task change * merged in master bbbyy * Enabled Library Loading from command line * Add alignment properties and key handling to TextBoxControls - Added `HorizontalContentAlignment` and `VerticalContentAlignment` properties to center content in `DoubleTextBoxControl` and `IntegerTextBoxControl`. - Introduced constructors to set alignment properties. - Overrode `OnKeyDown` to clear focus on Return key press. - Included `System.Windows` namespace in both control files. * Replace TextBox with custom numeric controls in XAML Replaced standard TextBox controls with custom IntegerTexBoxControl and DoubleTextBoxControl in various XAML files to improve input validation and user experience. Removed the CheckIfNumber event handler and method from code-behind files as the new custom controls handle validation internally. Updated tooltips and adjusted layout properties for consistency. --------- Co-authored-by: Nic Bollis Co-authored-by: Edwin Laboy <63374885+elaboy@users.noreply.github.com> --- .../GUI/TaskWindows/CalibrateTaskWindow.xaml | 36 ++++----- .../TaskWindows/CalibrateTaskWindow.xaml.cs | 5 -- .../GUI/TaskWindows/GPTMDTaskWindow.xaml | 48 +++++------ .../GUI/TaskWindows/GPTMDTaskWindow.xaml.cs | 5 -- .../TaskWindows/GlycoSearchTaskWindow.xaml | 30 +++---- .../TaskWindows/GlycoSearchTaskWindow.xaml.cs | 5 -- .../GUI/TaskWindows/SearchTaskWindow.xaml | 79 ++++++++++--------- .../GUI/TaskWindows/SearchTaskWindow.xaml.cs | 6 -- .../GUI/TaskWindows/XLSearchTaskWindow.xaml | 22 +++--- .../TaskWindows/XLSearchTaskWindow.xaml.cs | 5 -- MetaMorpheus/GUI/Util/DoubleTexBoxControl.cs | 20 ++++- .../GUI/Util/IntegerTextBoxControl.cs | 24 +++++- .../Views/FileSpecificParametersWindow.xaml | 12 +-- .../FileSpecificParametersWindow.xaml.cs | 5 -- 14 files changed, 156 insertions(+), 146 deletions(-) diff --git a/MetaMorpheus/GUI/TaskWindows/CalibrateTaskWindow.xaml b/MetaMorpheus/GUI/TaskWindows/CalibrateTaskWindow.xaml index 0769a279a..99c3f48de 100644 --- a/MetaMorpheus/GUI/TaskWindows/CalibrateTaskWindow.xaml +++ b/MetaMorpheus/GUI/TaskWindows/CalibrateTaskWindow.xaml @@ -92,13 +92,13 @@ @@ -188,17 +188,17 @@ diff --git a/MetaMorpheus/GUI/TaskWindows/CalibrateTaskWindow.xaml.cs b/MetaMorpheus/GUI/TaskWindows/CalibrateTaskWindow.xaml.cs index 68aa2fc4c..12b88340b 100644 --- a/MetaMorpheus/GUI/TaskWindows/CalibrateTaskWindow.xaml.cs +++ b/MetaMorpheus/GUI/TaskWindows/CalibrateTaskWindow.xaml.cs @@ -299,11 +299,6 @@ private void SaveButton_Click(object sender, RoutedEventArgs e) DialogResult = true; } - private void CheckIfNumber(object sender, TextCompositionEventArgs e) - { - e.Handled = GlobalGuiSettings.CheckIsPositiveInteger(e.Text); - } - private void KeyPressed(object sender, KeyEventArgs e) { if (e.Key == Key.Return) diff --git a/MetaMorpheus/GUI/TaskWindows/GPTMDTaskWindow.xaml b/MetaMorpheus/GUI/TaskWindows/GPTMDTaskWindow.xaml index 48060ddd7..bfb5d6c8a 100644 --- a/MetaMorpheus/GUI/TaskWindows/GPTMDTaskWindow.xaml +++ b/MetaMorpheus/GUI/TaskWindows/GPTMDTaskWindow.xaml @@ -66,13 +66,13 @@ @@ -90,19 +90,19 @@ @@ -156,13 +156,13 @@ @@ -242,7 +242,7 @@ diff --git a/MetaMorpheus/GUI/TaskWindows/GPTMDTaskWindow.xaml.cs b/MetaMorpheus/GUI/TaskWindows/GPTMDTaskWindow.xaml.cs index fa0270c33..4c3449f93 100644 --- a/MetaMorpheus/GUI/TaskWindows/GPTMDTaskWindow.xaml.cs +++ b/MetaMorpheus/GUI/TaskWindows/GPTMDTaskWindow.xaml.cs @@ -481,11 +481,6 @@ private void SaveButton_Click(object sender, RoutedEventArgs e) DialogResult = true; } - private void CheckIfNumber(object sender, TextCompositionEventArgs e) - { - e.Handled = GlobalGuiSettings.CheckIsPositiveInteger(e.Text); - } - private void KeyPressed(object sender, KeyEventArgs e) { if (e.Key == Key.Return) diff --git a/MetaMorpheus/GUI/TaskWindows/GlycoSearchTaskWindow.xaml b/MetaMorpheus/GUI/TaskWindows/GlycoSearchTaskWindow.xaml index 0c0d9265b..7be5c8b7d 100644 --- a/MetaMorpheus/GUI/TaskWindows/GlycoSearchTaskWindow.xaml +++ b/MetaMorpheus/GUI/TaskWindows/GlycoSearchTaskWindow.xaml @@ -114,7 +114,7 @@ @@ -179,11 +179,11 @@ @@ -215,7 +215,7 @@ @@ -233,17 +233,17 @@ @@ -270,11 +270,11 @@ @@ -448,7 +448,7 @@ - + @@ -457,7 +457,7 @@ - + @@ -713,35 +714,35 @@ @@ -842,7 +843,7 @@ @@ -893,7 +894,7 @@ @@ -964,8 +965,8 @@ diff --git a/MetaMorpheus/GUI/TaskWindows/SearchTaskWindow.xaml.cs b/MetaMorpheus/GUI/TaskWindows/SearchTaskWindow.xaml.cs index 678e1392c..1767492b3 100644 --- a/MetaMorpheus/GUI/TaskWindows/SearchTaskWindow.xaml.cs +++ b/MetaMorpheus/GUI/TaskWindows/SearchTaskWindow.xaml.cs @@ -69,12 +69,6 @@ public SearchTaskWindow(SearchTask task) base.Closing += this.OnClosing; } - - private void CheckIfNumber(object sender, TextCompositionEventArgs e) - { - e.Handled = GlobalGuiSettings.CheckIsPositiveInteger(e.Text); - } - private void Row_DoubleClick(object sender, MouseButtonEventArgs e) { var ye = sender as DataGridCell; diff --git a/MetaMorpheus/GUI/TaskWindows/XLSearchTaskWindow.xaml b/MetaMorpheus/GUI/TaskWindows/XLSearchTaskWindow.xaml index 8c3ae3c27..81de1944f 100644 --- a/MetaMorpheus/GUI/TaskWindows/XLSearchTaskWindow.xaml +++ b/MetaMorpheus/GUI/TaskWindows/XLSearchTaskWindow.xaml @@ -81,7 +81,7 @@ @@ -185,7 +185,7 @@ @@ -207,13 +207,13 @@ @@ -241,11 +241,11 @@ diff --git a/MetaMorpheus/GUI/TaskWindows/XLSearchTaskWindow.xaml.cs b/MetaMorpheus/GUI/TaskWindows/XLSearchTaskWindow.xaml.cs index 477d53d2f..42eac5f43 100644 --- a/MetaMorpheus/GUI/TaskWindows/XLSearchTaskWindow.xaml.cs +++ b/MetaMorpheus/GUI/TaskWindows/XLSearchTaskWindow.xaml.cs @@ -54,11 +54,6 @@ public XLSearchTaskWindow(XLSearchTask task) internal XLSearchTask TheTask { get; private set; } - private void CheckIfNumber(object sender, TextCompositionEventArgs e) - { - e.Handled = GlobalGuiSettings.CheckIsPositiveInteger(e.Text); - } - private void PopulateChoices() { foreach (var crosslinker in GlobalVariables.Crosslinkers) diff --git a/MetaMorpheus/GUI/Util/DoubleTexBoxControl.cs b/MetaMorpheus/GUI/Util/DoubleTexBoxControl.cs index c26bbd9f8..633b3d4b4 100644 --- a/MetaMorpheus/GUI/Util/DoubleTexBoxControl.cs +++ b/MetaMorpheus/GUI/Util/DoubleTexBoxControl.cs @@ -1,4 +1,5 @@ -using System.Windows.Controls; +using System.Windows; +using System.Windows.Controls; using System.Windows.Input; namespace MetaMorpheusGUI @@ -8,6 +9,12 @@ namespace MetaMorpheusGUI /// public class DoubleTextBoxControl : TextBox { + public DoubleTextBoxControl() + { + HorizontalContentAlignment = HorizontalAlignment.Center; + VerticalContentAlignment = VerticalAlignment.Center; + } + protected override void OnPreviewTextInput(TextCompositionEventArgs e) { foreach (var character in e.Text) @@ -26,5 +33,16 @@ protected override void OnPreviewTextInput(TextCompositionEventArgs e) } e.Handled = false; } + + /// + /// Cursor is removed from text box on pressing Return + /// + /// + protected override void OnKeyDown(KeyEventArgs e) + { + base.OnKeyDown(e); + if (e.Key == Key.Return) + Keyboard.ClearFocus(); + } } } diff --git a/MetaMorpheus/GUI/Util/IntegerTextBoxControl.cs b/MetaMorpheus/GUI/Util/IntegerTextBoxControl.cs index a3ec1c315..f0b59a44e 100644 --- a/MetaMorpheus/GUI/Util/IntegerTextBoxControl.cs +++ b/MetaMorpheus/GUI/Util/IntegerTextBoxControl.cs @@ -1,4 +1,5 @@ -using System.Windows.Controls; +using System.Windows; +using System.Windows.Controls; using System.Windows.Input; namespace MetaMorpheusGUI @@ -8,6 +9,16 @@ namespace MetaMorpheusGUI /// public class IntegerTexBoxControl : TextBox { + public IntegerTexBoxControl() + { + HorizontalContentAlignment = HorizontalAlignment.Center; + VerticalContentAlignment = VerticalAlignment.Center; + } + + /// + /// Ensures only integers can be inputted into the text box + /// + /// protected override void OnPreviewTextInput(TextCompositionEventArgs e) { foreach (var character in e.Text) @@ -20,5 +31,16 @@ protected override void OnPreviewTextInput(TextCompositionEventArgs e) } e.Handled = false; } + + /// + /// Cursor is removed from text box on pressing Return + /// + /// + protected override void OnKeyDown(KeyEventArgs e) + { + base.OnKeyDown(e); + if (e.Key == Key.Return) + Keyboard.ClearFocus(); + } } } diff --git a/MetaMorpheus/GUI/Views/FileSpecificParametersWindow.xaml b/MetaMorpheus/GUI/Views/FileSpecificParametersWindow.xaml index 43b038c9a..f07125e38 100644 --- a/MetaMorpheus/GUI/Views/FileSpecificParametersWindow.xaml +++ b/MetaMorpheus/GUI/Views/FileSpecificParametersWindow.xaml @@ -23,7 +23,7 @@