/// <summary>
        /// Selects all enumerable objects in the given context</summary>
        /// <param name="selectionContext">Context holding selection</param>
        /// <param name="enumerableContext">Context holding enumeration of selectable objects</param>
        /// <returns>True iff all objects were selected</returns>
        public bool SelectAll(ISelectionContext selectionContext, IEnumerableContext enumerableContext)
        {
            if (selectionContext != null &&
                enumerableContext != null)
            {
                selectionContext.SetRange(enumerableContext.Items);
                return true;
            }

            return false;
        }
Esempio n. 2
0
        /// <summary>
        /// Selects all enumerable objects in the given context</summary>
        /// <param name="selectionContext">Context holding selection</param>
        /// <param name="enumerableContext">Context holding enumeration of selectable objects</param>
        /// <returns>True iff all objects were selected</returns>
        public bool SelectAll(ISelectionContext selectionContext, IEnumerableContext enumerableContext)
        {
            if (selectionContext != null &&
                enumerableContext != null)
            {
                selectionContext.SetRange(enumerableContext.Items);
                return(true);
            }

            return(false);
        }
Esempio n. 3
0
        private static void UngroupGroups(CircuitEditingContext circuitEditingContext, ISelectionContext selectionContext)
        {
            var graphContainer = circuitEditingContext.CircuitContainer;
            var newSelection   = new List <object>();

            foreach (var group in selectionContext.Selection.AsIEnumerable <Group>())
            {
                newSelection.AddRange(group.Elements);
                UngroupGroup(group, graphContainer);
            }
            selectionContext.SetRange(newSelection);
        }
Esempio n. 4
0
        protected virtual void HandlePick(MouseEventArgs e)
        {
            SelectMode        selectMode = InputScheme.GetSelectMode(Control.ModifierKeys);
            ISelectionContext selection  = DesignView.Context.As <ISelectionContext>();
            var  hits        = Pick(e);
            bool multiSelect = DragOverThreshold;

            if (multiSelect == false && hits.Any())
            {
                List <object> singleHit = new List <object>();
                if (selectMode == SelectMode.Normal)
                {
                    m_hitIndex++;
                    if (m_hitIndex >= hits.Count())
                    {
                        m_hitIndex = 0;
                    }
                    singleHit.Add(hits.ElementAt(m_hitIndex));
                }
                else
                {
                    singleHit.Add(hits.ElementAt(0));
                }
                hits = singleHit;
            }

            switch (selectMode)
            {
            case SelectMode.Normal:
                selection.SetRange(hits);
                break;

            case SelectMode.Extend:
                selection.AddRange(hits);
                break;

            case SelectMode.Toggle:
                selection.ToggleRange(hits);
                break;

            case SelectMode.Remove:
                selection.RemoveRange(hits);
                break;

            default:
                break;
            }
        }
Esempio n. 5
0
        private void SelectAllInstances(DomNodeType nodeType)
        {
            ISelectionContext sc = GetSelectionContext();

            if (sc != null)
            {
                List <object> nodes = new List <object>();
                foreach (DomNode node in Util.FindAll(nodeType, true))
                {
                    nodes.Add(Util.AdaptDomPath(node));
                }
                if (nodes.Count > 0)
                {
                    sc.SetRange(nodes);
                }
                else
                {
                    sc.Clear();
                }
            }
        }
Esempio n. 6
0
        private void SelectAllInstances()
        {
            DomNodeType domNodeType = SelectedNodeType;

            if (domNodeType == null)
            {
                return;
            }

            ISelectionContext selectionContext = SelectionContext;

            if (selectionContext == null)
            {
                return;
            }

            DomNode rootNode = GetRootNode(selectionContext);

            if (rootNode == null)
            {
                return;
            }


            selectionContext.Clear();
            List <Path <object> > newSelection = new List <Path <object> >();

            foreach (DomNode domNode in GetNodesOfType(rootNode, domNodeType))
            {
                newSelection.Add(Util.AdaptDomPath(domNode));
            }
            if (newSelection.Count > 0)
            {
                selectionContext.SetRange(newSelection);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Inverts the selection in the given context (deselect all selected, and select all deselected objects)</summary>
        /// <param name="selectionContext">Context holding selection</param>
        /// <param name="enumerableContext">Context holding enumeration of selectable objects</param>
        /// <returns>True iff selection was inverted</returns>
        public bool InvertSelection(ISelectionContext selectionContext, IEnumerableContext enumerableContext)
        {
            if (selectionContext != null &&
                enumerableContext != null)
            {
                HashSet <object> selected = new HashSet <object>(selectionContext.Selection);
                List <object>    inverted = new List <object>(enumerableContext.Items);
                for (int i = 0; i < inverted.Count;)
                {
                    if (selected.Contains(inverted[i]))
                    {
                        inverted.RemoveAt(i);
                    }
                    else
                    {
                        i++;
                    }
                }

                selectionContext.SetRange(inverted);
            }

            return(false);
        }
Esempio n. 8
0
            public ClonedPropertyEditor(PropertyEditor propEditor)
            {
                var editingContext = propEditor.PropertyGrid.PropertyGridView.EditingContext;

                // there is no reason to clone empty property editor.
                if (editingContext == null)
                {
                    throw new ArgumentException("propEditor");
                }

                // don't create cloned property editor
                // if there is nothing to edit
                if (editingContext.PropertyDescriptors == null || !editingContext.PropertyDescriptors.Any())
                {
                    return;
                }

                if (editingContext is SelectionPropertyEditingContext)
                {
                    m_context = ((SelectionPropertyEditingContext)editingContext).SelectionContext;
                }
                else
                {
                    m_context = editingContext;
                }


                m_propertyEditor = propEditor;
                m_propertyEditor.Configure(out m_propertyGrid, out m_controlInfo);


                m_selectionButton = new ToolStripButton();
                m_selectionButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
                m_selectionButton.Image        = ResourceUtil.GetImage16(Resources.SelectionFindImage);
                m_selectionButton.Name         = "selectionButton";
                m_selectionButton.Size         = new Size(29, 22);
                m_selectionButton.ToolTipText  = "Select bound object(s)".Localize();
                m_selectionButton.Click       += (sender, e) =>
                {
                    // select bound object
                    ISelectionContext selCntx = m_context.As <ISelectionContext>();
                    var edCntx = m_propertyGrid.PropertyGridView.EditingContext;
                    if (selCntx != null && edCntx != null)
                    {
                        selCntx.SetRange(edCntx.Items);
                    }
                };

                m_propertyGrid.ToolStrip.Items.Add(m_selectionButton);
                m_propertyGrid.PropertyGridView.ContextRegistry = propEditor.ContextRegistry;

                m_controlInfo.Name              = propEditor.m_controlInfo.DisplayName + "_" + ++s_cloneId;
                m_controlInfo.Group             = PropertyEditor.ClonedEditorGroup;
                m_controlInfo.UnregisterOnClose = true;
                m_propertyEditor.ControlHostService.RegisterControl(m_propertyGrid, m_controlInfo, this);

                m_propertyEditingContext = new CustomPropertyEditingContext(editingContext);
                m_propertyGrid.Bind(m_propertyEditingContext);

                m_propertyGrid.PropertySorting = propEditor.PropertyGrid.PropertySorting;

                // copy expansion state
                var zip = propEditor.PropertyGrid.PropertyGridView.Categories.Zip(m_propertyGrid.PropertyGridView.Categories, (src, dest) => new { src, dest });

                foreach (var pair in zip)
                {
                    if (pair.dest.Name == pair.src.Name)
                    {
                        pair.dest.Expanded = pair.src.Expanded;
                    }
                }

                m_propertyGrid.MouseUp += (sender, e) => OnPropertyGridMouseUp(e);

                // subscribe to events.
                // It is necessary to unsubscribe to allow this object to be garbage collected.

                if (m_propertyEditor.DocumentRegistry != null)
                {
                    m_propertyEditor.DocumentRegistry.DocumentRemoved       += DocumentRegistry_DocumentRemoved;
                    m_propertyEditor.DocumentRegistry.ActiveDocumentChanged += DocumentRegistry_ActiveDocumentChanged;
                }
                m_observableContext = m_context.As <IObservableContext>();
                m_validationContext = m_context.As <IValidationContext>();

                if (m_observableContext != null)
                {
                    m_observableContext.ItemChanged  += observableContext_ItemChanged;
                    m_observableContext.ItemInserted += observableContext_ItemInserted;
                    m_observableContext.ItemRemoved  += observableContext_ItemRemoved;
                }
                if (m_validationContext != null)
                {
                    m_validationContext.Beginning += validationContext_Beginning;
                    m_validationContext.Ended     += validationContext_Ended;
                    m_validationContext.Cancelled += validationContext_Cancelled;
                }
            }
        /// <summary>
        /// Inverts the selection in the given context (deselect all selected, and select all deselected objects)</summary>
        /// <param name="selectionContext">Context holding selection</param>
        /// <param name="enumerableContext">Context holding enumeration of selectable objects</param>
        /// <returns>True iff selection was inverted</returns>
        public bool InvertSelection(ISelectionContext selectionContext, IEnumerableContext enumerableContext)
        {
            if (selectionContext != null &&
                enumerableContext != null)
            {
                HashSet<object> selected = new HashSet<object>(selectionContext.Selection);
                List<object> inverted = new List<object>(enumerableContext.Items);
                for (int i = 0; i < inverted.Count; )
                {
                    if (selected.Contains(inverted[i]))
                        inverted.RemoveAt(i);
                    else
                        i++;
                }

                selectionContext.SetRange(inverted);
            }

            return false;
        }
Esempio n. 10
0
 private static void UngroupGroups(CircuitEditingContext circuitEditingContext, ISelectionContext selectionContext)
 {
     var graphContainer = circuitEditingContext.CircuitContainer;
     var newSelection = new List<object>();
     foreach (var group in selectionContext.Selection.AsIEnumerable<Group>())
     {
         newSelection.AddRange(group.Elements);
         UngroupGroup(group, graphContainer);
     }
     selectionContext.SetRange(newSelection);
 }
Esempio n. 11
0
        public ManipulatorActiveOperation(
            string name, ISelectionContext selectionContext,
            FilterDelegate filter,
            bool duplicate)
        {
            TransactionContextList = new List <ITransactionContext>();
            NodeList      = new List <ITransformable>();
            IsDuplicating = duplicate;

            var selection = selectionContext.Selection;
            IEnumerable <DomNode> rootDomNodes = DomNode.GetRoots(selection.AsIEnumerable <DomNode>());

            SetupTransactionContexts(rootDomNodes);

            if (duplicate)
            {
                List <DomNode> originals = new List <DomNode>();
                foreach (DomNode node in rootDomNodes)
                {
                    ITransformable transformable = node.As <ITransformable>();
                    if (!CanManipulate(transformable, filter))
                    {
                        continue;
                    }

                    originals.Add(node);
                }

                if (originals.Count > 0)
                {
                    DomNode[] copies = DomNode.Copy(originals);

                    foreach (var t in TransactionContextList)
                    {
                        t.Begin(("Copy And" + name).Localize());
                    }

                    List <object> newSelection = new List <object>();
                    // re-parent copy
                    for (int i = 0; i < copies.Length; i++)
                    {
                        DomNode copy     = copies[i];
                        DomNode original = originals[i];

                        ChildInfo chInfo = original.ChildInfo;
                        if (chInfo.IsList)
                        {
                            original.Parent.GetChildList(chInfo).Add(copy);
                        }
                        else
                        {
                            original.Parent.SetChild(chInfo, copy);
                        }

                        newSelection.Add(Util.AdaptDomPath(copy));
                        copy.InitializeExtensions();
                    }

                    selectionContext.SetRange(newSelection);
                    NodeList.AddRange(copies.AsIEnumerable <ITransformable>());
                }
            }
            else
            {
                foreach (DomNode node in rootDomNodes)
                {
                    ITransformable transformable = node.As <ITransformable>();
                    if (!CanManipulate(transformable, filter))
                    {
                        continue;
                    }
                    NodeList.Add(transformable);
                }

                if (NodeList.Count > 0)
                {
                    foreach (var t in TransactionContextList)
                    {
                        t.Begin(name.Localize());
                    }
                }
            }

            for (int k = 0; k < NodeList.Count; k++)
            {
                IManipulatorNotify notifier = NodeList[k].As <IManipulatorNotify>();
                if (notifier != null)
                {
                    notifier.OnBeginDrag();
                }
            }
        }
Esempio n. 12
0
        public ManipulatorActiveOperation(
            string name, ISelectionContext selectionContext,
            FilterDelegate filter,
            bool duplicate)
        {
            TransactionContextList = new List<ITransactionContext>();
            NodeList = new List<ITransformable>();
            IsDuplicating = duplicate;

            var selection = selectionContext.Selection;
            IEnumerable<DomNode> rootDomNodes = DomNode.GetRoots(selection.AsIEnumerable<DomNode>());

            SetupTransactionContexts(rootDomNodes);

            if (duplicate)
            {
                List<DomNode> originals = new List<DomNode>();
                foreach (DomNode node in rootDomNodes)
                {
                    ITransformable transformable = node.As<ITransformable>();
                    if (!CanManipulate(transformable, filter)) continue;

                    originals.Add(node);
                }

                if (originals.Count > 0)
                {
                    DomNode[] copies = DomNode.Copy(originals);

                    foreach (var t in TransactionContextList)
                        t.Begin(("Copy And" + name).Localize());

                    List<object> newSelection = new List<object>();
                    // re-parent copy
                    for (int i = 0; i < copies.Length; i++)
                    {
                        DomNode copy = copies[i];
                        DomNode original = originals[i];

                        ChildInfo chInfo = original.ChildInfo;
                        if (chInfo.IsList)
                            original.Parent.GetChildList(chInfo).Add(copy);
                        else
                            original.Parent.SetChild(chInfo, copy);

                        newSelection.Add(Util.AdaptDomPath(copy));
                        copy.InitializeExtensions();
                    }

                    selectionContext.SetRange(newSelection);
                    NodeList.AddRange(copies.AsIEnumerable<ITransformable>());
                }

            }
            else
            {
                foreach (DomNode node in rootDomNodes)
                {
                    ITransformable transformable = node.As<ITransformable>();
                    if (!CanManipulate(transformable, filter)) continue;
                    NodeList.Add(transformable);
                }

                if (NodeList.Count > 0)
                    foreach (var t in TransactionContextList)
                        t.Begin(name.Localize());
            }

            for (int k = 0; k < NodeList.Count; k++)
            {
                IManipulatorNotify notifier = NodeList[k].As<IManipulatorNotify>();
                if (notifier != null) notifier.OnBeginDrag();
            }
        }