Esempio n. 1
0
            protected override string GetItemStatusCore()
            {
                if (!LocalAppContextSwitches.UseLegacyAccessibilityFeatures2)
                {
                    return(String.Empty);
                }
                UIElement sourceDesigner      = VirtualizedContainerService.TryGetVirtualizedElement(FreeFormPanel.GetSourceConnectionPoint(this.Owner).ParentDesigner);
                string    sourceId            = sourceDesigner.GetValue(AutomationProperties.ItemStatusProperty) as string;
                UIElement destinationDesigner = VirtualizedContainerService.TryGetVirtualizedElement(FreeFormPanel.GetDestinationConnectionPoint(this.Owner).ParentDesigner);
                string    destinationId       = destinationDesigner.GetValue(AutomationProperties.ItemStatusProperty) as string;

                return(string.Format(CultureInfo.InvariantCulture, "Source={0} Destination={1} Points={2}", sourceId, destinationId, ((Connector)this.Owner).Points));
            }
Esempio n. 2
0
 void PopulateContent()
 {
     if (this.Item != null)
     {
         VirtualizedContainerService containerService = this.Context.Services.GetService <VirtualizedContainerService>();
         UIElement itemView = containerService.GetContainer(this.Item, this);
         this.contentGrid.Children.Clear();
         this.contentGrid.Children.Add(itemView);
     }
     else
     {
         contentGrid.Children.Clear();
         contentGrid.Children.Add(text);
     }
 }
        void PopulateContent()
        {
            this.panel.Items.Clear();

            if (this.Items != null)
            {
                // index 0 is header.
                ContentControl header = new ContentControl();
                header.Focusable       = false;
                header.ContentTemplate = this.HeaderTemplate;
                header.SetValue(IndexProperty, 0);
                header.Drop += new DragEventHandler(OnSpacerDrop);
                this.panel.Items.Add(header);

                // index 1 is first spacer
                FrameworkElement startSpacer = CreateSpacer();
                this.panel.Items.Add(startSpacer);

                foreach (ModelItem item in this.Items)
                {
                    // index 2 + i*2 is itemView i
                    VirtualizedContainerService containerService = this.Context.Services.GetService <VirtualizedContainerService>();
                    UIElement itemView = containerService.GetContainer(item, this);
                    this.panel.Items.Add(itemView as UIElement);
                    // index 2 + i*2 + 1 is spacer i+1
                    FrameworkElement spacer = CreateSpacer();
                    this.panel.Items.Add(spacer);
                }
                // index 2 + count*2 is footer
                ContentControl footer = new ContentControl();
                footer.ContentTemplate  = this.FooterTemplate;
                footer.Focusable        = true;
                footer.IsHitTestVisible = true;
                footer.IsTabStop        = true;
                footer.SetValue(IndexProperty, addAtEndMarker);
                footer.Drop      += new DragEventHandler(OnSpacerDrop);
                footer.LostFocus += new RoutedEventHandler(OnSpacerLostFocus);
                footer.GotFocus  += new RoutedEventHandler(OnSpacerGotFocus);
                this.panel.Items.Add(footer);
                footer.Focusable = false;
            }
            UpdateHintTextVisibility(HintText);
        }
        void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            // if this.Items is null, and we are getting a collection changed that
            // means this event some how happened before this can get the unloaded event
            // and unsubscribe from this event.
            if (this.Items == null)
            {
                return;
            }
            bool fullRepopulateNeeded = true;

            // when one item is dropped into this items presenter focus on the new view element for it.
            if (e.Action == NotifyCollectionChangedAction.Add &&
                e.NewItems != null &&
                e.NewItems.Count == 1)
            {
                // insert itemview and spacer
                fullRepopulateNeeded = false;
                int itemViewIndex = GetViewIndexForItem(e.NewStartingIndex);
                VirtualizedContainerService containerService = this.Context.Services.GetService <VirtualizedContainerService>();
                UIElement itemView = containerService.GetContainer((ModelItem)e.NewItems[0], this);
                this.panel.Items.Insert(itemViewIndex, itemView as UIElement);
                // index 2 + i*2 + 1 is spacer i+1
                FrameworkElement spacer = CreateSpacer();
                this.panel.Items.Insert(itemViewIndex + 1, spacer);


                ModelItem insertedItem = (ModelItem)e.NewItems[0];
                this.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, (Action)(() =>
                {
                    UIElement view = (UIElement)insertedItem.View;
                    if (view != null)
                    {
                        Keyboard.Focus(view);
                    }
                }));
            }

            else if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                if (e.OldItems != null && e.OldItems.Count == 1)
                {
                    fullRepopulateNeeded = false;
                    int itemViewIndex = GetViewIndexForItem(e.OldStartingIndex);
                    this.panel.Items.RemoveAt(itemViewIndex);
                    //remove spacer also
                    this.panel.Items.RemoveAt(itemViewIndex);
                }

                if (this.Items.Count == 0)
                {
                    fullRepopulateNeeded = true;
                }

                // deselect removed items
                if (this.Context != null)
                {
                    IList <ModelItem> selectedItems = this.Context.Items.GetValue <Selection>().SelectedObjects.ToList();
                    foreach (ModelItem selectedAndRemovedItem in selectedItems.Intersect(e.OldItems.Cast <ModelItem>()))
                    {
                        Selection.Toggle(this.Context, selectedAndRemovedItem);
                    }
                }
            }
            if (this.Items.Count > 0)
            {
                this.hintTextGrid.Visibility = Visibility.Collapsed;
            }
            else
            {
                this.hintTextGrid.Visibility = Visibility.Visible;
            }

            if (fullRepopulateNeeded)
            {
                PopulateContent();
            }
        }
        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
                                        );
        }