From 0e1bb232e68ce71f4c3dd331ed6331665238a065 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 17 Dec 2021 15:54:05 +1100 Subject: UI: move "undo history" from a custom popup to a menu type This lets the undo history expand as a regular sub-menu instead of being a popup. Also disable the active undo step menu item as this is a no-op. --- source/blender/editors/undo/ed_undo.c | 87 +++++------------------------------ 1 file changed, 12 insertions(+), 75 deletions(-) (limited to 'source/blender/editors/undo') diff --git a/source/blender/editors/undo/ed_undo.c b/source/blender/editors/undo/ed_undo.c index aca99f81e7b..c6fa5acfff5 100644 --- a/source/blender/editors/undo/ed_undo.c +++ b/source/blender/editors/undo/ed_undo.c @@ -64,6 +64,7 @@ #include "RNA_access.h" #include "RNA_define.h" +#include "RNA_enum_types.h" #include "UI_interface.h" #include "UI_resources.h" @@ -759,81 +760,16 @@ void ED_undo_operator_repeat_cb_evt(bContext *C, void *arg_op, int UNUSED(arg_un /* -------------------------------------------------------------------- */ /** \name Undo History Operator + * + * See `TOPBAR_MT_undo_history` which is used to access this operator. * \{ */ -/* create enum based on undo items */ -static const EnumPropertyItem *rna_undo_itemf(bContext *C, int *totitem) -{ - EnumPropertyItem item_tmp = {0}, *item = NULL; - int i = 0; - - wmWindowManager *wm = CTX_wm_manager(C); - if (wm->undo_stack == NULL) { - return NULL; - } - - for (UndoStep *us = wm->undo_stack->steps.first; us; us = us->next, i++) { - if (us->skip == false) { - item_tmp.identifier = us->name; - item_tmp.name = IFACE_(us->name); - if (us == wm->undo_stack->step_active) { - item_tmp.icon = ICON_LAYER_ACTIVE; - } - else { - item_tmp.icon = ICON_NONE; - } - item_tmp.value = i; - RNA_enum_item_add(&item, totitem, &item_tmp); - } - } - RNA_enum_item_end(&item, totitem); - - return item; -} - -static int undo_history_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) -{ - int totitem = 0; - - { - const EnumPropertyItem *item = rna_undo_itemf(C, &totitem); - - if (totitem > 0) { - uiPopupMenu *pup = UI_popup_menu_begin( - C, WM_operatortype_name(op->type, op->ptr), ICON_NONE); - uiLayout *layout = UI_popup_menu_layout(pup); - uiLayout *split = uiLayoutSplit(layout, 0.0f, false); - uiLayout *column = NULL; - const int col_size = 20 + totitem / 12; - int i, c; - bool add_col = true; - - for (c = 0, i = totitem; i--;) { - if (add_col && !(c % col_size)) { - column = uiLayoutColumn(split, false); - add_col = false; - } - if (item[i].identifier) { - uiItemIntO(column, item[i].name, item[i].icon, op->type->idname, "item", item[i].value); - c++; - add_col = true; - } - } - - MEM_freeN((void *)item); - - UI_popup_menu_end(C, pup); - } - } - return OPERATOR_CANCELLED; -} - /* NOTE: also check #ed_undo_step() in top if you change notifiers. */ static int undo_history_exec(bContext *C, wmOperator *op) { PropertyRNA *prop = RNA_struct_find_property(op->ptr, "item"); if (RNA_property_is_set(op->ptr, prop)) { - int item = RNA_property_int_get(op->ptr, prop); + const int item = RNA_property_int_get(op->ptr, prop); const int ret = ed_undo_step_by_index(C, item, op->reports); if (ret & OPERATOR_FINISHED) { ed_undo_refresh_for_op(C); @@ -845,14 +781,15 @@ static int undo_history_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } -static bool undo_history_poll(bContext *C) +static int undo_history_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (!ed_undo_is_init_and_screenactive_poll(C)) { - return false; + PropertyRNA *prop = RNA_struct_find_property(op->ptr, "item"); + if (RNA_property_is_set(op->ptr, prop)) { + return undo_history_exec(C, op); } - 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; + + WM_menu_name_call(C, "TOPBAR_MT_undo_history", WM_OP_INVOKE_DEFAULT); + return OPERATOR_FINISHED; } void ED_OT_undo_history(wmOperatorType *ot) @@ -865,7 +802,7 @@ void ED_OT_undo_history(wmOperatorType *ot) /* api callbacks */ ot->invoke = undo_history_invoke; ot->exec = undo_history_exec; - ot->poll = undo_history_poll; + ot->poll = ed_undo_is_init_and_screenactive_poll; RNA_def_int(ot->srna, "item", 0, 0, INT_MAX, "Item", "", 0, INT_MAX); } -- cgit v1.2.3