Blender V5.0
asset_shelf_settings.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
12
13#include "DNA_screen_types.h"
14#include "DNA_userdef_types.h"
15
16#include "BLO_read_write.hh"
17
18#include "BLI_listbase.h"
19#include "BLI_string.h"
20#include "BLI_string_utf8.h"
21
22#include "BKE_asset.hh"
23#include "BKE_preferences.h"
24#include "BKE_screen.hh"
25
26#include "asset_shelf.hh"
27
28using namespace blender;
29using namespace blender::ed::asset;
30
31AssetShelfSettings::AssetShelfSettings() = default;
32
33AssetShelfSettings::AssetShelfSettings(const AssetShelfSettings &other)
34{
35 operator=(other);
36}
37
38AssetShelfSettings &AssetShelfSettings::operator=(const AssetShelfSettings &other)
39{
40 if (this == &other) {
41 return *this; /* Handle self-assignment safely. */
42 }
43
44 /* Free existing properties. Check if they point to the same memory first, #AssetShelfSettings
45 * might have been shallow copied before. */
48 }
49 if (this->active_catalog_path != other.active_catalog_path) {
51 }
52
53 /* Copy from 'other'. */
56 this->preview_size = other.preview_size;
57 this->display_flag = other.display_flag;
58
59 if (other.active_catalog_path) {
61 }
63
64 return *this;
65}
66
67AssetShelfSettings::~AssetShelfSettings()
68{
71}
72
74
82
88
91{
92 MEM_delete(settings.active_catalog_path);
93 settings.active_catalog_path = BLI_strdupn(path.c_str(), path.length());
94}
95
97{
98 MEM_delete(settings.active_catalog_path);
99 settings.active_catalog_path = nullptr;
100}
101
104{
105 return settings.active_catalog_path && settings.active_catalog_path == path.str();
106}
107
109{
110 return !settings.active_catalog_path || !settings.active_catalog_path[0];
111}
112
114{
115 return shelf.type && (shelf.type->flag & ASSET_SHELF_TYPE_FLAG_STORE_CATALOGS_IN_PREFS);
116}
117
119{
122 &U, shelf.idname);
123 return pref_settings ? &pref_settings->enabled_catalog_paths : nullptr;
124 }
125 return &shelf.settings.enabled_catalog_paths;
126}
127
129{
130 return const_cast<ListBase *>(
131 get_enabled_catalog_path_list(const_cast<const AssetShelf &>(shelf)));
132}
133
135{
136 ListBase *enabled_catalog_paths = get_enabled_catalog_path_list(shelf);
137 if (enabled_catalog_paths) {
138 BKE_asset_catalog_path_list_free(*enabled_catalog_paths);
139 BLI_assert(BLI_listbase_is_empty(enabled_catalog_paths));
140 }
141}
142
145{
146 const ListBase *enabled_catalog_paths = get_enabled_catalog_path_list(shelf);
147 if (!enabled_catalog_paths) {
148 return false;
149 }
150
151 return BKE_asset_catalog_path_list_has_path(*enabled_catalog_paths, path.c_str());
152}
153
156{
159 &U, shelf.idname, path.c_str()))
160 {
161 U.runtime.is_dirty = true;
162 }
163 }
164 else {
165 if (!BKE_asset_catalog_path_list_has_path(shelf.settings.enabled_catalog_paths, path.c_str()))
166 {
167 BKE_asset_catalog_path_list_add_path(shelf.settings.enabled_catalog_paths, path.c_str());
168 }
169 }
170}
171
173 const AssetShelf &shelf,
174 FunctionRef<void(const asset_system::AssetCatalogPath &catalog_path)> fn)
175{
176 const ListBase *enabled_catalog_paths = get_enabled_catalog_path_list(shelf);
177 if (!enabled_catalog_paths) {
178 return;
179 }
180
181 LISTBASE_FOREACH (const AssetCatalogPathLink *, path_link, enabled_catalog_paths) {
182 fn(asset_system::AssetCatalogPath(path_link->path));
183 }
184}
185
186} // namespace blender::ed::asset::shelf
void BKE_asset_catalog_path_list_free(ListBase &catalog_path_list)
ListBase BKE_asset_catalog_path_list_duplicate(const ListBase &catalog_path_list)
void BKE_asset_catalog_path_list_blend_write(BlendWriter *writer, const ListBase &catalog_path_list)
bool BKE_asset_catalog_path_list_has_path(const ListBase &catalog_path_list, const char *catalog_path)
void BKE_asset_catalog_path_list_blend_read_data(BlendDataReader *reader, ListBase &catalog_path_list)
void BKE_asset_catalog_path_list_add_path(ListBase &catalog_path_list, const char *catalog_path)
bUserAssetShelfSettings * BKE_preferences_asset_shelf_settings_get(const UserDef *userdef, const char *shelf_idname)
bool BKE_preferences_asset_shelf_settings_ensure_catalog_path_enabled(UserDef *userdef, const char *shelf_idname, const char *catalog_path)
@ ASSET_SHELF_TYPE_FLAG_STORE_CATALOGS_IN_PREFS
#define BLI_assert(a)
Definition BLI_assert.h:46
#define LISTBASE_FOREACH(type, var, list)
BLI_INLINE bool BLI_listbase_is_empty(const ListBase *lb)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
Definition string.cc:41
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition string.cc:30
#define STRNCPY_UTF8(dst, src)
#define BLO_write_struct(writer, struct_name, data_ptr)
void BLO_read_string(BlendDataReader *reader, char **ptr_p)
Definition readfile.cc:5828
void BLO_write_string(BlendWriter *writer, const char *data_ptr)
#define MEM_SAFE_FREE(v)
#define U
btGeneric6DofConstraint & operator=(btGeneric6DofConstraint &other)
void settings_clear_enabled_catalogs(AssetShelf &shelf)
static bool use_enabled_catalogs_from_prefs(const AssetShelf &shelf)
bool settings_is_all_catalog_active(const AssetShelfSettings &settings)
void settings_blend_read_data(BlendDataReader *reader, AssetShelfSettings &settings)
void settings_foreach_enabled_catalog_path(const AssetShelf &shelf, FunctionRef< void(const asset_system::AssetCatalogPath &catalog_path)> fn)
static const ListBase * get_enabled_catalog_path_list(const AssetShelf &shelf)
void settings_set_all_catalog_active(AssetShelfSettings &settings)
bool settings_is_catalog_path_enabled(const AssetShelf &shelf, const asset_system::AssetCatalogPath &path)
bool settings_is_active_catalog(const AssetShelfSettings &settings, const asset_system::AssetCatalogPath &path)
void settings_set_catalog_path_enabled(AssetShelf &shelf, const asset_system::AssetCatalogPath &path)
void settings_blend_write(BlendWriter *writer, const AssetShelfSettings &settings)
void settings_set_active_catalog(AssetShelfSettings &settings, const asset_system::AssetCatalogPath &path)
AssetLibraryReference asset_library_reference
const char * active_catalog_path