[Bf-blender-cvs] [b7075049732] master: UI: Edit Menu - Undo History List and Operator Polling

Harley Acheson noreply at git.blender.org
Tue Jan 28 18:35:08 CET 2020


Commit: b7075049732a0df53be6483ab5fc2333398b9ebb
Author: Harley Acheson
Date:   Tue Jan 28 09:33:41 2020 -0800
Branches: master
https://developer.blender.org/rBb7075049732a0df53be6483ab5fc2333398b9ebb

UI: Edit Menu - Undo History List and Operator Polling

Enable and Disable Edit Menu items based on whether those actions are currently applicable.

https://developer.blender.org/D4846

Reviewed by Brecht Van Lommel

===================================================================

M	source/blender/editors/screen/screen_ops.c
M	source/blender/editors/undo/ed_undo.c

===================================================================

diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index 0e1ae03fd20..14ea3aca623 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -3643,6 +3643,15 @@ static void SCREEN_OT_spacedata_cleanup(wmOperatorType *ot)
 /** \name Repeat Last Operator
  * \{ */
 
+static bool repeat_history_poll(bContext *C)
+{
+  if (!ED_operator_screenactive(C)) {
+    return false;
+  }
+  wmWindowManager *wm = CTX_wm_manager(C);
+  return !BLI_listbase_is_empty(&wm->operators);
+}
+
 static int repeat_last_exec(bContext *C, wmOperator *UNUSED(op))
 {
   wmWindowManager *wm = CTX_wm_manager(C);
@@ -3676,7 +3685,7 @@ static void SCREEN_OT_repeat_last(wmOperatorType *ot)
   /* api callbacks */
   ot->exec = repeat_last_exec;
 
-  ot->poll = ED_operator_screenactive;
+  ot->poll = repeat_history_poll;
 }
 
 /** \} */
@@ -3743,8 +3752,7 @@ static void SCREEN_OT_repeat_history(wmOperatorType *ot)
   /* api callbacks */
   ot->invoke = repeat_history_invoke;
   ot->exec = repeat_history_exec;
-
-  ot->poll = ED_operator_screenactive;
+  ot->poll = repeat_history_poll;
 
   RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "", 0, 1000);
 }
@@ -3775,8 +3783,7 @@ static void SCREEN_OT_redo_last(wmOperatorType *ot)
 
   /* api callbacks */
   ot->invoke = redo_last_invoke;
-
-  ot->poll = ED_operator_screenactive;
+  ot->poll = repeat_history_poll;
 }
 
 /** \} */
diff --git a/source/blender/editors/undo/ed_undo.c b/source/blender/editors/undo/ed_undo.c
index 9770b52158a..8e190ed9c73 100644
--- a/source/blender/editors/undo/ed_undo.c
+++ b/source/blender/editors/undo/ed_undo.c
@@ -464,6 +464,15 @@ static bool ed_undo_redo_poll(bContext *C)
           WM_operator_check_ui_enabled(C, last_op->type->name));
 }
 
+static bool ed_undo_poll(bContext *C)
+{
+  if (!ed_undo_is_init_and_screenactive_poll(C)) {
+    return false;
+  }
+  UndoStack *undo_stack = CTX_wm_manager(C)->undo_stack;
+  return (undo_stack->step_active != NULL) && (undo_stack->step_active->prev != NULL);
+}
+
 void ED_OT_undo(wmOperatorType *ot)
 {
   /* identifiers */
@@ -473,7 +482,7 @@ void ED_OT_undo(wmOperatorType *ot)
 
   /* api callbacks */
   ot->exec = ed_undo_exec;
-  ot->poll = ed_undo_is_init_and_screenactive_poll;
+  ot->poll = ed_undo_poll;
 }
 
 void ED_OT_undo_push(wmOperatorType *ot)
@@ -498,6 +507,15 @@ void ED_OT_undo_push(wmOperatorType *ot)
                  "");
 }
 
+static bool ed_redo_poll(bContext *C)
+{
+  if (!ed_undo_is_init_and_screenactive_poll(C)) {
+    return false;
+  }
+  UndoStack *undo_stack = CTX_wm_manager(C)->undo_stack;
+  return (undo_stack->step_active != NULL) && (undo_stack->step_active->next != NULL);
+}
+
 void ED_OT_redo(wmOperatorType *ot)
 {
   /* identifiers */
@@ -507,7 +525,7 @@ void ED_OT_redo(wmOperatorType *ot)
 
   /* api callbacks */
   ot->exec = ed_redo_exec;
-  ot->poll = ed_undo_is_init_and_screenactive_poll;
+  ot->poll = ed_redo_poll;
 }
 
 void ED_OT_undo_redo(wmOperatorType *ot)
@@ -697,6 +715,16 @@ static int undo_history_exec(bContext *C, wmOperator *op)
   return OPERATOR_CANCELLED;
 }
 
+static bool undo_history_poll(bContext *C)
+{
+  if (!ed_undo_is_init_and_screenactive_poll(C)) {
+    return false;
+  }
+  UndoStack *undo_stack = CTX_wm_manager(C)->undo_stack;
+  /* More than just original state entry. */
+  return BLI_listbase_count_at_most(&undo_stack->steps, 2) > 1;
+}
+
 void ED_OT_undo_history(wmOperatorType *ot)
 {
   /* identifiers */
@@ -707,7 +735,7 @@ void ED_OT_undo_history(wmOperatorType *ot)
   /* api callbacks */
   ot->invoke = undo_history_invoke;
   ot->exec = undo_history_exec;
-  ot->poll = ed_undo_is_init_and_screenactive_poll;
+  ot->poll = undo_history_poll;
 
   RNA_def_int(ot->srna, "item", 0, 0, INT_MAX, "Item", "", 0, INT_MAX);
 }



More information about the Bf-blender-cvs mailing list