*/}}
Procházet zdrojové kódy

Prevent undo while reading files

YimingWu před 1 týdnem
rodič
revize
9663dbe546
1 změnil soubory, kde provedl 13 přidání a 9 odebrání
  1. 13 9
      la_data.c

+ 13 - 9
la_data.c

@@ -772,7 +772,7 @@ laProp* laPropContainerManageable(laPropContainer* pc, int offset_of_dummy_list)
         laAddSubGroup(MAIN.SaverDummyContainer, "__file", "File", "The file this block came from/saves to", "managed_udf",
             0,LA_WIDGET_COLLECTION_SELECTOR,laui_ManagedUDFItem,-1,laget_InstanceUDF,laget_InstanceActiveUDF,laget_ListNext,laset_InstanceUDF,0,0,0,LA_UDF_REFER|LA_UDF_IGNORE);
     }
-    pc->SaverDummy=laAddSubGroup(pc,"__single_saver_dummy","Saver","Saver dummy","la_saver_dummy",0,0,0,-1,0,0,0,0,0,0,offset_of_dummy_list,0);
+    pc->SaverDummy=laAddSubGroup(pc,"__single_saver_dummy","Saver","Saver dummy","la_saver_dummy",0,0,0,-1,0,0,0,0,0,0,offset_of_dummy_list,LA_UDF_IGNORE);
     return pc->SaverDummy;
 }
 
@@ -4127,14 +4127,15 @@ void la_ClearUDFRegistryAndFolders(){
 
 //==========================================================================[undo]
 
-void laPushDifferenceOnly(char* Description, u64bit hint){
+void laPushDifferenceOnly(char* Description, u64bit hint){ if(MAIN.IsReadingUDF){ return; }
     laDiff* d=memAcquire(sizeof(laDiff));
     lstAppendItem(&MAIN.Differences, d);
     if(MAIN.HeadDifference && Description) strSafeSet(&MAIN.HeadDifference->Description,Description);
     d->Hint=hint; MAIN.HeadDifference=d;
     laNotifyUsers("la.differences");
 }
-void laPushDifferences(char* Description, u64bit hint){
+void laPushDifferences(char* Description, u64bit hint){ if(MAIN.IsReadingUDF){ return; }
+    if(MAIN.HeadDifference && (!MAIN.HeadDifference->Commands.pFirst) && (!MAIN.HeadDifference->CustomCommands.pFirst)) return;
     memFreeRemainingLeftNodes();
     laPushDifferenceOnly(Description,hint);
 }
@@ -4799,6 +4800,9 @@ laDBProp* laFindStartingDBProp(laProp* p, void* Instance, laPropContainer* Insta
     if(!MAIN.DBInstLink){ return 0; }
     laListHandle* l=hsh65536DoHashLongPtr(MAIN.DBInstLink, Instance); if(!l) return 0;
     for(laListItem* li=l->pFirst;li;li=li->pNext){
+        // TODO: `dbi->pc==InstancePC` does not handle `something.single_self` type of prop path well, because single_self will be
+        // recorded as child PC initially and `laRecordDifferences` won't work. However `laRecordInstanceDifferences will work.
+        // This means programs like Our Paint should also manually push canvas self instance in pusheverything().
         laDBInst* dbi=(laDBInst*)(((char*)li)-sizeof(laListItem)); if(dbi->OriginalInstance==Instance && dbi->pc==InstancePC){
             if(p){ for(laDBProp*dbp=dbi->Props.pFirst;dbp;dbp=dbp->Item.pNext){ if(dbp->p == p){ *r_DBInst=dbi; return dbp; } } }
             else{ *r_DBInst=dbi; return 0; }
@@ -4806,12 +4810,12 @@ laDBProp* laFindStartingDBProp(laProp* p, void* Instance, laPropContainer* Insta
     }
     return 0;
 }
-void laRecordCustomDifferences(void* Data, laDiffCommandUndoF Undo, laDiffCommandRedoF Redo, laDiffCommandFreeF Free){
+void laRecordCustomDifferences(void* Data, laDiffCommandUndoF Undo, laDiffCommandRedoF Redo, laDiffCommandFreeF Free){ if(MAIN.IsReadingUDF){ return 0; }
     laDiffCommandCustom* dcc=memAcquire(sizeof(laDiffCommandCustom));
     dcc->Data=Data; dcc->Undo=Undo; dcc->Redo=Redo; dcc->Free=Free;
     lstAppendItem(&MAIN.HeadDifference->CustomCommands,dcc);
 }
-int laRecordDifferences(laPropPack* base, char* path){
+int laRecordDifferences(laPropPack* base, char* path){ if(MAIN.IsReadingUDF){ return 0; }
     laPropPack PP={0};
     if(!la_GetPropFromPath(&PP,base,path,0)) return 0;
     la_StepPropPack(&PP);
@@ -4832,7 +4836,7 @@ int laRecordDifferences(laPropPack* base, char* path){
     la_FreePropStepCache(PP.Go);
     return success;
 }
-int laRecordInstanceDifferences(void* instance, const char* container){
+int laRecordInstanceDifferences(void* instance, const char* container){ if(MAIN.IsReadingUDF){ return 0; }
     laPropContainer* pc=la_ContainerLookup(container);
     if(!pc){ logPrintNew("Undo warning: No container named \"%s\"\n",container); return 0; }
     laDBInst* FromDBI=0;
@@ -4851,17 +4855,17 @@ int laRecordInstanceDifferences(void* instance, const char* container){
 
     return success;
 }
-void laRecordAndPush(laPropPack* base, char* path, char* description, uint64_t hint){
+void laRecordAndPush(laPropPack* base, char* path, char* description, uint64_t hint){ if(MAIN.IsReadingUDF){ return; }
     if(laRecordDifferences(base, path)){ laPushDifferences(description, hint); }
 }
-void laRecordAndPushProp(laPropPack* base, char* path){
+void laRecordAndPushProp(laPropPack* base, char* path){ if(MAIN.IsReadingUDF){ return; }
     char buf[256]={0};
     if(laRecordDifferences(base, path)){
         la_GetPropPackFullPath(base,&buf[strlen(buf)]);if(path){sprintf(&buf[strlen(buf)],"%s%s",base?".":"",path);}
         laPushDifferences(buf, 0);
     }
 }
-void laRecordEverythingAndPush(){
+void laRecordEverythingAndPush(){ if(MAIN.IsReadingUDF){ return; }
     for(laDBRecordedProp* rp=MAIN.DBRecordedProps.pFirst;rp;rp=rp->Item.pNext){
         laRecordAndPushProp(0, rp->OriginalPath->Ptr);
     }