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<KeyGesture> gestures = null; if (defaultGestures.TryGetValue(cmd, out gestures)) { gestures.ForEach((gesture) => { if (!this.ContainsGesture(cmd, gesture)) { cmd.InputGestures.Add(gesture); } }); } } }
void InitializeMenuActions() { this.isCommandServiceEnabled = () => { return null != this.Context.Services.GetService<ICommandService>(); }; this.areBreakpointServicesEnabled = () => { return null != this.Context.Services.GetService<IDesignerDebugView>() && this.isCommandServiceEnabled(); }; this.isCommandSupported = commandId => { return this.Context.Services.GetService<ICommandService>().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<ViewService>(); 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<ViewService>(); 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<IDesignerDebugView>(); 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<WorkflowCommandExtensionItem> 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<MenuItem>()) { this.RefreshContextMenu(menuItem); } } } if (item.CommandExtensionCallback.GetType() == typeof(DefaultCommandExtensionCallback)) { this.ReorderCommandBindings(); this.SetChordKeyGesturesOwner(); } }; //subscribe for command extension callback changes; this.context.Items.Subscribe<WorkflowCommandExtensionItem>(new SubscribeContextCallback<WorkflowCommandExtensionItem>(updateCommands)); //if entry already exists - invoke update; if entry doesn't exist - do nothing. perhaps it will be added later by the user if (this.context.Items.Contains<WorkflowCommandExtensionItem>()) { updateCommands(this.context.Items.GetValue<WorkflowCommandExtensionItem>()); } }