Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Thu, 13 Sep 2018 13:38:53 +0000 (23:38 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 13 Sep 2018 13:38:53 +0000 (23:38 +1000)
1  2 
source/blender/editors/undo/ed_undo.c

index 279f3e7cf38559d1163b5b24b751a9eae6815a07,e0a1faf04b8766d37d4a54e6445d28d12f15422c..515e96db25d35f50e6d6304746123df42754f3e1
@@@ -36,7 -36,6 +36,7 @@@
  #include "CLG_log.h"
  
  #include "DNA_scene_types.h"
 +#include "DNA_object_types.h"
  
  #include "BLI_utildefines.h"
  #include "BLI_callbacks.h"
  #include "BKE_context.h"
  #include "BKE_global.h"
  #include "BKE_main.h"
 +#include "BKE_scene.h"
  #include "BKE_screen.h"
 +#include "BKE_layer.h"
  #include "BKE_undo_system.h"
 +#include "BKE_workspace.h"
 +#include "BKE_paint.h"
  
  #include "ED_gpencil.h"
  #include "ED_render.h"
 +#include "ED_object.h"
  #include "ED_screen.h"
  #include "ED_undo.h"
  
  #include "WM_api.h"
  #include "WM_types.h"
 +#include "WM_toolsystem.h"
  
  #include "RNA_access.h"
  #include "RNA_define.h"
@@@ -112,9 -105,7 +112,8 @@@ static int ed_undo_step(bContext *C, in
  {
        CLOG_INFO(&LOG, 1, "name='%s', step=%d", undoname, step);
        wmWindowManager *wm = CTX_wm_manager(C);
-       wmWindow *win = CTX_wm_window(C);
        Scene *scene = CTX_data_scene(C);
 +      ScrArea *sa = CTX_wm_area(C);
  
        /* undo during jobs are running can easily lead to freeing data using by jobs,
         * or they can just lead to freezing job in some other cases */
        if (ED_gpencil_session_active()) {
                return ED_undo_gpencil_step(C, step, undoname);
        }
 +      if (sa && (sa->spacetype == SPACE_VIEW3D)) {
 +              Object *obact = CTX_data_active_object(C);
 +              if (obact && (obact->type == OB_GPENCIL)) {
 +                      ED_gpencil_toggle_brush_cursor(C, false, NULL);
 +              }
 +      }
  
        UndoStep *step_data_from_name = NULL;
        int step_for_callback = step;
                else {
                        BKE_undosys_step_undo_compat_only(wm->undo_stack, C, step);
                }
 +
 +              /* Set special modes for grease pencil */
 +              if (sa && (sa->spacetype == SPACE_VIEW3D)) {
 +                      Object *obact = CTX_data_active_object(C);
 +                      if (obact && (obact->type == OB_GPENCIL)) {
 +                              /* set cursor */
 +                              if (ELEM(obact->mode, OB_MODE_GPENCIL_PAINT, OB_MODE_GPENCIL_SCULPT, OB_MODE_GPENCIL_WEIGHT)) {
 +                                      ED_gpencil_toggle_brush_cursor(C, true, NULL);
 +                              }
 +                              else {
 +                                      ED_gpencil_toggle_brush_cursor(C, false, NULL);
 +                              }
 +                              /* set workspace mode */
 +                              Base *basact = CTX_data_active_base(C);
 +                              ED_object_base_activate(C, basact);
 +                      }
 +              }
        }
  
        /* App-Handlers (post). */
        WM_event_add_notifier(C, NC_WINDOW, NULL);
        WM_event_add_notifier(C, NC_WM | ND_UNDO, NULL);
  
-       if (win) {
-               win->addmousemove = true;
-       }
 +      Main *bmain = CTX_data_main(C);
 +      WM_toolsystem_refresh_screen_all(bmain);
 +
        return OPERATOR_FINISHED;
  }
  
@@@ -280,7 -241,12 +275,12 @@@ static int ed_undo_exec(bContext *C, wm
  {
        /* "last operator" should disappear, later we can tie this with undo stack nicer */
        WM_operator_stack_clear(CTX_wm_manager(C));
-       return ed_undo_step(C, 1, NULL);
+       int ret = ed_undo_step(C, 1, NULL);
+       if (ret & OPERATOR_FINISHED) {
+               /* Keep button under the cursor active. */
+               WM_event_add_mousemove(C);
+       }
+       return ret;
  }
  
  static int ed_undo_push_exec(bContext *C, wmOperator *op)
  
  static int ed_redo_exec(bContext *C, wmOperator *UNUSED(op))
  {
-       return ed_undo_step(C, -1, NULL);
+       int ret = ed_undo_step(C, -1, NULL);
+       if (ret & OPERATOR_FINISHED) {
+               /* Keep button under the cursor active. */
+               WM_event_add_mousemove(C);
+       }
+       return ret;
  }
  
  static int ed_undo_redo_exec(bContext *C, wmOperator *UNUSED(op))
  {
        wmOperator *last_op = WM_operator_last_redo(C);
-       const int ret = ED_undo_operator_repeat(C, last_op);
-       return ret ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
+       int ret = ED_undo_operator_repeat(C, last_op);
+       ret = ret ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
+       if (ret & OPERATOR_FINISHED) {
+               /* Keep button under the cursor active. */
+               WM_event_add_mousemove(C);
+       }
+       return ret;
  }
  
  static bool ed_undo_redo_poll(bContext *C)
@@@ -368,7 -344,7 +378,7 @@@ void ED_OT_undo_redo(wmOperatorType *ot
   * \{ */
  
  /* ui callbacks should call this rather than calling WM_operator_repeat() themselves */
 -int ED_undo_operator_repeat(bContext *C, struct wmOperator *op)
 +int ED_undo_operator_repeat(bContext *C, wmOperator *op)
  {
        int ret = 0;
  
                struct Scene *scene = CTX_data_scene(C);
  
                /* keep in sync with logic in view3d_panel_operator_redo() */
 -              ARegion *ar = CTX_wm_region(C);
 -              ARegion *ar1 = BKE_area_find_region_active_win(CTX_wm_area(C));
 +              ARegion *ar_orig = CTX_wm_region(C);
 +              ARegion *ar_win = BKE_area_find_region_active_win(CTX_wm_area(C));
  
 -              if (ar1)
 -                      CTX_wm_region_set(C, ar1);
 +              if (ar_win) {
 +                      CTX_wm_region_set(C, ar_win);
 +              }
  
                if ((WM_operator_repeat_check(C, op)) &&
                    (WM_operator_poll(C, op->type)) &&
                {
                        int retval;
  
 -                      ED_viewport_render_kill_jobs(wm, CTX_data_main(C), true);
 -
                        if (G.debug & G_DEBUG)
                                printf("redo_cb: operator redo %s\n", op->type->name);
  
                                }
                        }
  
 +                      if (op->type->flag & OPTYPE_USE_EVAL_DATA) {
 +                              /* We need to force refresh of depsgraph after undo step,
 +                               * redoing the operator *may* rely on some valid evaluated data. */
 +                              Main *bmain = CTX_data_main(C);
 +                              scene = CTX_data_scene(C);
 +                              ViewLayer *view_layer = CTX_data_view_layer(C);
 +                              BKE_scene_view_layer_graph_evaluated_ensure(bmain, scene, view_layer);
 +                      }
 +
                        retval = WM_operator_repeat(C, op);
                        if ((retval & OPERATOR_FINISHED) == 0) {
                                if (G.debug & G_DEBUG)
                }
  
                /* set region back */
 -              CTX_wm_region_set(C, ar);
 +              CTX_wm_region_set(C, ar_orig);
        }
        else {
                CLOG_WARN(&LOG, "called with NULL 'op'");
@@@ -481,7 -449,7 +491,7 @@@ static const EnumPropertyItem *rna_undo
                        item_tmp.identifier = us->name;
                        item_tmp.name = IFACE_(us->name);
                        if (us == wm->undo_stack->step_active) {
 -                              item_tmp.icon = ICON_RESTRICT_VIEW_OFF;
 +                              item_tmp.icon = ICON_HIDE_OFF;
                        }
                        else {
                                item_tmp.icon = ICON_NONE;
@@@ -564,24 -532,3 +574,24 @@@ void ED_OT_undo_history(wmOperatorType 
  }
  
  /** \} */
 +
 +/* -------------------------------------------------------------------- */
 +/** \name Undo Helper Functions
 + * \{ */
 +
 +void ED_undo_object_set_active_or_warn(ViewLayer *view_layer, Object *ob, const char *info, CLG_LogRef *log)
 +{
 +      Object *ob_prev = OBACT(view_layer);
 +      if (ob_prev != ob) {
 +              Base *base = BKE_view_layer_base_find(view_layer, ob);
 +              if (base != NULL) {
 +                      view_layer->basact = base;
 +              }
 +              else {
 +                      /* Should never fail, may not crash but can give odd behavior. */
 +                      CLOG_WARN(log, "'%s' failed to restore active object: '%s'", info, ob->id.name + 2);
 +              }
 +      }
 +}
 +
 +/** \} */