diff --git a/src/Calculator/Resources/en-US/Resources.resw b/src/Calculator/Resources/en-US/Resources.resw
index 5d38a1a..e4c1033 100644
--- a/src/Calculator/Resources/en-US/Resources.resw
+++ b/src/Calculator/Resources/en-US/Resources.resw
@@ -549,11 +549,11 @@
%1, value %2
{Locked="%1","%2"}. String used in automation name for each bit in bit flip. %1 will be replaced by the position of the bit (1st bit, 3rd bit), %2 by a binary value (1 or 0)
-
+
%1 bit
{Locked="%1"}. Sub-string used to indicate the position of a bit (e.g. 1st bit, 2nd bit...)
-
+
63rd
Sub-string used in automation name for 63 bit in bit flip
@@ -805,9 +805,9 @@
1st
Sub-string used in automation name for 1 bit in bit flip
-
- 0th
- Sub-string used in automation name for 0 bit in bit flip
+
+ least significant bit
+ Used to describe the first bit of a binary number. Used in bit flip
Open memory flyout
@@ -3427,4 +3427,8 @@
Calculation failed
Text displayed when the application is not able to do a calculation
-
+
+ most significant bit
+ Used to describe the last bit of a binary number. Used in bit flip
+
+
\ No newline at end of file
diff --git a/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml.cpp b/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml.cpp
index 068f48d..e9b6439 100644
--- a/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml.cpp
+++ b/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml.cpp
@@ -50,6 +50,7 @@ void CalculatorProgrammerBitFlipPanel::SubscribePropertyChanged()
if (Model != nullptr)
{
m_propertyChangedToken = Model->PropertyChanged += ref new PropertyChangedEventHandler(this, &CalculatorProgrammerBitFlipPanel::OnPropertyChanged);
+ m_currentValueBitLength = Model->ValueBitLength;
UpdateCheckedStates(true);
}
}
@@ -68,8 +69,10 @@ void CalculatorProgrammerBitFlipPanel::OnPropertyChanged(Object ^ sender, Proper
if (e->PropertyName == StandardCalculatorViewModel::BinaryDigitsPropertyName)
{
UpdateCheckedStates(false);
+ m_currentValueBitLength = Model->ValueBitLength;
}
- else if (e->PropertyName == StandardCalculatorViewModel::IsBitFlipCheckedPropertyName
+ else if (
+ e->PropertyName == StandardCalculatorViewModel::IsBitFlipCheckedPropertyName
|| e->PropertyName == StandardCalculatorViewModel::IsProgrammerPropertyName)
{
if (Model->IsBitFlipChecked && Model->IsProgrammer)
@@ -190,14 +193,20 @@ void CalculatorProgrammerBitFlipPanel::UpdateCheckedStates(bool updateAutomation
m_updatingCheckedStates = true;
auto it = m_flipButtons.begin();
int index = 0;
+ bool mustUpdateTextOfMostSignificantDigits = m_currentValueBitLength != Model->ValueBitLength;
+ int previousMSDPosition = GetIndexOfLastBit(m_currentValueBitLength);
+ int newMSDPosition = GetIndexOfLastBit(Model->ValueBitLength);
for (bool val : Model->BinaryDigits)
{
FlipButtons ^ flipButton = *it;
- if (updateAutomationPropertiesNames)
- {
- flipButton->SetValue(AutomationProperties::NameProperty, GenerateAutomationPropertiesName(index, flipButton->IsChecked->Value));
- }
+ bool hasValueChanged = flipButton->IsChecked->Value != val;
flipButton->IsChecked = val;
+ if (updateAutomationPropertiesNames
+ || hasValueChanged
+ || (mustUpdateTextOfMostSignificantDigits && (index == previousMSDPosition || index == newMSDPosition)))
+ {
+ flipButton->SetValue(AutomationProperties::NameProperty, GenerateAutomationPropertiesName(index, val));
+ }
++it;
++index;
}
@@ -215,29 +224,53 @@ void CalculatorProgrammerBitFlipPanel::UpdateAutomationPropertiesNames()
}
bool CalculatorProgrammerBitFlipPanel::ShouldEnableBit(BitLength length, int index)
+{
+ return index <= GetIndexOfLastBit(length);
+}
+
+int CalculatorProgrammerBitFlipPanel::GetIndexOfLastBit(BitLength length) const
{
switch (length)
{
case BitLength::BitLengthQWord:
- return index <= 63;
+ return 63;
case BitLength::BitLengthDWord:
- return index <= 31;
+ return 31;
case BitLength::BitLengthWord:
- return index <= 15;
+ return 15;
case BitLength::BitLengthByte:
- return index <= 7;
+ return 7;
}
- return false;
+ return -1;
}
-String ^ CalculatorProgrammerBitFlipPanel::GenerateAutomationPropertiesName(int position, bool value) const
+String ^ CalculatorProgrammerBitFlipPanel::GenerateAutomationPropertiesName(int position, bool value)
{
auto resourceLoader = AppResourceProvider::GetInstance();
-
- String ^ indexName = resourceLoader.GetResourceString(ref new Platform::String(to_wstring(position).c_str()));
String ^ automationNameTemplate = resourceLoader.GetResourceString(L"BitFlipItemAutomationName");
- String ^ bitPositionTemplate = resourceLoader.GetResourceString(L"BitPosition");
+ wstring bitPosition;
+ if (position == 0)
+ {
+ bitPosition = wstring(resourceLoader.GetResourceString(L"LeastSignificantBit")->Data());
+ }
+ else
+ {
+ int lastPosition = -1;
+ if (Model != nullptr)
+ {
+ lastPosition = GetIndexOfLastBit(Model->ValueBitLength);
+ }
- wstring bitPosition = LocalizationStringUtil::GetLocalizedString(bitPositionTemplate->Data(), indexName->Data());
+ if (position == lastPosition)
+ {
+ bitPosition = wstring(resourceLoader.GetResourceString(L"MostSignificantBit")->Data());
+ }
+ else
+ {
+ String ^ indexName = resourceLoader.GetResourceString(ref new Platform::String(to_wstring(position).c_str()));
+ String ^ bitPositionTemplate = resourceLoader.GetResourceString(L"BitPosition");
+ bitPosition = LocalizationStringUtil::GetLocalizedString(bitPositionTemplate->Data(), indexName->Data());
+ }
+ }
return ref new String(LocalizationStringUtil::GetLocalizedString(automationNameTemplate->Data(), bitPosition.c_str(), value ? L"1" : L"0").c_str());
}
diff --git a/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml.h b/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml.h
index 7ff77ea..db8b64c 100644
--- a/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml.h
+++ b/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml.h
@@ -22,7 +22,7 @@ namespace CalculatorApp
bool ShouldEnableBit(CalculatorApp::Common::BitLength length, int index);
property CalculatorApp::ViewModel::StandardCalculatorViewModel
- ^ Model { CalculatorApp::ViewModel::StandardCalculatorViewModel ^ get(); }
+ ^ Model { CalculatorApp::ViewModel::StandardCalculatorViewModel ^ get(); }
private : void OnLoaded(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void OnUnloaded(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
@@ -37,12 +37,14 @@ namespace CalculatorApp
private:
Windows::Foundation::EventRegistrationToken m_propertyChangedToken;
- Platform::String ^ GenerateAutomationPropertiesName(int position, bool value) const;
+ Platform::String ^ GenerateAutomationPropertiesName(int position, bool value);
void UpdateCheckedStates(bool updateAutomationPropertiesNames);
void UpdateAutomationPropertiesNames();
+ int GetIndexOfLastBit(CalculatorApp::Common::BitLength length) const;
static const unsigned int s_numBits = 64;
std::array m_flipButtons;
bool m_updatingCheckedStates;
+ CalculatorApp::Common::BitLength m_currentValueBitLength;
};
}