Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / View / DesignerView.Commands.cs / 1305376 / DesignerView.Commands.cs
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//---------------------------------------------------------------
namespace System.Activities.Presentation.View
{
using System.Activities.Debugger;
using System.Activities.Presentation.Debug;
using System.Activities.Presentation.Hosting;
using System.Activities.Presentation.Internal.PropertyEditing;
using System.Activities.Presentation.Model;
using System.Activities.Presentation.Services;
using System.Activities.Statements;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Microsoft.Win32;
public partial class DesignerView
{
public const string CustomMenuItemsSeparatorCommand = "6F455692-EA19-4ac9-ABEE-57F6DF20A687";
public static readonly DependencyProperty CommandMenuModeProperty =
DependencyProperty.RegisterAttached("CommandMenuMode", typeof(CommandMenuMode), typeof(DesignerView), new UIPropertyMetadata(CommandMenuMode.FullCommandMenu));
static readonly DependencyProperty MenuItemOriginProperty =
DependencyProperty.RegisterAttached("MenuItemOrigin", typeof(FrameworkElement), typeof(DesignerView));
public static readonly DependencyProperty MenuItemStyleProperty =
DependencyProperty.Register("MenuItemStyle", typeof(Style), typeof(DesignerView), new UIPropertyMetadata(null));
public static readonly DependencyProperty MenuSeparatorStyleProperty =
DependencyProperty.Register("MenuSeparatorStyle", typeof(Style), typeof(DesignerView), new UIPropertyMetadata(null));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes,
Justification = "The class RoutedCommand just has readonly properties, hence the referencetype instance cannot be modified")]
public static readonly ICommand GoToParentCommand = new RoutedCommand("GoToParentCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand ExpandCommand = new RoutedCommand("ExpandCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand ExpandAllCommand = new RoutedCommand("ExpandAllCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand CollapseCommand = new RoutedCommand("CollapseCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand ExpandInPlaceCommand = new RoutedCommand("ExpandInPlaceCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand InsertBreakpointCommand = new RoutedCommand("InsertBreakpointCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand DeleteBreakpointCommand = new RoutedCommand("DeleteBreakpointParentCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand EnableBreakpointCommand = new RoutedCommand("EnableBreakpointCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand DisableBreakpointCommand = new RoutedCommand("DisableBreakpointCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand SaveAsImageCommand = new RoutedCommand("SaveAsImageCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand CopyAsImageCommand = new RoutedCommand("CopyAsImageCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand ZoomInCommand = new RoutedCommand("ZoomInCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand ZoomOutCommand = new RoutedCommand("ZoomOutCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand ToggleArgumentDesignerCommand = new RoutedCommand("ToggleArgumentDesignerCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand ToggleImportsDesignerCommand = new RoutedCommand("ToggleImportsDesignerCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand ToggleVariableDesignerCommand = new RoutedCommand("ToggleVariableDesignerCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand CreateVariableCommand = new RoutedCommand("CreateVariableCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand ToggleMiniMapCommand = new RoutedCommand("ToggleMinimapCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand CycleThroughDesignerCommand = new RoutedCommand("CycleThroughDesignerCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand CreateWorkflowElementCommand = new RoutedCommand("CreateWorkflowElementCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand CreateArgumentCommand = new RoutedCommand("CreateArgumentCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand CommitCommand = new RoutedCommand("CommitCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand FitToScreenCommand = new RoutedCommand("FitToScreenCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand ResetZoomCommand = new RoutedCommand("ResetZoomCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand MoveFocusCommand = new RoutedCommand("MoveFocusCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand ToggleSelectionCommand = new RoutedCommand("ToggleSelectionCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand CutCommand = new RoutedCommand("CutCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand CopyCommand = new RoutedCommand("CopyCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand PasteCommand = new RoutedCommand("PasteCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand SelectAllCommand = new RoutedCommand("SelectAllCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand UndoCommand = new RoutedCommand("UndoCommand", typeof(DesignerView));
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)]
public static readonly ICommand RedoCommand = new RoutedCommand("RedoCommand", typeof(DesignerView));
WorkflowViewElement contextMenuTarget;
HashSet ignoreCommands = new HashSet();
Func navigateToParentFunction;
Func navigateToChildFunction;
Func getBreakpointType;
Func isCommandServiceEnabled;
Func areBreakpointServicesEnabled;
Func isCommandSupported;
bool ContainsChordKeyGestures(InputGestureCollection collection)
{
if (collection == null)
{
return false;
}
else
{
foreach (KeyGesture gesture in collection)
{
if (gesture.GetType() == typeof(DefaultCommandExtensionCallback.ChordKeyGesture))
{
return true;
}
}
return false;
}
}
// Set chordkey gestures owner to this class, so that the chordkey can clear other chord key's mode
// after executing.
void SetChordKeyGesturesOwner()
{
foreach (CommandBinding binding in this.CommandBindings)
{
RoutedCommand cmd = binding.Command as RoutedCommand;
foreach (KeyGesture gesture in cmd.InputGestures)
{
if (gesture.GetType() == typeof(DefaultCommandExtensionCallback.ChordKeyGesture))
{
((DefaultCommandExtensionCallback.ChordKeyGesture)gesture).Owner = this;
}
}
}
}
// Let the chord command in front, so that the chord command (e.g. Ctrl+E,Ctrl+V) will match
// before the (e.g. Ctrl+V).
void ReorderCommandBindings()
{
CommandBindingCollection chordCommandBindings = new CommandBindingCollection();
CommandBindingCollection basicCommandBindings = new CommandBindingCollection();
foreach (CommandBinding binding in this.CommandBindings)
{
RoutedCommand cmd = binding.Command as RoutedCommand;
if (ContainsChordKeyGestures(cmd.InputGestures))
{
chordCommandBindings.Add(binding);
}
else
{
basicCommandBindings.Add(binding);
}
}
this.CommandBindings.Clear();
this.CommandBindings.AddRange(chordCommandBindings);
this.CommandBindings.AddRange(basicCommandBindings);
}
internal void ResetAllChordKeyGesturesMode()
{
foreach (CommandBinding binding in this.CommandBindings)
{
RoutedCommand cmd = binding.Command as RoutedCommand;
foreach(KeyGesture gesture in cmd.InputGestures)
{
if(gesture.GetType() == typeof(DefaultCommandExtensionCallback.ChordKeyGesture))
{
((DefaultCommandExtensionCallback.ChordKeyGesture)gesture).ResetChordMode();
}
}
}
}
void InitializeMenuActions()
{
this.isCommandServiceEnabled = () =>
{
return null != this.Context.Services.GetService();
};
this.areBreakpointServicesEnabled = () =>
{
return null != this.Context.Services.GetService() && this.isCommandServiceEnabled();
};
this.isCommandSupported = commandId =>
{
return this.Context.Services.GetService().IsCommandSupported(commandId);
};
this.navigateToParentFunction = (selection, shouldExecute) =>
{
bool result = false;
ModelItem target = null;
if (null != selection && selection.Equals(this.RootDesigner))
{
if (null != selection.ModelItem.Parent)
{
WorkflowViewService viewService = (WorkflowViewService)this.Context.Services.GetService();
target = selection.ModelItem;
do
{
target = target.Parent;
if (target == null)
{
break;
}
}
while (!viewService.ShouldAppearOnBreadCrumb(target, true));
result = (null != target);
}
}
if (shouldExecute && result)
{
this.MakeRootDesigner(target);
}
return result ? Visibility.Visible : Visibility.Collapsed;
};
this.navigateToChildFunction = (selection, shouldExecute) =>
{
bool result = false;
ModelItem target = null;
if (null != selection && !selection.Equals(this.RootDesigner))
{
target = selection.ModelItem;
WorkflowViewService viewService = (WorkflowViewService)this.Context.Services.GetService();
result = viewService.ShouldAppearOnBreadCrumb(target, true);
}
if (shouldExecute && result)
{
this.MakeRootDesigner(target);
}
return result ? Visibility.Visible : Visibility.Collapsed;
};
this.getBreakpointType = selection =>
{
IDesignerDebugView debugView = this.Context.Services.GetService();
var breakpoints = debugView.GetBreakpointLocations();
BreakpointTypes result = BreakpointTypes.None;
if (null != breakpoints && null != debugView.SelectedLocation)
{
breakpoints.TryGetValue(debugView.SelectedLocation, out result);
}
return result;
};
this.ContextMenu.ClipToBounds = false;
//workflow command extension callback invoker
Action updateCommands = (item) =>
{
//if there are any commands which were ignored - add them back to bindings collections
foreach (CommandBinding binding in this.ignoreCommands)
{
this.CommandBindings.Add(binding);
}
this.ignoreCommands.Clear();
if (null != item.CommandExtensionCallback)
{
foreach (CommandBinding cb in this.CommandBindings)
{
//if callback returns false, it means that user will handle the command, add it to ingore list
CommandInfo ci = new CommandInfo(cb.Command);
item.CommandExtensionCallback.OnWorkflowCommandLoaded(ci);
if (!ci.IsBindingEnabledInDesigner)
{
this.ignoreCommands.Add(cb);
}
}
//remove all commands from ignore list from bindings - let the commands bubble up to the client
foreach (CommandBinding cb in this.ignoreCommands)
{
this.CommandBindings.Remove(cb);
}
if (null != this.ContextMenu && this.ContextMenu.HasItems)
{
foreach (MenuItem menuItem in this.ContextMenu.Items.OfType