Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/undo/ed_undo.c
| Show All 28 Lines | |||||
| ED_outliner_select_sync_from_all_tag(C); | ED_outliner_select_sync_from_all_tag(C); | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| static int ed_undo_push_exec(bContext *C, wmOperator *op) | static int ed_undo_push_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| if (G.background) { | if (G.background) { | ||||
| /* Exception for background mode, see: T60934. | /* Exception for background mode, see: T60934. | ||||
| * Note: since the undo stack isn't initialized on startup, background mode behavior | * Note: since the undo stack isn't initialized on startup, background mode behavior | ||||
brecht: Leave out the `wm->undo_stack->step_active != wm->undo_stack->step_active->prev` test, that… | |||||
| * won't match regular usage, this is just for scripts to do explicit undo pushes. */ | * won't match regular usage, this is just for scripts to do explicit undo pushes. */ | ||||
Not Done Inline ActionsThis function could be simplified as: 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);`brecht: This function could be simplified as:
```
if (!ed_undo_is_init_and_screenactive_poll(C)) {… | |||||
| wmWindowManager *wm = CTX_wm_manager(C); | wmWindowManager *wm = CTX_wm_manager(C); | ||||
| if (wm->undo_stack == NULL) { | if (wm->undo_stack == NULL) { | ||||
| wm->undo_stack = BKE_undosys_stack_create(); | wm->undo_stack = BKE_undosys_stack_create(); | ||||
| } | } | ||||
| } | } | ||||
| char str[BKE_UNDO_STR_MAX]; | char str[BKE_UNDO_STR_MAX]; | ||||
| RNA_string_get(op->ptr, "message", str); | RNA_string_get(op->ptr, "message", str); | ||||
| ED_undo_push(C, str); | ED_undo_push(C, str); | ||||
| Show All 27 Lines | |||||
| /* Disable in background mode, we could support if it's useful, T60934. */ | /* Disable in background mode, we could support if it's useful, T60934. */ | ||||
| static bool ed_undo_is_init_poll(bContext *C) | static bool ed_undo_is_init_poll(bContext *C) | ||||
| { | { | ||||
| wmWindowManager *wm = CTX_wm_manager(C); | wmWindowManager *wm = CTX_wm_manager(C); | ||||
| if (wm->undo_stack == NULL) { | if (wm->undo_stack == NULL) { | ||||
| CTX_wm_operator_poll_msg_set(C, "Undo disabled at startup"); | CTX_wm_operator_poll_msg_set(C, "Undo disabled at startup"); | ||||
| return false; | return false; | ||||
| } | } | ||||
Not Done Inline ActionsLeave out the wm->undo_stack->step_active != wm->undo_stack->step_active->next test. brecht: Leave out the `wm->undo_stack->step_active != wm->undo_stack->step_active->next` test. | |||||
| return true; | return true; | ||||
| } | } | ||||
| static bool ed_undo_is_init_and_screenactive_poll(bContext *C) | static bool ed_undo_is_init_and_screenactive_poll(bContext *C) | ||||
| { | { | ||||
| if (ed_undo_is_init_poll(C) == false) { | if (ed_undo_is_init_poll(C) == false) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| return ED_operator_screenactive(C); | return ED_operator_screenactive(C); | ||||
| } | } | ||||
| static bool ed_undo_redo_poll(bContext *C) | static bool ed_undo_redo_poll(bContext *C) | ||||
| { | { | ||||
| wmOperator *last_op = WM_operator_last_redo(C); | wmOperator *last_op = WM_operator_last_redo(C); | ||||
| return (last_op && ed_undo_is_init_and_screenactive_poll(C) && | return (last_op && ed_undo_is_init_and_screenactive_poll(C) && | ||||
| WM_operator_check_ui_enabled(C, last_op->type->name)); | 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) | void ED_OT_undo(wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Undo"; | ot->name = "Undo"; | ||||
| ot->description = "Undo previous action"; | ot->description = "Undo previous action"; | ||||
| ot->idname = "ED_OT_undo"; | ot->idname = "ED_OT_undo"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->exec = ed_undo_exec; | 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) | void ED_OT_undo_push(wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Undo Push"; | ot->name = "Undo Push"; | ||||
| ot->description = "Add an undo state (internal use only)"; | ot->description = "Add an undo state (internal use only)"; | ||||
| ot->idname = "ED_OT_undo_push"; | ot->idname = "ED_OT_undo_push"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->exec = ed_undo_push_exec; | ot->exec = ed_undo_push_exec; | ||||
| /* Unlike others undo operators this initializes undo stack. */ | /* Unlike others undo operators this initializes undo stack. */ | ||||
| ot->poll = ED_operator_screenactive; | ot->poll = ED_operator_screenactive; | ||||
| ot->flag = OPTYPE_INTERNAL; | ot->flag = OPTYPE_INTERNAL; | ||||
| RNA_def_string(ot->srna, | RNA_def_string(ot->srna, | ||||
| "message", | "message", | ||||
| "Add an undo step *function may be moved*", | "Add an undo step *function may be moved*", | ||||
| BKE_UNDO_STR_MAX, | BKE_UNDO_STR_MAX, | ||||
| "Undo Message", | "Undo Message", | ||||
| ""); | ""); | ||||
| } | } | ||||
| 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) | void ED_OT_redo(wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Redo"; | ot->name = "Redo"; | ||||
| ot->description = "Redo previous action"; | ot->description = "Redo previous action"; | ||||
| ot->idname = "ED_OT_redo"; | ot->idname = "ED_OT_redo"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->exec = ed_redo_exec; | 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) | void ED_OT_undo_redo(wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Undo and Redo"; | ot->name = "Undo and Redo"; | ||||
| ot->description = "Undo and redo previous action"; | ot->description = "Undo and redo previous action"; | ||||
| ot->idname = "ED_OT_undo_redo"; | ot->idname = "ED_OT_undo_redo"; | ||||
| ▲ Show 20 Lines • Show All 173 Lines • ▼ Show 20 Lines | |||||
| WM_operator_stack_clear(CTX_wm_manager(C)); | WM_operator_stack_clear(CTX_wm_manager(C)); | ||||
| ed_undo_step_by_index(C, item, op->reports); | ed_undo_step_by_index(C, item, op->reports); | ||||
| WM_event_add_notifier(C, NC_WINDOW, NULL); | WM_event_add_notifier(C, NC_WINDOW, NULL); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| return OPERATOR_CANCELLED; | 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 */ | |||||
brechtUnsubmitted Not Done Inline ActionsComment style: full capitalized sentence ending in dot. brecht: Comment style: full capitalized sentence ending in dot. | |||||
| return BLI_listbase_count_at_most(&undo_stack->steps, 2) > 1; | |||||
| } | |||||
| void ED_OT_undo_history(wmOperatorType *ot) | void ED_OT_undo_history(wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Undo History"; | ot->name = "Undo History"; | ||||
| ot->description = "Redo specific action in history"; | ot->description = "Redo specific action in history"; | ||||
| ot->idname = "ED_OT_undo_history"; | ot->idname = "ED_OT_undo_history"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->invoke = undo_history_invoke; | ot->invoke = undo_history_invoke; | ||||
| ot->exec = undo_history_exec; | 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); | RNA_def_int(ot->srna, "item", 0, 0, INT_MAX, "Item", "", 0, INT_MAX); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Undo Helper Functions | /** \name Undo Helper Functions | ||||
| ▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines | |||||
Leave out the wm->undo_stack->step_active != wm->undo_stack->step_active->prev test, that can't happen as far as I know. If that would be the case the data structures would be quite broken.