From d9a32fdf4f09e1d9870fd76873465d43cd094cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Fri, 23 Sep 2022 00:22:59 +0200 Subject: [PATCH 01/14] Include cstdint in CalcErr.h for uint32_t et al (#1892) --- src/CalcManager/Ratpack/CalcErr.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CalcManager/Ratpack/CalcErr.h b/src/CalcManager/Ratpack/CalcErr.h index ebdc6730..9e4223e6 100644 --- a/src/CalcManager/Ratpack/CalcErr.h +++ b/src/CalcManager/Ratpack/CalcErr.h @@ -3,6 +3,8 @@ #pragma once +#include + // CalcErr.h // // Defines the error codes thrown by ratpak and caught by Calculator From d9ef114dbef63450280a98795fdbaf7717d5d42b Mon Sep 17 00:00:00 2001 From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Fri, 23 Sep 2022 12:04:28 -0400 Subject: [PATCH 02/14] Use "make_unique" instead of manually allocating and then creating a unique pointer (#1899) --- src/CalcViewModel/Common/LocalizationStringUtil.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CalcViewModel/Common/LocalizationStringUtil.h b/src/CalcViewModel/Common/LocalizationStringUtil.h index 33aa482d..d7e08032 100644 --- a/src/CalcViewModel/Common/LocalizationStringUtil.h +++ b/src/CalcViewModel/Common/LocalizationStringUtil.h @@ -16,7 +16,7 @@ namespace CalculatorApp::ViewModel { std::wstring returnString = L""; const UINT32 length = 1024; - std::unique_ptr spBuffer = std::unique_ptr(new wchar_t[length]); + std::unique_ptr spBuffer = std::make_unique(length); va_list args = NULL; va_start(args, pMessage); DWORD fmtReturnVal = FormatMessage(FORMAT_MESSAGE_FROM_STRING, pMessage->Data(), 0, 0, spBuffer.get(), length, &args); From 135c37d6f7345aceb0d15b958c92939da66f7b4b Mon Sep 17 00:00:00 2001 From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Fri, 23 Sep 2022 12:05:20 -0400 Subject: [PATCH 03/14] Fix DwWordBitWidthFromeNumWidth typo (#1898) --- src/CalcManager/CEngine/calc.cpp | 2 +- src/CalcManager/CEngine/sciset.cpp | 6 +++--- src/CalcManager/Header Files/CalcEngine.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/CalcManager/CEngine/calc.cpp b/src/CalcManager/CEngine/calc.cpp index dd70fb63..713a661c 100644 --- a/src/CalcManager/CEngine/calc.cpp +++ b/src/CalcManager/CEngine/calc.cpp @@ -101,7 +101,7 @@ CCalcEngine::CCalcEngine( { InitChopNumbers(); - m_dwWordBitWidth = DwWordBitWidthFromeNumWidth(m_numwidth); + m_dwWordBitWidth = DwWordBitWidthFromNumWidth(m_numwidth); m_maxTrigonometricNum = RationalMath::Pow(10, 100); diff --git a/src/CalcManager/CEngine/sciset.cpp b/src/CalcManager/CEngine/sciset.cpp index cb143559..57aeda3b 100644 --- a/src/CalcManager/CEngine/sciset.cpp +++ b/src/CalcManager/CEngine/sciset.cpp @@ -39,7 +39,7 @@ void CCalcEngine::SetRadixTypeAndNumWidth(RadixType radixtype, NUM_WIDTH numwidt if (numwidth >= NUM_WIDTH::QWORD_WIDTH && numwidth <= NUM_WIDTH::BYTE_WIDTH) { m_numwidth = numwidth; - m_dwWordBitWidth = DwWordBitWidthFromeNumWidth(numwidth); + m_dwWordBitWidth = DwWordBitWidthFromNumWidth(numwidth); } // inform ratpak that a change in base or precision has occurred @@ -50,7 +50,7 @@ void CCalcEngine::SetRadixTypeAndNumWidth(RadixType radixtype, NUM_WIDTH numwidt DisplayNum(); } -int32_t CCalcEngine::DwWordBitWidthFromeNumWidth(NUM_WIDTH numwidth) +int32_t CCalcEngine::DwWordBitWidthFromNumWidth(NUM_WIDTH numwidth) { switch (numwidth) { @@ -85,7 +85,7 @@ uint32_t CCalcEngine::NRadixFromRadixType(RadixType radixtype) // Toggles a given bit into the number representation. returns true if it changed it actually. bool CCalcEngine::TryToggleBit(CalcEngine::Rational& rat, uint32_t wbitno) { - uint32_t wmax = DwWordBitWidthFromeNumWidth(m_numwidth); + uint32_t wmax = DwWordBitWidthFromNumWidth(m_numwidth); if (wbitno >= wmax) { return false; // ignore error cant happen diff --git a/src/CalcManager/Header Files/CalcEngine.h b/src/CalcManager/Header Files/CalcEngine.h index 7709cf61..f387c020 100644 --- a/src/CalcManager/Header Files/CalcEngine.h +++ b/src/CalcManager/Header Files/CalcEngine.h @@ -179,7 +179,7 @@ private: CalcEngine::Rational SciCalcFunctions(CalcEngine::Rational const& rat, uint32_t op); CalcEngine::Rational DoOperation(int operation, CalcEngine::Rational const& lhs, CalcEngine::Rational const& rhs); void SetRadixTypeAndNumWidth(RadixType radixtype, NUM_WIDTH numwidth); - int32_t DwWordBitWidthFromeNumWidth(NUM_WIDTH numwidth); + int32_t DwWordBitWidthFromNumWidth(NUM_WIDTH numwidth); uint32_t NRadixFromRadixType(RadixType radixtype); double GenerateRandomNumber(); From 5c98b6e53c2a33cd2079327d7620582eaf9068c9 Mon Sep 17 00:00:00 2001 From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Fri, 23 Sep 2022 12:06:49 -0400 Subject: [PATCH 04/14] Resolve TODO - MSFT 12735088 (#1901) Since we use minimum version 17763, we can safely remove these namespaces --- src/CalcViewModel/pch.h | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/CalcViewModel/pch.h b/src/CalcViewModel/pch.h index 6d4cd9c2..5b188017 100644 --- a/src/CalcViewModel/pch.h +++ b/src/CalcViewModel/pch.h @@ -42,14 +42,3 @@ #include "winrt/Windows.UI.Xaml.h" #include "winrt/Windows.Foundation.Metadata.h" #include "winrt/Windows.Management.Policies.h" - -// The following namespaces exist as a convenience to resolve -// ambiguity for Windows types in the Windows::UI::Xaml::Automation::Peers -// namespace that only exist on RS3. -// Once the app switches to min version RS3, the namespaces can be removed. -// TODO - MSFT 12735088 -namespace StandardPeers = Windows::UI::Xaml::Automation::Peers; -namespace CalculatorApp::ViewModel::Common::Automation -{ -} -namespace CustomPeers = CalculatorApp::ViewModel::Common::Automation; From 65761364652742982022f5eb76ec839c210ba863 Mon Sep 17 00:00:00 2001 From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Fri, 23 Sep 2022 12:09:01 -0400 Subject: [PATCH 05/14] Use a switch statement instead of an array (#1900) This makes processing of opCodes faster --- src/CalcManager/CEngine/scicomm.cpp | 34 ++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/CalcManager/CEngine/scicomm.cpp b/src/CalcManager/CEngine/scicomm.cpp index 4d671fbd..dcf1c44f 100644 --- a/src/CalcManager/CEngine/scicomm.cpp +++ b/src/CalcManager/CEngine/scicomm.cpp @@ -30,17 +30,31 @@ namespace // 0 is returned. Higher the number, higher the precedence of the operator. int NPrecedenceOfOp(int nopCode) { - static uint16_t rgbPrec[] = { 0, 0, IDC_OR, 0, IDC_XOR, 0, IDC_AND, 1, IDC_NAND, 1, IDC_NOR, 1, IDC_ADD, 2, IDC_SUB, 2, IDC_RSHF, 3, - IDC_LSHF, 3, IDC_RSHFL, 3, IDC_MOD, 3, IDC_DIV, 3, IDC_MUL, 3, IDC_PWR, 4, IDC_ROOT, 4, IDC_LOGBASEY, 4 }; - - for (unsigned int iPrec = 0; iPrec < size(rgbPrec); iPrec += 2) + switch (nopCode) { - if (nopCode == rgbPrec[iPrec]) - { - return rgbPrec[iPrec + 1]; - } + default: + case IDC_OR: + case IDC_XOR: + return 0; + case IDC_AND: + case IDC_NAND: + case IDC_NOR: + return 1; + case IDC_ADD: + case IDC_SUB: + return 2; + case IDC_LSHF: + case IDC_RSHF: + case IDC_RSHFL: + case IDC_MOD: + case IDC_DIV: + case IDC_MUL: + return 3; + case IDC_PWR: + case IDC_ROOT: + case IDC_LOGBASEY: + return 4; } - return 0; } } @@ -518,7 +532,7 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam) if (wParam == IDC_OPENP) { - // if there's an omitted multiplication sign + // if there's an omitted multiplication sign if (IsDigitOpCode(m_nLastCom) || IsUnaryOpCode(m_nLastCom) || m_nLastCom == IDC_PNT || m_nLastCom == IDC_CLOSEP) { ProcessCommand(IDC_MUL); From 095a81fecc4d80ca7adb3b0f5f6da2c2ab6e26a0 Mon Sep 17 00:00:00 2001 From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Fri, 23 Sep 2022 14:59:28 -0400 Subject: [PATCH 06/14] Use copy_n instead of of copy (#1897) It is a better choice for this occasion and more performant. --- src/CalcManager/CEngine/Number.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/CalcManager/CEngine/Number.cpp b/src/CalcManager/CEngine/Number.cpp index 7b3be21b..da443b12 100644 --- a/src/CalcManager/CEngine/Number.cpp +++ b/src/CalcManager/CEngine/Number.cpp @@ -22,10 +22,9 @@ namespace CalcEngine Number::Number(PNUMBER p) noexcept : m_sign{ p->sign } , m_exp{ p->exp } - , m_mantissa{} { m_mantissa.reserve(p->cdigit); - copy(p->mant, p->mant + p->cdigit, back_inserter(m_mantissa)); + copy_n(p->mant, p->cdigit, back_inserter(m_mantissa)); } PNUMBER Number::ToPNUMBER() const From b06e4403db5d18ed7f114a04f13c10cddc8a218f Mon Sep 17 00:00:00 2001 From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Fri, 23 Sep 2022 17:24:34 -0400 Subject: [PATCH 07/14] Remove always-false UITest check (#1904) startUpTimeout can never be null. It is impossible. Fixes build warning --- src/CalculatorUITestFramework/WindowsDriverServiceBuilder.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/CalculatorUITestFramework/WindowsDriverServiceBuilder.cs b/src/CalculatorUITestFramework/WindowsDriverServiceBuilder.cs index bdf60574..dec24fe0 100644 --- a/src/CalculatorUITestFramework/WindowsDriverServiceBuilder.cs +++ b/src/CalculatorUITestFramework/WindowsDriverServiceBuilder.cs @@ -45,10 +45,6 @@ namespace CalculatorUITestFramework public WindowsDriverServiceBuilder WithStartUpTimeOut(TimeSpan startUpTimeout) { - if (startUpTimeout == null) - { - throw new ArgumentNullException("A startup timeout should not be NULL"); - } this.StartUpTimeout = startUpTimeout; return this; } From febb10ccc493d2015d0209919dcd702b11fd054f Mon Sep 17 00:00:00 2001 From: Matt Cooley Date: Sun, 25 Sep 2022 18:40:53 -0700 Subject: [PATCH 08/14] Nuget updates (#1891) * Update Microsoft.NETCore.UniversalWindowsPlatform 6.2.10 -> 6.2.14 * Update Microsoft.UI.Xaml 2.8.0 -> 2.8.1 * Update MSTest NuGet packages to 2.2.10 * Update Microsoft.NET.Test.Sdk 17.0.0 -> 17.3.1 * Update Appium.WebDriver 4.3.1 -> 4.3.2 --- src/Calculator/Calculator.csproj | 4 ++-- .../CalculatorUITestFramework.csproj | 4 ++-- src/CalculatorUITests/CalculatorUITests.csproj | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Calculator/Calculator.csproj b/src/Calculator/Calculator.csproj index f47de837..aa7e1f17 100644 --- a/src/Calculator/Calculator.csproj +++ b/src/Calculator/Calculator.csproj @@ -792,9 +792,9 @@ - 6.2.10 + 6.2.14 - + diff --git a/src/CalculatorUITestFramework/CalculatorUITestFramework.csproj b/src/CalculatorUITestFramework/CalculatorUITestFramework.csproj index 0fc0236f..dc33a259 100644 --- a/src/CalculatorUITestFramework/CalculatorUITestFramework.csproj +++ b/src/CalculatorUITestFramework/CalculatorUITestFramework.csproj @@ -3,7 +3,7 @@ net6.0 - - + + \ No newline at end of file diff --git a/src/CalculatorUITests/CalculatorUITests.csproj b/src/CalculatorUITests/CalculatorUITests.csproj index 1d4416e6..984842cd 100644 --- a/src/CalculatorUITests/CalculatorUITests.csproj +++ b/src/CalculatorUITests/CalculatorUITests.csproj @@ -4,10 +4,10 @@ false - - - - + + + + From 71330d5b855c6f2d17fec7853fee1e8e32731c4f Mon Sep 17 00:00:00 2001 From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Sun, 25 Sep 2022 23:38:07 -0400 Subject: [PATCH 09/14] Use using instead of typedef (#1903) --- src/CalcManager/Ratpack/CalcErr.h | 2 +- src/CalcManager/UnitConverter.h | 9 ++++----- src/GraphingInterfaces/IGraphAnalyzer.h | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/CalcManager/Ratpack/CalcErr.h b/src/CalcManager/Ratpack/CalcErr.h index 9e4223e6..5f7ae524 100644 --- a/src/CalcManager/Ratpack/CalcErr.h +++ b/src/CalcManager/Ratpack/CalcErr.h @@ -38,7 +38,7 @@ // This format is based loosely on an OLE HRESULT and is compatible with the // SUCCEEDED and FAILED macros as well as the HRESULT_CODE macro -typedef int32_t ResultCode; +using ResultCode = int32_t; // CALC_E_DIVIDEBYZERO // diff --git a/src/CalcManager/UnitConverter.h b/src/CalcManager/UnitConverter.h index 0ee06ae3..44255816 100644 --- a/src/CalcManager/UnitConverter.h +++ b/src/CalcManager/UnitConverter.h @@ -156,13 +156,12 @@ namespace UnitConversionManager std::wstring targetCurrencyCode; }; - typedef std::tuple, UnitConversionManager::Unit, UnitConversionManager::Unit> CategorySelectionInitializer; - typedef std::unordered_map< + using CategorySelectionInitializer = std::tuple, UnitConversionManager::Unit, UnitConversionManager::Unit>; + using UnitToUnitToConversionDataMap = std::unordered_map< UnitConversionManager::Unit, std::unordered_map, - UnitConversionManager::UnitHash> - UnitToUnitToConversionDataMap; - typedef std::unordered_map> CategoryToUnitVectorMap; + UnitConversionManager::UnitHash>; + using CategoryToUnitVectorMap = std::unordered_map>; class IViewModelCurrencyCallback { diff --git a/src/GraphingInterfaces/IGraphAnalyzer.h b/src/GraphingInterfaces/IGraphAnalyzer.h index 5e6233b6..0e832163 100644 --- a/src/GraphingInterfaces/IGraphAnalyzer.h +++ b/src/GraphingInterfaces/IGraphAnalyzer.h @@ -11,7 +11,7 @@ namespace Graphing::Analyzer { - typedef unsigned int NativeAnalysisType; // PerformAnalysisType + using NativeAnalysisType = unsigned int; // PerformAnalysisType struct IGraphAnalyzer : public NonCopyable, public NonMoveable { From dbc924cac9c27b31a83f9f131e5f9f4e8769b6c8 Mon Sep 17 00:00:00 2001 From: Matt Cooley Date: Sun, 25 Sep 2022 20:42:31 -0700 Subject: [PATCH 10/14] Clarify that Windows 11 is required to build (#1893) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5582b172..cc68ddb1 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Calculator ships regularly with new features and bug fixes. You can get the late ## Getting started Prerequisites: -- Your computer must be running Windows 10, version 1809 or newer. Windows 11 is recommended. +- Your computer must be running Windows 11, build 22000 or newer. - Install the latest version of [Visual Studio](https://developer.microsoft.com/en-us/windows/downloads) (the free community edition is sufficient). - Install the "Universal Windows Platform Development" workload. - Install the optional "C++ Universal Windows Platform tools" component. From 6f9e142fb03a18cf431c72b4e450352afd72b22c Mon Sep 17 00:00:00 2001 From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Mon, 26 Sep 2022 10:15:59 -0400 Subject: [PATCH 11/14] Make the Ping method thread-safe (#1905) So we do not risk blocking the main UI thread --- .../WindowsDriverLocalService.cs | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/CalculatorUITestFramework/WindowsDriverLocalService.cs b/src/CalculatorUITestFramework/WindowsDriverLocalService.cs index 8841c6cb..60fba41d 100644 --- a/src/CalculatorUITestFramework/WindowsDriverLocalService.cs +++ b/src/CalculatorUITestFramework/WindowsDriverLocalService.cs @@ -20,6 +20,7 @@ using System.IO; using System.Net; using System.Net.Http; using System.Runtime.CompilerServices; +using System.Threading.Tasks; namespace CalculatorUITestFramework { @@ -146,20 +147,23 @@ namespace CalculatorUITestFramework { Uri status; Uri service = this.ServiceUrl; - HttpClient httpClient = new HttpClient(); - httpClient.Timeout = this.InitializationTimeout; + using (HttpClient httpClient = new HttpClient()) + { + httpClient.Timeout = this.InitializationTimeout; - if (service.IsLoopback) - { - status = new Uri("http://localhost:" + Convert.ToString(this.Port) + "/status"); + if (service.IsLoopback) + { + status = new Uri("http://localhost:" + Convert.ToString(this.Port) + "/status"); + } + else + { + status = new Uri(service + "/status"); + } + + var httpResponse = Task.Run(() => httpClient.GetAsync(status)).ConfigureAwait(false).GetAwaiter().GetResult(); + + return httpResponse.IsSuccessStatusCode; } - else - { - status = new Uri(service + "/status"); - } - - var httpResponse = httpClient.GetAsync(status); - return httpResponse.Result.IsSuccessStatusCode; } } } From 2addaae64c38c6de391e5caa3d81a84ca00925b1 Mon Sep 17 00:00:00 2001 From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Mon, 26 Sep 2022 13:03:00 -0400 Subject: [PATCH 12/14] Use enhanced switches (#1908) --- .../NavigationMenu.cs | 76 +++++-------------- .../ScientificOperatorsPanel.cs | 20 ++--- 2 files changed, 26 insertions(+), 70 deletions(-) diff --git a/src/CalculatorUITestFramework/NavigationMenu.cs b/src/CalculatorUITestFramework/NavigationMenu.cs index 13dab3ac..6de7ac15 100644 --- a/src/CalculatorUITestFramework/NavigationMenu.cs +++ b/src/CalculatorUITestFramework/NavigationMenu.cs @@ -41,63 +41,27 @@ namespace CalculatorUITestFramework /// The mode to be changed to public void ChangeCalculatorMode(CalculatorMode mode) { - string modeAccessibilityId; - switch (mode) + string modeAccessibilityId = mode switch { - case CalculatorMode.StandardCalculator: - modeAccessibilityId = "Standard"; - break; - case CalculatorMode.ScientificCalculator: - modeAccessibilityId = "Scientific"; - break; - case CalculatorMode.ProgrammerCalculator: - modeAccessibilityId = "Programmer"; - break; - case CalculatorMode.DateCalculator: - modeAccessibilityId = "Date"; - break; - case CalculatorMode.Currency: - modeAccessibilityId = "Currency"; - break; - case CalculatorMode.Volume: - modeAccessibilityId = "Volume"; - break; - case CalculatorMode.Length: - modeAccessibilityId = "Length"; - break; - case CalculatorMode.Weight: - modeAccessibilityId = "Weight"; - break; - case CalculatorMode.Temperature: - modeAccessibilityId = "Temperature"; - break; - case CalculatorMode.Energy: - modeAccessibilityId = "Energy"; - break; - case CalculatorMode.Area: - modeAccessibilityId = "Area"; - break; - case CalculatorMode.Speed: - modeAccessibilityId = "Speed"; - break; - case CalculatorMode.Time: - modeAccessibilityId = "Time"; - break; - case CalculatorMode.Power: - modeAccessibilityId = "Power"; - break; - case CalculatorMode.Data: - modeAccessibilityId = "Data"; - break; - case CalculatorMode.Pressure: - modeAccessibilityId = "Pressure"; - break; - case CalculatorMode.Angle: - modeAccessibilityId = "Angle"; - break; - default: - throw (new ArgumentException("The mode is not valid")); - } + CalculatorMode.StandardCalculator => "Standard", + CalculatorMode.ScientificCalculator => "Scientific", + CalculatorMode.ProgrammerCalculator => "Programmer", + CalculatorMode.DateCalculator => "Date", + CalculatorMode.Currency => "Currency", + CalculatorMode.Volume => "Volume", + CalculatorMode.Length => "Length", + CalculatorMode.Weight => "Weight", + CalculatorMode.Temperature => "Temperature", + CalculatorMode.Energy => "Energy", + CalculatorMode.Area => "Area", + CalculatorMode.Speed => "Speed", + CalculatorMode.Time => "Time", + CalculatorMode.Power => "Power", + CalculatorMode.Data => "Data", + CalculatorMode.Pressure => "Pressure", + CalculatorMode.Angle => "Angle", + _ => throw (new ArgumentException("The mode is not valid")) + }; this.NavigationMenuButton.Click(); this.NavigationMenuPane.WaitForDisplayed(); diff --git a/src/CalculatorUITestFramework/ScientificOperatorsPanel.cs b/src/CalculatorUITestFramework/ScientificOperatorsPanel.cs index ce94241c..b1146f05 100644 --- a/src/CalculatorUITestFramework/ScientificOperatorsPanel.cs +++ b/src/CalculatorUITestFramework/ScientificOperatorsPanel.cs @@ -109,21 +109,13 @@ namespace CalculatorUITestFramework public void SetAngleOperator(AngleOperatorState value) { //set the desired string value for the button - string desiredId; - switch (value) + string desiredId = value switch { - case AngleOperatorState.Degrees: - desiredId = "degButton"; - break; - case AngleOperatorState.Gradians: - desiredId = "gradButton"; - break; - case AngleOperatorState.Radians: - desiredId = "radButton"; - break; - default: - throw new NotImplementedException(); - } + AngleOperatorState.Degrees => "degButton", + AngleOperatorState.Gradians => "gradButton", + AngleOperatorState.Radians => "radButton", + _ => throw new NotImplementedException() + }; while (this.DegRadGradButton.GetAttribute("AutomationId") != desiredId) { this.DegRadGradButton.Click(); From 0de7449460d5251e11b79fca4b2908c8d64228ce Mon Sep 17 00:00:00 2001 From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Wed, 28 Sep 2022 09:17:09 -0400 Subject: [PATCH 13/14] Simplify SetTrigRowVisibility (#1913) --- src/Calculator/Views/CalculatorScientificOperators.xaml.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Calculator/Views/CalculatorScientificOperators.xaml.cs b/src/Calculator/Views/CalculatorScientificOperators.xaml.cs index ee2213a6..7a1be787 100644 --- a/src/Calculator/Views/CalculatorScientificOperators.xaml.cs +++ b/src/Calculator/Views/CalculatorScientificOperators.xaml.cs @@ -124,11 +124,11 @@ namespace CalculatorApp { InverseHyperbolicTrigFunctions.Visibility = Visibility.Visible; } - else if (isShiftChecked && !isHypeChecked) + else if (isShiftChecked) { InverseTrigFunctions.Visibility = Visibility.Visible; } - else if (!isShiftChecked && isHypeChecked) + else if (isHypeChecked) { HyperbolicTrigFunctions.Visibility = Visibility.Visible; } From edf08514a6773443bc75b8c3add497e1ab454ebe Mon Sep 17 00:00:00 2001 From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Wed, 28 Sep 2022 12:31:41 -0400 Subject: [PATCH 14/14] Use lambdas instead of making new Handler objects (#1915) --- .../Common/AlwaysSelectedCollectionView.cs | 4 +-- src/Calculator/Controls/CalculationResult.cs | 22 +++++++-------- src/Calculator/Controls/CalculatorButton.cs | 8 +++--- src/Calculator/Controls/OverflowTextBlock.cs | 8 +++--- src/Calculator/Views/Calculator.xaml.cs | 6 ++--- .../EquationInputArea.xaml.cs | 27 ++++++------------- .../GraphingCalculator.xaml.cs | 8 +++--- .../GraphingCalculator/GraphingNumPad.xaml.cs | 2 +- src/Calculator/Views/TitleBar.xaml.cs | 22 +++++++-------- src/Calculator/Views/UnitConverter.xaml.cs | 11 +++----- src/Calculator/WindowFrameService.cs | 4 +-- 11 files changed, 52 insertions(+), 70 deletions(-) diff --git a/src/Calculator/Common/AlwaysSelectedCollectionView.cs b/src/Calculator/Common/AlwaysSelectedCollectionView.cs index cada6702..21e7b8f0 100644 --- a/src/Calculator/Common/AlwaysSelectedCollectionView.cs +++ b/src/Calculator/Common/AlwaysSelectedCollectionView.cs @@ -44,10 +44,10 @@ namespace CalculatorApp // restore the selection to the way we wanted it to begin with if (CurrentPosition >= 0 && CurrentPosition < m_source.Count) { - Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() => + Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { CurrentChanged?.Invoke(this, null); - })).AsTask().Wait(); + }).AsTask().Wait(); } return false; } diff --git a/src/Calculator/Controls/CalculationResult.cs b/src/Calculator/Controls/CalculationResult.cs index 78a65d0d..07f02992 100644 --- a/src/Calculator/Controls/CalculationResult.cs +++ b/src/Calculator/Controls/CalculationResult.cs @@ -33,11 +33,11 @@ namespace CalculatorApp // Using a DependencyProperty as the backing store for MinFontSize. This enables animation, styling, binding, etc... public static readonly DependencyProperty MinFontSizeProperty = - DependencyProperty.Register(nameof(MinFontSize), typeof(double), typeof(CalculationResult), new PropertyMetadata(0.0, new PropertyChangedCallback((sender, args) => + DependencyProperty.Register(nameof(MinFontSize), typeof(double), typeof(CalculationResult), new PropertyMetadata(0.0, (sender, args) => { var self = (CalculationResult)sender; self.OnMinFontSizePropertyChanged((double)args.OldValue, (double)args.NewValue); - }))); + })); public double MaxFontSize { @@ -47,11 +47,11 @@ namespace CalculatorApp // Using a DependencyProperty as the backing store for MaxFontSize. This enables animation, styling, binding, etc... public static readonly DependencyProperty MaxFontSizeProperty = - DependencyProperty.Register(nameof(MaxFontSize), typeof(double), typeof(CalculationResult), new PropertyMetadata(30.0, new PropertyChangedCallback((sender, args) => + DependencyProperty.Register(nameof(MaxFontSize), typeof(double), typeof(CalculationResult), new PropertyMetadata(30.0, (sender, args) => { var self = (CalculationResult)sender; self.OnMaxFontSizePropertyChanged((double)args.OldValue, (double)args.NewValue); - }))); + })); public Thickness DisplayMargin { @@ -71,11 +71,11 @@ namespace CalculatorApp // Using a DependencyProperty as the backing store for IsActive. This enables animation, styling, binding, etc... public static readonly DependencyProperty IsActiveProperty = - DependencyProperty.Register(nameof(IsActive), typeof(bool), typeof(CalculationResult), new PropertyMetadata(default(bool), new PropertyChangedCallback((sender, args) => + DependencyProperty.Register(nameof(IsActive), typeof(bool), typeof(CalculationResult), new PropertyMetadata(default(bool), (sender, args) => { var self = (CalculationResult)sender; self.OnIsActivePropertyChanged((bool)args.OldValue, (bool)args.NewValue); - }))); + })); public string DisplayValue { @@ -85,11 +85,11 @@ namespace CalculatorApp // Using a DependencyProperty as the backing store for DisplayValue. This enables animation, styling, binding, etc... public static readonly DependencyProperty DisplayValueProperty = - DependencyProperty.Register(nameof(DisplayValue), typeof(string), typeof(CalculationResult), new PropertyMetadata(string.Empty, new PropertyChangedCallback((sender, args) => + DependencyProperty.Register(nameof(DisplayValue), typeof(string), typeof(CalculationResult), new PropertyMetadata(string.Empty, (sender, args) => { var self = (CalculationResult)sender; self.OnDisplayValuePropertyChanged((string)args.OldValue, (string)args.NewValue); - }))); + })); public bool IsInError { @@ -99,11 +99,11 @@ namespace CalculatorApp // Using a DependencyProperty as the backing store for IsInError. This enables animation, styling, binding, etc... public static readonly DependencyProperty IsInErrorProperty = - DependencyProperty.Register(nameof(IsInError), typeof(bool), typeof(CalculationResult), new PropertyMetadata(default(bool), new PropertyChangedCallback((sender, args) => + DependencyProperty.Register(nameof(IsInError), typeof(bool), typeof(CalculationResult), new PropertyMetadata(default(bool), (sender, args) => { var self = (CalculationResult)sender; self.OnIsInErrorPropertyChanged((bool)args.OldValue, (bool)args.NewValue); - }))); + })); public bool IsOperatorCommand { @@ -151,7 +151,7 @@ namespace CalculatorApp if (widthDiff > WIDTHCUTOFF) { - fontSizeChange = Math.Min((double)Math.Max((double)Math.Floor(WIDTHTOFONTSCALAR * widthDiff) - WIDTHTOFONTOFFSET, INCREMENTOFFSET), MAXFONTINCREMENT); + fontSizeChange = Math.Min(Math.Max(Math.Floor(WIDTHTOFONTSCALAR * widthDiff) - WIDTHTOFONTOFFSET, INCREMENTOFFSET), MAXFONTINCREMENT); } if (m_textBlock.ActualWidth < containerSize && Math.Abs(m_textBlock.FontSize - MaxFontSize) > FONTTOLERANCE && !m_haveCalculatedMax) { diff --git a/src/Calculator/Controls/CalculatorButton.cs b/src/Calculator/Controls/CalculatorButton.cs index a081eeff..eae30f2c 100644 --- a/src/Calculator/Controls/CalculatorButton.cs +++ b/src/Calculator/Controls/CalculatorButton.cs @@ -33,11 +33,11 @@ namespace CalculatorApp // Using a DependencyProperty as the backing store for ButtonId. This enables animation, styling, binding, etc... public static readonly DependencyProperty ButtonIdProperty = - DependencyProperty.Register(nameof(ButtonId), typeof(NumbersAndOperatorsEnum), typeof(CalculatorButton), new PropertyMetadata(default(NumbersAndOperatorsEnum), new PropertyChangedCallback((sender, args) => + DependencyProperty.Register(nameof(ButtonId), typeof(NumbersAndOperatorsEnum), typeof(CalculatorButton), new PropertyMetadata(default(NumbersAndOperatorsEnum), (sender, args) => { var self = (CalculatorButton)sender; self.OnButtonIdPropertyChanged((NumbersAndOperatorsEnum)args.OldValue, (NumbersAndOperatorsEnum)args.NewValue); - }))); + })); public string AuditoryFeedback { @@ -47,11 +47,11 @@ namespace CalculatorApp // Using a DependencyProperty as the backing store for AuditoryFeedback. This enables animation, styling, binding, etc... public static readonly DependencyProperty AuditoryFeedbackProperty = - DependencyProperty.Register(nameof(AuditoryFeedback), typeof(string), typeof(CalculatorButton), new PropertyMetadata(string.Empty, new PropertyChangedCallback((sender, args) => + DependencyProperty.Register(nameof(AuditoryFeedback), typeof(string), typeof(CalculatorButton), new PropertyMetadata(string.Empty, (sender, args) => { var self = (CalculatorButton)sender; self.OnAuditoryFeedbackPropertyChanged((string)args.OldValue, (string)args.NewValue); - }))); + })); public Windows.UI.Xaml.Media.Brush HoverBackground { diff --git a/src/Calculator/Controls/OverflowTextBlock.cs b/src/Calculator/Controls/OverflowTextBlock.cs index 13d4d951..8039c3e3 100644 --- a/src/Calculator/Controls/OverflowTextBlock.cs +++ b/src/Calculator/Controls/OverflowTextBlock.cs @@ -37,11 +37,11 @@ namespace CalculatorApp // Using a DependencyProperty as the backing store for TokensUpdated. This enables animation, styling, binding, etc... public static readonly DependencyProperty TokensUpdatedProperty = - DependencyProperty.Register(nameof(TokensUpdated), typeof(bool), typeof(OverflowTextBlock), new PropertyMetadata(default(bool), new PropertyChangedCallback((sender, args) => + DependencyProperty.Register(nameof(TokensUpdated), typeof(bool), typeof(OverflowTextBlock), new PropertyMetadata(default(bool), (sender, args) => { var self = (OverflowTextBlock)sender; self.OnTokensUpdatedPropertyChanged((bool)args.OldValue, (bool)args.NewValue); - }))); + })); public OverflowButtonPlacement ScrollButtonsPlacement { @@ -51,11 +51,11 @@ namespace CalculatorApp // Using a DependencyProperty as the backing store for ScrollButtonsPlacement. This enables animation, styling, binding, etc... public static readonly DependencyProperty ScrollButtonsPlacementProperty = - DependencyProperty.Register(nameof(ScrollButtonsPlacement), typeof(OverflowButtonPlacement), typeof(OverflowTextBlock), new PropertyMetadata(default(OverflowButtonPlacement), new PropertyChangedCallback((sender, args) => + DependencyProperty.Register(nameof(ScrollButtonsPlacement), typeof(OverflowButtonPlacement), typeof(OverflowTextBlock), new PropertyMetadata(default(OverflowButtonPlacement), (sender, args) => { var self = (OverflowTextBlock)sender; self.OnScrollButtonsPlacementPropertyChanged((OverflowButtonPlacement)args.OldValue, (OverflowButtonPlacement)args.NewValue); - }))); + })); public bool IsActive { diff --git a/src/Calculator/Views/Calculator.xaml.cs b/src/Calculator/Views/Calculator.xaml.cs index c12e95a8..d2503346 100644 --- a/src/Calculator/Views/Calculator.xaml.cs +++ b/src/Calculator/Views/Calculator.xaml.cs @@ -234,7 +234,7 @@ namespace CalculatorApp // Delay load things later when we get a chance. WeakReference weakThis = new WeakReference(this); _ = this.Dispatcher.RunAsync( - CoreDispatcherPriority.Normal, new DispatchedHandler(() => + CoreDispatcherPriority.Normal, () => { if (TraceLogger.GetInstance().IsWindowIdInLog(ApplicationView.GetApplicationViewIdForWindow(CoreWindow.GetForCurrentThread()))) { @@ -243,7 +243,7 @@ namespace CalculatorApp refThis.GetMemory(); } } - })); + }); } private void LoadResourceStrings() @@ -533,7 +533,7 @@ namespace CalculatorApp // Since we need different font sizes for different numeric system, // we use a table of optimal font sizes for each numeric system. - private static readonly FontTable[] fontTables = new FontTable[] { + private static readonly FontTable[] fontTables = { new FontTable { numericSystem = "Arab", fullFont = 104, fullFontMin = 29.333, portraitMin = 23, snapFont = 40, fullNumPadFont = 56, snapScientificNumPadFont = 40, portraitScientificNumPadFont = 56 }, new FontTable { numericSystem = "ArabExt", fullFont = 104, fullFontMin = 29.333, portraitMin = 23, snapFont = 40, diff --git a/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.cs b/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.cs index d6d03d8e..de66892d 100644 --- a/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.cs +++ b/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.cs @@ -258,8 +258,7 @@ namespace CalculatorApp } if (submission.Source == EquationSubmissionSource.ENTER_KEY - || (submission.Source == EquationSubmissionSource.FOCUS_LOST && submission.HasTextChanged && eq.Expression != null - && eq.Expression.Length > 0)) + || (submission.Source == EquationSubmissionSource.FOCUS_LOST && submission.HasTextChanged && !string.IsNullOrEmpty(eq.Expression))) { if (submission.Source == EquationSubmissionSource.ENTER_KEY) { @@ -355,13 +354,13 @@ namespace CalculatorApp { WeakReference weakThis = new WeakReference(this); - _ = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() => + _ = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { if (weakThis.Target is EquationInputArea refThis && refThis.m_isHighContrast == refThis.m_accessibilitySettings.HighContrast) { refThis.ReloadAvailableColors(false, false); } - })); + }); } private void EquationTextBox_RemoveButtonClicked(object sender, RoutedEventArgs e) @@ -436,10 +435,7 @@ namespace CalculatorApp if (index >= 0) { var container = (UIElement)EquationInputList.ContainerFromIndex(index); - if (container != null) - { - container.StartBringIntoView(); - } + container?.StartBringIntoView(); } } } @@ -466,10 +462,7 @@ namespace CalculatorApp if (index >= 0) { var container = (UIElement)EquationInputList.ContainerFromIndex(index); - if (container != null) - { - container.StartBringIntoView(); - } + container?.StartBringIntoView(); } } } @@ -594,11 +587,11 @@ namespace CalculatorApp { TimeSpan timeSpan = new TimeSpan(10000000); // 1 tick = 100 nanoseconds, and 10000000 ticks = 1 second. DispatcherTimerDelayer delayer = new DispatcherTimerDelayer(timeSpan); - delayer.Action += new EventHandler((object s, object arg) => + delayer.Action += (s, arg) => { CalculatorApp.ViewModel.Common.TraceLogger.GetInstance().LogVariableChanged("Slider", name); variableSliders.Remove(name); - }); + }; delayer.Start(); variableSliders.Add(name, delayer); } @@ -612,12 +605,8 @@ namespace CalculatorApp private EquationViewModel GetViewModelFromEquationTextBox(object sender) { var tb = (EquationTextBox)sender; - if (tb == null) - { - return null; - } - var eq = (EquationViewModel)tb.DataContext; + var eq = (EquationViewModel)tb?.DataContext; return eq; } diff --git a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cs b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cs index 8e6526a1..80f206b4 100644 --- a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cs +++ b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cs @@ -752,13 +752,13 @@ namespace CalculatorApp private void OnColorValuesChanged(UISettings sender, object args) { WeakReference weakThis = new WeakReference(this); - _ = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() => + _ = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { if (weakThis.Target is GraphingCalculator refThis && IsMatchAppTheme) { refThis.UpdateGraphTheme(); } - })); + }); } private void UpdateGraphTheme() @@ -788,13 +788,13 @@ namespace CalculatorApp IsMatchAppTheme = isMatchAppTheme; WeakReference weakThis = new WeakReference(this); - _ = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() => + _ = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { if (weakThis.Target is GraphingCalculator refThis) { refThis.UpdateGraphTheme(); } - })); + }); } private const double zoomInScale = 1 / 1.0625; diff --git a/src/Calculator/Views/GraphingCalculator/GraphingNumPad.xaml.cs b/src/Calculator/Views/GraphingCalculator/GraphingNumPad.xaml.cs index 4f1ffc2a..20091a1c 100644 --- a/src/Calculator/Views/GraphingCalculator/GraphingNumPad.xaml.cs +++ b/src/Calculator/Views/GraphingCalculator/GraphingNumPad.xaml.cs @@ -187,7 +187,7 @@ namespace CalculatorApp } } - private static readonly Dictionary> buttonOutput = new Dictionary>() + private static readonly Dictionary> buttonOutput = new Dictionary> { { NumbersAndOperatorsEnum.Sin, Tuple.Create("sin()", 4, 0) }, { NumbersAndOperatorsEnum.Cos, Tuple.Create("cos()", 4, 0) }, diff --git a/src/Calculator/Views/TitleBar.xaml.cs b/src/Calculator/Views/TitleBar.xaml.cs index 54ca2025..30baf0a2 100644 --- a/src/Calculator/Views/TitleBar.xaml.cs +++ b/src/Calculator/Views/TitleBar.xaml.cs @@ -92,7 +92,7 @@ namespace CalculatorApp { if (Frame.RequestedThemeProperty == dp) { - _ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() => { SetTitleBarControlColors(); })); + _ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, SetTitleBarControlColors); } } @@ -120,8 +120,8 @@ namespace CalculatorApp return; } - double leftAddition = 0; - double rightAddition = 0; + double leftAddition; + double rightAddition; if (FlowDirection == FlowDirection.LeftToRight) { @@ -140,18 +140,14 @@ namespace CalculatorApp private void ColorValuesChanged(Windows.UI.ViewManagement.UISettings sender, object e) { - _ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() => { SetTitleBarControlColors(); })); + _ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, SetTitleBarControlColors); } private void SetTitleBarControlColors() { var applicationView = ApplicationView.GetForCurrentView(); - if (applicationView == null) - { - return; - } - var applicationTitleBar = applicationView.TitleBar; + var applicationTitleBar = applicationView?.TitleBar; if (applicationTitleBar == null) { return; @@ -184,11 +180,11 @@ namespace CalculatorApp private void OnHighContrastChanged(Windows.UI.ViewManagement.AccessibilitySettings sender, object args) { - _ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() => + _ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { SetTitleBarControlColors(); SetTitleBarVisibility(false); - })); + }); } private void OnWindowActivated(object sender, WindowActivatedEventArgs e) @@ -281,12 +277,12 @@ namespace CalculatorApp public static readonly DependencyProperty BackButtonSpaceReservedProperty = DependencyProperty.Register( nameof(BackButtonSpaceReserved), typeof(bool), typeof(TitleBar), - new PropertyMetadata(false, new PropertyChangedCallback((sender, args) => + new PropertyMetadata(false, (sender, args) => { var self = sender as TitleBar; VisualStateManager.GoToState( self, (bool)args.NewValue ? self.BackButtonVisible.Name : self.BackButtonCollapsed.Name, true); - }))); + })); private readonly Windows.ApplicationModel.Core.CoreApplicationViewTitleBar m_coreTitleBar; private readonly Windows.UI.ViewManagement.UISettings m_uiSettings; diff --git a/src/Calculator/Views/UnitConverter.xaml.cs b/src/Calculator/Views/UnitConverter.xaml.cs index 5ea4ff66..c1a7dc44 100644 --- a/src/Calculator/Views/UnitConverter.xaml.cs +++ b/src/Calculator/Views/UnitConverter.xaml.cs @@ -86,7 +86,7 @@ namespace CalculatorApp public void SetDefaultFocus() { - Control[] focusPrecedence = new Control[] { Value1, CurrencyRefreshBlockControl, OfflineBlock, ClearEntryButtonPos0 }; + Control[] focusPrecedence = { Value1, CurrencyRefreshBlockControl, OfflineBlock, ClearEntryButtonPos0 }; foreach (Control control in focusPrecedence) { @@ -368,10 +368,7 @@ namespace CalculatorApp private void HideProgressRing() { - if (m_delayTimer != null) - { - m_delayTimer.Stop(); - } + m_delayTimer?.Stop(); CurrencyLoadingProgressRing.IsActive = false; } @@ -391,8 +388,8 @@ namespace CalculatorApp private static readonly Lazy uiSettings = new Lazy(true); private readonly Windows.UI.Xaml.Controls.MenuFlyout m_resultsFlyout = default; - private readonly string m_chargesMayApplyText = string.Empty; - private readonly string m_failedToRefreshText = string.Empty; + private readonly string m_chargesMayApplyText; + private readonly string m_failedToRefreshText; private bool m_meteredConnectionOverride; diff --git a/src/Calculator/WindowFrameService.cs b/src/Calculator/WindowFrameService.cs index e2501b3a..55f5c7d8 100644 --- a/src/Calculator/WindowFrameService.cs +++ b/src/Calculator/WindowFrameService.cs @@ -59,7 +59,7 @@ namespace CalculatorApp public Task HandleViewRelease() { TaskCompletionSource tsource = new TaskCompletionSource(); - _ = m_coreDispatcher.RunAsync(CoreDispatcherPriority.Low, new DispatchedHandler(() => + _ = m_coreDispatcher.RunAsync(CoreDispatcherPriority.Low, () => { KeyboardShortcutManager.OnWindowClosed(this.m_viewId); Window.Current.Content = null; @@ -70,7 +70,7 @@ namespace CalculatorApp tsource.SetResult(new object()); this.m_coreDispatcher.StopProcessEvents(); Window.Current.Close(); - })); + }); return tsource.Task; }