*/}}
浏览代码

node fix and undo restriction

YimingWu 1 周之前
父节点
当前提交
d7526bc0ac
共有 3 个文件被更改,包括 12 次插入6 次删除
  1. 2 1
      la_data.c
  2. 1 0
      la_interface.h
  3. 9 5
      resources/la_nodes_basic.c

+ 2 - 1
la_data.c

@@ -4833,7 +4833,8 @@ int laRecordDifferences(laPropPack* base, char* path){
     return success;
 }
 int laRecordInstanceDifferences(void* instance, const char* container){
-    laPropContainer* pc=la_ContainerLookup(container); if(!pc) return 0;
+    laPropContainer* pc=la_ContainerLookup(container);
+    if(!pc){ logPrintNew("Undo warning: No container named \"%s\"\n",container); return 0; }
     laDBInst* FromDBI=0;
     laFindStartingDBProp(0,instance,pc,&FromDBI); if(!FromDBI) return 0;
     laPropPack PP={0}; laPropStep PS={0}; PS.UseInstance=instance; PP.LastPs=&PS; 

+ 1 - 0
la_interface.h

@@ -357,6 +357,7 @@ STRUCTURE(laInitArguments){
     int HasHalftoneOption;
     int GLDebug;
     int EnableLogStdOut;
+    int DisableUnsupportedUndo;
 };
 
 NEED_STRUCTURE(laAnimation);

+ 9 - 5
resources/la_nodes_basic.c

@@ -1018,7 +1018,7 @@ int OPINV_AddNodesRack(laOperator* a, laEvent *e){
 
 laBaseNode* la_CreateNode(laNodeRack* ir, laBaseNodeType* NodeType){
     laBaseNode* bn=memAcquire(NodeType->NodeSize);
-    bn->Type=NodeType; NodeType->Init(bn, 0); bn->InitDone=1; lstAppendItem(&ir->Nodes, bn); bn->InRack=ir;
+    bn->Type=NodeType; NodeType->Init(bn, 0); bn->InitDone=1; lstAppendItem(&ir->Nodes, bn); memAssignRef(bn,&bn->InRack,ir);
     laNotifyInstanceUsers(ir); laRecordInstanceDifferences(ir->ParentPage,"la_rack_page"); laPushDifferences("Add Node", 0);
     return bn;
 }
@@ -1068,6 +1068,10 @@ laNodeRack* la_NewRackAfter(laRackPage* parent,laNodeRack* rr){
     r->ParentPage=parent; r->RackType=parent->RackType;
     return r;
 }
+
+int OPCHK_MoveNodeToRack(laPropPack *This, laStringSplitor *Instructions){
+    return !MAIN.InitArgs.DisableUnsupportedUndo;
+}
 int OPINV_MoveNodeToRack(laOperator* a, laEvent *e){
     laBaseNode* n=a->This?a->This->EndInstance:0; if(!n||!n->InRack) return LA_CANCELED;
     laBaseNodeType* bnt=0; laNodeRack* target;
@@ -1078,9 +1082,9 @@ int OPINV_MoveNodeToRack(laOperator* a, laEvent *e){
     else{ target=n->InRack->Item.pNext; if(!target){ target=la_NewRackAfter(n->InRack->ParentPage,n->InRack->ParentPage->Racks.pLast); } }
     if(!target) return LA_CANCELED;
 
-    lstRemoveItem(&n->InRack->Nodes, n); lstAppendItem(&target->Nodes,n); n->InRack=target;
+    lstRemoveItem(&n->InRack->Nodes, n); lstAppendItem(&target->Nodes,n); memAssignRef(n,&n->InRack,target);
 
-    laNotifyInstanceUsers(n->InRack->ParentPage); laRecordInstanceDifferences(n->InRack->ParentPage,"la_node_page"); laPushDifferences("Move Node", 0);
+    laNotifyInstanceUsers(n->InRack->ParentPage); laRecordInstanceDifferences(n->InRack->ParentPage,"la_rack_page"); laPushDifferences("Move Node", 0);
 
     return LA_FINISHED;
 }
@@ -1215,7 +1219,7 @@ void la_RegisterBasicNodes(){
     laCreateOperatorType("LA_add_rack", "Add Rack", "Add a rack for nodes", 0,0,0,OPINV_AddNodesRack,0,'+',0);
     at=laCreateOperatorType("OPINV_AddNode", "Add Node", "Add a node to the rack",0,0,0,OPINV_AddNode,OPMOD_AddNode,'+',0);
     at->UiDefine=laui_AddNode;
-    laCreateOperatorType("LA_move_node_to_rack", "Move Node", "Move node to another rack",0,0,0,OPINV_MoveNodeToRack,0,0,0);
+    laCreateOperatorType("LA_move_node_to_rack", "Move Node", "Move node to another rack",OPCHK_MoveNodeToRack,0,0,OPINV_MoveNodeToRack,0,0,0);
     laCreateOperatorType("LA_delete_node", "Delete Node", "Delete this node",0,0,0,OPINV_DeleteNode,0,0,0);
     laCreateOperatorType("LA_move_rack", "Move Rack", "Move this rack",0,0,0,OPINV_MoveRack,0,0,0);
     laCreateOperatorType("LA_insert_rack", "Insert Rack", "Insert a new rack",0,0,0,OPINV_InsertRack,0,0,0);
@@ -1625,7 +1629,7 @@ laRackPage* laDuplicateRackPage(laRackPage* new_optional, laRackPage* from){
         nnr->ParentPage=nr; nnr->RackType=r->RackType;
         for(laBaseNode* n=r->Nodes.pFirst;n;n=n->Item.pNext){
             laBaseNode* nn=memAcquire(n->Type->NodeSize);
-            nn->Type=n->Type; nn->InitDone=1; lstAppendItem(&nnr->Nodes, nn); nn->InRack=nnr; n->Duplicated=nn;
+            nn->Type=n->Type; nn->InitDone=1; lstAppendItem(&nnr->Nodes, nn); memAssignRef(nn,&nn->InRack,nnr); n->Duplicated=nn;
             nn->Type->Init(nn, 0); nn->Type->Copy(nn,n,0);
         }
     }