11#include <shared_mutex>
53 static std::optional<bke::BlenderProject>
project;
66 static std::shared_mutex project_mutex;
96 prop_template.
f = 0.0f;
110 this->
prop() = *tmp_property;
123 this->
prop() = other.prop();
129 if (
this != &other) {
131 this->
prop() = other.prop();
189 if (this->
ui_data->description ==
nullptr) {
197 MEM_delete(this->
ui_data->description);
198 this->
ui_data->description = MEM_new_array<char>(description.
size() + 1,
199 "ProjectVariable description");
216 this->root_path_ = root_path;
223 this->ocio_config_path_ = ocio_config_path;
230 this->splash_image_path_ = splash_image_path;
258 if (var ==
nullptr) {
262 for (
int i : this->
variables.index_range()) {
275 this->
variables.append(std::make_unique<ProjectVariable>(
"", type));
308 if (from_index == to_index) {
312 if (from_index < to_index) {
313 std::rotate(this->
variables.data() + from_index,
314 this->variables.data() + from_index + 1,
315 this->variables.data() + to_index + 1);
317 else if (from_index > to_index) {
318 std::rotate(this->
variables.data() + to_index,
319 this->variables.data() + from_index,
320 this->variables.data() + from_index + 1);
329 if (variable_index < 0 || variable_index >= this->
variables.size()) {
335 auto is_variable_name_used = [&](
StringRef name) ->
bool {
336 for (
int i = 0; i < this->
variables.size(); i++) {
337 if (i == variable_index) {
342 if (this->
variables[i]->name_get() == name) {
350 this->
variables[variable_index]->prop().name[0] =
'\0';
354 this->variables[variable_index]->prop().name,
377 std::string new_name(name);
380 if (new_name.size() == 0) {
381 new_name.push_back(
'_');
385 if (new_name[0] >=
'0' && new_name[0] <=
'9') {
397 for (
int i = 0; i < new_name.size(); i++) {
398 const char c = new_name[i];
399 const bool is_valid_identifier_char = (c >=
'a' && c <=
'z') || (c >=
'A' && c <=
'Z') ||
400 (c >=
'0' && c <=
'9') || c ==
'_';
401 if (!is_valid_identifier_char) {
420 STRNCPY(project_root_path, path);
423 bool found_project =
false;
424 char project_root_path_test[
FILE_MAX];
430 STRNCPY(project_root_path_test, project_root_path);
432 found_project =
BLI_is_dir(project_root_path_test);
440 return project_root_path;
473 project->set_root_path(root_path);
481 if (!bmain || !filepath[0]) {
486 if (new_root_path.empty()) {
493 if (
project !=
nullptr && new_root_path ==
project->get_root_path()) {
509 for (
auto &user_library :
U.asset_libraries.items_mutable()) {
524 const bool path_is_template,
527 const std::string path_str = path;
528 const std::string path_escaped = path_is_template ? path_str :
538 std::string(
project.get_root_path());
540 const bool walk_up =
false;
543 path_str.c_str(), root.c_str(), walk_up, path_relative,
sizeof(path_relative)))
547 if (path_relative[0] ==
'\0') {
548 return "{project_root}";
553 const std::string path_relative_escaped = path_is_template ?
554 std::string(path_relative) :
556 return "{project_root}/" + path_relative_escaped;
577 return path_expanded;
584 return BLI_is_dir(project_config_dir.c_str());
599 for (
const auto &item :
recents::Section(
"project").get<RecentProjectsTOML>(
"recent")) {
600 const auto path = item.find(
"path");
601 if (path == item.end() || path->second.empty()) {
604 const auto name = item.find(
"name");
605 projects.
append({path->second,
606 (name != item.end() && !name->second.empty()) ?
617 items.push_back({{
"name",
project.name}, {
"path",
project.path}});
622 section.
set(
"recent", items);
648 projects.
insert(0, *active);
650 if (projects.
size() >
U.recent_files) {
651 projects.
resize(
U.recent_files);
#define BLENDER_PROJECT_CONFIG_DIR
#define IDP_float_get(prop)
#define IDP_int_get(prop)
#define IDP_int_set(prop, value)
#define IDP_string_get(prop)
#define IDP_float_set(prop, value)
Functions and classes for evaluating template expressions in filepaths.
File and directory operations.
constexpr const char * c_str() const
constexpr StringRefNull()
int64_t remove_if(Predicate &&predicate)
void append(const T &value)
void insert(const int64_t insert_index, const T &value)
void resize(const int64_t new_size)
void set_root_path(StringRef root_path)
void rename_variable(int variable_index, StringRef name)
StringRefNull get_splash_image_path() const
void set_splash_image_path(StringRef splash_image_path)
Vector< std::unique_ptr< ProjectVariable > > variables
StringRefNull get_root_path() const
int find_variable_index(ProjectVariable *var)
StringRefNull get_ocio_config_path() const
int active_variable_index
void move_variable(int from_index, int to_index)
void set_ocio_config_path(StringRef ocio_config_path)
StringRefNull get_name() const
ProjectVariable * new_variable(StringRef name, ProjectVariableType type)
void set_name(StringRef name)
int remove_variable(ProjectVariable *var)
void string_subtype_set(ProjectVariableStringSubtype type)
ProjectVariable & operator=(const ProjectVariable &other)=delete
void description_set(StringRef description)
ProjectVariable(StringRef name, ProjectVariableType type)
StringRefNull description_get() const
float value_float_get() const
void value_set(StringRefNull value)
StringRefNull value_string_get() const
ProjectVariableStringSubtype string_subtype_get() const
ProjectVariableType type_get() const
StringRefNull name_get() const
int value_int_get() const
constexpr bool is_empty() const
constexpr int64_t size() const
void copy_unsafe(char *dst) const
void copy_utf8_truncated(char *dst, int64_t dst_size) const
T get(const std::string &item_key) const
void set(const std::string &item_key, const T &value)
void with_blender_project_write_lock(FunctionRef< void()> lambda)
std::string ensure_is_valid_project_variable_name(StringRef name)
void with_blender_project_read_lock(FunctionRef< void()> lambda)
bool is_valid_project_variable_name(StringRef name)
ProjectVariableStringSubtype
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static std::shared_mutex & get_project_mutex()
char * STRNCPY(char(&dst)[N], const char *src)
std::string BKE_blender_project_path_resolve(StringRef path, const bke::BlenderProject &project)
void BLI_path_slash_forward_from_native(char *path) ATTR_NONNULL(1)
Vector< RecentProject > BKE_blender_project_recent_get()
void BKE_blender_project_recent_clear(bool only_missing)
@ ASSET_LIBRARY_PROJECT_DEFINED
bke::BlenderProject * BKE_blender_project_get(const Main *bmain)
void BKE_blender_project_refresh(Main *bmain, const char *filepath)
void BKE_preferences_asset_library_remove(struct UserDef *userdef, struct bUserAssetLibrary *library) ATTR_NONNULL()
size_t BLI_path_append(char *__restrict dst, size_t dst_maxncpy, const char *__restrict file) ATTR_NONNULL(1
auto BKE_blender_project_read_callback(const Main *bmain, Fn lambda)
IDProperty * IDP_NewString(const char *st, StringRef name, eIDPropertyFlag flags={}) ATTR_WARN_UNUSED_RESULT
void MEM_delete_void(void *vmemh)
bool BLI_path_relative_to(const char *path, const char *base_dir, bool walk_up, char *r_path_relative, size_t r_path_relative_maxncpy) ATTR_NONNULL(1
static void recent_projects_set(const Span< RecentProject > projects)
void BKE_blender_project_clear()
Vector< bke::path_templates::Error > BKE_path_apply_template(char *path, int path_maxncpy, const bke::path_templates::VariableMap &template_variables)
size_t void BLI_uniquename_cb(FunctionRef< bool(StringRefNull)> unique_check, const char *defname, char delim, char *name, size_t name_maxncpy) ATTR_NONNULL(2
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
void BLI_path_slash_rstrip(char *path) ATTR_NONNULL(1)
void void BLI_path_split_dir_part(const char *filepath, char *dir, size_t dir_maxncpy) ATTR_NONNULL(1
void IDP_ClearProperty(IDProperty *prop)
std::string BKE_path_template_escape(StringRef text)
void BKE_blender_project_recent_update(const Main *bmain)
bool BLI_path_is_abs_from_cwd(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
void IDP_AssignString(IDProperty *prop, const char *st) ATTR_NONNULL()
int BLI_path_normalize(char *path) ATTR_NONNULL(1)
void BKE_add_template_variables_for_project(bke::path_templates::VariableMap &variables, const bke::BlenderProject &project)
static std::optional< bke::BlenderProject > & get_project()
bool BLI_is_dir(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
std::string BKE_is_path_inside_blender_project(const char *path)
bool BKE_blender_project_init(blender::StringRef name, blender::StringRef root_path)
bool BLI_path_parent_dir(char *path) ATTR_NONNULL(1)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
bool BLI_path_is_rel(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
IDProperty * IDP_New(char type, const IDPropertyTemplate *val, StringRef name, eIDPropertyFlag flags={}) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
bool BKE_blender_project_dir_is_project(StringRef path)
IDPropertyUIData * IDP_ui_data_ensure(IDProperty *prop)
bool BLI_is_file(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
bool BKE_blender_project_init_from_root_path(Main *bmain, std::string project_root_path)
std::string BKE_blender_project_path_make_relative(StringRef path, bool path_is_template, const bke::BlenderProject &project)
std::vector< std::map< std::string, std::string > > RecentProjectsTOML
IDPropertyUIData * ui_data