WIP: #104303: WM panel parent API #105193

Draft
Pratyaksh Raj wants to merge 2 commits from Pratyaksh-Raj/blender:WM-Panel-API into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
9 changed files with 35 additions and 40 deletions

View File

@ -208,11 +208,7 @@ static PanelType *fmodifier_subpanel_register(ARegionType *region_type,
panel_type->poll = poll;
panel_type->flag = PANEL_TYPE_DEFAULT_CLOSED;
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));
BLI_addtail(&region_type->paneltypes, panel_type);
Review

This line should not be removed, it's not handled by the call to WM_paneltype_subpanel_add.

This line should not be removed, it's not handled by the call to `WM_paneltype_subpanel_add`.
WM_paneltype_subpanel_add(parent,pt, true);
Review

WM_paneltype_subpanel_add(parent, pt, false); (you do not want to use order here).

` WM_paneltype_subpanel_add(parent, pt, false);` (you do not want to use order here).
return panel_type;
}

View File

@ -665,12 +665,11 @@ 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;
pt->flag = PANEL_TYPE_DEFAULT_CLOSED;
pt->poll = nla_strip_eval_panel_poll;
BLI_addtail(&pt_properties->children, BLI_genericNodeN(pt));
WM_paneltype_subpanel_add(pt_properties, pt, true);
Review

WM_paneltype_subpanel_add(parent, pt, false); (you do not want to use order here).

` WM_paneltype_subpanel_add(parent, pt, false);` (you do not want to use order here).
BLI_addtail(&art->paneltypes, pt);
Review

Remove extra spaces...

Remove extra spaces...
pt = MEM_callocN(sizeof(PanelType), "spacetype nla panel animated strip time");
strcpy(pt->idname, "NLA_PT_animated_strip_time");
strcpy(pt->parent_id, "NLA_PT_properties");
@ -679,12 +678,10 @@ 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;
pt->flag = PANEL_TYPE_DEFAULT_CLOSED;
pt->poll = nla_strip_eval_panel_poll;
BLI_addtail(&pt_properties->children, BLI_genericNodeN(pt));
WM_paneltype_subpanel_add(pt_properties, pt, true);
Review

WM_paneltype_subpanel_add(parent, pt, false); (you do not want to use order here).

` WM_paneltype_subpanel_add(parent, pt, false);` (you do not want to use order here).
BLI_addtail(&art->paneltypes, pt);
Review

No need to remove that line

No need to remove that line
pt = MEM_callocN(sizeof(PanelType), "spacetype nla panel modifiers");
strcpy(pt->idname, "NLA_PT_modifiers");
strcpy(pt->label, N_("Modifiers"));

View File

@ -391,11 +391,7 @@ PanelType *gpencil_modifier_subpanel_register(ARegionType *region_type,
panel_type->poll = gpencil_modifier_ui_poll;
panel_type->flag = PANEL_TYPE_DEFAULT_CLOSED;
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));
BLI_addtail(&region_type->paneltypes, panel_type);
Review

This line should not be removed, it's not handled by the call to WM_paneltype_subpanel_add.

This line should not be removed, it's not handled by the call to `WM_paneltype_subpanel_add`.
WM_paneltype_subpanel_add(parent, pt, true);
Review

WM_paneltype_subpanel_add(parent, pt, false); (you do not want to use order here).

` WM_paneltype_subpanel_add(parent, pt, false);` (you do not want to use order here).
return panel_type;
}

View File

@ -389,19 +389,9 @@ static StructRNA *rna_Panel_register(Main *bmain,
}
/* Insert into list. */
BLI_insertlinkafter(&art->paneltypes, pt_iter, pt);
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();
@ -410,7 +400,9 @@ static StructRNA *rna_Panel_register(Main *bmain,
}
}
WM_paneltype_add(pt);
WM_paneltype_add(pt);
Review

No need for extra empty lines here.

No need for extra empty lines here.
/* update while blender is running */
WM_main_add_notifier(NC_WINDOW, NULL);

View File

@ -483,11 +483,7 @@ PanelType *modifier_subpanel_register(ARegionType *region_type,
panel_type->poll = modifier_ui_poll;
panel_type->flag = PANEL_TYPE_DEFAULT_CLOSED;
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));
BLI_addtail(&region_type->paneltypes, panel_type);
Review

This line should not be removed, it's not handled by the call to WM_paneltype_subpanel_add.

This line should not be removed, it's not handled by the call to `WM_paneltype_subpanel_add`.
WM_paneltype_subpanel_add(parent, pt, true);
Review

WM_paneltype_subpanel_add(parent, pt, false); (you do not want to use order here).

` WM_paneltype_subpanel_add(parent, pt, false);` (you do not want to use order here).
return panel_type;
}

View File

@ -262,11 +262,7 @@ PanelType *shaderfx_subpanel_register(ARegionType *region_type,
panel_type->poll = shaderfx_ui_poll;
panel_type->flag = PANEL_TYPE_DEFAULT_CLOSED;
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));
BLI_addtail(&region_type->paneltypes, panel_type);
Review

This line should not be removed, it's not handled by the call to WM_paneltype_subpanel_add.

This line should not be removed, it's not handled by the call to `WM_paneltype_subpanel_add`.
WM_paneltype_subpanel_add(parent, pt, true);
Review

WM_paneltype_subpanel_add(parent, pt, false); (you do not want to use order here).

` WM_paneltype_subpanel_add(parent, pt, false);` (you do not want to use order here).
return panel_type;
}

View File

@ -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(PanelType *pt, PanelType *parent, bool use_order);
void WM_paneltype_remove(struct PanelType *pt);
void WM_paneltype_idname_visit_for_search(const struct bContext *C,

View File

@ -47,6 +47,27 @@ bool WM_paneltype_add(PanelType *pt)
return true;
}
Review

Style: Please leave an empty line between function definitions.

Style: Please leave an empty line between function definitions.
void WM_paneltype_subpanel_add(PanelType *pt, PanelType *parent, 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));
}
}
Review

Wondering where art comes from here...? Missing parameter?

Wondering where `art` comes from here...? Missing parameter?
}
void WM_paneltype_remove(PanelType *pt)
{
const bool ok = BLI_ghash_remove(g_paneltypes_hash, pt->idname, NULL, NULL);

@ -1 +1 @@
Subproject commit e133fc08cd3254bb3d3bd1345028c8486700bca4
Subproject commit 27826b4aed138b7e3aed882d0eab96740c3a55c7
Review

This should not be here, in fact this has been removed recently, you need to update your patch against latest main branch.

This should not be here, in fact this has been removed recently, you need to update your patch against latest `main` branch.
Review

Sir In my 2nd commit there is no such submodule. Updated my main branch. Now For removing this should I need to change my branch and then put another PR?

Sir In my 2nd commit there is no such submodule. Updated my main branch. Now For removing this should I need to change my branch and then put another PR?
Review

Yes just rebase on latest main branch, and force-push on your fork.

Yes just rebase on latest `main` branch, and force-push on your fork.