UI: Add a context argument to tree view item rename functions. #111522

Merged
Lukas Tönne merged 1 commits from LukasTonne/blender:context_for_tree_view_rename into main 2023-08-25 16:00:12 +02:00
6 changed files with 14 additions and 14 deletions

View File

@ -188,7 +188,7 @@ class AbstractViewItem {
*
* \return True if the renaming was successful.
*/
virtual bool rename(StringRefNull new_name);
virtual bool rename(const bContext &C, StringRefNull new_name);
/**
* Get the string that should be used for renaming, typically the item's label. This string will
* not be modified, but if the renaming is canceled, the value will be reset to this.
@ -249,7 +249,7 @@ class AbstractViewItem {
bool is_renaming() const;
void begin_renaming();
void end_renaming();
void rename_apply();
void rename_apply(const bContext &C);
template<typename ToType = AbstractViewItem>
static ToType *from_item_handle(uiViewItemHandle *handle);

View File

@ -207,7 +207,7 @@ class AbstractTreeViewItem : public AbstractViewItem, public TreeViewItemContain
/** See AbstractViewItem::get_rename_string(). */
/* virtual */ StringRef get_rename_string() const override;
/** See AbstractViewItem::rename(). */
/* virtual */ bool rename(StringRefNull new_name) override;
/* virtual */ bool rename(const bContext &C, StringRefNull new_name) override;
/**
* Return whether the item can be collapsed. Used to disable collapsing for items with children.

View File

@ -200,7 +200,7 @@ class LayerViewItem : public AbstractTreeViewItem {
return true;
}
bool rename(StringRefNull new_name) override
bool rename(const bContext & /*C*/, StringRefNull new_name) override
{
grease_pencil_.rename_node(layer_.as_node(), new_name);
return true;
@ -309,7 +309,7 @@ class LayerGroupViewItem : public AbstractTreeViewItem {
return true;
}
bool rename(StringRefNull new_name) override
bool rename(const bContext & /*C*/, StringRefNull new_name) override
{
grease_pencil_.rename_node(group_.as_node(), new_name);
return true;

View File

@ -106,7 +106,7 @@ bool AbstractViewItem::supports_renaming() const
/* No renaming by default. */
return false;
}
bool AbstractViewItem::rename(StringRefNull /*new_name*/)
bool AbstractViewItem::rename(const bContext & /*C*/, StringRefNull /*new_name*/)
{
/* No renaming by default. */
return false;
@ -138,10 +138,10 @@ void AbstractViewItem::begin_renaming()
std::copy(std::begin(initial_str), std::end(initial_str), std::begin(view.get_rename_buffer()));
}
void AbstractViewItem::rename_apply()
void AbstractViewItem::rename_apply(const bContext &C)
{
const AbstractView &view = get_view();
rename(view.get_rename_buffer().data());
rename(C, view.get_rename_buffer().data());
end_renaming();
}
@ -179,12 +179,12 @@ static AbstractViewItem *find_item_from_rename_button(const uiBut &rename_but)
return nullptr;
}
static void rename_button_fn(bContext * /*C*/, void *arg, char * /*origstr*/)
static void rename_button_fn(bContext *C, void *arg, char * /*origstr*/)
{
const uiBut *rename_but = static_cast<uiBut *>(arg);
AbstractViewItem *item = find_item_from_rename_button(*rename_but);
BLI_assert(item);
item->rename_apply();
item->rename_apply(*C);
}
void AbstractViewItem::add_rename_button(uiBlock &block)

View File

@ -410,7 +410,7 @@ StringRef AbstractTreeViewItem::get_rename_string() const
return label_;
}
bool AbstractTreeViewItem::rename(StringRefNull new_name)
bool AbstractTreeViewItem::rename(const bContext & /*C*/, StringRefNull new_name)
{
/* It is important to update the label after renaming, so #AbstractTreeViewItem::matches_single()
* recognizes the item. (It only compares labels by default.) */

View File

@ -87,7 +87,7 @@ class AssetCatalogTreeViewItem : public ui::BasicTreeViewItem {
void build_context_menu(bContext &C, uiLayout &column) const override;
bool supports_renaming() const override;
bool rename(StringRefNull new_name) override;
bool rename(const bContext &C, StringRefNull new_name) override;
/** Add drag support for catalog items. */
std::unique_ptr<ui::AbstractViewItemDragController> create_drag_controller() const override;
@ -330,10 +330,10 @@ bool AssetCatalogTreeViewItem::supports_renaming() const
return !ED_asset_catalogs_read_only(*tree_view.asset_library_);
}
bool AssetCatalogTreeViewItem::rename(StringRefNull new_name)
bool AssetCatalogTreeViewItem::rename(const bContext &C, StringRefNull new_name)
{
/* Important to keep state. */
BasicTreeViewItem::rename(new_name);
BasicTreeViewItem::rename(C, new_name);
const AssetCatalogTreeView &tree_view = static_cast<const AssetCatalogTreeView &>(
get_tree_view());