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-09-29 18:01:13 +0300
committerJulian Eisel <julian@blender.org>2021-09-29 18:15:23 +0300
commit9d9f205dc4a9ddae3d654c64894eaca8443cacc0 (patch)
treeb41b40fe69987849bb02415ddcd63d465df10501 /source/blender/editors/asset
parentdf9120b365380cc1d64006e0d37a650eaaff9776 (diff)
Asset Browser: Initial Asset Catalog UI
The Asset Browser now displays a tree with asset catalogs in the left sidebar. This replaces the asset categories. It uses the new UI tree-view API (https://wiki.blender.org/wiki/Source/Interface/Views#Tree-View). Buttons are displayed for adding and removing of catalogs. Parent items can be collapsed, but the collapsed/uncollapsed state is not stored in files yet. Note that edits to catalogs (e.g. new or removed catalogs) are only written to the asset library's catalog definition files when saving a .blend. In the "Current File" asset library, we try to show asset catalogs from a parent asset library, or if that fails, from the directory the file is stored in. See adaf4f56e1ed. There are plenty of TODOs and smaller glitches to be fixed still. Plus a UI polishing pass should be done. Important missing UI features: * Dragging assets into catalogs (WIP, close to being ready). * Renaming catalogs * Proper handling of catalogs in the "Current File" asset library (currently not working well). The "Current File" asset library is especially limited still. Since this is the only place where you can assign assets to a catalog, this makes the catalogs very cumbersome in general. To assign an asset to a catalog, one has to manually copy the Catalog ID (a random hash like number) to the asset metadata through a temporary UI in the Asset Browser Sidebar. These limitations should be addressed over the next few days, they are high priority. Differential Revision: https://developer.blender.org/D12670
Diffstat (limited to 'source/blender/editors/asset')
-rw-r--r--source/blender/editors/asset/CMakeLists.txt2
-rw-r--r--source/blender/editors/asset/ED_asset_catalog.hh35
-rw-r--r--source/blender/editors/asset/intern/asset_catalog.cc87
-rw-r--r--source/blender/editors/asset/intern/asset_ops.cc88
4 files changed, 212 insertions, 0 deletions
diff --git a/source/blender/editors/asset/CMakeLists.txt b/source/blender/editors/asset/CMakeLists.txt
index 31c07580570..b6657bfca63 100644
--- a/source/blender/editors/asset/CMakeLists.txt
+++ b/source/blender/editors/asset/CMakeLists.txt
@@ -31,6 +31,7 @@ set(INC_SYS
)
set(SRC
+ intern/asset_catalog.cc
intern/asset_filter.cc
intern/asset_handle.cc
intern/asset_library_reference.cc
@@ -40,6 +41,7 @@ set(SRC
intern/asset_ops.cc
intern/asset_temp_id_consumer.cc
+ ED_asset_catalog.hh
ED_asset_filter.h
ED_asset_handle.h
ED_asset_library.h
diff --git a/source/blender/editors/asset/ED_asset_catalog.hh b/source/blender/editors/asset/ED_asset_catalog.hh
new file mode 100644
index 00000000000..cffd7728a60
--- /dev/null
+++ b/source/blender/editors/asset/ED_asset_catalog.hh
@@ -0,0 +1,35 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup edasset
+ */
+
+#pragma once
+
+#include "BKE_asset_catalog.hh"
+
+#include "BLI_string_ref.hh"
+
+struct AssetLibrary;
+namespace blender::bke {
+class AssetCatalog;
+} // namespace blender::bke
+
+blender::bke::AssetCatalog *ED_asset_catalog_add(AssetLibrary *library,
+ blender::StringRefNull name,
+ blender::StringRef parent_path = nullptr);
+void ED_asset_catalog_remove(AssetLibrary *library, const blender::bke::CatalogID &catalog_id);
diff --git a/source/blender/editors/asset/intern/asset_catalog.cc b/source/blender/editors/asset/intern/asset_catalog.cc
new file mode 100644
index 00000000000..202d4234051
--- /dev/null
+++ b/source/blender/editors/asset/intern/asset_catalog.cc
@@ -0,0 +1,87 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup edasset
+ */
+
+#include "BKE_asset_catalog.hh"
+#include "BKE_asset_library.hh"
+
+#include "BLI_string_utils.h"
+
+#include "ED_asset_catalog.hh"
+
+using namespace blender;
+using namespace blender::bke;
+
+struct CatalogUniqueNameFnData {
+ const AssetCatalogService &catalog_service;
+ StringRef parent_path;
+};
+
+static std::string to_full_path(StringRef parent_path, StringRef name)
+{
+ return parent_path.is_empty() ?
+ std::string(name) :
+ std::string(parent_path) + AssetCatalogService::PATH_SEPARATOR + name;
+}
+
+static bool catalog_name_exists_fn(void *arg, const char *name)
+{
+ CatalogUniqueNameFnData &fn_data = *static_cast<CatalogUniqueNameFnData *>(arg);
+ std::string fullpath = to_full_path(fn_data.parent_path, name);
+ return fn_data.catalog_service.find_catalog_by_path(fullpath);
+}
+
+static std::string catalog_name_ensure_unique(AssetCatalogService &catalog_service,
+ StringRefNull name,
+ StringRef parent_path)
+{
+ CatalogUniqueNameFnData fn_data = {catalog_service, parent_path};
+
+ char unique_name[NAME_MAX] = "";
+ BLI_uniquename_cb(
+ catalog_name_exists_fn, &fn_data, name.c_str(), '.', unique_name, sizeof(unique_name));
+
+ return unique_name;
+}
+
+AssetCatalog *ED_asset_catalog_add(::AssetLibrary *library,
+ StringRefNull name,
+ StringRef parent_path)
+{
+ bke::AssetCatalogService *catalog_service = BKE_asset_library_get_catalog_service(library);
+ if (!catalog_service) {
+ return nullptr;
+ }
+
+ std::string unique_name = catalog_name_ensure_unique(*catalog_service, name, parent_path);
+ std::string fullpath = to_full_path(parent_path, unique_name);
+
+ return catalog_service->create_catalog(fullpath);
+}
+
+void ED_asset_catalog_remove(::AssetLibrary *library, const CatalogID &catalog_id)
+{
+ bke::AssetCatalogService *catalog_service = BKE_asset_library_get_catalog_service(library);
+ if (!catalog_service) {
+ BLI_assert_unreachable();
+ return;
+ }
+
+ catalog_service->delete_catalog(catalog_id);
+}
diff --git a/source/blender/editors/asset/intern/asset_ops.cc b/source/blender/editors/asset/intern/asset_ops.cc
index a18b7649060..5424bae77b4 100644
--- a/source/blender/editors/asset/intern/asset_ops.cc
+++ b/source/blender/editors/asset/intern/asset_ops.cc
@@ -18,13 +18,18 @@
* \ingroup edasset
*/
+#include "BKE_asset_catalog.hh"
#include "BKE_context.h"
#include "BKE_lib_id.h"
#include "BKE_report.h"
+#include "BLI_string_ref.hh"
#include "BLI_vector.hh"
#include "ED_asset.h"
+#include "ED_asset_catalog.hh"
+/* XXX needs access to the file list, should all be done via the asset system in future. */
+#include "ED_fileselect.h"
#include "RNA_access.h"
#include "RNA_define.h"
@@ -32,6 +37,8 @@
#include "WM_api.h"
#include "WM_types.h"
+using namespace blender;
+
/* -------------------------------------------------------------------- */
using PointerRNAVec = blender::Vector<PointerRNA>;
@@ -372,10 +379,91 @@ static void ASSET_OT_list_refresh(struct wmOperatorType *ot)
/* -------------------------------------------------------------------- */
+static bool asset_catalog_operator_poll(bContext *C)
+{
+ const SpaceFile *sfile = CTX_wm_space_file(C);
+ return asset_operation_poll(C) && sfile && ED_fileselect_active_asset_library_get(sfile);
+}
+
+static int asset_catalog_new_exec(bContext *C, wmOperator *op)
+{
+ SpaceFile *sfile = CTX_wm_space_file(C);
+ struct AssetLibrary *asset_library = ED_fileselect_active_asset_library_get(sfile);
+ char *parent_path = RNA_string_get_alloc(op->ptr, "parent_path", nullptr, 0, nullptr);
+
+ ED_asset_catalog_add(asset_library, "Catalog", parent_path);
+
+ MEM_freeN(parent_path);
+
+ WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr);
+
+ return OPERATOR_FINISHED;
+}
+
+static void ASSET_OT_catalog_new(struct wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "New Asset Catalog";
+ ot->description = "Create a new catalog to put assets in";
+ ot->idname = "ASSET_OT_catalog_new";
+
+ /* api callbacks */
+ ot->exec = asset_catalog_new_exec;
+ ot->poll = asset_catalog_operator_poll;
+
+ RNA_def_string(ot->srna,
+ "parent_path",
+ nullptr,
+ 0,
+ "Parent Path",
+ "Optional path defining the location to put the new catalog under");
+}
+
+static int asset_catalog_delete_exec(bContext *C, wmOperator *op)
+{
+ SpaceFile *sfile = CTX_wm_space_file(C);
+ struct AssetLibrary *asset_library = ED_fileselect_active_asset_library_get(sfile);
+ char *catalog_id_str = RNA_string_get_alloc(op->ptr, "catalog_id", nullptr, 0, nullptr);
+ bke::CatalogID catalog_id;
+ if (!BLI_uuid_parse_string(&catalog_id, catalog_id_str)) {
+ return OPERATOR_CANCELLED;
+ }
+
+ ED_asset_catalog_remove(asset_library, catalog_id);
+
+ MEM_freeN(catalog_id_str);
+
+ WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr);
+
+ return OPERATOR_FINISHED;
+}
+
+static void ASSET_OT_catalog_delete(struct wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Delete Asset Catalog";
+ ot->description =
+ "Remove an asset catalog from the asset library (contained assets will not be affected and "
+ "show up as unassigned)";
+ ot->idname = "ASSET_OT_catalog_delete";
+
+ /* api callbacks */
+ ot->exec = asset_catalog_delete_exec;
+ ot->invoke = WM_operator_confirm;
+ ot->poll = asset_catalog_operator_poll;
+
+ RNA_def_string(ot->srna, "catalog_id", nullptr, 0, "Catalog ID", "ID of the catalog to delete");
+}
+
+/* -------------------------------------------------------------------- */
+
void ED_operatortypes_asset(void)
{
WM_operatortype_append(ASSET_OT_mark);
WM_operatortype_append(ASSET_OT_clear);
+ WM_operatortype_append(ASSET_OT_catalog_new);
+ WM_operatortype_append(ASSET_OT_catalog_delete);
+
WM_operatortype_append(ASSET_OT_list_refresh);
}