[Bf-blender-cvs] [13d24d5124e] asset-browser: Asset Browser: Support custom asset repository paths through Preferences
Julian Eisel
noreply at git.blender.org
Thu Dec 3 01:58:54 CET 2020
Commit: 13d24d5124ebd0be367c882c0a6a18c9c0402124
Author: Julian Eisel
Date: Wed Dec 2 20:51:28 2020 +0100
Branches: asset-browser
https://developer.blender.org/rB13d24d5124ebd0be367c882c0a6a18c9c0402124
Asset Browser: Support custom asset repository paths through Preferences
Idea is simple: In {nav Preferences > File Paths}, you can create custom repositories, give them a name and select a path.
Currently, this has to be a path to a .blend, only .blend files are supported as repositories right now. But directories should be supported as well, see {T82682}.
Differential Revision: https://developer.blender.org/D9722
===================================================================
M release/scripts/startup/bl_ui/space_userpref.py
A source/blender/blenkernel/BKE_preferences.h
M source/blender/blenkernel/CMakeLists.txt
M source/blender/blenkernel/intern/blender.c
M source/blender/blenkernel/intern/blendfile.c
A source/blender/blenkernel/intern/preferences.c
M source/blender/blenloader/intern/readfile.c
M source/blender/blenloader/intern/versioning_userdef.c
M source/blender/blenloader/intern/writefile.c
M source/blender/editors/interface/interface_handlers.c
M source/blender/editors/space_buttons/buttons_ops.c
M source/blender/editors/space_userpref/userpref_ops.c
M source/blender/makesdna/DNA_userdef_types.h
M source/blender/makesrna/RNA_access.h
M source/blender/makesrna/intern/rna_userdef.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 8d73b0a0b93..868e485dde2 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -1335,6 +1335,29 @@ class USERPREF_PT_saveload_autorun(FilePathsPanel, Panel):
row.operator("preferences.autoexec_path_remove", text="", icon='X', emboss=False).index = i
+class USERPREF_PT_file_paths_asset_repositories(FilePathsPanel, Panel):
+ bl_label = "Asset Repositories"
+
+ def draw(self, context):
+ layout = self.layout
+ layout.use_property_split = False
+ layout.use_property_decorate = False
+
+ paths = context.preferences.filepaths
+
+ box = layout.box()
+ for i, repository in enumerate(paths.asset_repositories):
+ row = box.row()
+ split = row.split(factor=0.35)
+ split.prop(repository, "name")
+ split.prop(repository, "path", text="")
+ row.operator("preferences.asset_repository_remove", text="", icon='X', emboss=False).index = i
+
+ row = box.row()
+ row.alignment = 'RIGHT'
+ row.operator("preferences.asset_repository_add", text="", icon='ADD', emboss=False)
+
+
# -----------------------------------------------------------------------------
# Save/Load Panels
@@ -2287,6 +2310,7 @@ classes = (
USERPREF_PT_file_paths_render,
USERPREF_PT_file_paths_applications,
USERPREF_PT_file_paths_development,
+ USERPREF_PT_file_paths_asset_repositories,
USERPREF_PT_saveload_blend,
USERPREF_PT_saveload_blend_autosave,
diff --git a/source/blender/blenkernel/BKE_preferences.h b/source/blender/blenkernel/BKE_preferences.h
new file mode 100644
index 00000000000..116c93c083f
--- /dev/null
+++ b/source/blender/blenkernel/BKE_preferences.h
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+/** \file
+ * \ingroup bke
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "BLI_compiler_attrs.h"
+
+struct UserDef;
+struct bUserAssetRepository;
+
+void BKE_preferences_asset_repository_free(struct bUserAssetRepository *repository) ATTR_NONNULL();
+
+struct bUserAssetRepository *BKE_preferences_asset_repository_add(struct UserDef *userdef,
+ const char *name,
+ const char *path)
+ ATTR_NONNULL(1);
+void BKE_preferences_asset_repository_name_set(struct UserDef *userdef,
+ struct bUserAssetRepository *repository,
+ const char *name) ATTR_NONNULL();
+
+void BKE_preferences_asset_repository_remove(struct UserDef *userdef,
+ struct bUserAssetRepository *repository)
+ ATTR_NONNULL();
+
+struct bUserAssetRepository *BKE_preferences_asset_repository_find_from_index(
+ const struct UserDef *userdef, int index) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+struct bUserAssetRepository *BKE_preferences_asset_repository_find_from_name(
+ const struct UserDef *userdef, const char *name) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+int BKE_preferences_asset_repository_get_index(const struct UserDef *userdef,
+ const struct bUserAssetRepository *repository)
+ ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+
+void BKE_preferences_asset_repository_default_add(struct UserDef *userdef) ATTR_NONNULL();
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 150da8a368a..3e8422397b4 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -212,6 +212,7 @@ set(SRC
intern/pbvh_bmesh.c
intern/pointcache.c
intern/pointcloud.cc
+ intern/preferences.c
intern/report.c
intern/rigidbody.c
intern/scene.c
@@ -370,6 +371,7 @@ set(SRC
BKE_persistent_data_handle.hh
BKE_pointcache.h
BKE_pointcloud.h
+ BKE_preferences.h
BKE_report.h
BKE_rigidbody.h
BKE_scene.h
diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c
index f4f25c3a153..021b1764d5d 100644
--- a/source/blender/blenkernel/intern/blender.c
+++ b/source/blender/blenkernel/intern/blender.c
@@ -296,6 +296,7 @@ void BKE_blender_userdef_data_free(UserDef *userdef, bool clear_fonts)
}
BLI_freelistN(&userdef->autoexec_paths);
+ BLI_freelistN(&userdef->asset_repositories);
BLI_freelistN(&userdef->uistyles);
BLI_freelistN(&userdef->uifonts);
diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c
index 567773507cf..f0f2049d92f 100644
--- a/source/blender/blenkernel/intern/blendfile.c
+++ b/source/blender/blenkernel/intern/blendfile.c
@@ -52,6 +52,7 @@
#include "BKE_layer.h"
#include "BKE_lib_id.h"
#include "BKE_main.h"
+#include "BKE_preferences.h"
#include "BKE_report.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
@@ -645,6 +646,8 @@ UserDef *BKE_blendfile_userdef_from_defaults(void)
/* Default studio light. */
BKE_studiolight_default(userdef->light_param, userdef->light_ambient);
+ BKE_preferences_asset_repository_default_add(userdef);
+
return userdef;
}
diff --git a/source/blender/blenkernel/intern/preferences.c b/source/blender/blenkernel/intern/preferences.c
new file mode 100644
index 00000000000..0e9f514de88
--- /dev/null
+++ b/source/blender/blenkernel/intern/preferences.c
@@ -0,0 +1,121 @@
+/*
+ * 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 bke
+ *
+ * User defined menu API.
+ */
+
+#include <string.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_listbase.h"
+#include "BLI_path_util.h"
+#include "BLI_string.h"
+#include "BLI_string_utf8.h"
+#include "BLI_string_utils.h"
+
+#include "BKE_appdir.h"
+#include "BKE_preferences.h"
+
+#include "BLT_translation.h"
+
+#include "DNA_userdef_types.h"
+
+#define U BLI_STATIC_ASSERT(false, "Global 'U' not allowed, only use arguments passed in!")
+
+/* -------------------------------------------------------------------- */
+/** \name Asset Repositories
+ * \{ */
+
+bUserAssetRepository *BKE_preferences_asset_repository_add(UserDef *userdef,
+ const char *name,
+ const char *path)
+{
+ bUserAssetRepository *repository = MEM_callocN(sizeof(*repository), "bUserAssetRepository");
+
+ BLI_addtail(&userdef->asset_repositories, repository);
+
+ if (name) {
+ BKE_preferences_asset_repository_name_set(userdef, repository, name);
+ }
+ if (path) {
+ BLI_strncpy(repository->path, path, sizeof(repository->path));
+ }
+
+ return repository;
+}
+
+void BKE_preferences_asset_repository_name_set(UserDef *userdef,
+ bUserAssetRepository *repository,
+ const char *name)
+{
+ BLI_strncpy_utf8(repository->name, name, sizeof(repository->name));
+ BLI_uniquename(&userdef->asset_repositories,
+ repository,
+ name,
+ '.',
+ offsetof(bUserAssetRepository, name),
+ sizeof(repository->name));
+}
+
+/**
+ * Unlink and free a repository preference member.
+ * \note Free's \a repository itself.
+ */
+void BKE_preferences_asset_repository_remove(UserDef *userdef, bUserAssetRepository *repository)
+{
+ BLI_freelinkN(&userdef->asset_repositories, repository);
+}
+
+bUserAssetRepository *BKE_preferences_asset_repository_find_from_index(const UserDef *userdef,
+ int index)
+{
+ return BLI_findlink(&userdef->asset_repositories, index);
+}
+
+bUserAssetRepository *BKE_preferences_asset_repository_find_from_name(const UserDef *userdef,
+ const char *name)
+{
+ return BLI_findstring(&userdef->asset_repositories, name, offsetof(bUserAssetRepository, name));
+}
+
+int BKE_preferences_asset_repository_get_index(const UserDef *userdef,
+ const bUserAssetRepository *repository)
+{
+ return BLI_findindex(&userdef->asset_repositories, repository);
+}
+
+void BKE_preferences_asset_repository_default_add(UserDef *userdef)
+{
+ const char *asset_blend_name = "assets.blend";
+ const char *doc_path = BKE_appdir_folder_default();
+
+ /* No home or documents path found, not much we can do. */
+ if (!doc_path || !doc_path[0]) {
+ return;
+ }
+
+ /* Add new "Default" repository under '[doc_path]/assets.blend'. */
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list