Beispiel #1
0
        public override void Cancel()
        {
            if (s_subContextBegan)
            {
                s_subContextBegan = false;
                MasterContext.Cancel();
                return;
            }

            if (IsMasterContext)
            {
                foreach (GameContext subContext in m_gameDocumentRegistry.SubDocuments.AsIEnumerable <GameContext>())
                {
                    subContext.Cancel();
                }
            }
            if (!InTransaction)
            {
                base.Undo();
            }
            base.Cancel();
            if (m_savedSelection != null)
            {
                MasterContext.SetRange(m_savedSelection);
                m_savedSelection = null;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Inserts the specified child into the specified parent</summary>
        /// <param name="parent">Parent to insert into</param>
        /// <param name="child">Child to be inserted</param>
        /// <remarks>This method is used by copy-paste and drag-drop from various sources.
        /// When making any changes to this method, please test the following:
        /// - Copy/Paste, Cut/Paste
        /// - Drag-drop from {Palette|ResourceLister} to {ProjectLister|DesignView}
        /// Pay special attention to:
        /// - (GameObjects with) GameObjectReferences
        /// - (GameObjects with) ResourceReferences incl. Locators
        /// - GameObjectGroups (and hierarchies thereof)
        /// - GameObjectFolders (and hierarchies thereof)
        /// - Pasting the same objects more than once</remarks>
        public void Insert(object parent, object child)
        {
            if (!CanInsert(parent, child))
            {
                return;
            }

            var hierarchical = parent.AsAll <IHierarchical>();

            // Extract node list from IDataObject
            IEnumerable <object> items = Util.ConvertData(child, true);

            DomNode parentRoot = null;
            DomNode parentNode = parent.As <DomNode>();

            if (parentNode != null)
            {
                parentRoot = parentNode.GetRoot();
            }

            List <DomNode> copyList   = new List <DomNode>();
            List <object>  objectlist = new List <object>();

            foreach (object item in items)
            {
                if (item.Is <IGameObject>() || item.Is <IGameObjectFolder>())
                {
                    DomNode childNode = item.As <DomNode>();
                    DomNode childRoot = childNode.GetRoot();

                    if ((parentRoot != null && childRoot.Is <IGame>() && parentRoot != childRoot))
                    {
                        childNode.RemoveFromParent();
                        copyList.Add(childNode);
                        continue;
                    }
                }
                objectlist.Add(item);
            }

            if (copyList.Count > 0)
            {
                IEnumerable <DomNode> copies = DomNode.Copy(copyList);
                // remvoe lock
                foreach (DomNode copy in copies)
                {
                    this.SetLocked(copy, false);
                }
                objectlist.AddRange(copies);
            }

            foreach (object obj in objectlist)
            {
                DomNode node = obj.As <DomNode>();
                if (node != null)
                {
                    node.InitializeExtensions();
                }
            }

            List <DomNode> insertedNodes = new List <DomNode>();

            foreach (object obj in objectlist)
            {
                object insertedObj = null;

                bool inserted = false;
                foreach (var h in hierarchical)
                {
                    if (h.AddChild(obj))
                    {
                        inserted = true;
                        break;
                    }
                }

                if (inserted)
                {
                    insertedObj = obj;
                }
                else
                {
                    IResource res = obj as IResource;
                    var       gob = m_resourceConverterService.Convert(res);
                    foreach (var h in hierarchical)
                    {
                        if (h.AddChild(gob))
                        {
                            inserted = true;
                            break;
                        }
                    }
                    if (inserted)
                    {
                        insertedObj = gob;
                    }
                }
                DomNode insertNode = Adapters.As <DomNode>(insertedObj);
                if (insertNode != null)
                {
                    insertedNodes.Add(insertNode);
                }
            }

            IEnumerable <DomNode> rootDomNodes = DomNode.GetRoots(insertedNodes);
            List <object>         newSelection = new List <object>();

            foreach (DomNode rootNode in rootDomNodes)
            {
                AdaptablePath <object> path = Util.AdaptDomPath(rootNode);

                if (path.First.Is <IGame>() && (rootNode.Is <IGameObject>() || rootNode.Is <IGameObjectFolder>()))
                {
                    newSelection.Add(path);
                }
            }
            if (newSelection.Count > 0)
            {
                if (InTransaction)
                {
                    m_savedSelection = new List <object>(MasterContext.Selection);
                }

                MasterContext.SetRange(newSelection);
            }
        }