Blender V4.3
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
11#include <type_traits>
12
14
15#include "DNA_screen_types.h"
16
17#include "BLO_read_write.hh"
18
19#include "BLI_listbase.h"
20#include "BLI_string.h"
21#include "BLI_string_ref.hh"
22
23#include "BKE_asset.hh"
24#include "BKE_preferences.h"
25#include "BKE_screen.hh"
26
27#include "asset_shelf.hh"
28
29using namespace blender;
30using namespace blender::ed::asset;
31
32AssetShelfSettings::AssetShelfSettings()
33{
34 memset(this, 0, sizeof(*this));
35}
36
37AssetShelfSettings::AssetShelfSettings(const AssetShelfSettings &other)
38{
39 operator=(other);
40}
41
42AssetShelfSettings &AssetShelfSettings::operator=(const AssetShelfSettings &other)
43{
44 /* Start with a shallow copy. */
45 memcpy(this, &other, sizeof(AssetShelfSettings));
46
47 next = prev = nullptr;
48
50 active_catalog_path = BLI_strdup(other.active_catalog_path);
51 }
53
54 return *this;
55}
56
57AssetShelfSettings::~AssetShelfSettings()
58{
60 MEM_delete(active_catalog_path);
61}
62
64
66{
67 BLO_write_struct(writer, AssetShelfSettings, &settings);
68
69 BKE_asset_catalog_path_list_blend_write(writer, settings.enabled_catalog_paths);
70 BLO_write_string(writer, settings.active_catalog_path);
71}
72
74{
75 BKE_asset_catalog_path_list_blend_read_data(reader, settings.enabled_catalog_paths);
76 BLO_read_string(reader, &settings.active_catalog_path);
77}
78
81{
82 MEM_delete(settings.active_catalog_path);
83 settings.active_catalog_path = BLI_strdupn(path.c_str(), path.length());
84}
85
87{
88 MEM_delete(settings.active_catalog_path);
89 settings.active_catalog_path = nullptr;
90}
91
94{
95 return settings.active_catalog_path && settings.active_catalog_path == path.str();
96}
97
99{
100 return !settings.active_catalog_path || !settings.active_catalog_path[0];
101}
102
104{
106}
107
109{
112 &U, shelf.idname);
113 return pref_settings ? &pref_settings->enabled_catalog_paths : nullptr;
114 }
115 return &shelf.settings.enabled_catalog_paths;
116}
117
119{
120 return const_cast<ListBase *>(
121 get_enabled_catalog_path_list(const_cast<const AssetShelf &>(shelf)));
122}
123
125{
126 ListBase *enabled_catalog_paths = get_enabled_catalog_path_list(shelf);
127 if (enabled_catalog_paths) {
128 BKE_asset_catalog_path_list_free(*enabled_catalog_paths);
129 BLI_assert(BLI_listbase_is_empty(enabled_catalog_paths));
130 }
131}
132
135{
136 const ListBase *enabled_catalog_paths = get_enabled_catalog_path_list(shelf);
137 if (!enabled_catalog_paths) {
138 return false;
139 }
140
141 return BKE_asset_catalog_path_list_has_path(*enabled_catalog_paths, path.c_str());
142}
143
146{
149 &U, shelf.idname, path.c_str()))
150 {
151 U.runtime.is_dirty = true;
152 }
153 }
154 else {
156 {
158 }
159 }
160}
161
163 const AssetShelf &shelf,
164 FunctionRef<void(const asset_system::AssetCatalogPath &catalog_path)> fn)
165{
166 const ListBase *enabled_catalog_paths = get_enabled_catalog_path_list(shelf);
167 if (!enabled_catalog_paths) {
168 return;
169 }
170
171 LISTBASE_FOREACH (const AssetCatalogPathLink *, path_link, enabled_catalog_paths) {
172 fn(asset_system::AssetCatalogPath(path_link->path));
173 }
174}
175
176} // 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:50
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
#define LISTBASE_FOREACH(type, var, list)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
Definition string.c:40
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition string.c:29
#define BLO_write_struct(writer, struct_name, data_ptr)
void BLO_read_string(BlendDataReader *reader, char **ptr_p)
Definition readfile.cc:4992
void BLO_write_string(BlendWriter *writer, const char *data_ptr)
btGeneric6DofConstraint & operator=(btGeneric6DofConstraint &other)
unsigned int U
Definition btGjkEpa3.h:78
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)
struct AssetShelfSettings * prev
struct AssetShelfSettings * next
const char * active_catalog_path
AssetShelfTypeFlag flag
struct AssetShelfType * type
AssetShelfSettings settings