Add error handling to graph and equations (#827)
* add error handling * Handle regraphing on certain errors * Fix high contrast * Hide KGF button in error state
This commit is contained in:
		| @@ -24,13 +24,13 @@ using namespace Windows::UI::Xaml::Controls::Primitives; | ||||
| DEPENDENCY_PROPERTY_INITIALIZATION(EquationTextBox, EquationColor); | ||||
| DEPENDENCY_PROPERTY_INITIALIZATION(EquationTextBox, ColorChooserFlyout); | ||||
| DEPENDENCY_PROPERTY_INITIALIZATION(EquationTextBox, EquationButtonContentIndex); | ||||
|  | ||||
| DEPENDENCY_PROPERTY_INITIALIZATION(EquationTextBox, HasError); | ||||
|  | ||||
| void EquationTextBox::OnApplyTemplate() | ||||
| { | ||||
|     m_equationButton = dynamic_cast<ToggleButton ^>(GetTemplateChild("EquationButton")); | ||||
|     m_kgfEquationButton = dynamic_cast<Button ^>(GetTemplateChild("KGFEquationButton")); | ||||
|     m_richEditBox = dynamic_cast<MathRichEditBox ^>(GetTemplateChild("EquationTextBox")); | ||||
|     m_richEditBox = dynamic_cast<MathRichEditBox ^>(GetTemplateChild("MathRichEditBox")); | ||||
|     m_deleteButton = dynamic_cast<Button ^>(GetTemplateChild("DeleteButton")); | ||||
|     m_removeButton = dynamic_cast<Button ^>(GetTemplateChild("RemoveButton")); | ||||
|     m_functionButton = dynamic_cast<Button ^>(GetTemplateChild("FunctionButton")); | ||||
| @@ -127,7 +127,7 @@ void EquationTextBox::OnKeyDown(KeyRoutedEventArgs ^ e) | ||||
|  | ||||
| void EquationTextBox::OnLostFocus(RoutedEventArgs ^ e) | ||||
| { | ||||
|     if (!m_richEditBox->ContextFlyout->IsOpen) | ||||
|     if (m_richEditBox != nullptr && !m_richEditBox->ContextFlyout->IsOpen) | ||||
|     { | ||||
|         EquationSubmitted(this, ref new RoutedEventArgs()); | ||||
|         if (m_functionButton && m_richEditBox->MathText != L"") | ||||
| @@ -168,6 +168,7 @@ void EquationTextBox::OnRichEditBoxLostFocus(Object ^ sender, RoutedEventArgs ^ | ||||
|     { | ||||
|         m_HasFocus = false; | ||||
|     } | ||||
|  | ||||
|     UpdateCommonVisualState(); | ||||
|     UpdateDeleteButtonVisualState(); | ||||
| } | ||||
| @@ -259,26 +260,38 @@ void EquationTextBox::UpdateCommonVisualState() | ||||
|     { | ||||
|         state = "Focused"; | ||||
|     } | ||||
|     else if ((m_isPointerOver && HasError) || (m_isColorChooserFlyoutOpen && HasError)) | ||||
|     { | ||||
|         state = "PointerOverError"; | ||||
|     } | ||||
|     else if (m_isPointerOver || m_isColorChooserFlyoutOpen) | ||||
|     { | ||||
|         state = "PointerOver"; | ||||
|     } | ||||
|     else if (HasError) | ||||
|     { | ||||
|         state = "Error"; | ||||
|     } | ||||
|  | ||||
|     VisualStateManager::GoToState(this, state, true); | ||||
| } | ||||
|  | ||||
| void EquationTextBox::OnHasErrorPropertyChanged(bool, bool) | ||||
| { | ||||
|     UpdateCommonVisualState(); | ||||
| } | ||||
|  | ||||
| Platform::String ^ EquationTextBox::GetEquationText() | ||||
| { | ||||
|     String ^ text; | ||||
|     if (m_richEditBox != nullptr) | ||||
|     { | ||||
|         // Clear formatting since the graph control doesn't work with bold/italic/underlines | ||||
|         // Clear formatting since the graph control doesn't work with bold/underlines | ||||
|         ITextRange ^ range = m_richEditBox->TextDocument->GetRange(0, m_richEditBox->TextDocument->Selection->EndPosition); | ||||
|  | ||||
|         if (range != nullptr) | ||||
|         { | ||||
|             range->CharacterFormat->Bold = FormatEffect::Off; | ||||
|             range->CharacterFormat->Italic = FormatEffect::Off; | ||||
|             range->CharacterFormat->Underline = UnderlineType::None; | ||||
|         } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user