~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/editors/util/undo.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
 
75
75
#include "util_intern.h"
76
76
 
77
 
#define MAXUNDONAME 64 /* XXX, make common define */
78
 
 
79
77
/* ***************** generic undo system ********************* */
80
78
 
81
79
void ED_undo_push(bContext *C, const char *str)
109
107
                PE_undo_push(CTX_data_scene(C), str);
110
108
        }
111
109
        else {
112
 
                if (U.uiflag & USER_GLOBALUNDO) 
113
 
                        BKE_write_undo(C, str);
 
110
                BKE_write_undo(C, str);
114
111
        }
115
112
        
116
113
        if (wm->file_saved) {
129
126
 
130
127
        /* undo during jobs are running can easily lead to freeing data using by jobs,
131
128
         * or they can just lead to freezing job in some other cases */
132
 
        if (WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C))) {
 
129
        if (WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C), WM_JOB_TYPE_ANY)) {
133
130
                return OPERATOR_CANCELLED;
134
131
        }
135
132
 
138
135
                return ED_undo_gpencil_step(C, step, undoname);
139
136
        }
140
137
 
141
 
        if (sa && sa->spacetype == SPACE_IMAGE) {
 
138
        if (sa && (sa->spacetype == SPACE_IMAGE)) {
142
139
                SpaceImage *sima = (SpaceImage *)sa->spacedata.first;
143
140
                
144
 
                if ((obact && obact->mode & OB_MODE_TEXTURE_PAINT) || sima->flag & SI_DRAWTOOL) {
 
141
                if ((obact && (obact->mode & OB_MODE_TEXTURE_PAINT)) || (sima->mode == SI_MODE_PAINT)) {
145
142
                        if (!ED_undo_paint_step(C, UNDO_PAINT_IMAGE, step, undoname) && undoname)
146
143
                                if (U.uiflag & USER_GLOBALUNDO)
147
144
                                        BKE_undo_name(C, undoname);
148
 
 
 
145
                        
149
146
                        WM_event_add_notifier(C, NC_WINDOW, NULL);
150
147
                        return OPERATOR_FINISHED;
151
148
                }
152
149
        }
153
150
 
154
 
        if (sa && sa->spacetype == SPACE_TEXT) {
 
151
        if (sa && (sa->spacetype == SPACE_TEXT)) {
155
152
                ED_text_undo_step(C, step);
156
153
        }
157
154
        else if (obedit) {
158
 
                if (ELEM7(obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE, OB_ARMATURE)) {
 
155
                if (OB_TYPE_SUPPORT_EDITMODE(obedit->type)) {
159
156
                        if (undoname)
160
157
                                undo_editmode_name(C, undoname);
161
158
                        else
162
159
                                undo_editmode_step(C, step);
163
 
 
 
160
                        
164
161
                        WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL);
165
162
                }
166
163
        }
167
164
        else {
168
 
                int do_glob_undo = 0;
169
 
                
 
165
                /* Note: we used to do a fall-through here where if the
 
166
                 * mode-specific undo system had no more steps to undo (or
 
167
                 * redo), the global undo would run.
 
168
                 *
 
169
                 * That was inconsistent with editmode, and also makes for
 
170
                 * unecessarily tricky interaction with the other undo
 
171
                 * systems. */
170
172
                if (obact && obact->mode & OB_MODE_TEXTURE_PAINT) {
171
 
                        if (!ED_undo_paint_step(C, UNDO_PAINT_IMAGE, step, undoname))
172
 
                                do_glob_undo = 1;
 
173
                        ED_undo_paint_step(C, UNDO_PAINT_IMAGE, step, undoname);
173
174
                }
174
175
                else if (obact && obact->mode & OB_MODE_SCULPT) {
175
 
                        if (!ED_undo_paint_step(C, UNDO_PAINT_MESH, step, undoname))
176
 
                                do_glob_undo = 1;
 
176
                        ED_undo_paint_step(C, UNDO_PAINT_MESH, step, undoname);
177
177
                }
178
178
                else if (obact && obact->mode & OB_MODE_PARTICLE_EDIT) {
179
179
                        if (step == 1)
181
181
                        else
182
182
                                PE_redo(CTX_data_scene(C));
183
183
                }
184
 
                else {
185
 
                        do_glob_undo = 1;
186
 
                }
187
 
                
188
 
                if (do_glob_undo) {
189
 
                        if (U.uiflag & USER_GLOBALUNDO) {
190
 
                                // note python defines not valid here anymore.
191
 
                                //#ifdef WITH_PYTHON
192
 
                                // XXX          BPY_scripts_clear_pyobjects();
193
 
                                //#endif
194
 
                                if (undoname)
195
 
                                        BKE_undo_name(C, undoname);
196
 
                                else
197
 
                                        BKE_undo_step(C, step);
198
 
 
199
 
                                WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, CTX_data_scene(C));
200
 
                        }
201
 
                        
 
184
                else if (U.uiflag & USER_GLOBALUNDO) {
 
185
                        // note python defines not valid here anymore.
 
186
                        //#ifdef WITH_PYTHON
 
187
                        // XXX          BPY_scripts_clear_pyobjects();
 
188
                        //#endif
 
189
                        if (undoname)
 
190
                                BKE_undo_name(C, undoname);
 
191
                        else
 
192
                                BKE_undo_step(C, step);
 
193
                                
 
194
                        WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, CTX_data_scene(C));
202
195
                }
203
196
        }
204
197
        
238
231
        if (sa && sa->spacetype == SPACE_IMAGE) {
239
232
                SpaceImage *sima = (SpaceImage *)sa->spacedata.first;
240
233
                
241
 
                if ((obact && obact->mode & OB_MODE_TEXTURE_PAINT) || sima->flag & SI_DRAWTOOL) {
 
234
                if ((obact && (obact->mode & OB_MODE_TEXTURE_PAINT)) || (sima->mode == SI_MODE_PAINT)) {
242
235
                        return 1;
243
236
                }
244
237
        }
245
238
        
246
 
        if (sa && sa->spacetype == SPACE_TEXT) {
 
239
        if (sa && (sa->spacetype == SPACE_TEXT)) {
247
240
                return 1;
248
241
        }
249
242
        else if (obedit) {
250
 
                if (ELEM7(obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE, OB_ARMATURE)) {
 
243
                if (OB_TYPE_SUPPORT_EDITMODE(obedit->type)) {
251
244
                        return undo_editmode_valid(undoname);
252
245
                }
253
246
        }
256
249
                /* if below tests fail, global undo gets executed */
257
250
                
258
251
                if (obact && obact->mode & OB_MODE_TEXTURE_PAINT) {
259
 
                        if (ED_undo_paint_valid(UNDO_PAINT_IMAGE, undoname) )
 
252
                        if (ED_undo_paint_valid(UNDO_PAINT_IMAGE, undoname))
260
253
                                return 1;
261
254
                }
262
255
                else if (obact && obact->mode & OB_MODE_SCULPT) {
263
 
                        if (ED_undo_paint_valid(UNDO_PAINT_MESH, undoname) )
 
256
                        if (ED_undo_paint_valid(UNDO_PAINT_MESH, undoname))
264
257
                                return 1;
265
258
                }
266
259
                else if (obact && obact->mode & OB_MODE_PARTICLE_EDIT) {
276
269
 
277
270
static int ed_undo_exec(bContext *C, wmOperator *UNUSED(op))
278
271
{
279
 
        /* "last operator" should disappear, later we can tie ths with undo stack nicer */
 
272
        /* "last operator" should disappear, later we can tie this with undo stack nicer */
280
273
        WM_operator_stack_clear(CTX_wm_manager(C));
281
274
        return ed_undo_step(C, 1, NULL);
282
275
}
283
276
 
284
277
static int ed_undo_push_exec(bContext *C, wmOperator *op)
285
278
{
286
 
        char str[MAXUNDONAME];
 
279
        char str[BKE_UNDO_STR_MAX];
287
280
        RNA_string_get(op->ptr, "message", str);
288
281
        ED_undo_push(C, str);
289
282
        return OPERATOR_FINISHED;
321
314
 
322
315
        ot->flag = OPTYPE_INTERNAL;
323
316
 
324
 
        RNA_def_string(ot->srna, "message", "Add an undo step *function may be moved*", MAXUNDONAME, "Undo Message", "");
 
317
        RNA_def_string(ot->srna, "message", "Add an undo step *function may be moved*", BKE_UNDO_STR_MAX, "Undo Message", "");
325
318
}
326
319
 
327
320
void ED_OT_redo(wmOperatorType *ot)
346
339
                wmWindowManager *wm = CTX_wm_manager(C);
347
340
                struct Scene *scene = CTX_data_scene(C);
348
341
 
 
342
                /* keep in sync with logic in view3d_panel_operator_redo() */
349
343
                ARegion *ar = CTX_wm_region(C);
350
 
                ARegion *ar1 = BKE_area_find_region_type(CTX_wm_area(C), RGN_TYPE_WINDOW);
 
344
                ARegion *ar1 = BKE_area_find_region_active_win(CTX_wm_area(C));
351
345
 
352
346
                if (ar1)
353
347
                        CTX_wm_region_set(C, ar1);
359
353
                      * (which copy their data), wont stop redo, see [#29579]],
360
354
                      *
361
355
                      * note, - WM_operator_check_ui_enabled() jobs test _must_ stay in sync with this */
362
 
                     (WM_jobs_test(wm, scene) == 0))
 
356
                     (WM_jobs_test(wm, scene, WM_JOB_TYPE_ANY) == 0))
363
357
                {
364
358
                        int retval;
365
359
 
413
407
 
414
408
/* ************************** */
415
409
 
416
 
#define UNDOSYSTEM_GLOBAL   1
417
 
#define UNDOSYSTEM_EDITMODE 2
418
 
#define UNDOSYSTEM_PARTICLE 3
 
410
enum {
 
411
        UNDOSYSTEM_GLOBAL   = 1,
 
412
        UNDOSYSTEM_EDITMODE = 2,
 
413
        UNDOSYSTEM_PARTICLE = 3
 
414
};
419
415
 
420
416
static int get_undo_system(bContext *C)
421
417
{
423
419
        
424
420
        /* find out which undo system */
425
421
        if (obedit) {
426
 
                if (ELEM7(obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE, OB_ARMATURE))
 
422
                if (OB_TYPE_SUPPORT_EDITMODE(obedit->type)) {
427
423
                        return UNDOSYSTEM_EDITMODE;
 
424
                }
428
425
        }
429
426
        else {
430
427
                Object *obact = CTX_data_active_object(C);
490
487
                if (totitem > 0) {
491
488
                        uiPopupMenu *pup = uiPupMenuBegin(C, RNA_struct_ui_name(op->type->srna), ICON_NONE);
492
489
                        uiLayout *layout = uiPupMenuLayout(pup);
493
 
                        uiLayout *split = uiLayoutSplit(layout, 0, 0), *column = NULL;
 
490
                        uiLayout *split = uiLayoutSplit(layout, 0.0f, FALSE);
 
491
                        uiLayout *column = NULL;
494
492
                        int i, c;
495
493
                        
496
494
                        for (c = 0, i = totitem - 1; i >= 0; i--, c++) {
497
495
                                if ( (c % 20) == 0)
498
 
                                        column = uiLayoutColumn(split, 0);
 
496
                                        column = uiLayoutColumn(split, FALSE);
499
497
                                if (item[i].identifier)
500
498
                                        uiItemIntO(column, item[i].name, item[i].icon, op->type->idname, "item", item[i].value);
501
499
                                
504
502
                        MEM_freeN(item);
505
503
                        
506
504
                        uiPupMenuEnd(C, pup);
507
 
                }               
 
505
                }
508
506
                
509
507
        }
510
508
        return OPERATOR_CANCELLED;