From 9f7c3209df9d5ea7deea3d5ad8da4b5696834345 Mon Sep 17 00:00:00 2001 From: tbulle Date: Thu, 6 Nov 2014 13:32:09 +0100 Subject: [PATCH 1/3] Handling KeyEvents for extension in case the extension needs it and a normal key event handling would interfer with the DesignPanel.cs keyhandling due to event bubbling prevention or such. --- .../WpfDesign.Designer/Project/DesignPanel.cs | 25 +++++++++++++++++++ .../WpfDesign/Project/WpfDesign.csproj | 1 + 2 files changed, 26 insertions(+) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs index 0a5ba978a3..a01b1046e8 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs @@ -29,6 +29,8 @@ using System.Windows.Threading; using ICSharpCode.WpfDesign.Adorners; using ICSharpCode.WpfDesign.Designer.Controls; using ICSharpCode.WpfDesign.Designer.Xaml; +using ICSharpCode.WpfDesign.Extensions; +using System.Linq; namespace ICSharpCode.WpfDesign.Designer { @@ -364,10 +366,33 @@ namespace ICSharpCode.WpfDesign.Designer placementOp = null; } } + //pass the key event to the underlying objects if they have implemented IKeyUp interface + //OBS!!!! this call needs to be here, after the placementOp.Commit(). + //In case the underlying object has a operation of its own this operation needs to be commited first + foreach (DesignItem di in Context.Services.Selection.SelectedItems.Reverse()) { + foreach (Extension ext in di.Extensions) { + var keyUp = ext as IKeyUp; + if (keyUp != null) { + keyUp.KeyUpAction(sender, e); + } + } + } } void DesignPanel_KeyDown(object sender, KeyEventArgs e) { + //pass the key event down to the underlying objects if they have implemented IKeyUp interface + //OBS!!!! this call needs to be here, before the PlacementOperation.Start. + //In case the underlying object has a operation of its own this operation needs to be set first + foreach (DesignItem di in Context.Services.Selection.SelectedItems) { + foreach (Extension ext in di.Extensions) { + var keyDown = ext as IKeyDown; + if (keyDown != null) { + keyDown.KeyDownAction(sender, e); + } + } + } + if (e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.Up || e.Key == Key.Down) { e.Handled = true; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj index 4d2b74cf43..bed1f23e23 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj @@ -74,6 +74,7 @@ + From 834c9101a59b4e40b41eb0ae509b0799d3d6d7ac Mon Sep 17 00:00:00 2001 From: tbulle Date: Thu, 6 Nov 2014 13:34:28 +0100 Subject: [PATCH 2/3] missing file --- .../Project/Extensions/ExtensionInterfaces.cs | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/ExtensionInterfaces.cs diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/ExtensionInterfaces.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/ExtensionInterfaces.cs new file mode 100644 index 0000000000..39eaa785ea --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/ExtensionInterfaces.cs @@ -0,0 +1,46 @@ +/* + * Created by SharpDevelop. + * User: trubra + * Date: 2014-11-06 + * Time: 11:45 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ +using System; +using System.Windows.Input; + +namespace ICSharpCode.WpfDesign.Extensions +{ + /// + /// interface that can be implemented if a control is to be alerted of KeyDown Event on DesignPanel + /// + public interface IKeyDown + { + /// + /// Action to be performed on keydown on specific control + /// + /// + /// + void KeyDownAction(object sender, KeyEventArgs e); + + /// + /// if that control wants the default DesignPanel action to be suppressed, let this return false + /// + bool InvokeDefaultAction { get; } + } + + /// + /// interface that can be implemented if a control is to be alerted of KeyUp Event on DesignPanel + /// + public interface IKeyUp + { + /// + /// Action to be performed on keyup on specific control + /// + /// + /// + void KeyUpAction(object sender, KeyEventArgs e); + } + + +} From cbd4600086da64d407fb5304b5ef96e9bb8c84c8 Mon Sep 17 00:00:00 2001 From: tbulle Date: Fri, 7 Nov 2014 08:27:00 +0100 Subject: [PATCH 3/3] Addition to DesignPanel to be able to suppress default key action for objects --- .../WpfDesign.Designer/Project/DesignPanel.cs | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs index a01b1046e8..3ccaef0d64 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs @@ -355,6 +355,21 @@ namespace ICSharpCode.WpfDesign.Designer int dx = 0; int dy = 0; + /// + /// If interface implementing class sets this to false defaultkeyaction will be + /// + /// + /// + bool InvokeDefaultKeyDownAction(Extension e) + { + var keyDown = e as IKeyDown; + if (keyDown != null) { + return keyDown.InvokeDefaultAction; + } + + return true; + } + private void DesignPanel_KeyUp(object sender, KeyEventArgs e) { if (e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.Up || e.Key == Key.Down) @@ -398,9 +413,17 @@ namespace ICSharpCode.WpfDesign.Designer e.Handled = true; if (placementOp == null) { + + //check if any objects don't want the default action to be invoked + List placedItems = Context.Services.Selection.SelectedItems.Where(x => x.Extensions.All(InvokeDefaultKeyDownAction)).ToList(); + + //if no remaining objects, break + if (placedItems.Count < 1) return; + dx = 0; dy = 0; - placementOp = PlacementOperation.Start(Context.Services.Selection.SelectedItems, PlacementType.Move); + + placementOp = PlacementOperation.Start(placedItems, PlacementType.Move); }