From 97cf8a4756fe0a422b7bf40a4b8b79a4e60ae6be Mon Sep 17 00:00:00 2001 From: Jacob Poteet <64765148+JacobPoteet@users.noreply.github.com> Date: Sat, 10 Feb 2024 13:38:33 -0500 Subject: [PATCH 1/8] Refactor KeyboardShortcutManager.cs for improved readability and maintainability The code changes in this commit simplify the logic in the `OnAcceleratorKeyActivated` method of `KeyboardShortcutManager.cs`. - Replaced nested if-else statements with concise conditional expressions - Removed redundant checks for `altPressed` and `controlKeyPressed` - Consolidated return statements based on key combinations --- .../Common/KeyboardShortcutManager.cs | 45 +++---------------- 1 file changed, 7 insertions(+), 38 deletions(-) diff --git a/src/Calculator/Common/KeyboardShortcutManager.cs b/src/Calculator/Common/KeyboardShortcutManager.cs index 22494bfa5..311d501a3 100644 --- a/src/Calculator/Common/KeyboardShortcutManager.cs +++ b/src/Calculator/Common/KeyboardShortcutManager.cs @@ -747,48 +747,17 @@ private static SortedDictionary> GetCurrentKey { int viewId = Utilities.GetWindowId(); - if (controlKeyPressed) + if (controlKeyPressed && !altPressed) { - if (altPressed) - { - return null; - } - else - { - if (shiftKeyPressed) - { - return s_VirtualKeyControlShiftChordsForButtons[viewId]; - } - else - { - return s_VirtualKeyControlChordsForButtons[viewId]; - } - } + return shiftKeyPressed ? s_VirtualKeyControlShiftChordsForButtons[viewId] : s_VirtualKeyControlChordsForButtons[viewId]; + } + else if (altPressed && !controlKeyPressed) + { + return shiftKeyPressed ? null : s_VirtualKeyAltChordsForButtons[viewId]; } else { - if (altPressed) - { - if (shiftKeyPressed) - { - return null; - } - else - { - return s_VirtualKeyAltChordsForButtons[viewId]; - } - } - else - { - if (shiftKeyPressed) - { - return s_VirtualKeyShiftChordsForButtons[viewId]; - } - else - { - return s_virtualKey[viewId]; - } - } + return shiftKeyPressed ? s_VirtualKeyShiftChordsForButtons[viewId] : s_virtualKey[viewId]; } } From d197d6922f593282f54d873ef94a2b86575ca872 Mon Sep 17 00:00:00 2001 From: Jacob Poteet <64765148+JacobPoteet@users.noreply.github.com> Date: Sat, 10 Feb 2024 14:48:44 -0500 Subject: [PATCH 2/8] Add Pressure_Torr as a new unit constant in UnitConverterDataConstants.h. This commit adds the Pressure_Torr constant to the list of unit constants in the UnitConverterDataConstants.h file. --- src/CalcViewModel/DataLoaders/UnitConverterDataConstants.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CalcViewModel/DataLoaders/UnitConverterDataConstants.h b/src/CalcViewModel/DataLoaders/UnitConverterDataConstants.h index db01aab77..7335d98ae 100644 --- a/src/CalcViewModel/DataLoaders/UnitConverterDataConstants.h +++ b/src/CalcViewModel/DataLoaders/UnitConverterDataConstants.h @@ -167,7 +167,8 @@ namespace CalculatorApp Energy_Kilowatthour = UnitStart + 166, Data_Nibble = UnitStart + 167, Length_Angstrom = UnitStart + 168, - UnitEnd = Length_Angstrom + Pressure_Torr = UnitStart + 169, + UnitEnd = Pressure_Torr }; } } From 79b2bf1a4d74af82c33faebd20d03c605a2699b6 Mon Sep 17 00:00:00 2001 From: Jacob Poteet <64765148+JacobPoteet@users.noreply.github.com> Date: Sat, 10 Feb 2024 15:33:37 -0500 Subject: [PATCH 3/8] Add Torr unit to pressure units in UnitConverterDataLoader.cpp This commit adds the Torr unit to the list of pressure units in the UnitConverterDataLoader.cpp file. The Torr unit is assigned a value of 7 and its localized name and abbreviation are retrieved using GetLocalizedStringName(). Additionally, the conversion data for Torr is added to the GetConversionData() function. --- src/CalcViewModel/DataLoaders/UnitConverterDataLoader.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/CalcViewModel/DataLoaders/UnitConverterDataLoader.cpp b/src/CalcViewModel/DataLoaders/UnitConverterDataLoader.cpp index 795091e9f..0123affe6 100644 --- a/src/CalcViewModel/DataLoaders/UnitConverterDataLoader.cpp +++ b/src/CalcViewModel/DataLoaders/UnitConverterDataLoader.cpp @@ -759,6 +759,8 @@ void UnitConverterDataLoader::GetUnits(_In_ unordered_map angleUnits; angleUnits.push_back(OrderedUnit{ UnitConverterUnits::Angle_Degree, @@ -947,7 +949,8 @@ void UnitConverterDataLoader::GetConversionData(_In_ unordered_map Date: Sat, 10 Feb 2024 15:44:36 -0500 Subject: [PATCH 4/8] Add Torr as a unit abbreviation for Pressure The code changes include adding the unit abbreviation "Torr" for pressure measurement in the Resources.resw file. This change allows users to use "Torr" as an abbreviation when working with pressure calculations. --- src/Calculator/Resources/en-US/Resources.resw | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Calculator/Resources/en-US/Resources.resw b/src/Calculator/Resources/en-US/Resources.resw index 384e80962..ab49e8d07 100644 --- a/src/Calculator/Resources/en-US/Resources.resw +++ b/src/Calculator/Resources/en-US/Resources.resw @@ -2361,6 +2361,10 @@ psi An abbreviation for a measurement unit of Pressure + + Torr + An abbreviation for a measurement unit of Pressure + cg An abbreviation for a measurement unit of weight From d0e3e45c6a122543d91610e5ca49efca795ef6d7 Mon Sep 17 00:00:00 2001 From: Jacob Poteet <64765148+JacobPoteet@users.noreply.github.com> Date: Sat, 10 Feb 2024 15:46:55 -0500 Subject: [PATCH 5/8] Add Torr as a measurement unit for Pressure. - Add new data entry for UnitName_Torr - Set value to "Torr" - Set comment to "A measurement unit for Pressure." --- src/Calculator/Resources/en-US/Resources.resw | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Calculator/Resources/en-US/Resources.resw b/src/Calculator/Resources/en-US/Resources.resw index ab49e8d07..7744d8a59 100644 --- a/src/Calculator/Resources/en-US/Resources.resw +++ b/src/Calculator/Resources/en-US/Resources.resw @@ -2457,6 +2457,10 @@ Pounds per square inch A measurement unit for Pressure. + + Torr + A measurement unit for Pressure. + Centigrams A measurement unit for weight. (Please choose the most appropriate plural form to fit any number between 0 and 999,999,999,999,999) From aecb9d3743a69e9dba2888700a550da4fa5275f2 Mon Sep 17 00:00:00 2001 From: Jacob Poteet <64765148+JacobPoteet@users.noreply.github.com> Date: Sat, 10 Feb 2024 15:55:34 -0500 Subject: [PATCH 6/8] Add conversion data for "Atmospheres-Torr" in Test.resw This commit adds a new conversion data entry for "Atmospheres-Torr" in the Test.resw file. The value of this conversion is 0.00131578947368. --- src/CalculatorUnitTests/Test.resw | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/CalculatorUnitTests/Test.resw b/src/CalculatorUnitTests/Test.resw index 346b24c0a..be3dab7d5 100644 --- a/src/CalculatorUnitTests/Test.resw +++ b/src/CalculatorUnitTests/Test.resw @@ -576,6 +576,9 @@ 0.068045961016531 + + 0.00131578947368 + 0.002 From f5439bf11d74f3725d0c205c5c77a2f44f05c2fb Mon Sep 17 00:00:00 2001 From: Jacob Poteet <64765148+JacobPoteet@users.noreply.github.com> Date: Sat, 10 Feb 2024 16:06:29 -0500 Subject: [PATCH 7/8] Refactor UnitConverterDataLoader.cpp to correctly add pressure units The commit fixes a bug in the code where the pressure units were not being added correctly. The issue was resolved by moving the `emplace` statement after adding the `pressureUnits` vector. --- src/CalcViewModel/DataLoaders/UnitConverterDataLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CalcViewModel/DataLoaders/UnitConverterDataLoader.cpp b/src/CalcViewModel/DataLoaders/UnitConverterDataLoader.cpp index 0123affe6..34bdc5029 100644 --- a/src/CalcViewModel/DataLoaders/UnitConverterDataLoader.cpp +++ b/src/CalcViewModel/DataLoaders/UnitConverterDataLoader.cpp @@ -758,9 +758,9 @@ void UnitConverterDataLoader::GetUnits(_In_ unordered_map angleUnits; angleUnits.push_back(OrderedUnit{ UnitConverterUnits::Angle_Degree, From b57154f75c31032c7fdcbadf920ab3a949d7b288 Mon Sep 17 00:00:00 2001 From: Jacob Poteet <64765148+JacobPoteet@users.noreply.github.com> Date: Sat, 10 Feb 2024 16:29:29 -0500 Subject: [PATCH 8/8] Revert unrelated optimization --- .../Common/KeyboardShortcutManager.cs | 45 ++++++++++++++++--- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/src/Calculator/Common/KeyboardShortcutManager.cs b/src/Calculator/Common/KeyboardShortcutManager.cs index 311d501a3..22494bfa5 100644 --- a/src/Calculator/Common/KeyboardShortcutManager.cs +++ b/src/Calculator/Common/KeyboardShortcutManager.cs @@ -747,17 +747,48 @@ private static SortedDictionary> GetCurrentKey { int viewId = Utilities.GetWindowId(); - if (controlKeyPressed && !altPressed) + if (controlKeyPressed) { - return shiftKeyPressed ? s_VirtualKeyControlShiftChordsForButtons[viewId] : s_VirtualKeyControlChordsForButtons[viewId]; - } - else if (altPressed && !controlKeyPressed) - { - return shiftKeyPressed ? null : s_VirtualKeyAltChordsForButtons[viewId]; + if (altPressed) + { + return null; + } + else + { + if (shiftKeyPressed) + { + return s_VirtualKeyControlShiftChordsForButtons[viewId]; + } + else + { + return s_VirtualKeyControlChordsForButtons[viewId]; + } + } } else { - return shiftKeyPressed ? s_VirtualKeyShiftChordsForButtons[viewId] : s_virtualKey[viewId]; + if (altPressed) + { + if (shiftKeyPressed) + { + return null; + } + else + { + return s_VirtualKeyAltChordsForButtons[viewId]; + } + } + else + { + if (shiftKeyPressed) + { + return s_VirtualKeyShiftChordsForButtons[viewId]; + } + else + { + return s_virtualKey[viewId]; + } + } } }