Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / DefaultCommandExtensionCallback.cs / 1305376 / DefaultCommandExtensionCallback.cs
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//---------------------------------------------------------------
namespace System.Activities.Presentation
{
using System.Activities.Presentation.View;
using System.Activities.Presentation.Hosting;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
using System.Globalization;
using System.Runtime;
//DefaultCommandExtensionCallback - provides default key input gestures for most of the
//WF commands. user can either implmeent his own class or override this one and provide special
//handling for specific commands
class DefaultCommandExtensionCallback : IWorkflowCommandExtensionCallback
{
Dictionary> defaultGestures = new Dictionary>();
public DefaultCommandExtensionCallback()
{
defaultGestures.Add(DesignerView.GoToParentCommand,
new List { new ChordKeyGesture(Key.E, Key.P) });
defaultGestures.Add(DesignerView.ExpandInPlaceCommand,
new List { new ChordKeyGesture(Key.E, Key.E) });
defaultGestures.Add(DesignerView.ExpandAllCommand,
new List { new ChordKeyGesture(Key.E, Key.X) });
defaultGestures.Add(DesignerView.CollapseCommand,
new List { new ChordKeyGesture(Key.E, Key.C) });
defaultGestures.Add(DesignerView.ZoomInCommand,
new List {
new KeyGesture(Key.OemPlus, ModifierKeys.Control, "Ctrl +"),
new KeyGesture(Key.Add, ModifierKeys.Control)});
defaultGestures.Add(DesignerView.ZoomOutCommand,
new List {
new KeyGesture(Key.OemMinus, ModifierKeys.Control, "Ctrl -"),
new KeyGesture(Key.Subtract, ModifierKeys.Control)});
defaultGestures.Add(DesignerView.ToggleArgumentDesignerCommand,
new List { new ChordKeyGesture(Key.E, Key.A) });
defaultGestures.Add(DesignerView.ToggleVariableDesignerCommand,
new List { new ChordKeyGesture(Key.E, Key.V) });
defaultGestures.Add(DesignerView.ToggleImportsDesignerCommand,
new List { new ChordKeyGesture(Key.E, Key.I) });
defaultGestures.Add(DesignerView.ToggleMiniMapCommand,
new List { new ChordKeyGesture(Key.E, Key.O) });
defaultGestures.Add(DesignerView.CreateVariableCommand,
new List { new ChordKeyGesture(Key.E, Key.N) });
defaultGestures.Add(DesignerView.CycleThroughDesignerCommand,
new List { new KeyGesture(Key.F6, ModifierKeys.Control | ModifierKeys.Alt, "Ctrl + Alt + F6") });
defaultGestures.Add(ExpressionTextBox.CompleteWordCommand,
new List { new KeyGesture(Key.Right, ModifierKeys.Alt, "Alt + Right Arrow") });
defaultGestures.Add(ExpressionTextBox.GlobalIntellisenseCommand,
new List { new KeyGesture(Key.J, ModifierKeys.Control, "Ctrl + J") });
defaultGestures.Add(ExpressionTextBox.ParameterInfoCommand,
new List { new ChordKeyGesture(Key.K, Key.P)});
defaultGestures.Add(ExpressionTextBox.QuickInfoCommand,
new List { new ChordKeyGesture(Key.K, Key.I)});
defaultGestures.Add(DesignerView.MoveFocusCommand,
new List { new ChordKeyGesture(Key.E, Key.M) });
defaultGestures.Add(DesignerView.ToggleSelectionCommand,
new List { new ChordKeyGesture(Key.E, Key.S) });
defaultGestures.Add(DesignerView.CutCommand,
new List { new KeyGesture(Key.X, ModifierKeys.Control) });
defaultGestures.Add(DesignerView.CopyCommand,
new List { new KeyGesture(Key.C, ModifierKeys.Control) });
defaultGestures.Add(DesignerView.PasteCommand,
new List { new KeyGesture(Key.V, ModifierKeys.Control) });
defaultGestures.Add(DesignerView.SelectAllCommand,
new List { new KeyGesture(Key.A, ModifierKeys.Control) });
defaultGestures.Add(DesignerView.UndoCommand,
new List { new KeyGesture(Key.Z, ModifierKeys.Control) });
defaultGestures.Add(DesignerView.RedoCommand,
new List { new KeyGesture(Key.Y, ModifierKeys.Control) });
defaultGestures.Add(ExpressionTextBox.IncreaseFilterLevelCommand,
new List { new KeyGesture(Key.Decimal, ModifierKeys.Alt) });
defaultGestures.Add(ExpressionTextBox.DecreaseFilterLevelCommand,
new List { new KeyGesture(Key.OemComma, ModifierKeys.Alt) });
}
public void OnWorkflowCommandLoaded(CommandInfo commandInfo)
{
if (commandInfo == null)
{
throw FxTrace.Exception.AsError(new ArgumentNullException("commandInfo"));
}
RoutedCommand cmd = commandInfo.Command as RoutedCommand;
if (cmd != null)
{
List gestures = null;
if (defaultGestures.TryGetValue(cmd, out gestures))
{
gestures.ForEach((gesture) =>
{
if (!this.ContainsGesture(cmd, gesture))
{
cmd.InputGestures.Add(gesture);
}
});
}
}
}
protected bool ContainsGesture(RoutedCommand cmd, KeyGesture gesture)
{
return cmd.InputGestures.OfType().Any(p => string.Equals(p.DisplayString, gesture.DisplayString));
}
//ChordKeyGesture - class derived from KeyGesture - provides simple state machine implementation
//to handle chord keyboard navigation. Invoke when ChordKey or ChordKey + Ctrl is pressed after
//entering chord mode
internal sealed class ChordKeyGesture : KeyGesture
{
bool isInKeyChordMode = false;
Key chordKey;
public DesignerView Owner
{
get;
set;
}
public ChordKeyGesture(Key key, Key chordKey) :
base(key, ModifierKeys.Control, string.Format(CultureInfo.InvariantCulture, "Ctrl+{0}, {1}", key, chordKey))
{
this.chordKey = chordKey;
}
public void ResetChordMode()
{
this.isInKeyChordMode = false;
}
public override bool Matches(object targetElement, InputEventArgs inputEventArgs)
{
bool result = false;
KeyEventArgs keyArgs = inputEventArgs as KeyEventArgs;
//lookup only for keyboard events
if (null != keyArgs)
{
//by default - check if we are entering double key navigation
if (!this.isInKeyChordMode)
{
//call base implementation to match Ctrl + actual key
if (base.Matches(targetElement, keyArgs))
{
this.isInKeyChordMode = true;
}
}
//if we are waiting for chord key
else if (keyArgs.Key == this.chordKey && (Keyboard.Modifiers == ModifierKeys.None || Keyboard.Modifiers == ModifierKeys.Control))
{
//ok - we found a match, reset state to default
System.Diagnostics.Debug.WriteLine(this.DisplayString);
result = true;
// reset all the chord key after this command
if (this.Owner != null)
{
this.Owner.ResetAllChordKeyGesturesMode();
}
}
//no, second key didn't match the chord
//if ctrl is pressed, just let it stay in chord mode
else if(Keyboard.Modifiers != ModifierKeys.Control)
{
this.isInKeyChordMode = false;
}
}
//any other input event resets state to default
else
{
this.isInKeyChordMode = false;
}
return result;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//---------------------------------------------------------------
namespace System.Activities.Presentation
{
using System.Activities.Presentation.View;
using System.Activities.Presentation.Hosting;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
using System.Globalization;
using System.Runtime;
//DefaultCommandExtensionCallback - provides default key input gestures for most of the
//WF commands. user can either implmeent his own class or override this one and provide special
//handling for specific commands
class DefaultCommandExtensionCallback : IWorkflowCommandExtensionCallback
{
Dictionary> defaultGestures = new Dictionary>();
public DefaultCommandExtensionCallback()
{
defaultGestures.Add(DesignerView.GoToParentCommand,
new List { new ChordKeyGesture(Key.E, Key.P) });
defaultGestures.Add(DesignerView.ExpandInPlaceCommand,
new List { new ChordKeyGesture(Key.E, Key.E) });
defaultGestures.Add(DesignerView.ExpandAllCommand,
new List { new ChordKeyGesture(Key.E, Key.X) });
defaultGestures.Add(DesignerView.CollapseCommand,
new List { new ChordKeyGesture(Key.E, Key.C) });
defaultGestures.Add(DesignerView.ZoomInCommand,
new List {
new KeyGesture(Key.OemPlus, ModifierKeys.Control, "Ctrl +"),
new KeyGesture(Key.Add, ModifierKeys.Control)});
defaultGestures.Add(DesignerView.ZoomOutCommand,
new List {
new KeyGesture(Key.OemMinus, ModifierKeys.Control, "Ctrl -"),
new KeyGesture(Key.Subtract, ModifierKeys.Control)});
defaultGestures.Add(DesignerView.ToggleArgumentDesignerCommand,
new List { new ChordKeyGesture(Key.E, Key.A) });
defaultGestures.Add(DesignerView.ToggleVariableDesignerCommand,
new List { new ChordKeyGesture(Key.E, Key.V) });
defaultGestures.Add(DesignerView.ToggleImportsDesignerCommand,
new List { new ChordKeyGesture(Key.E, Key.I) });
defaultGestures.Add(DesignerView.ToggleMiniMapCommand,
new List { new ChordKeyGesture(Key.E, Key.O) });
defaultGestures.Add(DesignerView.CreateVariableCommand,
new List { new ChordKeyGesture(Key.E, Key.N) });
defaultGestures.Add(DesignerView.CycleThroughDesignerCommand,
new List { new KeyGesture(Key.F6, ModifierKeys.Control | ModifierKeys.Alt, "Ctrl + Alt + F6") });
defaultGestures.Add(ExpressionTextBox.CompleteWordCommand,
new List { new KeyGesture(Key.Right, ModifierKeys.Alt, "Alt + Right Arrow") });
defaultGestures.Add(ExpressionTextBox.GlobalIntellisenseCommand,
new List { new KeyGesture(Key.J, ModifierKeys.Control, "Ctrl + J") });
defaultGestures.Add(ExpressionTextBox.ParameterInfoCommand,
new List { new ChordKeyGesture(Key.K, Key.P)});
defaultGestures.Add(ExpressionTextBox.QuickInfoCommand,
new List { new ChordKeyGesture(Key.K, Key.I)});
defaultGestures.Add(DesignerView.MoveFocusCommand,
new List { new ChordKeyGesture(Key.E, Key.M) });
defaultGestures.Add(DesignerView.ToggleSelectionCommand,
new List { new ChordKeyGesture(Key.E, Key.S) });
defaultGestures.Add(DesignerView.CutCommand,
new List { new KeyGesture(Key.X, ModifierKeys.Control) });
defaultGestures.Add(DesignerView.CopyCommand,
new List { new KeyGesture(Key.C, ModifierKeys.Control) });
defaultGestures.Add(DesignerView.PasteCommand,
new List { new KeyGesture(Key.V, ModifierKeys.Control) });
defaultGestures.Add(DesignerView.SelectAllCommand,
new List { new KeyGesture(Key.A, ModifierKeys.Control) });
defaultGestures.Add(DesignerView.UndoCommand,
new List { new KeyGesture(Key.Z, ModifierKeys.Control) });
defaultGestures.Add(DesignerView.RedoCommand,
new List { new KeyGesture(Key.Y, ModifierKeys.Control) });
defaultGestures.Add(ExpressionTextBox.IncreaseFilterLevelCommand,
new List { new KeyGesture(Key.Decimal, ModifierKeys.Alt) });
defaultGestures.Add(ExpressionTextBox.DecreaseFilterLevelCommand,
new List { new KeyGesture(Key.OemComma, ModifierKeys.Alt) });
}
public void OnWorkflowCommandLoaded(CommandInfo commandInfo)
{
if (commandInfo == null)
{
throw FxTrace.Exception.AsError(new ArgumentNullException("commandInfo"));
}
RoutedCommand cmd = commandInfo.Command as RoutedCommand;
if (cmd != null)
{
List gestures = null;
if (defaultGestures.TryGetValue(cmd, out gestures))
{
gestures.ForEach((gesture) =>
{
if (!this.ContainsGesture(cmd, gesture))
{
cmd.InputGestures.Add(gesture);
}
});
}
}
}
protected bool ContainsGesture(RoutedCommand cmd, KeyGesture gesture)
{
return cmd.InputGestures.OfType().Any(p => string.Equals(p.DisplayString, gesture.DisplayString));
}
//ChordKeyGesture - class derived from KeyGesture - provides simple state machine implementation
//to handle chord keyboard navigation. Invoke when ChordKey or ChordKey + Ctrl is pressed after
//entering chord mode
internal sealed class ChordKeyGesture : KeyGesture
{
bool isInKeyChordMode = false;
Key chordKey;
public DesignerView Owner
{
get;
set;
}
public ChordKeyGesture(Key key, Key chordKey) :
base(key, ModifierKeys.Control, string.Format(CultureInfo.InvariantCulture, "Ctrl+{0}, {1}", key, chordKey))
{
this.chordKey = chordKey;
}
public void ResetChordMode()
{
this.isInKeyChordMode = false;
}
public override bool Matches(object targetElement, InputEventArgs inputEventArgs)
{
bool result = false;
KeyEventArgs keyArgs = inputEventArgs as KeyEventArgs;
//lookup only for keyboard events
if (null != keyArgs)
{
//by default - check if we are entering double key navigation
if (!this.isInKeyChordMode)
{
//call base implementation to match Ctrl + actual key
if (base.Matches(targetElement, keyArgs))
{
this.isInKeyChordMode = true;
}
}
//if we are waiting for chord key
else if (keyArgs.Key == this.chordKey && (Keyboard.Modifiers == ModifierKeys.None || Keyboard.Modifiers == ModifierKeys.Control))
{
//ok - we found a match, reset state to default
System.Diagnostics.Debug.WriteLine(this.DisplayString);
result = true;
// reset all the chord key after this command
if (this.Owner != null)
{
this.Owner.ResetAllChordKeyGesturesMode();
}
}
//no, second key didn't match the chord
//if ctrl is pressed, just let it stay in chord mode
else if(Keyboard.Modifiers != ModifierKeys.Control)
{
this.isInKeyChordMode = false;
}
}
//any other input event resets state to default
else
{
this.isInKeyChordMode = false;
}
return result;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- BoundColumn.cs
- Parser.cs
- FlowDocumentPageViewerAutomationPeer.cs
- ArraySegment.cs
- LayoutDump.cs
- PropertyInfo.cs
- TogglePattern.cs
- TableAdapterManagerGenerator.cs
- CodeVariableReferenceExpression.cs
- XmlReflectionImporter.cs
- BitmapFrame.cs
- DataProtection.cs
- SerializableAttribute.cs
- NullableBoolConverter.cs
- SettingsBindableAttribute.cs
- HtmlHead.cs
- ChannelSinkStacks.cs
- MetadataSource.cs
- RegistryPermission.cs
- ButtonAutomationPeer.cs
- NativeWindow.cs
- OperationResponse.cs
- CopyOfAction.cs
- SafeEventLogWriteHandle.cs
- DuplicateDetector.cs
- ImageCodecInfo.cs
- DataGridTable.cs
- TransformProviderWrapper.cs
- SrgsSemanticInterpretationTag.cs
- WebPartTransformerCollection.cs
- ImageMapEventArgs.cs
- SqlFunctionAttribute.cs
- InstancePersistenceCommand.cs
- BasicBrowserDialog.cs
- StrokeNodeOperations2.cs
- DataError.cs
- Part.cs
- StaticDataManager.cs
- MetadataItem_Static.cs
- TypedTableBase.cs
- LongValidator.cs
- ScriptReference.cs
- Image.cs
- MaskDesignerDialog.cs
- State.cs
- XslCompiledTransform.cs
- MDIControlStrip.cs
- MouseActionConverter.cs
- EmissiveMaterial.cs
- ListParagraph.cs
- DescendentsWalker.cs
- DateTimeConverter.cs
- SoapObjectWriter.cs
- UniqueConstraint.cs
- RoleManagerSection.cs
- DiagnosticsConfigurationHandler.cs
- TemplateApplicationHelper.cs
- CheckBox.cs
- StylusShape.cs
- HScrollBar.cs
- MailDefinition.cs
- PropertyChange.cs
- QuaternionRotation3D.cs
- IteratorDescriptor.cs
- ApplicationBuildProvider.cs
- GridViewCancelEditEventArgs.cs
- IUnknownConstantAttribute.cs
- GetPageCompletedEventArgs.cs
- sqlinternaltransaction.cs
- MenuEventArgs.cs
- HtmlMeta.cs
- SqlMetaData.cs
- UntypedNullExpression.cs
- XPathChildIterator.cs
- BevelBitmapEffect.cs
- BindingValueChangedEventArgs.cs
- ComplusTypeValidator.cs
- _UriSyntax.cs
- SpotLight.cs
- HwndMouseInputProvider.cs
- MeasureItemEvent.cs
- PermissionRequestEvidence.cs
- CustomError.cs
- DbMetaDataColumnNames.cs
- LocatorManager.cs
- ComAdminInterfaces.cs
- SqlBooleanMismatchVisitor.cs
- DocumentXPathNavigator.cs
- ProxyAttribute.cs
- ImageField.cs
- ThreadTrace.cs
- Animatable.cs
- ScriptIgnoreAttribute.cs
- RadioButtonList.cs
- DataGridViewColumn.cs
- TextFormatterHost.cs
- XmlConvert.cs
- ZipIOLocalFileDataDescriptor.cs
- ToolStripPanel.cs
- DiscoveryMessageSequenceGenerator.cs