protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            if (e != null && !this.Disabled)
            {
                this.offset = e.GetPosition(this);
                this.CaptureMouse();
                if (this.scope != null)
                {
                    this.ParentStateContainerEditor.StoreShapeSizeWithUndoRecursively(this.ParentStateContainerEditor.ModelItem);
                }
                // Select the designer when it is being resized
                WorkflowViewElement designer = this.ParentStateContainerEditor.ModelItem.View as WorkflowViewElement;

                if (!designer.IsKeyboardFocusWithin)
                {
                    // Fix 185562 - if the designer has the keyboard focus (i.e. DisplayName being edited)
                    // then there is no need to refocus on the designer again.  That prevents the
                    // DisplayName editing to be group into the same EditingScope as resizing, and
                    // also the defaultDisplayNameReadOnlyControl from being Visible but not modified.
                    Keyboard.Focus(designer);
                }

                StateMachineDesigner stateMachineDesigner = VisualTreeUtils.FindVisualAncestor <StateMachineDesigner>(this.ParentStateContainerEditor);
                stateMachineDesigner.IsResizing = true;

                e.Handled = true;
            }
            base.OnPreviewMouseLeftButtonDown(e);
        }
示例#2
0
        private void OnWIPPreviewDragEnter(object sender, DragEventArgs e)
        {
            // We want to disable hover-to-expand for WIPs when dragging from the designer surface.
            // This is because after hover-to-expand, the transition designer will be unloaded.
            // As a result, 1) there is no way to update other transitions if the shared trigger is updated, and
            // 2) The ReorderableListEditor will be cleared and there is no way to update the source container
            // for actions if actions are updated.

            WorkflowItemPresenter presenter = (WorkflowItemPresenter)sender;

            if (presenter.Item != null && DragDropHelper.GetDraggedModelItems(e).Count <ModelItem>() > 0)
            {
                WorkflowViewElement topmostWFViewElement = this.FindTopmostWorkflowViewelementByHitTest(
                    presenter, e.GetPosition(presenter));
                bool isAlreadyExpanded = topmostWFViewElement != null ? topmostWFViewElement.ShowExpanded : false;
                if (!isAlreadyExpanded)
                {
                    // Handling the DragEnter would not only disable Auot-expand but also Auto-surround UI gesture (Bug 202880).
                    // To circumvent this problem, a new method (ShowSpacerHelperOnDraggedItems) is used to show
                    // the spacer directly.
                    presenter.ShowSpacerHelperOnDraggedItems(e);
                    e.Handled = true;
                }
            }
        }
 public void RegisterViewElement(WorkflowViewElement view)
 {
     if (!this.views.Contains(view))
     {
         this.views.Add(view);
     }
 }
 public void RegisterViewElement(WorkflowViewElement view)
 {
     if (!this.views.Contains(view))
     {
         this.views.Add(view);
     }
 }
 public void UnregisterViewElement(WorkflowViewElement view)
 {
     if (this.views.Contains(view))
     {
         this.views.Remove(view);
     }
 }
        public static void MakeRootDesigner(WorkflowViewElement wve)
        {
            DesignerView designerView = wve.Context.Services.GetService <DesignerView>();

            if (!wve.Equals(designerView.RootDesigner))
            {
                designerView.MakeRootDesigner(wve.ModelItem);
            }
        }
示例#7
0
        /// <summary>
        /// Contruct a ViewChangedEventArgs object
        /// </summary>
        /// <param name="view">the workflow view element that is created</param>
        public ViewCreatedEventArgs(WorkflowViewElement view)
        {
            if (view == null)
            {
                throw FxTrace.Exception.ArgumentNull("view");
            }

            this.view = view;
        }
        /// <summary>
        /// Contruct a ViewChangedEventArgs object
        /// </summary>
        /// <param name="view">the workflow view element that is created</param>
        public ViewCreatedEventArgs(WorkflowViewElement view)
        {
            if (view == null)
            {
                throw FxTrace.Exception.ArgumentNull("view");
            }

            this.view = view;
        }
        public static void MakeParentRootDesigner <TParentType>(WorkflowViewElement wve)
            where TParentType : WorkflowViewElement
        {
            WorkflowViewElement view = FindParentDesigner <TParentType>(wve);

            if (view != null)
            {
                MakeRootDesigner(view);
            }
        }
示例#10
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            WorkflowViewElement workflowViewElement = value as WorkflowViewElement;

            if (null != workflowViewElement)
            {
                return(workflowViewElement.IsRootDesigner);
            }

            return(false);
        }
示例#11
0
        private WorkflowViewElement GenerateErrorElement(ModelItem modelItem, string errorString)
        {
            WorkflowViewElement errorElement = new WorkflowViewElement();
            string errorText = string.Format(CultureInfo.CurrentCulture, SR.CouldNotGenerateView, modelItem.ItemType.Name);

            ShowErrorInViewElement(errorElement, errorText, errorString);
            errorElement.Context   = this.context;
            errorElement.ModelItem = modelItem;
            ((IModelTreeItem)modelItem).SetCurrentView(errorElement);
            errorElement.DataContext = errorElement;
            return(errorElement);
        }
示例#12
0
        public WorkflowViewElement GetViewElement(ModelItem modelItem, ICompositeView sourceContainer)
        {
            WorkflowViewElement itemView = (WorkflowViewElement)this.ViewService.GetView(modelItem);

            if (null != sourceContainer)
            {
                DragDropHelper.SetCompositeView(itemView, (UIElement)sourceContainer);
            }
            itemView.Loaded   += this.OnViewLoaded;
            itemView.Unloaded += this.OnViewUnloaded;

            return(itemView);
        }
示例#13
0
        protected WorkflowViewElement CreateViewElement(ModelItem modelItem)
        {
            Fx.Assert(modelItem != null, "The passed in ModelItem is null");
            WorkflowViewElement viewElement = null;

            Type designerType = GetDesignerType(modelItem.ItemType, true);

            if (designerType != null && typeof(WorkflowViewElement).IsAssignableFrom(designerType))
            {
                viewElement = (WorkflowViewElement)Activator.CreateInstance(designerType);
            }
            return(viewElement);
        }
示例#14
0
        public WorkflowViewElement GetViewElement(ModelItem modelItem)
        {
            WorkflowViewElement viewElement = null;
            string errorString = string.Empty;

            if (modelItem == null)
            {
                return(null);
            }

            try
            {
                // try to make one from the type specified in Designer attribute.
                // reuse existing views that are not currently parented
                if (modelItem.View != null && ((WorkflowViewElement)modelItem.View).Parent == null)
                {
                    viewElement = (WorkflowViewElement)modelItem.View;
                }
                else
                {
                    viewElement = CreateViewElement(modelItem);
                }

                // now we successfully got a viewElement, lets initialize it with ModelItem;
                if (viewElement != null)
                {
                    viewElement.Context   = this.context;
                    viewElement.ModelItem = modelItem;
                    ((IModelTreeItem)modelItem).SetCurrentView(viewElement);
                    viewElement.DataContext = viewElement;

                    // Generate an event that we created a new view element.  This could be used by
                    // the Debugger Service to insert a breakpoint on the view element.
                    if (this.ViewCreated != null)
                    {
                        this.ViewCreated(this, new ViewCreatedEventArgs(viewElement));
                    }
                }
            }
            // never crash here
            // always report error to the customer.
            catch (Exception e)
            {
                errorString = e.ToString();
            }
            if (viewElement == null || !(string.IsNullOrEmpty(errorString)))
            {
                viewElement = GenerateErrorElement(modelItem, errorString);
            }
            return(viewElement);
        }
示例#15
0
 protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
 {
     if (e != null && !this.Disabled)
     {
         this.Cursor = Cursors.SizeNWSE;
         this.offset = e.GetPosition(this);
         this.CaptureMouse();
         // Select the designer when it is being resized
         WorkflowViewElement designer = this.ParentStateContainerEditor.ModelItem.View as WorkflowViewElement;
         Keyboard.Focus(designer);
         e.Handled = true;
     }
     base.OnPreviewMouseLeftButtonDown(e);
 }
示例#16
0
        internal WorkflowViewElement CreateDetachedViewElement(ModelItem modelItem)
        {
            WorkflowViewElement viewElement = CreateViewElement(modelItem);

            // now we successfully got a viewElement, lets initialize it with ModelItem;
            if (viewElement != null)
            {
                viewElement.Context     = this.context;
                viewElement.ModelItem   = modelItem;
                viewElement.DataContext = viewElement;
            }

            return(viewElement);
        }
示例#17
0
        internal static void ShowErrorInViewElement(WorkflowViewElement errorElement, string windowText, string toolTipText)
        {
            Grid errorGrid = new Grid();

            errorGrid.Background = Brushes.Red;
            errorGrid.Margin     = new Thickness(20.0);
            TextBlock text = new TextBlock();

            text.Text       = windowText;
            text.Foreground = SystemColors.WindowBrush;
            errorGrid.Children.Add(text);
            errorGrid.ToolTip    = toolTipText;
            errorElement.Content = errorGrid;
        }
示例#18
0
        protected bool IsUndoRedoInProgress()
        {
            bool isUndoRedoInProgress;
            WorkflowViewElement designer = (WorkflowViewElement)this.flowSwitchModelItem.View;

            if (designer == null)
            {
                isUndoRedoInProgress = false;
            }
            else
            {
                isUndoRedoInProgress = designer.Context.Services.GetService <UndoEngine>().IsUndoRedoInProgress;
            }
            return(isUndoRedoInProgress);
        }
        static TParentType FindParentDesigner <TParentType>(WorkflowViewElement wve)
            where TParentType : WorkflowViewElement
        {
            ModelItem parent = wve.ModelItem.Parent;

            while (parent != null)
            {
                if (parent.View != null && parent.View is TParentType)
                {
                    return((TParentType)parent.View);
                }
                parent = parent.Parent;
            }
            return(null);
        }
        private void StateDesignerToolTipOpening(object sender, ToolTipEventArgs e)
        {
            StateContainerEditor stateContainerEditor = (StateContainerEditor)sender;

            if (StateContainerEditor.CopiedTransitionDestinationState != null)
            {
                WorkflowViewElement view = VisualTreeUtils.FindVisualAncestor <WorkflowViewElement>(stateContainerEditor);
                if (view != null)
                {
                    StateContainerEditor container = (StateContainerEditor)DragDropHelper.GetCompositeView(view);
                    string errorMessage;
                    if (container != null && container.CanPasteTransition(StateContainerEditor.CopiedTransitionDestinationState, out errorMessage, view.ModelItem))
                    {
                        stateContainerEditor.ToolTip = SR.EditStateToolTip + Environment.NewLine + SR.PasteTransitionToolTip;
                        return;
                    }
                }
            }

            stateContainerEditor.ToolTip = SR.EditStateToolTip;
        }
        internal static void MeasureView(WorkflowViewElement view, bool measureAsCollapsed)
        {
            bool expandState = view.ExpandState;
            bool pinState    = view.PinState;

            if (measureAsCollapsed)
            {
                view.ForceCollapse();
            }

            view.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            view.UpdateLayout();

            if (view.ExpandState != expandState)
            {
                view.ExpandState = expandState;
            }
            if (view.PinState != pinState)
            {
                view.PinState = pinState;
            }
        }
        private bool ShouldClearSelectioinIfNothingSelected()
        {
            Selection curSelection = this.context.Items.GetValue <Selection>();

            if (curSelection == null || curSelection.SelectionCount == 0)
            {
                return(false);
            }

            // only one ModelItem is selected and the ModelItem is root designer.
            // do not clear selection
            if (curSelection.SelectionCount == 1)
            {
                ModelItem           item = curSelection.PrimarySelection;
                WorkflowViewElement view = item == null ? null : (item.View as WorkflowViewElement);
                if (view != null && view.IsRootDesigner)
                {
                    return(false);
                }
            }

            return(true);
        }
        private bool IsMouseOnDragHandle(MouseButtonEventArgs e)
        {
            HitTestResult result = VisualTreeHelper.HitTest(this.Designer.scrollableContent, e.GetPosition(this.Designer.scrollableContent));

            if (result != null)
            {
                WorkflowViewElement view = VisualTreeUtils.FindVisualAncestor <WorkflowViewElement>(result.VisualHit);
                if (view != null && view.DragHandle != null)
                {
                    GeneralTransform transform = view.DragHandle.TransformToAncestor(this.Designer);
                    Fx.Assert(transform != null, "transform should not be null");
                    Point topLeft        = transform.Transform(new Point(0, 0));
                    Point bottomRight    = transform.Transform(new Point(view.DragHandle.ActualWidth, view.DragHandle.ActualHeight));
                    Rect  dragHandleRect = new Rect(topLeft, bottomRight);
                    if (dragHandleRect.Contains(e.GetPosition(this.Designer)))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        protected ModelItemCollection GetVariableCollection(DependencyObject target)
        {
            ModelItemCollection variables = null;

            // Get model service.
            WorkflowViewElement element      = target as WorkflowViewElement;
            ModelService        modelService = element.Context.Services.GetService <ModelService>();

            // Locate the top-most sequence.
            var       list      = modelService.Find(modelService.Root, typeof(Activity));
            ModelItem container = null;

            // Get the container item. If there is no top-most container, just return the
            // the immediate Sequence activity.
            container = (list.Count() > 0) ? list.First <ModelItem>() : element.ModelItem;

            // Get the variable collection.
            if (container.Properties["Variables"] != null)
            {
                variables = container.Properties["Variables"].Collection;
            }

            return(variables);
        }
        public FreeFormPanel GetStateMachineFreeFormPanel()
        {
            StateDesigner       current = this;
            WorkflowViewElement parent  = VisualTreeUtils.FindVisualAncestor <WorkflowViewElement>(current);

            while (parent != null)
            {
                if (parent is StateDesigner)
                {
                    current = (StateDesigner)parent;
                    parent  = VisualTreeUtils.FindVisualAncestor <WorkflowViewElement>(current);
                }
                else if (parent is StateMachineDesigner)
                {
                    return(VisualTreeUtils.FindVisualAncestor <FreeFormPanel>(current));
                }
                else
                {
                    return(null);
                }
            }

            return(null);
        }
        void UnloadContextMenu(ContextMenu contextMenuToUnload)
        {
            if (null != contextMenuToUnload && null != this.contextMenuTarget)
            {
                // this should happen only for single selection
                //select all menu items which do not belong to DesignerView
                var items = contextMenuToUnload.Items.OfType<Control>()
                    .Where(p => DesignerView.GetMenuItemOrigin(p) != null)
                    .Reverse();

                foreach (Control item in items)
                {
                    //remove item from designer menu's location
                    contextMenuToUnload.Items.Remove(item);

                    //and add it back to activity designer
                    DesignerView.GetMenuItemOrigin(item).ContextMenu.Items.Insert(0, item);
                    DesignerView.SetMenuItemOrigin(item, null);
                }
                this.contextMenuTarget = null;
                contextMenuToUnload.Loaded -= this.OnWorkflowViewContextMenuLoaded;
                contextMenuToUnload.Unloaded -= this.OnWorkflowViewContextMenuClosed;
            }
        }
        internal static void MeasureView(WorkflowViewElement view, bool measureAsCollapsed)
        {
            bool expandState = view.ExpandState;
            bool pinState = view.PinState;
         
            if (measureAsCollapsed)
            {
                view.ForceCollapse();
            }

            view.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            view.UpdateLayout();

            if (view.ExpandState != expandState)
            {
                view.ExpandState = expandState;
            }
            if (view.PinState != pinState)
            {
                view.PinState = pinState;
            }
        }
示例#28
0
        private bool NavigateTo(SearchableEntry entry)
        {
            if (entry.SearchableEntryType == SearchableEntryOption.Variable)
            {
                itemToFocus = entry.ModelItem.Parent.Parent;
                HighlightModelItem(itemToFocus);
                this.lastNavigatedItem = itemToFocus;
                var designerView = this.editingContext.Services.GetService <DesignerView>();
                // Open the variable designer.
                designerView.CheckButtonVariables();
                designerView.variables1.SelectVariable(entry.ModelItem);
            }
            else if (entry.SearchableEntryType == SearchableEntryOption.Argument)
            {
                itemToFocus = this.modelService.Root;
                HighlightModelItem(itemToFocus);
                var designerView = this.editingContext.Services.GetService <DesignerView>();
                // Open the argument designer.
                designerView.CheckButtonArguments();
                designerView.arguments1.SelectArgument(entry.ModelItem);
                this.lastNavigatedItem = entry.ModelItem;
            }
            else
            {
                itemToFocus = entry.ModelItem;
                HighlightModelItem(itemToFocus);
                this.lastNavigatedItem = itemToFocus;
                ICommandService commandService = this.editingContext.Services.GetService <ICommandService>();
                if (commandService != null)
                {
                    commandService.ExecuteCommand(CommandValues.ShowProperties, null);
                }

                PropertyInspector propertiesGrid = this.designer.PropertyInspectorView as PropertyInspector;
                propertiesGrid.SelectPropertyByPath(entry.PropertyPath);
                if (ShouldShowSearchToolTip(itemToFocus))
                {
                    Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
                    {
                        WorkflowViewElement viewElement = itemToFocus.View as WorkflowViewElement;
                        if (viewElement != null)
                        {
                            this.adornerLayer = AdornerLayer.GetAdornerLayer(viewElement as WorkflowViewElement);
                            if (this.adornerLayer != null)
                            {
                                DesignerView designerView = this.editingContext.Services.GetService <DesignerView>();
                                string toolTipText        = string.Format(CultureInfo.CurrentUICulture, SR.SearchHintText, entry.ModelProperty.Name);
                                this.toolTipAdorner       = new SearchToolTipAdorner(viewElement, designerView, toolTipText);

                                viewElement.CustomItemStatus = "SearchToolTip=" + toolTipText;
                                this.lastWorkflowViewElement = viewElement;

                                this.adornerLayer.Add(this.toolTipAdorner);
                            }
                        }
                    }), DispatcherPriority.ApplicationIdle);
                }
            }

            return(true);
        }
 internal AnnotationManager(WorkflowViewElement workflowViewElement)
 {
     this.workflowViewElement = workflowViewElement;
 }
        public void OnItemsPasted(List <object> itemsToPaste, List <object> metaData, Point pastePoint, WorkflowViewElement pastePointReference)
        {
            Fx.Assert(this.panel != null, "This code shouldn't be hit if panel is null");
            HashSet <Activity> workflowElementsPasted = new HashSet <Activity>();
            List <ModelItem>   modelItemsToSelect     = new List <ModelItem>();
            bool shouldStoreCurrentSizeViewState      = true;

            Fx.Assert(this.ModelItem is IModelTreeItem, "this.ModelItem must implement IModelTreeItem");
            using (EditingScope editingScope = ((IModelTreeItem)this.ModelItem).ModelTreeManager.CreateEditingScope(System.Activities.Presentation.SR.CollectionAddEditingScopeDescription))
            {
                if (metaData != null)
                {
                    List <ModelItem> modelItemsPerMetaData = new List <ModelItem>();
                    foreach (object designerMetaData in metaData)
                    {
                        if (designerMetaData is List <FlowNode> )
                        {
                            //This is flowchart metadata.
                            foreach (FlowNode element in designerMetaData as List <FlowNode> )
                            {
                                FlowStep step = element as FlowStep;
                                if (step != null)
                                {
                                    workflowElementsPasted.Add(step.Action);
                                }

                                if (shouldStoreCurrentSizeViewState)
                                {
                                    // Pasting may change the size of flowchart; need this to undo the size change.
                                    this.StoreCurrentSizeViewStateWithUndo();
                                    shouldStoreCurrentSizeViewState = false;
                                }

                                ModelItem item = this.ModelItem.Properties["Nodes"].Collection.Add(element);

                                // if the pasted item is a flowswitch but the default target is not in the pasted selection,
                                // reset the DefaultCaseDisplayName to "Default".
                                if (GenericFlowSwitchHelper.IsGenericFlowSwitch(item.ItemType) &&
                                    item.Properties["Default"].Value == null)
                                {
                                    item.Properties[FlowSwitchLabelFeature.DefaultCaseDisplayNamePropertyName].SetValue(FlowSwitchLabelFeature.DefaultCaseDisplayNameDefaultValue);
                                }

                                modelItemsPerMetaData.Add(item);
                                if (item != null)
                                {
                                    if (item.ItemType.Equals(typeof(FlowStep)))
                                    {
                                        modelItemsToSelect.Add(item.Properties["Action"].Value);
                                    }
                                    else
                                    {
                                        modelItemsToSelect.Add(item);
                                    }
                                }
                            }
                            if (pastePoint.X > 0 && pastePoint.Y > 0)
                            {
                                Point panelPoint = this.TranslatePoint(pastePoint, this.panel);
                                if (pastePointReference != null && !pastePointReference.Equals(this))
                                {
                                    if (pastePointReference.ModelItem != null && this.modelElement.ContainsKey(pastePointReference.ModelItem))
                                    {
                                        panelPoint = pastePointReference.TranslatePoint(pastePoint, this.panel);
                                    }
                                }
                                panelPoint.X = panelPoint.X < 0 ? 0 : panelPoint.X;
                                panelPoint.Y = panelPoint.Y < 0 ? 0 : panelPoint.Y;
                                UpdateViewStateOnPastePoint(modelItemsPerMetaData, panelPoint);
                            }
                            else
                            {
                                UpdateViewStateToAvoidOverlapOnPaste(modelItemsPerMetaData);
                            }
                            modelItemsPerMetaData.Clear();
                        }
                    }
                }

                foreach (object itemToPaste in itemsToPaste)
                {
                    Activity workflowElementToPaste = itemToPaste as Activity;
                    if (workflowElementToPaste != null && !workflowElementsPasted.Contains(workflowElementToPaste))
                    {
                        FlowStep flowStep = new FlowStep {
                            Action = workflowElementToPaste, Next = null
                        };
                        if (shouldStoreCurrentSizeViewState)
                        {
                            // Pasting may change the size of flowchart; need this to undo the size change.
                            this.StoreCurrentSizeViewStateWithUndo();
                            shouldStoreCurrentSizeViewState = false;
                        }

                        // When paste a non-flowstep object to flowchart, the existing hintsize of the object
                        // should be removed, and let flowchart panel to compute the right size.
                        VirtualizedContainerService.SetHintSize(workflowElementToPaste, null);
                        ModelItem flowStepItem = this.ModelItem.Properties["Nodes"].Collection.Add(flowStep);

                        if (flowStepItem != null)
                        {
                            modelItemsToSelect.Add(flowStepItem.Properties["Action"].Value);
                        }
                    }
                }

                editingScope.Complete();
            }

            this.Dispatcher.BeginInvoke(() =>
            {
                if (modelItemsToSelect.Count > 0 && modelItemsToSelect[0] != null)
                {
                    Keyboard.Focus(modelItemsToSelect[0].View as IInputElement);
                }
                this.Context.Items.SetValue(new Selection(modelItemsToSelect));
            },
                                        DispatcherPriority.ApplicationIdle
                                        );
        }
 public void UnregisterViewElement(WorkflowViewElement viewElement)
 {
     if (this.rubberBandSelector != null)
     {
         this.rubberBandSelector.UnregisterViewElement(viewElement);
     }
 }
        private bool NavigateTo(SearchableEntry entry)
        {
            if (entry.SearchableEntryType == SearchableEntryOption.Variable)
            {
                itemToFocus = entry.ModelItem.Parent.Parent;
                HighlightModelItem(itemToFocus);
                this.lastNavigatedItem = itemToFocus;
                var designerView = this.editingContext.Services.GetService<DesignerView>();
                // Open the variable designer.
                designerView.CheckButtonVariables();
                designerView.variables1.SelectVariable(entry.ModelItem);
            }
            else if (entry.SearchableEntryType == SearchableEntryOption.Argument)
            {
                itemToFocus = this.modelService.Root;
                HighlightModelItem(itemToFocus);
                var designerView = this.editingContext.Services.GetService<DesignerView>();
                // Open the argument designer.
                designerView.CheckButtonArguments();
                designerView.arguments1.SelectArgument(entry.ModelItem);
                this.lastNavigatedItem = entry.ModelItem;
            }
            else
            {
                itemToFocus = entry.ModelItem;
                HighlightModelItem(itemToFocus);
                this.lastNavigatedItem = itemToFocus;
                ICommandService commandService = this.editingContext.Services.GetService<ICommandService>();
                if (commandService != null)
                {
                    commandService.ExecuteCommand(CommandValues.ShowProperties, null);
                }

                PropertyInspector propertiesGrid = this.designer.PropertyInspectorView as PropertyInspector;
                propertiesGrid.SelectPropertyByPath(entry.PropertyPath);
                if (ShouldShowSearchToolTip(itemToFocus))
                {
                    Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
                    {
                        WorkflowViewElement viewElement = itemToFocus.View as WorkflowViewElement;
                        if (viewElement != null)
                        {
                            this.adornerLayer = AdornerLayer.GetAdornerLayer(viewElement as WorkflowViewElement);
                            if (this.adornerLayer != null)
                            {
                                DesignerView designerView = this.editingContext.Services.GetService<DesignerView>();
                                string toolTipText = string.Format(CultureInfo.CurrentUICulture, SR.SearchHintText, entry.ModelProperty.Name);
                                this.toolTipAdorner = new SearchToolTipAdorner(viewElement, designerView, toolTipText);

                                viewElement.CustomItemStatus = "SearchToolTip=" + toolTipText;
                                this.lastWorkflowViewElement = viewElement;

                                this.adornerLayer.Add(this.toolTipAdorner);
                            }
                        }
                    }), DispatcherPriority.ApplicationIdle);
                }
            }

            return true;
        }
        public void OnItemsPasted(List <object> itemsToPaste, List <object> metaData, Point pastePoint, WorkflowViewElement pastePointReference)
        {
            List <ModelItem> modelItemsPasted = new List <ModelItem>();
            List <State>     states           = new List <State>();

            foreach (object obj in itemsToPaste)
            {
                State state;
                if (obj is FinalState)
                {
                    state = new State()
                    {
                        DisplayName = SR.DefaultFinalStateDisplayName, IsFinal = true
                    };
                }
                else
                {
                    state = (State)obj;
                    if (state.DisplayName == null)
                    {
                        state.DisplayName = SR.DefaultStateDisplayName;
                    }
                }
                states.Add(state);
            }

            RemoveDanglingTransitions(states);
            foreach (State state in states)
            {
                ModelItem stateModelItem = this.ModelItem.Properties[ChildStatesPropertyName].Collection.Add(state);
                modelItemsPasted.Add(stateModelItem);
            }
            if (modelItemsPasted.Count > 0)
            {
                // translate location view states to be in the coordinate system of the pasting target
                this.UpdateLocationViewStatesByMetaData(modelItemsPasted, metaData);
                if (pastePoint.X > 0 && pastePoint.Y > 0)
                {
                    if (pastePointReference != null)
                    {
                        pastePoint   = pastePointReference.TranslatePoint(pastePoint, this.panel);
                        pastePoint.X = pastePoint.X < 0 ? 0 : pastePoint.X;
                        pastePoint.Y = pastePoint.Y < 0 ? 0 : pastePoint.Y;
                    }
                    this.UpdateLocationViewStatesByPoint(modelItemsPasted, pastePoint);
                }
                // If paste point is not available, paste the items to the top left corner.
                else
                {
                    this.UpdateLocationViewStatesToTopLeft(modelItemsPasted);
                }
            }

            this.Context.Items.SetValue(new Selection(modelItemsPasted));
        }
        public void OnItemsPasted(List <object> itemsToPaste, List <object> metaData, Point pastePoint, WorkflowViewElement pastePointReference)
        {
            if (this.ModelItem.ItemType == typeof(State))
            {
                WorkflowViewElement view = VisualTreeUtils.FindVisualAncestor <WorkflowViewElement>(this);
                if (view != null)
                {
                    StateContainerEditor container = (StateContainerEditor)DragDropHelper.GetCompositeView(view);
                    container.OnItemsPasted(itemsToPaste, metaData, pastePoint, pastePointReference);
                }

                return;
            }

            if (itemsToPaste.Count == 1 && itemsToPaste.First() is Transition)
            {
                if (metaData == null || metaData.Count != 1 || !(metaData.First() is string))
                {
                    ShowMessageBox(SR.PasteTransitionWithoutDestinationState);
                    return;
                }

                ModelItem destinationState = FindState(metaData.First() as string);

                if (destinationState == null)
                {
                    ShowMessageBox(SR.PasteTransitionWithoutDestinationState);
                    return;
                }

                this.PopulateVirtualizingContainer(destinationState);

                ModelItem[] selectedItems = this.Context.Items.GetValue <Selection>().SelectedObjects.ToArray();
                string      errorMessage;
                if (!CanPasteTransition(destinationState, out errorMessage, selectedItems))
                {
                    ShowMessageBox(errorMessage);
                    return;
                }

                Transition pastedTransition = itemsToPaste.First() as Transition;
                Fx.Assert(pastedTransition != null, "Copied Transition should not be null.");

                using (EditingScope es = (EditingScope)this.ModelItem.BeginEdit(System.Activities.Presentation.SR.PropertyChangeEditingScopeDescription))
                {
                    string displayName = pastedTransition.DisplayName;
                    bool   isFirst     = true;
                    foreach (ModelItem selectedItem in selectedItems)
                    {
                        if (!isFirst)
                        {
                            StringReader reader = new StringReader(XamlServices.Save(pastedTransition));
                            pastedTransition = (Transition)XamlServices.Load(reader);
                        }

                        ModelItem transitionModelItem = this.Context.Services.GetRequiredService <ModelTreeManager>().WrapAsModelItem(pastedTransition);
                        ModelItem sourceState         = selectedItem;
                        sourceState.Properties[StateDesigner.TransitionsPropertyName].Collection.Add(transitionModelItem);
                        transitionModelItem.Properties[TransitionDesigner.ToPropertyName].SetValue(destinationState);

                        if (isFirst)
                        {
                            this.ViewStateService.RemoveViewState(transitionModelItem, ConnectorLocationViewStateKey);
                            this.ViewStateService.RemoveViewState(transitionModelItem, SrcConnectionPointIndexStateKey);
                            this.ViewStateService.RemoveViewState(transitionModelItem, DestConnectionPointIndexStateKey);
                            isFirst = false;
                        }
                    }

                    es.Complete();
                }
            }
            else
            {
                List <ModelItem> modelItemsPasted = new List <ModelItem>();
                List <State>     states           = new List <State>();

                foreach (object obj in itemsToPaste)
                {
                    State state;
                    if (obj is FinalState)
                    {
                        state = new State()
                        {
                            DisplayName = DefaultFinalStateDisplayName, IsFinal = true
                        };
                    }
                    else
                    {
                        state = (State)obj;
                        if (state.DisplayName == null)
                        {
                            state.DisplayName = DefaultStateDisplayName;
                        }
                    }
                    states.Add(state);
                }

                RemoveDanglingTransitions(states);

                using (EditingScope es = (EditingScope)this.ModelItem.BeginEdit(
                           System.Activities.Presentation.SR.CollectionAddEditingScopeDescription))
                {
                    // Fix 157591 by storing the height and width of the container "before" the new states are added to the
                    // panel, and group the insertion inside one editing scope - such that Undo will also restore the
                    // size of the StateMachineContainer to pre-insert size.
                    StoreShapeSizeWithUndoRecursively(this.ModelItem);

                    foreach (State state in states)
                    {
                        ModelItem stateModelItem =
                            (this.ModelItem.ItemType == typeof(StateMachine)) ?
                            this.ModelItem.Properties[StateMachineDesigner.StatesPropertyName].Collection.Add(state) :
                            GetStateMachineModelItem(this.ModelItem).Properties[StateMachineDesigner.StatesPropertyName].Collection.Add(state);
                        modelItemsPasted.Add(stateModelItem);
                    }

                    es.Complete();
                }

                if (modelItemsPasted.Count > 0)
                {
                    // translate location view states to be in the coordinate system of the pasting target
                    Fx.Assert(this.ModelItem.ItemType == typeof(StateMachine), "Only StateMachine contain the StateContainerEditor.");

                    this.UpdateLocationViewStatesByMetaData(modelItemsPasted, metaData, this);

                    if (pastePoint.X > 0 && pastePoint.Y > 0)
                    {
                        if (pastePointReference != null)
                        {
                            pastePoint   = pastePointReference.TranslatePoint(pastePoint, this.panel);
                            pastePoint.X = pastePoint.X < 0 ? 0 : pastePoint.X;
                            pastePoint.Y = pastePoint.Y < 0 ? 0 : pastePoint.Y;
                        }
                        this.UpdateLocationViewStatesByPoint(modelItemsPasted, pastePoint);
                    }
                    // If paste point is not available, paste the items to the top left corner.
                    else
                    {
                        this.UpdateLocationViewStatesToAvoidOverlap(modelItemsPasted);
                    }
                }

                this.Dispatcher.BeginInvoke(() =>
                {
                    if (modelItemsPasted.Count > 0 && modelItemsPasted[0] != null)
                    {
                        Keyboard.Focus(modelItemsPasted[0].View as IInputElement);
                    }
                    this.Context.Items.SetValue(new Selection(modelItemsPasted));
                },
                                            DispatcherPriority.ApplicationIdle
                                            );
            }
        }
        void LoadContextMenu(UIElement sender, bool openedByKeyboard)
        {
            if (this.ContextMenu == null)
            {
                return;
            }

            if (!Selection.MultipleObjectsSelected(this.Context) && sender != null && CommandMenuMode.Equals(CommandMenuMode.NoCommandMenu, GetCommandMenuMode(sender)))
            {
                return;
            }

            //clear context menu state
            this.UnloadContextMenu(this.ContextMenu);

            this.contextMenuTarget = sender as WorkflowViewElement;

            //because of WPF caching behaviour, i have to create new instance of context menu each time it is shown
            ContextMenu newMenu = new ContextMenu() { ItemContainerStyleSelector = new ContextMenuItemStyleSelector(this) };
            newMenu.Loaded += this.OnWorkflowViewContextMenuLoaded;
            newMenu.Unloaded += this.OnWorkflowViewContextMenuClosed;
            foreach (var entry in this.ContextMenu.Items.OfType<Control>().Reverse())
            {
                this.ContextMenu.Items.Remove(entry);
                entry.Visibility = Visibility.Visible;
                newMenu.Items.Insert(0, entry);
            }
            this.ContextMenu = newMenu;

            if (!Selection.MultipleObjectsSelected(this.Context))
            {
                if (null != this.contextMenuTarget && null != this.contextMenuTarget.ContextMenu)
                {
                    var items = this.contextMenuTarget.ContextMenu.Items.OfType<Control>().Reverse();
                    int insertIndex = this.ContextMenu.Items.Count;

                    foreach (var item in items)
                    {
                        this.contextMenuTarget.ContextMenu.Items.Remove(item);
                        DesignerView.SetMenuItemOrigin(item, this.contextMenuTarget);
                        this.ContextMenu.Items.Insert(insertIndex, item);
                    }
                }

                Fx.Assert(this.contextMenuTarget.IsVisible, string.Format(CultureInfo.InvariantCulture, "ContextMenuTarget {0} is not visible", this.contextMenuTarget.GetType()));
                this.ContextMenu.Placement = openedByKeyboard ? PlacementMode.Relative : PlacementMode.MousePoint;
                this.ContextMenu.PlacementTarget = this.contextMenuTarget;
            }
            else
            {
                this.ContextMenu.Placement = openedByKeyboard ? PlacementMode.Center : PlacementMode.MousePoint;
                this.ContextMenu.PlacementTarget = this;
            }

            this.ContextMenu.IsOpen = true;
        }
 public void UnregisterViewElement(WorkflowViewElement view)
 {
     if (this.views.Contains(view))
     {
         this.views.Remove(view);
     }
 }
示例#37
0
        // referenceTransitionModelItem is used when a connector is re-linked.
        void CreateTransition(ConnectionPoint sourceConnPoint, ConnectionPoint destConnPoint, ModelItem referenceTransitionModelItem, bool isSourceMoved)
        {
            Debug.Assert(this.IsOutmostStateContainerEditor(), "Should only be called by the outmost editor.");

            WorkflowViewElement srcDesigner  = sourceConnPoint.ParentDesigner as WorkflowViewElement;
            WorkflowViewElement destDesigner = destConnPoint.ParentDesigner as WorkflowViewElement;

            Debug.Assert(srcDesigner is StateDesigner && destDesigner is StateDesigner, "The source and destination designers should both be StateDesigner");

            ModelItem srcModelItem        = srcDesigner.ModelItem;
            ModelItem destModelItem       = destDesigner.ModelItem;
            ModelItem transitionModelItem = null;

            // We are moving the connector.
            if (referenceTransitionModelItem != null && referenceTransitionModelItem.ItemType == typeof(Transition))
            {
                transitionModelItem = referenceTransitionModelItem;
                // We are moving the start of the connector. We only preserve the trigger if it is not shared.
                if (isSourceMoved)
                {
                    Transition referenceTransition = referenceTransitionModelItem.GetCurrentValue() as Transition;
                    ModelItem  stateModelItem      = GetParentStateModelItemForTransition(referenceTransitionModelItem);
                    State      state           = stateModelItem.GetCurrentValue() as State;
                    bool       isTriggerShared = false;
                    foreach (Transition transition in state.Transitions)
                    {
                        if (transition != referenceTransition && transition.Trigger == referenceTransition.Trigger)
                        {
                            isTriggerShared = true;
                            break;
                        }
                    }
                    if (isTriggerShared)
                    {
                        transitionModelItem.Properties[TransitionDesigner.TriggerPropertyName].SetValue(null);
                    }
                }
                transitionModelItem.Properties[TransitionDesigner.ToPropertyName].SetValue(destModelItem);
                srcModelItem.Properties[StateDesigner.TransitionsPropertyName].Collection.Add(transitionModelItem);
            }
            // We are creating a new connector.
            else
            {
                Transition newTransition = new Transition()
                {
                    DisplayName = string.Empty
                };
                newTransition.To = destModelItem.GetCurrentValue() as State;
                // Assign the shared trigger.
                if (sourceConnPoint.AttachedConnectors.Count > 0)
                {
                    Connector  connector          = sourceConnPoint.AttachedConnectors[0];
                    Transition existingTransition = StateContainerEditor.GetConnectorModelItem(connector).GetCurrentValue() as Transition;
                    newTransition.Trigger = existingTransition.Trigger;
                }
                transitionModelItem = srcModelItem.Properties[StateDesigner.TransitionsPropertyName].Collection.Add(newTransition);
            }
            if (transitionModelItem != null)
            {
                PointCollection connectorViewState = new PointCollection(ConnectorRouter.Route(this.panel, sourceConnPoint, destConnPoint));
                this.StoreConnectorLocationViewState(transitionModelItem, connectorViewState, true);
            }
        }
示例#38
0
 void StoreShapeLocationViewState(WorkflowViewElement view, Point newLocation)
 {
     StoreShapeLocationViewState(view.ModelItem, newLocation);
 }
示例#39
0
 internal AnnotationManager(WorkflowViewElement workflowViewElement)
 {
     this.workflowViewElement = workflowViewElement;
 }