Exemplo n.º 1
0
        /// <summary>
        /// Inserts the data object into the context</summary>
        /// <param name="insertingObject">Data to insert; e.g., System.Windows.Forms.IDataObject</param>
        public void Insert(object insertingObject)
        {
            IDataObject dataObject = (IDataObject)insertingObject;

            object[] items = dataObject.GetData(typeof(object[])) as object[];
            if (items == null)
            {
                return;
            }

            object[] itemCopies = DomNode.Copy(Adapters.AsIEnumerable <DomNode>(items));

            // create a new prototype
            DomNode   node      = new DomNode(PrototypeType);
            Prototype prototype = node.As <Prototype>();

            prototype.Name = "Prototype".Localize("Circuit prototype");
            foreach (Element module in Adapters.AsIEnumerable <Element>(itemCopies))
            {
                prototype.Modules.Add(module);
            }
            foreach (Wire connection in Adapters.AsIEnumerable <Wire>(itemCopies))
            {
                prototype.Connections.Add(connection);
            }

            PrototypeFolder folder = Adapters.As <PrototypeFolder>(m_activeItem);

            if (folder == null)
            {
                folder = PrototypeFolder;
            }

            folder.Prototypes.Add(prototype);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Obtains enumeration of the children of the given parent object</summary>
        /// <param name="parent">Parent object</param>
        /// <returns>Enumeration of children of the parent object</returns>
        IEnumerable <object> ITreeView.GetChildren(object parent)
        {
            PrototypeFolder folder = Adapters.As <PrototypeFolder>(parent);

            if (folder != null)
            {
                foreach (PrototypeFolder childFolder in folder.Folders)
                {
                    yield return(childFolder);
                }
                foreach (Prototype prototype in folder.Prototypes)
                {
                    yield return(prototype);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Sets the item's name</summary>
        /// <param name="item">Item to name</param>
        /// <param name="name">New item name</param>
        void INamingContext.SetName(object item, string name)
        {
            Prototype prototype = Adapters.As <Prototype>(item);

            if (prototype != null)
            {
                prototype.Name = name;
            }
            else
            {
                PrototypeFolder folder = Adapters.As <PrototypeFolder>(item);
                if (folder != null)
                {
                    folder.Name = name;
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the item's name in the context, or null if none</summary>
        /// <param name="item">Item</param>
        /// <returns>Item's name in the context, or null if none</returns>
        string INamingContext.GetName(object item)
        {
            Prototype prototype = Adapters.As <Prototype>(item);

            if (prototype != null)
            {
                return(prototype.Name);
            }

            PrototypeFolder folder = Adapters.As <PrototypeFolder>(item);

            if (folder != null)
            {
                return(folder.Name);
            }

            return(null);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Fills in or modifies the given display info for the item</summary>
        /// <param name="item">Item</param>
        /// <param name="info">Display info to update</param>
        public void GetInfo(object item, ItemInfo info)
        {
            PrototypeFolder category = Adapters.As <PrototypeFolder>(item);

            if (category != null)
            {
                info.Label = category.Name;
            }
            else
            {
                Prototype prototype = Adapters.As <Prototype>(item);
                if (prototype != null)
                {
                    info.Label = prototype.Name;
                    //info.ImageIndex = info.GetImageList().Images.IndexOfKey(Resources.AndImage); TOFIX
                    info.IsLeaf = true;
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets the IDataObject for the items being dragged from a prototype lister, for
        /// use in a drag-and-drop operation</summary>
        /// <param name="items">Objects being dragged</param>
        /// <returns>IDataObject representing the dragged items</returns>
        public IDataObject GetInstances(IEnumerable <object> items)
        {
            List <object> instances = new List <object>();

            foreach (object item in items)
            {
                Prototype prototype = Adapters.As <Prototype>(item);
                if (prototype != null)
                {
                    instances.AddRange(Adapters.AsIEnumerable <object>(prototype.Modules));
                    instances.AddRange(Adapters.AsIEnumerable <object>(prototype.Connections));
                    continue;
                }

                PrototypeFolder folder = Adapters.As <PrototypeFolder>(item);
                if (folder != null)
                {
                    instances.Add(folder);
                }
            }
            return(new DataObject(instances.ToArray()));
        }