Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2021-10-06 15:18:12 +0300
committerJulian Eisel <julian@blender.org>2021-10-06 15:25:26 +0300
commit539575b585a018eabda9137d724967692433165a (patch)
tree81cbc66ac926dcf2b02f3784c6e3a7aa66f94d66 /source/blender/editors/space_file
parent335f40ebfa28d36d0e4c3c562eb572554282a3ff (diff)
Assets: Support Renaming Catalogs in the UI
Catalogs can now be renamed by double clicking them in the Asset Browser. This is mostly done through the tree-view API, the asset specific code is very little. There is some polish left to be done here, e.g. the double click currently also collapses/uncollapses and activates the clicked item. And the rename button takes the full width of the row. But addressing these is better done as part of some other behavioral changes that are planned anyway.
Diffstat (limited to 'source/blender/editors/space_file')
-rw-r--r--source/blender/editors/space_file/asset_catalog_tree_view.cc26
1 files changed, 25 insertions, 1 deletions
diff --git a/source/blender/editors/space_file/asset_catalog_tree_view.cc b/source/blender/editors/space_file/asset_catalog_tree_view.cc
index 291582dac08..85912268286 100644
--- a/source/blender/editors/space_file/asset_catalog_tree_view.cc
+++ b/source/blender/editors/space_file/asset_catalog_tree_view.cc
@@ -52,6 +52,7 @@ using namespace blender::bke;
namespace blender::ed::asset_browser {
class AssetCatalogTreeView : public ui::AbstractTreeView {
+ bke::AssetCatalogService *catalog_service_;
/** The asset catalog tree this tree-view represents. */
bke::AssetCatalogTree *catalog_tree_;
FileAssetSelectParams *params_;
@@ -99,6 +100,9 @@ class AssetCatalogTreeViewItem : public ui::BasicTreeViewItem {
const wmDrag &drag,
const wmEvent &event) const override;
bool on_drop(const wmDrag &drag) override;
+
+ bool can_rename() const override;
+ bool rename(StringRefNull new_name) override;
};
/** Only reason this isn't just `BasicTreeViewItem` is to add a '+' icon for adding a root level
@@ -124,7 +128,8 @@ class AssetCatalogTreeViewUnassignedItem : public ui::BasicTreeViewItem {
AssetCatalogTreeView::AssetCatalogTreeView(::AssetLibrary *library,
FileAssetSelectParams *params,
SpaceFile &space_file)
- : catalog_tree_(BKE_asset_library_get_catalog_tree(library)),
+ : catalog_service_(BKE_asset_library_get_catalog_service(library)),
+ catalog_tree_(BKE_asset_library_get_catalog_tree(library)),
params_(params),
space_file_(space_file)
{
@@ -309,6 +314,25 @@ bool AssetCatalogTreeViewItem::on_drop(const wmDrag &drag)
tree_view, drag, catalog_item_.get_catalog_id(), catalog_item_.get_simple_name());
}
+bool AssetCatalogTreeViewItem::can_rename() const
+{
+ return true;
+}
+
+bool AssetCatalogTreeViewItem::rename(StringRefNull new_name)
+{
+ /* Important to keep state. */
+ BasicTreeViewItem::rename(new_name);
+
+ const AssetCatalogTreeView &tree_view = static_cast<const AssetCatalogTreeView &>(
+ get_tree_view());
+
+ AssetCatalogPath new_path = catalog_item_.catalog_path().parent();
+ new_path = new_path / StringRef(new_name);
+ tree_view.catalog_service_->update_catalog_path(catalog_item_.get_catalog_id(), new_path);
+ return true;
+}
+
/* ---------------------------------------------------------------------- */
void AssetCatalogTreeViewAllItem::build_row(uiLayout &row)