Esempio n. 1
0
        public void DeleteElement(BaseElement el)
        {
            if ((el == null) || (el is ConnectorElement)) return;
            //Delete link
            if (el is BaseLinkElement)
            {
                var lnk = (BaseLinkElement) el;
                DeleteLink(lnk);
                return;
            }

            //Delete node
            if (el is NodeElement)
            {
                var conn = ((NodeElement) el);
                foreach (var elconn in conn.Connectors)
                {
                    for (var i = elconn.Links.Count - 1; i>=0; i--)
                    {
                        var lnk = (BaseLinkElement) elconn.Links[i];
                        DeleteLink(lnk);
                    }
                }
                    
                if (SelectedNodes.Contains(el))
                    SelectedNodes.Remove(el);
            }

            if (SelectedElements.Contains(el))
                SelectedElements.Remove(el);

            Elements.Remove(el);
                
            OnAppearancePropertyChanged(new EventArgs());
        }
        private void OnTreeSelectionChanged(object sender, EventArgs e)
        {
            var info = _treeControl.SelectedItemInfo;

            if (info.Branch != null)
            {
                var options = 0;
                var selObj  = info.Branch.GetObject(info.Row, info.Column, TreeGridDesignerBranch.BrowsingObject, ref options);
                if (selObj != null)
                {
                    var willNotUpdateSelection = SelectedElements.Contains(selObj);

                    SetSelectedComponents(new[] { selObj });

                    // SetSelectedComponents will not fire selection events if the row has not changed
                    // the column might have changed so we keep/compare state in order to fire the event
                    if ((_previouslySelectedColumn == null || TreeControl.CurrentColumn != _previouslySelectedColumn) &&
                        willNotUpdateSelection)
                    {
                        OnSelectionChanged(EventArgs.Empty);
                    }

                    _previouslySelectedColumn = TreeControl.CurrentColumn;
                }
                else
                {
                    SetSelectedComponents(new object[] { });
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// 删除选中元素
 /// </summary>
 /// <param name="element"></param>
 private void SelectedElementRemove(UIElement element)
 {
     if (SelectedElements.Contains(element))
     {
         SelectedElements.Remove(element);
         ((IControlBase)element).SetUnFocus();
     }
 }
Esempio n. 4
0
 /// <summary>
 /// 添加选中元素
 /// </summary>
 /// <param name="element"></param>
 private void SelectedElementAdd(UIElement element)
 {
     if (!SelectedElements.Contains(element))
     {
         SelectedElements.Add(element);
         this.ReorderZindex();
         ((IControlBase)element).SetFocus();
     }
 }
Esempio n. 5
0
        public void SelectElements(Rectangle selectionRectangle)
        {
            SelectedElements.EnabledCalc = false;
            SelectedNodes.EnabledCalc    = false;

            // Add all "hitable" elements
            foreach (BaseElement element in Elements)
            {
                if (!(element is IControllable))
                {
                    continue;
                }
                var ctrl = ((IControllable)element).GetController();
                if (!ctrl.HitTest(selectionRectangle))
                {
                    continue;
                }
                if (!(element is ConnectorElement))
                {
                    SelectedElements.Add(element);
                }

                if (element is NodeElement)
                {
                    SelectedNodes.Add(element);
                }
            }

            //if the seleciont isn't a expecific link, remove links
            // without 2 elements in selection
            if (SelectedElements.Count > 1)
            {
                foreach (BaseElement el in Elements)
                {
                    var lnk = el as BaseLinkElement;
                    if (lnk == null)
                    {
                        continue;
                    }

                    if ((!SelectedElements.Contains(lnk.Connector1.ParentElement)) ||
                        (!SelectedElements.Contains(lnk.Connector2.ParentElement)))
                    {
                        SelectedElements.Remove(lnk);
                    }
                }
            }

            SelectedElements.EnabledCalc = true;
            SelectedNodes.EnabledCalc    = true;

            OnElementSelection(this, new ElementSelectionEventArgs(SelectedElements));
        }
Esempio n. 6
0
        private void HighlightOnlySelectedElements()
        {
            Cursor = Cursors.Arrow;

            FirstResizeVisual.IsVisible  = false;
            SecondResizeVisual.IsVisible = false;

            foreach (var element in HighlightBoxVisuals.Where(x => !SelectedElements.Contains(x.Key)).Select(x => x.Value))
            {
                element.Opacity = 0.0;
            }

            highlighted.Clear();
        }
Esempio n. 7
0
 public void DeleteLink(BaseLinkElement lnk, bool callHandler = true)
 {
     if (lnk == null) return;
     lnk.Connector1.RemoveLink(lnk);
     lnk.Connector2.RemoveLink(lnk);
                     
     if (Elements.Contains(lnk))
         Elements.Remove(lnk);
     if (SelectedElements.Contains(lnk))
         SelectedElements.Remove(lnk);
     if (callHandler)
         OnLinkRemoved(new ElementEventArgs(lnk));
     OnAppearancePropertyChanged(new EventArgs());
 }
Esempio n. 8
0
        private void InternalSelectedElements_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (SuppressNotificationsCounter > 0)
            {
                return;
            }

            try
            {
                SuppressNotifications();
                switch (e.Action)
                {
                case NotifyCollectionChangedAction.Add:
                case NotifyCollectionChangedAction.Remove:
                case NotifyCollectionChangedAction.Replace:
                    if (e.OldItems != null)
                    {
                        foreach (var item in e.OldItems.Cast <FieldExposer <T_Item> >())
                        {
                            if (SelectedElements.Contains(item.InnerItem))
                            {
                                SelectedElements.Remove(item.InnerItem);
                            }
                        }
                    }
                    if (e.NewItems != null)
                    {
                        foreach (var item in e.NewItems.Cast <FieldExposer <T_Item> >())
                        {
                            if (!SelectedElements.Contains(item.InnerItem))
                            {
                                SelectedElements.Add(item.InnerItem);
                            }
                        }
                    }
                    break;

                case NotifyCollectionChangedAction.Reset:
                    SelectedElements.Clear();
                    break;
                }
            }
            finally
            {
                AllowNotifications();
            }
        }
Esempio n. 9
0
        public void DeleteElement(BaseElement el)
        {
            if ((el != null) && !(el is ConnectorElement))
            {
                //Delete link
                if (el is BaseLinkElement)
                {
                    BaseLinkElement lnk = (BaseLinkElement)el;
                    DeleteLink(lnk);
                    return;
                }

                //Delete node
                if (el is NodeElement)
                {
                    NodeElement conn = ((NodeElement)el);
                    foreach (ConnectorElement elconn in conn.Connectors)
                    {
                        BaseLinkElement lnk;
                        for (int i = elconn.Links.Count - 1; i >= 0; i--)
                        {
                            lnk = (BaseLinkElement)elconn.Links[i];
                            DeleteLink(lnk);
                        }
                    }

                    if (selectedNodes.Contains(el))
                    {
                        selectedNodes.Remove(el);
                    }
                }

                if (SelectedElements.Contains(el))
                {
                    selectedElements.Remove(el);
                }

                elements.Remove(el);
                el.OnRemovedFromDocument(new DocumentEventArgs {
                    Document = this
                });
                OnAppearancePropertyChanged(new EventArgs());
            }
            el = null;
        }
Esempio n. 10
0
        public void DeleteLink(BaseLinkElement linkElement)
        {
            if (linkElement != null)
            {
                linkElement.Connector1.RemoveLink(linkElement);
                linkElement.Connector2.RemoveLink(linkElement);

                if (_elements.Contains(linkElement))
                {
                    _elements.Remove(linkElement);
                }
                if (SelectedElements.Contains(linkElement))
                {
                    SelectedElements.Remove(linkElement);
                }
                OnAppearancePropertyChanged(new EventArgs());
            }
        }
Esempio n. 11
0
        public void DeleteElement(BaseElement element)
        {
            if ((element != null) && !(element is ConnectorElement))
            {
                //Delete link
                if (element is BaseLinkElement)
                {
                    var linkElement = (BaseLinkElement)element;
                    DeleteLink(linkElement);
                    return;
                }

                //Delete node
                if (element is NodeElement)
                {
                    var conn = (NodeElement)element;
                    foreach (var connectorElement in conn.Connectors)
                    {
                        for (var i = connectorElement.Links.Count - 1; i >= 0; i--)
                        {
                            var linkElement = (BaseLinkElement)connectorElement.Links[i];
                            DeleteLink(linkElement);
                        }
                    }

                    if (SelectedNodes.Contains(element))
                    {
                        SelectedNodes.Remove(element);
                    }
                }

                if (SelectedElements.Contains(element))
                {
                    SelectedElements.Remove(element);
                }

                _elements.Remove(element);

                OnAppearancePropertyChanged(new EventArgs());
            }
        }