Blender V4.5
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
21#include "BKE_asset.hh"
22#include "BKE_preferences.h"
23#include "BKE_screen.hh"
24
25#include "asset_shelf.hh"
26
27using namespace blender;
28using namespace blender::ed::asset;
29
30AssetShelfSettings::AssetShelfSettings() = default;
31
32AssetShelfSettings::AssetShelfSettings(const AssetShelfSettings &other)
33{
34 operator=(other);
35}
36
37AssetShelfSettings &AssetShelfSettings::operator=(const AssetShelfSettings &other)
38{
39 /* Start with a shallow copy. */
40 memcpy(this, &other, sizeof(AssetShelfSettings));
41
44 }
46
47 return *this;
48}
49
50AssetShelfSettings::~AssetShelfSettings()
51{
53 MEM_delete(active_catalog_path);
54}
55
57
65
71
74{
75 MEM_delete(settings.active_catalog_path);
76 settings.active_catalog_path = BLI_strdupn(path.c_str(), path.length());
77}
78
80{
81 MEM_delete(settings.active_catalog_path);
82 settings.active_catalog_path = nullptr;
83}
84
87{
88 return settings.active_catalog_path && settings.active_catalog_path == path.str();
89}
90
92{
93 return !settings.active_catalog_path || !settings.active_catalog_path[0];
94}
95
100
102{
105 &U, shelf.idname);
106 return pref_settings ? &pref_settings->enabled_catalog_paths : nullptr;
107 }
108 return &shelf.settings.enabled_catalog_paths;
109}
110
112{
113 return const_cast<ListBase *>(
114 get_enabled_catalog_path_list(const_cast<const AssetShelf &>(shelf)));
115}
116
118{
119 ListBase *enabled_catalog_paths = get_enabled_catalog_path_list(shelf);
120 if (enabled_catalog_paths) {
121 BKE_asset_catalog_path_list_free(*enabled_catalog_paths);
122 BLI_assert(BLI_listbase_is_empty(enabled_catalog_paths));
123 }
124}
125
128{
129 const ListBase *enabled_catalog_paths = get_enabled_catalog_path_list(shelf);
130 if (!enabled_catalog_paths) {
131 return false;
132 }
133
134 return BKE_asset_catalog_path_list_has_path(*enabled_catalog_paths, path.c_str());
135}
136
139{
142 &U, shelf.idname, path.c_str()))
143 {
144 U.runtime.is_dirty = true;
145 }
146 }
147 else {
148 if (!BKE_asset_catalog_path_list_has_path(shelf.settings.enabled_catalog_paths, path.c_str()))
149 {
150 BKE_asset_catalog_path_list_add_path(shelf.settings.enabled_catalog_paths, path.c_str());
151 }
152 }
153}
154
156 const AssetShelf &shelf,
157 FunctionRef<void(const asset_system::AssetCatalogPath &catalog_path)> fn)
158{
159 const ListBase *enabled_catalog_paths = get_enabled_catalog_path_list(shelf);
160 if (!enabled_catalog_paths) {
161 return;
162 }
163
164 LISTBASE_FOREACH (const AssetCatalogPathLink *, path_link, enabled_catalog_paths) {
165 fn(asset_system::AssetCatalogPath(path_link->path));
166 }
167}
168
169} // 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 BLO_write_struct(writer, struct_name, data_ptr)
void BLO_read_string(BlendDataReader *reader, char **ptr_p)
Definition readfile.cc:5351
void BLO_write_string(BlendWriter *writer, const char *data_ptr)
struct AssetShelfSettings AssetShelfSettings
#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)
const char * active_catalog_path