From 2074db6f78ed80d70acaf9a285c6fd11950a1ae1 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 141298bb9..c3fe992d1 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 5901d205325390c77eb2d6d90963717b41a6df25 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 057b6da02..0b4a666df 100644 --- a/src/CalcViewModel/DataLoaders/UnitConverterDataConstants.h +++ b/src/CalcViewModel/DataLoaders/UnitConverterDataConstants.h @@ -166,7 +166,8 @@ namespace CalculatorApp Area_Pyeong = UnitStart + 165, Energy_Kilowatthour = UnitStart + 166, Data_Nibble = UnitStart + 167, - UnitEnd = Data_Nibble + Pressure_Torr = UnitStart + 168, + UnitEnd = Pressure_Torr }; } } From 9681cfc37c241ad888f8a3ff54fa21b7768cbdfa 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 844dd3fe1..a5c9b9162 100644 --- a/src/CalcViewModel/DataLoaders/UnitConverterDataLoader.cpp +++ b/src/CalcViewModel/DataLoaders/UnitConverterDataLoader.cpp @@ -757,6 +757,8 @@ void UnitConverterDataLoader::GetUnits(_In_ unordered_map angleUnits; angleUnits.push_back(OrderedUnit{ UnitConverterUnits::Angle_Degree, @@ -944,7 +946,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 3d27bd36e..efbd1e6af 100644 --- a/src/Calculator/Resources/en-US/Resources.resw +++ b/src/Calculator/Resources/en-US/Resources.resw @@ -2353,6 +2353,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 593e05cf3f58a345289c177c223c1819fe435a19 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 efbd1e6af..f928ee20a 100644 --- a/src/Calculator/Resources/en-US/Resources.resw +++ b/src/Calculator/Resources/en-US/Resources.resw @@ -2449,6 +2449,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 c251337a531852902be3d7f5393a4105dd660d9e 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 bc8b6f69c..9e61bbd1d 100644 --- a/src/CalculatorUnitTests/Test.resw +++ b/src/CalculatorUnitTests/Test.resw @@ -573,6 +573,9 @@ 0.068045961016531 + + 0.00131578947368 + 0.002 From a01f7a9e3c834b983377205c0c5ebcb0ff59b716 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 a5c9b9162..0e1bbd7ef 100644 --- a/src/CalcViewModel/DataLoaders/UnitConverterDataLoader.cpp +++ b/src/CalcViewModel/DataLoaders/UnitConverterDataLoader.cpp @@ -756,9 +756,9 @@ void UnitConverterDataLoader::GetUnits(_In_ unordered_map angleUnits; angleUnits.push_back(OrderedUnit{ UnitConverterUnits::Angle_Degree, From afbb7243fb2128c11e526ab226e6874d42f4ca71 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 c3fe992d1..141298bb9 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]; + } + } } }