support ctrl+- and + (#882)

This commit is contained in:
Rudy Huyn 2019-12-18 16:06:13 -08:00 committed by Pepe Rivera
commit 38da8d7b38
5 changed files with 57 additions and 75 deletions

View file

@ -44,10 +44,15 @@ static multimap<int, multimap<MyVirtualKey, WeakReference>> s_VirtualKeyControlS
static multimap<int, multimap<MyVirtualKey, WeakReference>> s_VirtualKeyInverseChordsForButtons; static multimap<int, multimap<MyVirtualKey, WeakReference>> s_VirtualKeyInverseChordsForButtons;
static multimap<int, multimap<MyVirtualKey, WeakReference>> s_VirtualKeyControlInverseChordsForButtons; static multimap<int, multimap<MyVirtualKey, WeakReference>> s_VirtualKeyControlInverseChordsForButtons;
static multimap<int, bool> s_ShiftKeyPressed; static map<int, bool> s_ShiftKeyPressed;
static multimap<int, bool> s_ControlKeyPressed; static map<int, bool> s_ControlKeyPressed;
static multimap<int, bool> s_ShiftButtonChecked; static map<int, bool> s_ShiftButtonChecked;
static multimap<int, bool> s_IsDropDownOpen; static map<int, bool> s_IsDropDownOpen;
static map<int, bool> s_ignoreNextEscape;
static map<int, bool> s_keepIgnoringEscape;
static map<int, bool> s_fHonorShortcuts;
static map<int, Flyout ^> s_AboutFlyout;
static reader_writer_lock s_keyboardShortcutMapLock; static reader_writer_lock s_keyboardShortcutMapLock;
@ -158,12 +163,6 @@ namespace CalculatorApp
} }
} }
static multimap<int, bool> s_ignoreNextEscape;
static multimap<int, bool> s_keepIgnoringEscape;
static multimap<int, bool> s_fHonorShortcuts;
static multimap<int, bool> s_fHandledEnter;
static multimap<int, Flyout ^> s_AboutFlyout;
void KeyboardShortcutManager::IgnoreEscape(bool onlyOnce) void KeyboardShortcutManager::IgnoreEscape(bool onlyOnce)
{ {
// Writer lock for the static maps // Writer lock for the static maps
@ -173,14 +172,12 @@ void KeyboardShortcutManager::IgnoreEscape(bool onlyOnce)
if (s_ignoreNextEscape.find(viewId) != s_ignoreNextEscape.end()) if (s_ignoreNextEscape.find(viewId) != s_ignoreNextEscape.end())
{ {
s_ignoreNextEscape.erase(viewId); s_ignoreNextEscape[viewId] = true;
s_ignoreNextEscape.insert(std::make_pair(viewId, true));
} }
if (s_keepIgnoringEscape.find(viewId) != s_keepIgnoringEscape.end()) if (s_keepIgnoringEscape.find(viewId) != s_keepIgnoringEscape.end())
{ {
s_keepIgnoringEscape.erase(viewId); s_keepIgnoringEscape[viewId] = !onlyOnce;
s_keepIgnoringEscape.insert(std::make_pair(viewId, !onlyOnce));
} }
} }
@ -193,14 +190,12 @@ void KeyboardShortcutManager::HonorEscape()
if (s_ignoreNextEscape.find(viewId) != s_ignoreNextEscape.end()) if (s_ignoreNextEscape.find(viewId) != s_ignoreNextEscape.end())
{ {
s_ignoreNextEscape.erase(viewId); s_ignoreNextEscape[viewId] = false;
s_ignoreNextEscape.insert(std::make_pair(viewId, false));
} }
if (s_keepIgnoringEscape.find(viewId) != s_keepIgnoringEscape.end()) if (s_keepIgnoringEscape.find(viewId) != s_keepIgnoringEscape.end())
{ {
s_keepIgnoringEscape.erase(viewId); s_keepIgnoringEscape[viewId] = false;
s_keepIgnoringEscape.insert(std::make_pair(viewId, false));
} }
} }
@ -474,8 +469,8 @@ const std::multimap<MyVirtualKey, WeakReference>& GetCurrentKeyDictionary(MyVirt
} }
else else
{ {
auto iterViewMap = s_VirtualKeyControlInverseChordsForButtons.find(viewId); auto iterViewMap = s_VirtualKeyInverseChordsForButtons.find(viewId);
if (iterViewMap != s_VirtualKeyControlInverseChordsForButtons.end()) if (iterViewMap != s_VirtualKeyInverseChordsForButtons.end())
{ {
for (auto iterator = iterViewMap->second.begin(); iterator != iterViewMap->second.end(); ++iterator) for (auto iterator = iterViewMap->second.begin(); iterator != iterViewMap->second.end(); ++iterator)
{ {
@ -558,8 +553,7 @@ void KeyboardShortcutManager::OnKeyDownHandler(CoreWindow ^ sender, KeyEventArgs
if (currControlKeyPressed != s_ControlKeyPressed.end()) if (currControlKeyPressed != s_ControlKeyPressed.end())
{ {
s_ControlKeyPressed.erase(viewId); s_ControlKeyPressed[viewId] = true;
s_ControlKeyPressed.insert(std::make_pair(viewId, true));
} }
return; return;
} }
@ -572,26 +566,24 @@ void KeyboardShortcutManager::OnKeyDownHandler(CoreWindow ^ sender, KeyEventArgs
if (currShiftKeyPressed != s_ShiftKeyPressed.end()) if (currShiftKeyPressed != s_ShiftKeyPressed.end())
{ {
s_ShiftKeyPressed.erase(viewId); s_ShiftKeyPressed[viewId] = true;
s_ShiftKeyPressed.insert(std::make_pair(viewId, true));
} }
return; return;
} }
const auto& lookupMap = GetCurrentKeyDictionary(static_cast<MyVirtualKey>(key));
auto buttons = lookupMap.equal_range(static_cast<MyVirtualKey>(key));
auto currentIsDropDownOpen = s_IsDropDownOpen.find(viewId);
if (currentHonorShortcuts != s_fHonorShortcuts.end()) if (currentHonorShortcuts != s_fHonorShortcuts.end())
{ {
if (currentHonorShortcuts->second) if (currentHonorShortcuts->second)
{ {
const auto myVirtualKey = static_cast<MyVirtualKey>(key);
const auto& lookupMap = GetCurrentKeyDictionary(myVirtualKey);
auto buttons = lookupMap.equal_range(myVirtualKey);
RunFirstEnabledButtonCommand(buttons); RunFirstEnabledButtonCommand(buttons);
// Ctrl+C and Ctrl+V shifts focus to some button because of which enter doesn't work after copy/paste. So don't shift focus if Ctrl+C or Ctrl+V // Ctrl+C and Ctrl+V shifts focus to some button because of which enter doesn't work after copy/paste. So don't shift focus if Ctrl+C or Ctrl+V
// is pressed. When drop down is open, pressing escape shifts focus to clear button. So dont's shift focus if drop down is open. Ctrl+Insert is // is pressed. When drop down is open, pressing escape shifts focus to clear button. So dont's shift focus if drop down is open. Ctrl+Insert is
// equivalent to Ctrl+C and Shift+Insert is equivalent to Ctrl+V // equivalent to Ctrl+C and Shift+Insert is equivalent to Ctrl+V
auto currentIsDropDownOpen = s_IsDropDownOpen.find(viewId);
if (currentIsDropDownOpen != s_IsDropDownOpen.end() && !currentIsDropDownOpen->second) if (currentIsDropDownOpen != s_IsDropDownOpen.end() && !currentIsDropDownOpen->second)
{ {
// Do not Light Up Buttons when Ctrl+C, Ctrl+V, Ctrl+Insert or Shift+Insert is pressed // Do not Light Up Buttons when Ctrl+C, Ctrl+V, Ctrl+Insert or Shift+Insert is pressed
@ -620,8 +612,7 @@ void KeyboardShortcutManager::OnKeyUpHandler(CoreWindow ^ sender, KeyEventArgs ^
if (currentShiftKeyPressed != s_ShiftKeyPressed.end()) if (currentShiftKeyPressed != s_ShiftKeyPressed.end())
{ {
s_ShiftKeyPressed.erase(viewId); s_ShiftKeyPressed[viewId] = false;
s_ShiftKeyPressed.insert(std::make_pair(viewId, false));
} }
} }
else if (key == VirtualKey::Control) else if (key == VirtualKey::Control)
@ -633,8 +624,7 @@ void KeyboardShortcutManager::OnKeyUpHandler(CoreWindow ^ sender, KeyEventArgs ^
if (currControlKeyPressed != s_ControlKeyPressed.end()) if (currControlKeyPressed != s_ControlKeyPressed.end())
{ {
s_ControlKeyPressed.erase(viewId); s_ControlKeyPressed[viewId] = false;
s_ControlKeyPressed.insert(std::make_pair(viewId, false));
} }
} }
} }
@ -712,8 +702,7 @@ void KeyboardShortcutManager::ShiftButtonChecked(bool checked)
if (s_ShiftButtonChecked.find(viewId) != s_ShiftButtonChecked.end()) if (s_ShiftButtonChecked.find(viewId) != s_ShiftButtonChecked.end())
{ {
s_ShiftButtonChecked.erase(viewId); s_ShiftButtonChecked[viewId] = checked;
s_ShiftButtonChecked.insert(std::make_pair(viewId, checked));
} }
} }
@ -723,8 +712,7 @@ void KeyboardShortcutManager::UpdateDropDownState(bool isOpen)
if (s_IsDropDownOpen.find(viewId) != s_IsDropDownOpen.end()) if (s_IsDropDownOpen.find(viewId) != s_IsDropDownOpen.end())
{ {
s_IsDropDownOpen.erase(viewId); s_IsDropDownOpen[viewId] = isOpen;
s_IsDropDownOpen.insert(std::make_pair(viewId, isOpen));
} }
} }
@ -734,8 +722,7 @@ void KeyboardShortcutManager::UpdateDropDownState(Flyout ^ aboutPageFlyout)
if (s_AboutFlyout.find(viewId) != s_AboutFlyout.end()) if (s_AboutFlyout.find(viewId) != s_AboutFlyout.end())
{ {
s_AboutFlyout.erase(viewId); s_AboutFlyout[viewId] = aboutPageFlyout;
s_AboutFlyout.insert(std::make_pair(viewId, aboutPageFlyout));
} }
} }
@ -748,19 +735,7 @@ void KeyboardShortcutManager::HonorShortcuts(bool allow)
if (s_fHonorShortcuts.find(viewId) != s_fHonorShortcuts.end()) if (s_fHonorShortcuts.find(viewId) != s_fHonorShortcuts.end())
{ {
s_fHonorShortcuts.erase(viewId); s_fHonorShortcuts[viewId] = allow;
s_fHonorShortcuts.insert(std::make_pair(viewId, allow));
}
}
void KeyboardShortcutManager::HandledEnter(bool ishandled)
{
int viewId = Utils::GetWindowId();
if (s_fHandledEnter.find(viewId) != s_fHandledEnter.end())
{
s_fHandledEnter.erase(viewId);
s_fHandledEnter.insert(std::make_pair(viewId, ishandled));
} }
} }
@ -812,15 +787,14 @@ void KeyboardShortcutManager::RegisterNewAppViewId()
s_VirtualKeyControlInverseChordsForButtons.insert(std::make_pair(appViewId, std::multimap<MyVirtualKey, WeakReference>())); s_VirtualKeyControlInverseChordsForButtons.insert(std::make_pair(appViewId, std::multimap<MyVirtualKey, WeakReference>()));
} }
s_ShiftKeyPressed.insert(std::make_pair(appViewId, false)); s_ShiftKeyPressed[appViewId] = false;
s_ControlKeyPressed.insert(std::make_pair(appViewId, false)); s_ControlKeyPressed[appViewId] = false;
s_ShiftButtonChecked.insert(std::make_pair(appViewId, false)); s_ShiftButtonChecked[appViewId] = false;
s_IsDropDownOpen.insert(std::make_pair(appViewId, false)); s_IsDropDownOpen[appViewId] = false;
s_ignoreNextEscape.insert(std::make_pair(appViewId, false)); s_ignoreNextEscape[appViewId] = false;
s_keepIgnoringEscape.insert(std::make_pair(appViewId, false)); s_keepIgnoringEscape[appViewId] = false;
s_fHonorShortcuts.insert(std::make_pair(appViewId, true)); s_fHonorShortcuts[appViewId] = true;
s_fHandledEnter.insert(std::make_pair(appViewId, true)); s_AboutFlyout[appViewId] = nullptr;
s_AboutFlyout.insert(std::make_pair(appViewId, nullptr));
} }
void KeyboardShortcutManager::OnWindowClosed(int viewId) void KeyboardShortcutManager::OnWindowClosed(int viewId)
@ -845,6 +819,5 @@ void KeyboardShortcutManager::OnWindowClosed(int viewId)
s_ignoreNextEscape.erase(viewId); s_ignoreNextEscape.erase(viewId);
s_keepIgnoringEscape.erase(viewId); s_keepIgnoringEscape.erase(viewId);
s_fHonorShortcuts.erase(viewId); s_fHonorShortcuts.erase(viewId);
s_fHandledEnter.erase(viewId);
s_AboutFlyout.erase(viewId); s_AboutFlyout.erase(viewId);
} }

View file

@ -43,7 +43,6 @@ namespace CalculatorApp
static void IgnoreEscape(bool onlyOnce); static void IgnoreEscape(bool onlyOnce);
static void HonorEscape(); static void HonorEscape();
static void HonorShortcuts(bool allow); static void HonorShortcuts(bool allow);
static void HandledEnter(bool ishandled);
static void UpdateDropDownState(bool); static void UpdateDropDownState(bool);
static void ShiftButtonChecked(bool checked); static void ShiftButtonChecked(bool checked);
static void UpdateDropDownState(Windows::UI::Xaml::Controls::Flyout ^ aboutPageFlyout); static void UpdateDropDownState(Windows::UI::Xaml::Controls::Flyout ^ aboutPageFlyout);

View file

@ -3883,10 +3883,6 @@
<value>Reset View</value> <value>Reset View</value>
<comment>Screen reader prompt for the reset zoom button.</comment> <comment>Screen reader prompt for the reset zoom button.</comment>
</data> </data>
<data name="zoomInButton.[using:CalculatorApp.Common]KeyboardShortcutManager.VirtualKeyControlChord" xml:space="preserve">
<value>Add</value>
<comment>{Locked}This is the shortcut for the zoom in button.</comment>
</data>
<data name="zoomInButton.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve"> <data name="zoomInButton.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
<value>Zoom In</value> <value>Zoom In</value>
<comment>This is the tool tip automation name for the Calculator zoom in button.</comment> <comment>This is the tool tip automation name for the Calculator zoom in button.</comment>
@ -3895,10 +3891,6 @@
<value>Zoom In</value> <value>Zoom In</value>
<comment>Screen reader prompt for the zoom in button.</comment> <comment>Screen reader prompt for the zoom in button.</comment>
</data> </data>
<data name="zoomOutButton.[using:CalculatorApp.Common]KeyboardShortcutManager.VirtualKeyControlChord" xml:space="preserve">
<value>Subtract</value>
<comment>{Locked}This is the shortcut for the zoom out button.</comment>
</data>
<data name="zoomOutButton.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve"> <data name="zoomOutButton.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
<value>Zoom Out</value> <value>Zoom Out</value>
<comment>This is the tool tip automation name for the Calculator zoom out button.</comment> <comment>This is the tool tip automation name for the Calculator zoom out button.</comment>

View file

@ -423,8 +423,8 @@
Style="{ThemeResource GraphControlCommandPanel}" Style="{ThemeResource GraphControlCommandPanel}"
RequestedTheme="Light"> RequestedTheme="Light">
<StackPanel Orientation="Vertical"> <StackPanel Orientation="Vertical">
<RepeatButton x:Name="ZoomInButton"
<RepeatButton x:Uid="zoomInButton" x:Uid="zoomInButton"
MinHeight="40" MinHeight="40"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
Style="{ThemeResource ThemedGraphRepeatButtonStyle}" Style="{ThemeResource ThemedGraphRepeatButtonStyle}"
@ -435,9 +435,13 @@
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" <FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}"
FontSize="14" FontSize="14"
Glyph="&#xE710;"/> Glyph="&#xE710;"/>
<RepeatButton.KeyboardAccelerators>
<KeyboardAccelerator Key="Add" Modifiers="Control"/>
</RepeatButton.KeyboardAccelerators>
</RepeatButton> </RepeatButton>
<RepeatButton x:Uid="zoomOutButton" <RepeatButton x:Name="ZoomOutButton"
x:Uid="zoomOutButton"
MinHeight="40" MinHeight="40"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
Style="{ThemeResource ThemedGraphRepeatButtonStyle}" Style="{ThemeResource ThemedGraphRepeatButtonStyle}"
@ -447,6 +451,9 @@
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" <FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}"
FontSize="14" FontSize="14"
Glyph="&#xE738;"/> Glyph="&#xE738;"/>
<RepeatButton.KeyboardAccelerators>
<KeyboardAccelerator Key="Subtract" Modifiers="Control"/>
</RepeatButton.KeyboardAccelerators>
</RepeatButton> </RepeatButton>
<Button x:Uid="zoomResetButton" <Button x:Uid="zoomResetButton"

View file

@ -66,6 +66,17 @@ GraphingCalculator::GraphingCalculator()
// And when the actual trace value changes // And when the actual trace value changes
GraphingControl->TracingValueChangedEvent += ref new TracingValueChangedEventHandler(this, &GraphingCalculator::OnTracePointChanged); GraphingControl->TracingValueChangedEvent += ref new TracingValueChangedEventHandler(this, &GraphingCalculator::OnTracePointChanged);
// OemMinus and OemAdd aren't declared in the VirtualKey enum, we can't add this accelerator XAML-side
auto virtualKey = ref new KeyboardAccelerator();
virtualKey->Key = (VirtualKey)187; //OemMinus key
virtualKey->Modifiers = VirtualKeyModifiers::Control;
ZoomOutButton->KeyboardAccelerators->Append(virtualKey);
virtualKey = ref new KeyboardAccelerator();
virtualKey->Key = (VirtualKey)189; //OemAdd key
virtualKey->Modifiers = VirtualKeyModifiers::Control;
ZoomInButton->KeyboardAccelerators->Append(virtualKey);
} }
void GraphingCalculator::OnShowTracePopupChanged(bool newValue) void GraphingCalculator::OnShowTracePopupChanged(bool newValue)