From 85dcdb87d2ee91844e1dc343b8bd48ace2717d77 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 2 May 2018 10:59:20 +0200 Subject: UI: fix operator redo showing empty popovers Many operators have no options, showing a popover button with no content isn't good. --- source/blender/editors/space_topbar/space_topbar.c | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'source/blender/editors/space_topbar') diff --git a/source/blender/editors/space_topbar/space_topbar.c b/source/blender/editors/space_topbar/space_topbar.c index fc76fd9c638..4c40353618b 100644 --- a/source/blender/editors/space_topbar/space_topbar.c +++ b/source/blender/editors/space_topbar/space_topbar.c @@ -57,6 +57,8 @@ #include "WM_message.h" +void topbar_panels_register(ARegionType *art); + /* ******************** default callbacks for topbar space ***************** */ static SpaceLink *topbar_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scene)) @@ -273,9 +275,58 @@ void ED_spacetype_topbar(void) art->layout = ED_region_header_layout; art->draw = ED_region_header_draw; + /* For popovers. */ + topbar_panels_register(art); + BLI_addhead(&st->regiontypes, art); recent_files_menu_register(); BKE_spacetype_register(st); } + + +/* -------------------------------------------------------------------- */ +/** \name Redo Panel + * \{ */ + +static int topbar_panel_operator_redo_poll(const bContext *C, PanelType *UNUSED(pt)) +{ + wmOperator *op = WM_operator_last_redo(C); + if (op == NULL) { + return false; + } + + return (WM_operator_poll((bContext *)C, op->type) && + WM_operator_check_ui_empty(op->type) == false); +} + +static void topbar_panel_operator_redo(const bContext *C, Panel *pa) +{ + wmOperator *op = WM_operator_last_redo(C); + if (op == NULL) { + return; + } + if (!WM_operator_check_ui_enabled(C, op->type->name)) { + uiLayoutSetEnabled(pa->layout, false); + } + uiLayout *col = uiLayoutColumn(pa->layout, false); + uiTemplateOperatorRedoProperties(col, C); +} + +void topbar_panels_register(ARegionType *art) +{ + PanelType *pt; + + pt = MEM_callocN(sizeof(PanelType), __func__); + strcpy(pt->idname, "TOPBAR_PT_redo"); + strcpy(pt->label, N_("Redo")); + strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA); + pt->draw = topbar_panel_operator_redo; + pt->poll = topbar_panel_operator_redo_poll; + pt->space_type = SPACE_TOPBAR; + pt->region_type = RGN_TYPE_HEADER; + BLI_addtail(&art->paneltypes, pt); +} + +/** \} */ -- cgit v1.2.3