Don't submit equation when opening context menu (#1220)
* Don't submit equation when opening context menu * Clean up
This commit is contained in:
parent
66b64afd75
commit
47760b4514
@ -112,7 +112,7 @@ void EquationTextBox::OnApplyTemplate()
|
|||||||
if (m_kgfEquationMenuItem != nullptr)
|
if (m_kgfEquationMenuItem != nullptr)
|
||||||
{
|
{
|
||||||
m_kgfEquationMenuItem->Text = resProvider->GetResourceString(L"functionAnalysisMenuItem");
|
m_kgfEquationMenuItem->Text = resProvider->GetResourceString(L"functionAnalysisMenuItem");
|
||||||
m_kgfEquationMenuItem->Click += ref new RoutedEventHandler(this, &EquationTextBox::OnFunctionButtonClicked);
|
m_kgfEquationMenuItem->Click += ref new RoutedEventHandler(this, &EquationTextBox::OnFunctionMenuButtonClicked);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ColorChooserFlyout != nullptr)
|
if (ColorChooserFlyout != nullptr)
|
||||||
@ -269,6 +269,17 @@ void EquationTextBox::OnColorChooserButtonClicked(Object ^ sender, RoutedEventAr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EquationTextBox::OnFunctionMenuButtonClicked(Object ^ sender, RoutedEventArgs ^ e)
|
||||||
|
{
|
||||||
|
// Submit the equation before trying to analyze it if invoked from context menu
|
||||||
|
if (m_richEditBox != nullptr)
|
||||||
|
{
|
||||||
|
m_richEditBox->SubmitEquation(::EquationSubmissionSource::FOCUS_LOST);
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyGraphFeaturesButtonClicked(this, ref new RoutedEventArgs());
|
||||||
|
}
|
||||||
|
|
||||||
void EquationTextBox::OnFunctionButtonClicked(Object ^ sender, RoutedEventArgs ^ e)
|
void EquationTextBox::OnFunctionButtonClicked(Object ^ sender, RoutedEventArgs ^ e)
|
||||||
{
|
{
|
||||||
KeyGraphFeaturesButtonClicked(this, ref new RoutedEventArgs());
|
KeyGraphFeaturesButtonClicked(this, ref new RoutedEventArgs());
|
||||||
@ -404,6 +415,11 @@ bool EquationTextBox::RichEditHasContent()
|
|||||||
|
|
||||||
void EquationTextBox::OnRichEditMenuOpened(Object ^ /*sender*/, Object ^ /*args*/)
|
void EquationTextBox::OnRichEditMenuOpened(Object ^ /*sender*/, Object ^ /*args*/)
|
||||||
{
|
{
|
||||||
|
if (m_removeMenuItem != nullptr)
|
||||||
|
{
|
||||||
|
m_removeMenuItem->IsEnabled = !IsAddEquationMode;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_kgfEquationMenuItem != nullptr)
|
if (m_kgfEquationMenuItem != nullptr)
|
||||||
{
|
{
|
||||||
m_kgfEquationMenuItem->IsEnabled = m_HasFocus && !HasError && RichEditHasContent();
|
m_kgfEquationMenuItem->IsEnabled = m_HasFocus && !HasError && RichEditHasContent();
|
||||||
|
@ -62,6 +62,7 @@ namespace CalculatorApp
|
|||||||
void OnRemoveButtonClicked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
|
void OnRemoveButtonClicked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
|
||||||
void OnColorChooserButtonClicked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
|
void OnColorChooserButtonClicked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
|
||||||
void OnFunctionButtonClicked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
|
void OnFunctionButtonClicked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
|
||||||
|
void OnFunctionMenuButtonClicked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||||
void OnRichEditMenuOpened(Platform::Object ^ sender, Platform::Object ^ args);
|
void OnRichEditMenuOpened(Platform::Object ^ sender, Platform::Object ^ args);
|
||||||
|
|
||||||
void OnCutClicked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
void OnCutClicked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||||
|
@ -12,10 +12,13 @@ using namespace std;
|
|||||||
using namespace Windows::ApplicationModel;
|
using namespace Windows::ApplicationModel;
|
||||||
using namespace Windows::UI::Core;
|
using namespace Windows::UI::Core;
|
||||||
using namespace Windows::UI::Xaml;
|
using namespace Windows::UI::Xaml;
|
||||||
|
using namespace Windows::UI::Xaml::Input;
|
||||||
using namespace Windows::UI::Xaml::Controls;
|
using namespace Windows::UI::Xaml::Controls;
|
||||||
using namespace Windows::UI::Text;
|
using namespace Windows::UI::Text;
|
||||||
|
using namespace Windows::Foundation;
|
||||||
using namespace Windows::Foundation::Collections;
|
using namespace Windows::Foundation::Collections;
|
||||||
using namespace Windows::System;
|
using namespace Windows::System;
|
||||||
|
using namespace Microsoft::WRL;
|
||||||
|
|
||||||
DEPENDENCY_PROPERTY_INITIALIZATION(MathRichEditBox, MathText);
|
DEPENDENCY_PROPERTY_INITIALIZATION(MathRichEditBox, MathText);
|
||||||
|
|
||||||
@ -62,16 +65,15 @@ MathRichEditBox::MathRichEditBox()
|
|||||||
|
|
||||||
// TODO when Windows 10 version 2004 SDK is adopted, replace with:
|
// TODO when Windows 10 version 2004 SDK is adopted, replace with:
|
||||||
// TextDocument->SetMathMode(Windows::UI::Text::RichEditMathMode::MathOnly);
|
// TextDocument->SetMathMode(Windows::UI::Text::RichEditMathMode::MathOnly);
|
||||||
Microsoft::WRL::ComPtr<Windows_2004_Prerelease::ITextDocument4> textDocument4;
|
ComPtr<Windows_2004_Prerelease::ITextDocument4> textDocument4;
|
||||||
reinterpret_cast<IInspectable*>(this->TextDocument)->QueryInterface(IID_PPV_ARGS(&textDocument4));
|
reinterpret_cast<IInspectable*>(this->TextDocument)->QueryInterface(IID_PPV_ARGS(&textDocument4));
|
||||||
auto hr = textDocument4->SetMathMode(Windows_2004_Prerelease::RichEditMathMode::MathOnly);
|
auto hr = textDocument4->SetMathMode(Windows_2004_Prerelease::RichEditMathMode::MathOnly);
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
throw Exception::CreateException(hr);
|
throw Exception::CreateException(hr);
|
||||||
}
|
}
|
||||||
this->LosingFocus += ref new Windows::Foundation::TypedEventHandler<Windows::UI::Xaml::UIElement ^, Windows::UI::Xaml::Input::LosingFocusEventArgs ^>(
|
this->LosingFocus += ref new TypedEventHandler<UIElement ^,LosingFocusEventArgs ^>(this, &MathRichEditBox::OnLosingFocus);
|
||||||
this, &CalculatorApp::Controls::MathRichEditBox::OnLosingFocus);
|
this->KeyUp += ref new KeyEventHandler(this, &MathRichEditBox::OnKeyUp);
|
||||||
this->KeyUp += ref new Windows::UI::Xaml::Input::KeyEventHandler(this, &CalculatorApp::Controls::MathRichEditBox::OnKeyUp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String ^ MathRichEditBox::GetMathTextProperty()
|
String ^ MathRichEditBox::GetMathTextProperty()
|
||||||
@ -81,7 +83,7 @@ String ^ MathRichEditBox::GetMathTextProperty()
|
|||||||
// this->TextDocument->GetMath(&text);
|
// this->TextDocument->GetMath(&text);
|
||||||
// return text;
|
// return text;
|
||||||
|
|
||||||
Microsoft::WRL::ComPtr<Windows_2004_Prerelease::ITextDocument4> textDocument4;
|
ComPtr<Windows_2004_Prerelease::ITextDocument4> textDocument4;
|
||||||
reinterpret_cast<IInspectable*>(this->TextDocument)->QueryInterface(IID_PPV_ARGS(&textDocument4));
|
reinterpret_cast<IInspectable*>(this->TextDocument)->QueryInterface(IID_PPV_ARGS(&textDocument4));
|
||||||
HSTRING math;
|
HSTRING math;
|
||||||
auto hr = textDocument4->GetMath(&math);
|
auto hr = textDocument4->GetMath(&math);
|
||||||
@ -110,15 +112,17 @@ void MathRichEditBox::SetMathTextProperty(String ^ newValue)
|
|||||||
this->IsReadOnly = readOnlyState;
|
this->IsReadOnly = readOnlyState;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CalculatorApp::Controls::MathRichEditBox::OnLosingFocus(Windows::UI::Xaml::UIElement ^ sender, Windows::UI::Xaml::Input::LosingFocusEventArgs ^ args)
|
void MathRichEditBox::OnLosingFocus(UIElement ^ sender, LosingFocusEventArgs ^ args)
|
||||||
{
|
{
|
||||||
if (!this->IsReadOnly)
|
if (this->IsReadOnly || this->ContextFlyout->IsOpen)
|
||||||
{
|
{
|
||||||
SubmitEquation(EquationSubmissionSource::FOCUS_LOST);
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CalculatorApp::Controls::MathRichEditBox::OnKeyUp(Platform::Object ^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs ^ e)
|
SubmitEquation(EquationSubmissionSource::FOCUS_LOST);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MathRichEditBox::OnKeyUp(Object ^ sender, KeyRoutedEventArgs ^ e)
|
||||||
{
|
{
|
||||||
if (!this->IsReadOnly && e->Key == VirtualKey::Enter)
|
if (!this->IsReadOnly && e->Key == VirtualKey::Enter)
|
||||||
{
|
{
|
||||||
@ -126,7 +130,7 @@ void CalculatorApp::Controls::MathRichEditBox::OnKeyUp(Platform::Object ^ sender
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CalculatorApp::Controls::MathRichEditBox::OnKeyDown(Windows::UI::Xaml::Input::KeyRoutedEventArgs ^ e)
|
void MathRichEditBox::OnKeyDown(KeyRoutedEventArgs ^ e)
|
||||||
{
|
{
|
||||||
// suppress control + B to prevent bold input from being entered
|
// suppress control + B to prevent bold input from being entered
|
||||||
if ((Window::Current->CoreWindow->GetKeyState(VirtualKey::Control) & CoreVirtualKeyStates::Down) != CoreVirtualKeyStates::Down ||
|
if ((Window::Current->CoreWindow->GetKeyState(VirtualKey::Control) & CoreVirtualKeyStates::Down) != CoreVirtualKeyStates::Down ||
|
||||||
@ -144,7 +148,7 @@ void MathRichEditBox::OnMathTextPropertyChanged(Platform::String ^ oldValue, Pla
|
|||||||
SetValue(MathTextProperty, GetMathTextProperty());
|
SetValue(MathTextProperty, GetMathTextProperty());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MathRichEditBox::InsertText(Platform::String ^ text, int cursorOffSet, int selectionLength)
|
void MathRichEditBox::InsertText(String ^ text, int cursorOffSet, int selectionLength)
|
||||||
{
|
{
|
||||||
// If the rich edit is empty, the math zone may not exist, and so selection (and thus the resulting text) will not be in a math zone.
|
// If the rich edit is empty, the math zone may not exist, and so selection (and thus the resulting text) will not be in a math zone.
|
||||||
// If the rich edit has content already, then the mathzone will already be created due to mathonly mode being set and the selection will exist inside the
|
// If the rich edit has content already, then the mathzone will already be created due to mathonly mode being set and the selection will exist inside the
|
||||||
|
@ -848,8 +848,8 @@
|
|||||||
DataContextChanged="EquationTextBox_DataContextChanged"
|
DataContextChanged="EquationTextBox_DataContextChanged"
|
||||||
EquationButtonClicked="EquationTextBox_EquationButtonClicked"
|
EquationButtonClicked="EquationTextBox_EquationButtonClicked"
|
||||||
EquationButtonContentIndex="{x:Bind FunctionLabelIndex, Mode=OneWay}"
|
EquationButtonContentIndex="{x:Bind FunctionLabelIndex, Mode=OneWay}"
|
||||||
EquationColor="{x:Bind local:EquationInputArea.ToSolidColorBrush(LineColor), Mode=OneWay}"
|
|
||||||
EquationButtonForegroundColor="{x:Bind local:EquationInputArea.GetForegroundColor(LineColor), Mode=OneWay}"
|
EquationButtonForegroundColor="{x:Bind local:EquationInputArea.GetForegroundColor(LineColor), Mode=OneWay}"
|
||||||
|
EquationColor="{x:Bind local:EquationInputArea.ToSolidColorBrush(LineColor), Mode=OneWay}"
|
||||||
EquationFormatRequested="EquationTextBox_EquationFormatRequested"
|
EquationFormatRequested="EquationTextBox_EquationFormatRequested"
|
||||||
EquationSubmitted="EquationTextBox_Submitted"
|
EquationSubmitted="EquationTextBox_Submitted"
|
||||||
ErrorText="{x:Bind vm:EquationViewModel.EquationErrorText(GraphEquation.GraphErrorType, GraphEquation.GraphErrorCode), Mode=OneWay}"
|
ErrorText="{x:Bind vm:EquationViewModel.EquationErrorText(GraphEquation.GraphErrorType, GraphEquation.GraphErrorCode), Mode=OneWay}"
|
||||||
|
Loading…
Reference in New Issue
Block a user