Two reported issues with undo #1667 and #1168
authorTon Roosendaal <ton@blender.org>
Tue, 19 Oct 2004 16:57:01 +0000 (16:57 +0000)
committerTon Roosendaal <ton@blender.org>
Tue, 19 Oct 2004 16:57:01 +0000 (16:57 +0000)
- press TAB without object active cleared undo stack
- typo (another!) in variable name, causing undo stack from wrong object
  to be used (when have edited more objects)

Plus i found:
- rule for preserving editmode undo stacks, while using global undo, made
  stricter now. Before it only checked name, now it checks for existance
  of pointers extra.

source/blender/src/editmode_undo.c
source/blender/src/toets.c

index a89e7d0078a54cf6070072586e69d29c0afb0504..1715b7382f747039a4bbafbca57c49be647f011f 100644 (file)
 
 #include "BKE_displist.h"
 #include "BKE_global.h"
+#include "BKE_object.h"
 
 #include "BLI_blenlib.h"
-#include "BLI_arithb.h"
-#include "BLI_editVert.h"
 #include "BLI_dynstr.h"
 
 #include "BKE_utildefines.h"
@@ -99,7 +98,8 @@ void undo_editmode_menu(void)                         // history menu
 #define MAXUNDONAME    64
 typedef struct UndoElem {
        struct UndoElem *next, *prev;
-       ID id;          // copy of editmode object ID
+       ID id;                  // copy of editmode object ID
+       Object *ob;             // pointer to edited object
        void *undodata;
        char name[MAXUNDONAME];
        void (*freedata)(void *);
@@ -182,16 +182,31 @@ void undo_editmode_push(char *name, void (*freedata)(void *),
 static void undo_clean_stack(void)
 {
        UndoElem *uel, *next;
-       int mixed= 0;
+       int mixed= 0, checknames= 1;
+       
+       /* global undo changes pointers, so we also exceptionally allow identical names,
+          but not when this object pointer exists in the stack, which happens for
+          example when you rename objects and add new one with old name */
+       for(uel= undobase.first; uel; uel= uel->next) {
+               if( exist_object(uel->ob)) break;
+       }
+       if(uel) checknames= 0;
        
        uel= undobase.first; 
        while(uel) {
                next= uel->next;
-               if(strcmp(curundo->id.name, G.obedit->id.name)!=0) {
-                       mixed= 1;
-                       BLI_remlink(&undobase, uel);
-                       uel->freedata(uel->undodata);
-                       MEM_freeN(uel);
+               if(uel->ob != G.obedit) {
+                       
+                       /* for when global undo changes pointers... */
+                       if(checknames && strcmp(uel->id.name, G.obedit->id.name)==0) {
+                               uel->ob= G.obedit;
+                       }
+                       else {
+                               mixed= 1;
+                               BLI_remlink(&undobase, uel);
+                               uel->freedata(uel->undodata);
+                               MEM_freeN(uel);
+                       }
                }
                uel= next;
        }
index 149c3d6d21d8a7b2b44dd5caeb0fffdf1c9630e4..32423501630b3169126295c17d5900fb6036452e 100644 (file)
@@ -745,9 +745,9 @@ int blenderqread(unsigned short event, short val)
                                        enter_meta();
                                else if(G.vd) {
                                        /* also when Alt-E */
-                                       if(G.obedit==0) {
+                                       if(G.obedit==NULL) {
                                                enter_editmode();
-                                               BIF_undo_push("Original");      // here, because all over code enter_editmode is abused
+                                               if(G.obedit) BIF_undo_push("Original"); // here, because all over code enter_editmode is abused
                                        }
                                        else
                                                exit_editmode(2); // freedata, and undo