// ----------------------------------------------------------------------
        void AddWrapInPackageIfAppropriate(ref iCS_MenuContext[] menu, iCS_EditorObject obj)
        {
            // Don't add if object cannot support a parent package.
            if (!obj.CanHavePackageAsParent())
            {
                return;
            }
            if (menu == null || menu.Length == 0)
            {
                menu    = new iCS_MenuContext[1];
                menu[0] = new iCS_MenuContext(WrapInPackageStr);
                return;
            }
            int i = GrowMenuBy(ref menu, 2);

            menu[i]     = new iCS_MenuContext(SeparatorStr);
            menu[i + 1] = new iCS_MenuContext(WrapInPackageStr);
        }
예제 #2
0
        // -------------------------------------------------------------------------
        // Wraps the given object in a package
        public iCS_EditorObject WrapInPackage(iCS_EditorObject obj)
        {
            if (obj == null || !obj.CanHavePackageAsParent())
            {
                return(null);
            }
            var parent  = obj.ParentNode;
            var package = CreatePackage(parent.InstanceId, obj.DisplayName);

            ChangeParent(obj, package);
            // Attempt to reposition the package ports to match the object ports.
            obj.ForEachChildPort(
                p => {
                var sourcePort = p.ProducerPort;
                if (sourcePort != null && sourcePort.ParentNode == package)
                {
                    sourcePort.Edge = p.Edge;
                    sourcePort.PortPositionRatio = p.PortPositionRatio;
                }
                else
                {
                    package.UntilMatchingChild(
                        pp => {
                        if (pp.ProducerPort == p)
                        {
                            pp.Edge = p.Edge;
                            pp.PortPositionRatio = p.PortPositionRatio;
                            return(true);
                        }
                        return(false);
                    }
                        );
                }
            }
                );
            ForcedRelayoutOfTree();
            return(package);
        }
예제 #3
0
        // ======================================================================
        // Node Wrapping in package.
        // ----------------------------------------------------------------------
        public static iCS_EditorObject WrapInPackage(iCS_EditorObject obj)
        {
            if (obj == null || !obj.CanHavePackageAsParent())
            {
                return(null);
            }
            if (!IsCreationAllowed())
            {
                return(null);
            }
            var iStorage = obj.IStorage;

            OpenTransaction(iStorage);
            iCS_EditorObject package = null;

            try {
                iStorage.AnimateGraph(null,
                                      _ => {
                    package = iStorage.WrapInPackage(obj);
                    iStorage.ForcedRelayoutOfTree();
                }
                                      );
            }
            catch (System.Exception) {
                CancelTransaction(iStorage);
                return(null);
            }
            if (package == null)
            {
                CancelTransaction(iStorage);
                return(null);
            }
            CloseTransaction(iStorage, "Wrap : " + obj.DisplayName);
            SystemEvents.AnnounceVisualScriptElementAdded(package);
            return(package);
        }