From 9270c8647b2e48dd6f3b4b5e3d66e91a76499a34 Mon Sep 17 00:00:00 2001 From: Pratyaksh Date: Sat, 11 Mar 2023 00:47:59 +0530 Subject: [PATCH] Added WM api to handle PanelType parent/child relationships --- .../blender/editors/animation/fmodifier_ui.c | 3 +-- .../blender/editors/space_nla/nla_buttons.c | 6 ++---- .../intern/MOD_gpencil_ui_common.c | 3 +-- source/blender/makesrna/intern/rna_ui.c | 13 +----------- .../blender/modifiers/intern/MOD_ui_common.c | 3 +-- .../blender/shader_fx/intern/FX_ui_common.c | 3 +-- source/blender/windowmanager/WM_api.h | 1 + .../windowmanager/intern/wm_panel_type.c | 21 +++++++++++++++++++ 8 files changed, 29 insertions(+), 24 deletions(-) diff --git a/source/blender/editors/animation/fmodifier_ui.c b/source/blender/editors/animation/fmodifier_ui.c index 4a562f2b420..3d073921806 100644 --- a/source/blender/editors/animation/fmodifier_ui.c +++ b/source/blender/editors/animation/fmodifier_ui.c @@ -210,8 +210,7 @@ static PanelType *fmodifier_subpanel_register(ARegionType *region_type, BLI_assert(parent != NULL); BLI_strncpy(panel_type->parent_id, parent->idname, BKE_ST_MAXNAME); - panel_type->parent = parent; - BLI_addtail(&parent->children, BLI_genericNodeN(panel_type)); + WM_paneltype_subpanel_add(parent, NULL, false); BLI_addtail(®ion_type->paneltypes, panel_type); return panel_type; diff --git a/source/blender/editors/space_nla/nla_buttons.c b/source/blender/editors/space_nla/nla_buttons.c index 4aff3766b12..7264680a007 100644 --- a/source/blender/editors/space_nla/nla_buttons.c +++ b/source/blender/editors/space_nla/nla_buttons.c @@ -665,10 +665,9 @@ void nla_buttons_register(ARegionType *art) strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA); pt->draw = nla_panel_evaluation; pt->draw_header = nla_panel_animated_influence_header; - pt->parent = pt_properties; + WM_paneltype_subpanel_add(NULL, pt, false); pt->flag = PANEL_TYPE_DEFAULT_CLOSED; pt->poll = nla_strip_eval_panel_poll; - BLI_addtail(&pt_properties->children, BLI_genericNodeN(pt)); BLI_addtail(&art->paneltypes, pt); pt = MEM_callocN(sizeof(PanelType), "spacetype nla panel animated strip time"); @@ -679,10 +678,9 @@ void nla_buttons_register(ARegionType *art) strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA); pt->draw = nla_panel_animated_strip_time; pt->draw_header = nla_panel_animated_strip_time_header; - pt->parent = pt_properties; + WM_paneltype_subpanel_add(NULL, pt, false); pt->flag = PANEL_TYPE_DEFAULT_CLOSED; pt->poll = nla_strip_eval_panel_poll; - BLI_addtail(&pt_properties->children, BLI_genericNodeN(pt)); BLI_addtail(&art->paneltypes, pt); pt = MEM_callocN(sizeof(PanelType), "spacetype nla panel modifiers"); diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.c b/source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.c index 7b2d44c2853..649abf598b5 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.c @@ -393,8 +393,7 @@ PanelType *gpencil_modifier_subpanel_register(ARegionType *region_type, BLI_assert(parent != NULL); BLI_strncpy(panel_type->parent_id, parent->idname, BKE_ST_MAXNAME); - panel_type->parent = parent; - BLI_addtail(&parent->children, BLI_genericNodeN(panel_type)); + WM_paneltype_subpanel_add(parent, NULL, false); BLI_addtail(®ion_type->paneltypes, panel_type); return panel_type; diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c index 9de32c24702..bfdc581746e 100644 --- a/source/blender/makesrna/intern/rna_ui.c +++ b/source/blender/makesrna/intern/rna_ui.c @@ -391,18 +391,7 @@ static StructRNA *rna_Panel_register(Main *bmain, /* Insert into list. */ BLI_insertlinkafter(&art->paneltypes, pt_iter, pt); - if (parent) { - pt->parent = parent; - LinkData *pt_child_iter = parent->children.last; - for (; pt_child_iter; pt_child_iter = pt_child_iter->prev) { - PanelType *pt_child = pt_child_iter->data; - if (pt_child->order <= pt->order) { - break; - } - } - BLI_insertlinkafter(&parent->children, pt_child_iter, BLI_genericNodeN(pt)); - } - + WM_paneltype_subpanel_add(parent, pt, true); { const char *owner_id = RNA_struct_state_owner_get(); if (owner_id) { diff --git a/source/blender/modifiers/intern/MOD_ui_common.c b/source/blender/modifiers/intern/MOD_ui_common.c index 0f6c40610a0..92eb0367f93 100644 --- a/source/blender/modifiers/intern/MOD_ui_common.c +++ b/source/blender/modifiers/intern/MOD_ui_common.c @@ -485,8 +485,7 @@ PanelType *modifier_subpanel_register(ARegionType *region_type, BLI_assert(parent != NULL); BLI_strncpy(panel_type->parent_id, parent->idname, BKE_ST_MAXNAME); - panel_type->parent = parent; - BLI_addtail(&parent->children, BLI_genericNodeN(panel_type)); + WM_paneltype_subpanel_add(parent, NULL, false); BLI_addtail(®ion_type->paneltypes, panel_type); return panel_type; diff --git a/source/blender/shader_fx/intern/FX_ui_common.c b/source/blender/shader_fx/intern/FX_ui_common.c index afbd75cee75..478afc9c7b7 100644 --- a/source/blender/shader_fx/intern/FX_ui_common.c +++ b/source/blender/shader_fx/intern/FX_ui_common.c @@ -264,8 +264,7 @@ PanelType *shaderfx_subpanel_register(ARegionType *region_type, BLI_assert(parent != NULL); BLI_strncpy(panel_type->parent_id, parent->idname, BKE_ST_MAXNAME); - panel_type->parent = parent; - BLI_addtail(&parent->children, BLI_genericNodeN(panel_type)); + WM_paneltype_subpanel_add(parent, NULL, false); BLI_addtail(®ion_type->paneltypes, panel_type); return panel_type; diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index faa22e6216e..257c06e4183 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -1154,6 +1154,7 @@ void WM_paneltype_init(void); void WM_paneltype_clear(void); struct PanelType *WM_paneltype_find(const char *idname, bool quiet); bool WM_paneltype_add(struct PanelType *pt); +void WM_paneltype_subpanel_add(struct PanelType *parent, struct PanelType *pt, bool use_order); void WM_paneltype_remove(struct PanelType *pt); void WM_paneltype_idname_visit_for_search(const struct bContext *C, diff --git a/source/blender/windowmanager/intern/wm_panel_type.c b/source/blender/windowmanager/intern/wm_panel_type.c index 860b53c1071..16e135350c8 100644 --- a/source/blender/windowmanager/intern/wm_panel_type.c +++ b/source/blender/windowmanager/intern/wm_panel_type.c @@ -47,6 +47,27 @@ bool WM_paneltype_add(PanelType *pt) return true; } +void WM_paneltype_subpanel_add(PanelType *parent, PanelType *pt, bool use_order) +{ + pt->parent = parent; + + if (parent) { + if (use_order) { + LinkData *pt_child_iter = parent->children.last; + for (; pt_child_iter; pt_child_iter = pt_child_iter->prev) { + PanelType *pt_child = pt_child_iter->data; + if (pt_child->order <= pt->order) { + break; + } + } + BLI_insertlinkafter(&parent->children, pt_child_iter, BLI_genericNodeN(pt)); + } + else { + BLI_addtail(&parent->children, BLI_genericNodeN(pt)); + } + } +} + void WM_paneltype_remove(PanelType *pt) { const bool ok = BLI_ghash_remove(g_paneltypes_hash, pt->idname, NULL, NULL); -- 2.30.2