Browse Source

#326: fast Ctrl[+Shift]+Tab will not be ignored

Quickly pressing Ctrl+Tab/Ctrl+Shift+Tab is often ignored.

This is happening because KeyDown is used to turn on navigator window and KeyUp is used to both intercept keys and turn navigator window off. When Ctrl+Tab pressed quickly KeyDown turn navigator window on, but there is no KeyUp for Ctrl+Tab (it's just Tab).

Proposed fix use PreviewKeyDown to activate and intercept navigator window keys; PreviewKeyUp to deactivate navigator window.
pull/331/head
Sergey Galich 12 years ago committed by Daniel Grunwald
parent
commit
b7c8d6ed68
  1. 70
      src/Libraries/AvalonDock/AvalonDock/DockingManager.cs

70
src/Libraries/AvalonDock/AvalonDock/DockingManager.cs

@ -1024,71 +1024,51 @@ namespace AvalonDock
} }
} }
protected override void OnPreviewKeyDown(KeyEventArgs e)
protected override void OnKeyDown(KeyEventArgs e)
{ {
// accept Control or Control+Shift // accept Control or Control+Shift
bool isCtrlDown = (Keyboard.Modifiers & ~ModifierKeys.Shift) == ModifierKeys.Control; bool isCtrlDown = (Keyboard.Modifiers & ~ModifierKeys.Shift) == ModifierKeys.Control;
bool _navigatorWindowIsVisible = navigatorWindow != null ? navigatorWindow.IsVisible : false; bool _navigatorWindowIsVisible = navigatorWindow != null ? navigatorWindow.IsVisible : false;
Debug.WriteLine(string.Format("OnKeyDn {0} CtrlDn={1}", e.Key, isCtrlDown)); Debug.WriteLine(string.Format("OnKeyDn {0} CtrlDn={1}", e.Key, isCtrlDown));
if (e.Key == Key.Tab && isCtrlDown) if(isCtrlDown) {
{
if (!_navigatorWindowIsVisible) if (!_navigatorWindowIsVisible && e.Key == Key.Tab) {
{
ShowNavigatorWindow(); ShowNavigatorWindow();
_navigatorWindowIsVisible = true;
} }
e.Handled = true; if (_navigatorWindowIsVisible)
} e.Handled = navigatorWindow.HandleKey(e.Key);
else if (NavigatorWindow.IsKeyHandled(e.Key))
{
HideNavigatorWindow();
} }
base.OnPreviewKeyDown(e);
base.OnKeyDown(e);
} }
protected override void OnKeyUp(KeyEventArgs e) protected override void OnPreviewKeyUp(KeyEventArgs e)
{ {
// accept Control or Control+Shift // accept Control or Control+Shift
bool isCtrlDown = (Keyboard.Modifiers & ~ModifierKeys.Shift) == ModifierKeys.Control; bool isCtrlDown = (Keyboard.Modifiers & ~ModifierKeys.Shift) == ModifierKeys.Control;
bool _navigatorWindowIsVisible = navigatorWindow != null ? navigatorWindow.IsVisible : false; bool _navigatorWindowIsVisible = navigatorWindow != null ? navigatorWindow.IsVisible : false;
Debug.WriteLine(string.Format("OnKeyUp {0} CtrlDn={1}", e.Key, isCtrlDown)); Debug.WriteLine(string.Format("OnKeyUp {0} CtrlDn={1}", e.Key, isCtrlDown));
if (NavigatorWindow.IsKeyHandled(e.Key) && isCtrlDown) if (!isCtrlDown && _navigatorWindowIsVisible)
{ {
if (!_navigatorWindowIsVisible && e.Key == Key.Tab) if (navigatorWindow.Documents.CurrentItem != null)
{ {
ShowNavigatorWindow(); var docSelected = (navigatorWindow.Documents.CurrentItem as NavigatorWindowDocumentItem).ItemContent as DocumentContent;
_navigatorWindowIsVisible = true; docSelected.Activate();
} }
else if (navigatorWindow.DockableContents.CurrentItem != null)
if (_navigatorWindowIsVisible)
e.Handled = navigatorWindow.HandleKey(e.Key);
}
else
{
if (_navigatorWindowIsVisible)
{ {
if (navigatorWindow.Documents.CurrentItem != null) var cntSelected = (navigatorWindow.DockableContents.CurrentItem as NavigatorWindowItem).ItemContent as DockableContent;
{ cntSelected.Activate();
var docSelected = (navigatorWindow.Documents.CurrentItem as NavigatorWindowDocumentItem).ItemContent as DocumentContent;
docSelected.Activate();
}
else if (navigatorWindow.DockableContents.CurrentItem != null)
{
var cntSelected = (navigatorWindow.DockableContents.CurrentItem as NavigatorWindowItem).ItemContent as DockableContent;
cntSelected.Activate();
}
HideNavigatorWindow();
} }
HideNavigatorWindow();
} }
base.OnKeyUp(e); base.OnPreviewKeyUp(e);
} }
#region DockablePane operations #region DockablePane operations

Loading…
Cancel
Save