Browse Source

Fixed SD2-1016 - #Develop menus cannot be navigated using arrow keys when a winform has the focus.

FormKeyHandler now uses Control.FromChildHandle to determine whether the key message actually comes from inside the forms designer.
Replaced Hashtable with generic Dictionary. Removed unused local variable "ctl".

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4948 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Christian Hornung 16 years ago
parent
commit
b537595e0b
  1. 19
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/FormKeyHandler.cs

19
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/FormKeyHandler.cs

@ -7,6 +7,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.ComponentModel.Design; using System.ComponentModel.Design;
using System.Reflection; using System.Reflection;
@ -18,12 +19,12 @@ using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.FormsDesigner namespace ICSharpCode.FormsDesigner
{ {
public class FormKeyHandler : IMessageFilter public sealed class FormKeyHandler : IMessageFilter
{ {
const int keyPressedMessage = 0x100; const int keyPressedMessage = 0x100;
const int leftMouseButtonDownMessage = 0x0202; const int leftMouseButtonDownMessage = 0x0202;
Hashtable keyTable = new Hashtable(); readonly Dictionary<Keys, CommandWrapper> keyTable = new Dictionary<Keys, CommandWrapper>();
public static bool inserted = false; public static bool inserted = false;
public static void Insert() public static void Insert()
{ {
@ -81,6 +82,13 @@ namespace ICSharpCode.FormsDesigner
return false; return false;
} }
Control originControl = Control.FromChildHandle(m.HWnd);
if (originControl != null && formDesigner.Control != null && !(formDesigner.Control == originControl || formDesigner.Control.Contains(originControl))) {
// Ignore if message origin not in forms designer
// (e.g. navigating the main menu)
return false;
}
Keys keyPressed = (Keys)m.WParam.ToInt32() | Control.ModifierKeys; Keys keyPressed = (Keys)m.WParam.ToInt32() | Control.ModifierKeys;
if (keyPressed == Keys.Escape) { if (keyPressed == Keys.Escape) {
@ -90,8 +98,8 @@ namespace ICSharpCode.FormsDesigner
} }
} }
CommandWrapper commandWrapper = (CommandWrapper)keyTable[keyPressed]; CommandWrapper commandWrapper;
if (commandWrapper != null) { if (keyTable.TryGetValue(keyPressed, out commandWrapper)) {
if (commandWrapper.CommandID == MenuCommands.Delete) { if (commandWrapper.CommandID == MenuCommands.Delete) {
// Check Delete menu is enabled. // Check Delete menu is enabled.
if (!formDesigner.EnableDelete) { if (!formDesigner.EnableDelete) {
@ -99,7 +107,6 @@ namespace ICSharpCode.FormsDesigner
} }
} }
LoggingService.Debug("Run menu command: " + commandWrapper.CommandID); LoggingService.Debug("Run menu command: " + commandWrapper.CommandID);
Control ctl = WorkbenchSingleton.ActiveControl;
IMenuCommandService menuCommandService = (IMenuCommandService)formDesigner.Host.GetService(typeof(IMenuCommandService)); IMenuCommandService menuCommandService = (IMenuCommandService)formDesigner.Host.GetService(typeof(IMenuCommandService));
ISelectionService selectionService = (ISelectionService)formDesigner.Host.GetService(typeof(ISelectionService)); ISelectionService selectionService = (ISelectionService)formDesigner.Host.GetService(typeof(ISelectionService));
@ -160,7 +167,7 @@ namespace ICSharpCode.FormsDesigner
return false; // invoke the CommandID return false; // invoke the CommandID
} }
class CommandWrapper sealed class CommandWrapper
{ {
CommandID commandID; CommandID commandID;
bool restoreSelection; bool restoreSelection;

Loading…
Cancel
Save