Example #1
0
        // ======================================================================
        // Object destruction.
        // ----------------------------------------------------------------------
        public static bool DeleteObject(iCS_EditorObject obj)
        {
#if SHOW_DEBUG
            Debug.Log("iCanScript: Deleting => " + obj.DisplayName);
#endif
            if (obj == null)
            {
                return(false);
            }
            if (!IsDeletionAllowed())
            {
                return(false);
            }
            if (!obj.CanBeDeleted())
            {
                ShowNotification("Port cannot be deleted=> " + obj.FullName);
                return(false);
            }
            var name     = obj.DisplayName;
            var iStorage = obj.IStorage;
            OpenTransaction(iStorage);
            if (obj.IsInstanceNodePort)
            {
                try {
                    iStorage.AnimateGraph(null,
                                          _ => {
                        iStorage.SelectedObject = obj.ParentNode;
                        SystemEvents.AnnounceVisualScriptElementWillBeRemoved(obj);
                        iStorage.PropertiesWizardDestroyAllObjectsAssociatedWithPort(obj);
                        iStorage.ForcedRelayoutOfTree();
                    }
                                          );
                }
                catch (System.Exception) {
                    CancelTransaction(iStorage);
                    return(false);
                }
                CloseTransaction(iStorage, "Delete " + name);
                return(true);
            }
            // TODO: Should animate parent node on node delete.
            try {
                iStorage.AnimateGraph(null,
                                      _ => {
                    // Move the selection to the parent node
                    var parent = obj.ParentNode;
                    iStorage.SelectedObject = parent;
                    SystemEvents.AnnounceVisualScriptElementWillBeRemoved(obj);
                    iStorage.DestroyInstance(obj.InstanceId);
                    iStorage.ForcedRelayoutOfTree();
                }
                                      );
            }
            catch (System.Exception) {
                CancelTransaction(iStorage);
                return(false);
            }
            CloseTransaction(iStorage, "Delete " + name);
            return(true);
        }
 // ----------------------------------------------------------------------
 void SelectedPortMenu(iCS_EditorObject port, iCS_IStorage storage)
 {
     iCS_MenuContext[] menu = new iCS_MenuContext[1];
     menu[0] = new iCS_MenuContext(ShowHierarchyStr);
     // Allow to delete a port if its parent is a module.
     if (port.CanBeDeleted())
     {
         AddDeleteMenuItem(ref menu);
     }
     ShowMenu(menu, port, storage);
 }