Esempio n. 1
0
        // ----------------------------------------------------------------------
        public static bool DeleteMultiSelectedObjects(iCS_IStorage iStorage)
        {
#if SHOW_DEBUG
            Debug.Log("iCanScript: Multi-Select Delete");
#endif
            if (iStorage == null)
            {
                return(false);
            }
            if (!IsDeletionAllowed())
            {
                return(false);
            }
            var selectedObjects = iStorage.GetMultiSelectedObjects();
            if (selectedObjects == null || selectedObjects.Length == 0)
            {
                return(false);
            }
            if (selectedObjects.Length == 1)
            {
                DeleteObject(selectedObjects[0]);
                return(true);
            }
            OpenTransaction(iStorage);
            try {
                iStorage.AnimateGraph(null,
                                      _ => {
                    foreach (var obj in selectedObjects)
                    {
                        if (!obj.CanBeDeleted())
                        {
                            ShowNotification("Fix port=> \"" + obj.DisplayName + "\" from node=> \"" + obj.ParentNode.FullName + "\" cannot be deleted.");
                            continue;
                        }
                        // Move the selection to the parent node
                        var parent = obj.ParentNode;
                        iStorage.SelectedObject = parent;

                        SystemEvents.AnnounceVisualScriptElementWillBeRemoved(obj);

                        if (obj.IsInstanceNodePort)
                        {
                            iStorage.PropertiesWizardDestroyAllObjectsAssociatedWithPort(obj);
                        }
                        else
                        {
                            iStorage.DestroyInstance(obj.InstanceId);
                        }
                        iStorage.ForcedRelayoutOfTree();
                    }
                }
                                      );
            }
            catch (System.Exception) {
                CancelTransaction(iStorage);
                return(false);
            }
            CloseTransaction(iStorage, "Delete Selection");
            return(true);
        }