Browse Source

Merge branch 'gumme-WpfDesignerExtensionKeyHandler'

pull/628/head
Siegfried Pammer 11 years ago
parent
commit
c07fd2adde
  1. 49
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs
  2. 46
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/ExtensionInterfaces.cs
  3. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj

49
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs

@ -34,6 +34,8 @@ using ICSharpCode.WpfDesign.Adorners; @@ -34,6 +34,8 @@ using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
using ICSharpCode.WpfDesign.Designer.Xaml;
using ICSharpCode.WpfDesign.Extensions;
using System.Linq;
namespace ICSharpCode.WpfDesign.Designer
{
@ -372,6 +374,21 @@ namespace ICSharpCode.WpfDesign.Designer @@ -372,6 +374,21 @@ namespace ICSharpCode.WpfDesign.Designer
int dx = 0;
int dy = 0;
/// <summary>
/// If interface implementing class sets this to false defaultkeyaction will be
/// </summary>
/// <param name="e"></param>
/// <returns></returns>
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)
@ -383,10 +400,33 @@ namespace ICSharpCode.WpfDesign.Designer @@ -383,10 +400,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;
@ -398,9 +438,16 @@ namespace ICSharpCode.WpfDesign.Designer @@ -398,9 +438,16 @@ namespace ICSharpCode.WpfDesign.Designer
}
if (placementOp == null) {
//check if any objects don't want the default action to be invoked
List<DesignItem> 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);
placementOp = PlacementOperation.Start(placedItems, placementType);
}
switch (e.Key) {

46
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/ExtensionInterfaces.cs

@ -0,0 +1,46 @@ @@ -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
{
/// <summary>
/// interface that can be implemented if a control is to be alerted of KeyDown Event on DesignPanel
/// </summary>
public interface IKeyDown
{
/// <summary>
/// Action to be performed on keydown on specific control
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void KeyDownAction(object sender, KeyEventArgs e);
/// <summary>
/// if that control wants the default DesignPanel action to be suppressed, let this return false
/// </summary>
bool InvokeDefaultAction { get; }
}
/// <summary>
/// interface that can be implemented if a control is to be alerted of KeyUp Event on DesignPanel
/// </summary>
public interface IKeyUp
{
/// <summary>
/// Action to be performed on keyup on specific control
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void KeyUpAction(object sender, KeyEventArgs e);
}
}

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj

@ -75,6 +75,7 @@ @@ -75,6 +75,7 @@
<Compile Include="Adorners\RelativePlacement.cs" />
<Compile Include="ExtensionMethods.cs" />
<Compile Include="Extensions\ExtensionAttribute.cs" />
<Compile Include="Extensions\ExtensionInterfaces.cs" />
<Compile Include="HitTestType.cs" />
<Compile Include="Metadata.cs" />
<Compile Include="PlacementInformation.cs" />

Loading…
Cancel
Save