Change the initialization time of Radio button's isChecked (#1312)

* Change the initialization time of Radio button's isChecked

* Rollback checkDefaultBitShift and Use Enum instead of String

* Fix Check Default
- In previous versions, there was an issue where button availability was reset when opening BitShift Flyout not when the mode is changed

* Reset Calculator Type in Calculator ViewModel when mode change to not Calculator mode

* Revert "Reset Calculator Type in Calculator ViewModel when mode change to not Calculator mode"

This reverts commit a0d2f84513bc2d36fea3d75445782e1c67bc2e8d.

* Check deferred load button
This commit is contained in:
Lee Won Jun 2020-08-21 07:30:48 +09:00 committed by GitHub
parent 8c53444a04
commit 9206520121
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 77 additions and 15 deletions

View File

@ -346,13 +346,13 @@
<Flyout x:Name="BitShiftFlyout"
Windows10version1809:AreOpenCloseAnimationsEnabled="False"
FlyoutPresenterStyle="{ThemeResource OperatorPanelFlyoutStyle}"
Placement="Bottom">
Placement="Bottom"
Opened="BitShiftFlyout_Opened">
<StackPanel MaxWidth="192" Padding="12">
<RadioButton x:Name="ArithmeticShiftButton"
x:Uid="arithmeticShiftButton"
AutomationProperties.AutomationId="arithmeticShiftButton"
Checked="BitshiftFlyout_Checked"
IsChecked="True"/>
Checked="BitshiftFlyout_Checked"/>
<RadioButton x:Name="LogicalShiftButton"
x:Uid="logicalShiftButton"
AutomationProperties.AutomationId="logicalShiftButton"

View File

@ -47,10 +47,31 @@ void CalculatorProgrammerRadixOperators::FlyoutButton_Clicked(_In_ Platform::Obj
void CalculatorProgrammerRadixOperators::checkDefaultBitShift()
{
this->ArithmeticShiftButton->IsChecked = true;
LoadDeferredLoadButtons();
if (IsButtonLoaded())
{
return;
}
CollapseBitshiftButtons();
m_selectedShiftButtonMode = BitShiftMode::Arithmetic;
LshButton->Visibility = ::Visibility::Visible;
RshButton->Visibility = ::Visibility::Visible;
LshButton->IsEnabled = true;
RshButton->IsEnabled = true;
}
void CalculatorProgrammerRadixOperators::BitshiftFlyout_Checked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
bool CalculatorApp::CalculatorProgrammerRadixOperators::IsButtonLoaded()
{
// Since arithmeticShiftButton defaults to IsChecked = true, this event an fire before we can load the deferred loaded controls. If that is the case, just
// return and do nothing.
return RolButton == nullptr || RorButton == nullptr || RolCarryButton == nullptr || RorCarryButton == nullptr || LshLogicalButton == nullptr
|| RshLogicalButton == nullptr;
}
void CalculatorApp::CalculatorProgrammerRadixOperators::LoadDeferredLoadButtons()
{
// Load deferred load buttons
if (RolButton == nullptr)
@ -62,11 +83,14 @@ void CalculatorProgrammerRadixOperators::BitshiftFlyout_Checked(Platform::Object
FindName("LshLogicalButton");
FindName("RshLogicalButton");
}
}
// Since arithmeticShiftButton defaults to IsChecked = true, this event an fire before we can load the deferred loaded controls. If that is the case, just
// return and do nothing.
if (RolButton == nullptr || RorButton == nullptr || RolCarryButton == nullptr || RorCarryButton == nullptr || LshLogicalButton == nullptr
|| RshLogicalButton == nullptr)
void CalculatorProgrammerRadixOperators::BitshiftFlyout_Checked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
{
// Load deferred load buttons
LoadDeferredLoadButtons();
if (IsButtonLoaded())
{
return;
}
@ -75,6 +99,7 @@ void CalculatorProgrammerRadixOperators::BitshiftFlyout_Checked(Platform::Object
auto radioButton = static_cast<RadioButton ^>(sender);
Platform::String ^ announcementString = L"";
BitShiftMode selectedButtonMode = m_selectedShiftButtonMode;
if (radioButton == ArithmeticShiftButton)
{
@ -83,6 +108,7 @@ void CalculatorProgrammerRadixOperators::BitshiftFlyout_Checked(Platform::Object
LshButton->IsEnabled = true;
RshButton->IsEnabled = true;
announcementString = m_arithmeticShiftButtonContent;
selectedButtonMode = BitShiftMode::Arithmetic;
}
else if (radioButton == LogicalShiftButton)
{
@ -91,6 +117,7 @@ void CalculatorProgrammerRadixOperators::BitshiftFlyout_Checked(Platform::Object
LshLogicalButton->IsEnabled = true;
RshLogicalButton->IsEnabled = true;
announcementString = m_logicalShiftButtonContent;
selectedButtonMode = BitShiftMode::LogicalShift;
}
else if (radioButton == RotateCircularButton)
{
@ -99,6 +126,7 @@ void CalculatorProgrammerRadixOperators::BitshiftFlyout_Checked(Platform::Object
RolButton->IsEnabled = true;
RorButton->IsEnabled = true;
announcementString = m_rotateCircularButtonContent;
selectedButtonMode = BitShiftMode::RotateCircular;
}
else if (radioButton == RotateCarryShiftButton)
{
@ -107,9 +135,15 @@ void CalculatorProgrammerRadixOperators::BitshiftFlyout_Checked(Platform::Object
RolCarryButton->IsEnabled = true;
RorCarryButton->IsEnabled = true;
announcementString = m_rotateCarryShiftButtonContent;
selectedButtonMode = BitShiftMode::RotateCarry;
}
if (selectedButtonMode != m_selectedShiftButtonMode)
{
this->BitShiftFlyout->Hide();
m_selectedShiftButtonMode = selectedButtonMode;
}
this->BitShiftFlyout->Hide();
Model->SetBitshiftRadioButtonCheckedAnnouncement(announcementString);
}
@ -176,3 +210,23 @@ void CalculatorProgrammerRadixOperators::ClearButton_LostFocus(Object ^ sender,
ClearEntryButton->Focus(::FocusState::Programmatic);
}
}
void CalculatorApp::CalculatorProgrammerRadixOperators::BitShiftFlyout_Opened(Platform::Object ^ sender, Platform::Object ^ e)
{
if (m_selectedShiftButtonMode == BitShiftMode::Arithmetic)
{
ArithmeticShiftButton->IsChecked = true;
}
else if (m_selectedShiftButtonMode == BitShiftMode::LogicalShift)
{
LogicalShiftButton->IsChecked = true;
}
else if (m_selectedShiftButtonMode == BitShiftMode::RotateCircular)
{
RotateCircularButton->IsChecked = true;
}
else if (m_selectedShiftButtonMode == BitShiftMode::RotateCarry)
{
RotateCarryShiftButton->IsChecked = true;
}
}

View File

@ -29,19 +29,30 @@ namespace CalculatorApp
Platform::String ^ ParenthesisCountToString(unsigned int count);
DEPENDENCY_PROPERTY_OWNER(CalculatorProgrammerRadixOperators);
void checkDefaultBitShift();
private:
enum class BitShiftMode
{
Arithmetic,
LogicalShift,
RotateCircular,
RotateCarry
};
void BitshiftFlyout_Checked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void FlyoutButton_Clicked(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs ^ e);
void CollapseBitshiftButtons();
void LoadResourceStrings();
void LoadDeferredLoadButtons();
bool IsButtonLoaded();
bool m_isErrorVisualState;
void OpenParenthesisButton_GotFocus(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void ClearEntryButton_LostFocus(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void ClearButton_LostFocus(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void BitShiftFlyout_Opened(Platform::Object ^ sender, Platform::Object ^ e);
BitShiftMode m_selectedShiftButtonMode;
Platform::String ^ m_arithmeticShiftButtonContent;
Platform::String ^ m_logicalShiftButtonContent;
Platform::String ^ m_rotateCircularButtonContent;

View File

@ -72,10 +72,7 @@ void OperatorsPanel::EnsureProgrammerRadixOps()
this->FindName(L"ProgrammerRadixOperators");
}
if (ProgrammerRadixOperators)
{
ProgrammerRadixOperators->checkDefaultBitShift();
}
ProgrammerRadixOperators->checkDefaultBitShift();
}
void OperatorsPanel::EnsureProgrammerBitFlipPanel()