UI: Add title to tree view context menus #120694
|
@ -205,7 +205,7 @@ static void catalog_selector_panel_draw(const bContext *C, Panel *panel)
|
|||
*block,
|
||||
"asset catalog tree view",
|
||||
std::make_unique<AssetCatalogSelectorTree>(*library, *shelf));
|
||||
|
||||
tree_view->set_context_menu_title("Catalog");
|
||||
|
||||
ui::TreeViewBuilder::build_tree_view(*tree_view, *layout);
|
||||
}
|
||||
|
||||
|
|
|
@ -63,9 +63,10 @@ class AbstractView {
|
|||
/* See #get_bounds(). */
|
||||
std::optional<rcti> bounds_;
|
||||
|
||||
std::string context_menu_title;
|
||||
|
||||
public:
|
||||
Julian Eisel
commented
I'd avoid public members in classes like this generally, plus I'd avoid mixing public and non-public members scattered throughout the class. Just add this to the other private members at the top of the struct definition, and add a public getter/setter. I'd avoid public members in classes like this generally, plus I'd avoid mixing public and non-public members scattered throughout the class. Just add this to the other private members at the top of the struct definition, and add a public getter/setter. `label` is also a bit misleading maybe. I'd just call it "context menu title", for as long as it's just that at least.
|
||||
virtual ~AbstractView() = default;
|
||||
|
||||
/**
|
||||
* If a view wants to support dropping data into it, it has to return a drop target here.
|
||||
* That is an object implementing #DropTargetInterface.
|
||||
|
@ -108,6 +109,9 @@ class AbstractView {
|
|||
*/
|
||||
std::optional<rcti> get_bounds() const;
|
||||
|
||||
std::string get_context_menu_title() const;
|
||||
void set_context_menu_title(std::string title);
|
||||
|
||||
protected:
|
||||
AbstractView() = default;
|
||||
|
||||
|
|
|
@ -1375,6 +1375,7 @@ std::optional<EnumPropertyItem> UI_but_rna_enum_item_get(bContext &C, uiBut &but
|
|||
std::string UI_but_string_get_rna_property_identifier(const uiBut &but);
|
||||
std::string UI_but_string_get_rna_struct_identifier(const uiBut &but);
|
||||
std::string UI_but_string_get_label(uiBut &but);
|
||||
std::string UI_but_context_menu_title_from_button(uiBut &but);
|
||||
/**
|
||||
* Query the result of #uiBut::tip_label_func().
|
||||
* Meant to allow overriding the label to be displayed in the tool-tip.
|
||||
|
|
|
@ -6431,9 +6431,23 @@ std::string UI_but_string_get_label(uiBut &but)
|
|||
}
|
||||
return but.str.substr(0, str_len);
|
||||
}
|
||||
|
||||
return UI_but_string_get_rna_label(but);
|
||||
}
|
||||
|
||||
std::string UI_but_context_menu_title_from_button(uiBut &but)
|
||||
Julian Eisel
commented
`but` can be `const`.
Pratik Borhade
commented
If we do this, we will also need to change "button parameter -> const" of few other functions. Example: If we do this, we will also need to change "button parameter -> const" of few other functions. Example: `UI_but_string_get_label`, `UI_but_string_get_rna_label`, `UI_but_operator_ptr_ensure` and possibly few more.
Maybe best to do it outside of this PR to avoid the noise? 😅
|
||||
{
|
||||
if (but.type == UI_BTYPE_VIEW_ITEM) {
|
||||
const uiButViewItem &view_item_but = static_cast<const uiButViewItem &>(but);
|
||||
Julian Eisel
commented
```cpp
const uiButViewItem &view_item_but = static_cast<const uiButViewItem &>(but);
```
|
||||
if (view_item_but.view_item == nullptr) {
|
||||
Julian Eisel
commented
`view_item` should be null-checked. Can return an empty string in that case I guess.
|
||||
return "";
|
||||
}
|
||||
blender::ui::AbstractView &tree_view = view_item_but.view_item->get_view();
|
||||
return IFACE_(tree_view.get_context_menu_title().c_str());
|
||||
}
|
||||
return UI_but_string_get_label(but);
|
||||
}
|
||||
|
||||
std::string UI_but_string_get_tooltip_label(const uiBut &but)
|
||||
{
|
||||
if (!but.tip_label_func) {
|
||||
|
|
|
@ -531,7 +531,7 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but, const wmEvent *ev
|
|||
uiLayout *layout;
|
||||
const bContextStore *previous_ctx = CTX_store_get(C);
|
||||
{
|
||||
pup = UI_popup_menu_begin(C, UI_but_string_get_label(*but).c_str(), ICON_NONE);
|
||||
pup = UI_popup_menu_begin(C, UI_but_context_menu_title_from_button(*but).c_str(), ICON_NONE);
|
||||
layout = UI_popup_menu_layout(pup);
|
||||
|
||||
set_layout_context_from_button(C, layout, but);
|
||||
|
|
|
@ -473,6 +473,7 @@ void uiTemplateBoneCollectionTree(uiLayout *layout, bContext *C)
|
|||
*block,
|
||||
"Bone Collection Tree View",
|
||||
std::make_unique<blender::ui::bonecollections::BoneCollectionTreeView>(*armature));
|
||||
tree_view->set_context_menu_title("Bone Collection");
|
||||
tree_view->set_min_rows(3);
|
||||
|
||||
ui::TreeViewBuilder::build_tree_view(*tree_view, *layout);
|
||||
|
|
|
@ -414,6 +414,7 @@ void uiTemplateGreasePencilLayerTree(uiLayout *layout, bContext *C)
|
|||
*block,
|
||||
"Grease Pencil Layer Tree View",
|
||||
std::make_unique<blender::ui::greasepencil::LayerTreeView>(grease_pencil));
|
||||
tree_view->set_context_menu_title("Grease Pencil Layer");
|
||||
tree_view->set_min_rows(3);
|
||||
|
||||
ui::TreeViewBuilder::build_tree_view(*tree_view, *layout);
|
||||
|
|
|
@ -399,6 +399,7 @@ void uiTemplateLightLinkingCollection(uiLayout *layout,
|
|||
*block,
|
||||
"Light Linking Collection Tree View",
|
||||
std::make_unique<blender::ui::light_linking::CollectionView>(*context_layout, *collection));
|
||||
tree_view->set_context_menu_title("Light Linking");
|
||||
tree_view->set_min_rows(3);
|
||||
|
||||
blender::ui::TreeViewBuilder::build_tree_view(*tree_view, *layout);
|
||||
|
|
|
@ -517,6 +517,7 @@ void uiTemplateNodeTreeInterface(uiLayout *layout, PointerRNA *ptr)
|
|||
*block,
|
||||
"Node Tree Declaration Tree View",
|
||||
std::make_unique<blender::ui::nodes::NodeTreeInterfaceView>(nodetree, interface));
|
||||
tree_view->set_context_menu_title("Node Tree Interface");
|
||||
tree_view->set_min_rows(3);
|
||||
|
||||
blender::ui::TreeViewBuilder::build_tree_view(*tree_view, *layout);
|
||||
|
|
|
@ -154,6 +154,15 @@ std::optional<rcti> AbstractView::get_bounds() const
|
|||
return bounds_;
|
||||
}
|
||||
|
||||
std::string AbstractView::get_context_menu_title() const
|
||||
{
|
||||
return context_menu_title;
|
||||
}
|
||||
|
||||
void AbstractView::set_context_menu_title(std::string title)
|
||||
{
|
||||
context_menu_title = title;
|
||||
}
|
||||
/** \} */
|
||||
|
||||
} // namespace blender::ui
|
||||
|
|
|
@ -767,7 +767,7 @@ void file_create_asset_catalog_tree_view_in_layout(asset_system::AssetLibrary *a
|
|||
"asset catalog tree view",
|
||||
std::make_unique<ed::asset_browser::AssetCatalogTreeView>(
|
||||
asset_library, params, *space_file));
|
||||
|
||||
tree_view->set_context_menu_title("Catalog");
|
||||
ui::TreeViewBuilder::build_tree_view(*tree_view, *layout);
|
||||
}
|
||||
|
||||
|
|
|
@ -318,7 +318,7 @@ void spreadsheet_data_set_panel_draw(const bContext *C, Panel *panel)
|
|||
"Data Set Tree View",
|
||||
std::make_unique<GeometryDataSetTreeView>(
|
||||
spreadsheet_get_display_geometry_set(sspreadsheet, object), *C));
|
||||
|
||||
tree_view->set_context_menu_title("Spreadsheet");
|
||||
ui::TreeViewBuilder::build_tree_view(*tree_view, *layout);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
These strings need translation.