diff --git a/source/blender/editors/animation/fmodifier_ui.c b/source/blender/editors/animation/fmodifier_ui.c index 7b7950be5fa..65f8c6d1856 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 ac6d4b69ccc..7c1b1e56191 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 935e442952e..0b4759dd971 100644 --- a/source/blender/makesrna/intern/rna_ui.c +++ b/source/blender/makesrna/intern/rna_ui.c @@ -403,18 +403,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 17eabfbbd7a..3e6770b232f 100644 --- a/source/blender/modifiers/intern/MOD_ui_common.c +++ b/source/blender/modifiers/intern/MOD_ui_common.c @@ -496,8 +496,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 ffb70843016..a6dc26283e2 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 c681049c4b7..3f688bef647 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -1163,6 +1163,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);