Add context menu to rich edit to allow for keyboard support (#854)
* Add context menu to rich edit to allow for keyboard support * Update src/Calculator/Controls/EquationTextBox.cpp Co-Authored-By: Pepe Rivera <joseartrivera@gmail.com> * Check for focus before triggering submit
This commit is contained in:
@@ -36,6 +36,12 @@ void EquationTextBox::OnApplyTemplate()
|
||||
m_removeButton = dynamic_cast<Button ^>(GetTemplateChild("RemoveButton"));
|
||||
m_functionButton = dynamic_cast<Button ^>(GetTemplateChild("FunctionButton"));
|
||||
m_colorChooserButton = dynamic_cast<ToggleButton ^>(GetTemplateChild("ColorChooserButton"));
|
||||
m_richEditContextMenu = dynamic_cast<MenuFlyout ^>(GetTemplateChild("MathRichEditContextMenu"));
|
||||
m_kgfEquationMenuItem = dynamic_cast<MenuFlyoutItem ^>(GetTemplateChild("FunctionAnalysisMenuItem"));
|
||||
m_removeMenuItem = dynamic_cast<MenuFlyoutItem ^>(GetTemplateChild("RemoveFunctionMenuItem"));
|
||||
m_colorChooserMenuItem = dynamic_cast<MenuFlyoutItem ^>(GetTemplateChild("ChangeFunctionStyleMenuItem"));
|
||||
|
||||
auto resProvider = AppResourceProvider::GetInstance();
|
||||
|
||||
if (m_richEditBox != nullptr)
|
||||
{
|
||||
@@ -50,13 +56,18 @@ void EquationTextBox::OnApplyTemplate()
|
||||
m_equationButton->Click += ref new RoutedEventHandler(this, &EquationTextBox::OnEquationButtonClicked);
|
||||
|
||||
auto toolTip = ref new ToolTip();
|
||||
auto resProvider = AppResourceProvider::GetInstance();
|
||||
auto equationButtonMessage = m_equationButton->IsChecked->Value ? resProvider->GetResourceString(L"showEquationButtonToolTip") : resProvider->GetResourceString(L"hideEquationButtonToolTip");
|
||||
toolTip->Content = equationButtonMessage;
|
||||
ToolTipService::SetToolTip(m_equationButton, toolTip);
|
||||
AutomationProperties::SetName(m_equationButton, equationButtonMessage);
|
||||
}
|
||||
|
||||
if (m_richEditContextMenu != nullptr)
|
||||
{
|
||||
m_richEditContextMenu->Opening +=
|
||||
ref new Windows::Foundation::EventHandler<Platform::Object ^>(this, &EquationTextBox::OnRichEditMenuOpening);
|
||||
}
|
||||
|
||||
if (m_kgfEquationButton != nullptr)
|
||||
{
|
||||
m_kgfEquationButton->Click += ref new RoutedEventHandler(this, &EquationTextBox::OnKGFEquationButtonClicked);
|
||||
@@ -72,17 +83,35 @@ void EquationTextBox::OnApplyTemplate()
|
||||
m_removeButton->Click += ref new RoutedEventHandler(this, &EquationTextBox::OnRemoveButtonClicked);
|
||||
}
|
||||
|
||||
if (m_removeMenuItem != nullptr)
|
||||
{
|
||||
m_removeMenuItem->Text = resProvider->GetResourceString(L"removeMenuItem");
|
||||
m_removeMenuItem->Click += ref new RoutedEventHandler(this, &EquationTextBox::OnRemoveButtonClicked);
|
||||
}
|
||||
|
||||
if (m_colorChooserButton != nullptr)
|
||||
{
|
||||
m_colorChooserButton->Click += ref new RoutedEventHandler(this, &EquationTextBox::OnColorChooserButtonClicked);
|
||||
}
|
||||
|
||||
if (m_colorChooserMenuItem != nullptr)
|
||||
{
|
||||
m_colorChooserMenuItem->Text = resProvider->GetResourceString(L"colorChooserMenuItem");
|
||||
m_colorChooserMenuItem->Click += ref new RoutedEventHandler(this, &EquationTextBox::OnColorChooserButtonClicked);
|
||||
}
|
||||
|
||||
if (m_functionButton != nullptr)
|
||||
{
|
||||
m_functionButton->Click += ref new RoutedEventHandler(this, &EquationTextBox::OnFunctionButtonClicked);
|
||||
m_functionButton->IsEnabled = false;
|
||||
}
|
||||
|
||||
if (m_kgfEquationMenuItem != nullptr)
|
||||
{
|
||||
m_kgfEquationMenuItem->Text = resProvider->GetResourceString(L"functionAnalysisMenuItem");
|
||||
m_kgfEquationMenuItem->Click += ref new RoutedEventHandler(this, &EquationTextBox::OnFunctionButtonClicked);
|
||||
}
|
||||
|
||||
if (ColorChooserFlyout != nullptr)
|
||||
{
|
||||
ColorChooserFlyout->Opened += ref new EventHandler<Object ^>(this, &EquationTextBox::OnColorFlyoutOpened);
|
||||
@@ -244,7 +273,7 @@ void EquationTextBox::UpdateDeleteButtonVisualState()
|
||||
{
|
||||
String ^ state;
|
||||
|
||||
if (ShouldDeleteButtonBeVisible())
|
||||
if (RichEditHasContent())
|
||||
{
|
||||
state = "ButtonVisible";
|
||||
}
|
||||
@@ -313,7 +342,7 @@ void EquationTextBox::SetEquationText(Platform::String ^ equationText)
|
||||
}
|
||||
}
|
||||
|
||||
bool EquationTextBox::ShouldDeleteButtonBeVisible()
|
||||
bool EquationTextBox::RichEditHasContent()
|
||||
{
|
||||
String ^ text;
|
||||
|
||||
@@ -323,3 +352,11 @@ bool EquationTextBox::ShouldDeleteButtonBeVisible()
|
||||
}
|
||||
return (!text->IsEmpty() && m_HasFocus);
|
||||
}
|
||||
|
||||
void EquationTextBox::OnRichEditMenuOpening(Object ^ /*sender*/, Object ^ /*args*/)
|
||||
{
|
||||
if (m_kgfEquationMenuItem != nullptr)
|
||||
{
|
||||
m_kgfEquationMenuItem->IsEnabled = EquationTextBox::RichEditHasContent();
|
||||
}
|
||||
}
|
||||
|
@@ -46,7 +46,7 @@ namespace CalculatorApp
|
||||
private:
|
||||
void UpdateCommonVisualState();
|
||||
void UpdateDeleteButtonVisualState();
|
||||
bool ShouldDeleteButtonBeVisible();
|
||||
bool RichEditHasContent();
|
||||
|
||||
void OnRichEditBoxGotFocus(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
|
||||
void OnRichEditBoxLostFocus(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
|
||||
@@ -58,6 +58,7 @@ namespace CalculatorApp
|
||||
void OnRemoveButtonClicked(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 OnRichEditMenuOpening(Platform::Object ^ sender, Platform::Object ^ args);
|
||||
|
||||
void OnColorFlyoutOpened(Platform::Object^ sender, Platform::Object^ e);
|
||||
void OnColorFlyoutClosed(Platform::Object^ sender, Platform::Object^ e);
|
||||
@@ -72,6 +73,11 @@ namespace CalculatorApp
|
||||
Windows::UI::Xaml::Controls::Button^ m_functionButton;
|
||||
Windows::UI::Xaml::Controls::Primitives::ToggleButton^ m_colorChooserButton;
|
||||
|
||||
Windows::UI::Xaml::Controls::MenuFlyout^ m_richEditContextMenu;
|
||||
Windows::UI::Xaml::Controls::MenuFlyoutItem^ m_kgfEquationMenuItem;
|
||||
Windows::UI::Xaml::Controls::MenuFlyoutItem^ m_removeMenuItem;
|
||||
Windows::UI::Xaml::Controls::MenuFlyoutItem^ m_colorChooserMenuItem;
|
||||
|
||||
bool m_isPointerOver;
|
||||
bool m_isColorChooserFlyoutOpen;
|
||||
};
|
||||
|
Reference in New Issue
Block a user