WIP: Basic Blender Project Support (experimental feature) #107655

Draft
Julian Eisel wants to merge 94 commits from blender-projects-basics into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
3 changed files with 26 additions and 5 deletions
Showing only changes of commit 2578c0ba92 - Show all commits

View File

@ -27,12 +27,17 @@ BlenderProject *BKE_project_active_get(void) ATTR_WARN_UNUSED_RESULT;
*/
void BKE_project_active_unset(void);
/**
* Attempt to load and activate a project based on the given path. If the path doesn't lead into a
* project, the active project is unset. Note that the project will be unset on any failure when
* loading the project.
* Check if \a path points into the project root path (i.e. if one of the ancestors of the
* referenced file/directory is a project root directory).
*/
bool BKE_project_contains_path(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
/**
* Attempt to load and activate a project based on the given path. If the path doesn't lead
* into a project, the active project is unset. Note that the project will be unset on any
* failure when loading the project.
*
* \note: When setting an active project, the previously active one will be destroyed, so pointers
* may dangle.
* \note: When setting an active project, the previously active one will be destroyed, so
* pointers may dangle.
*/
BlenderProject *BKE_project_active_load_from_path(const char *path) ATTR_NONNULL();

View File

@ -296,6 +296,12 @@ void BKE_project_active_unset(void)
bke::BlenderProject::set_active_from_settings(nullptr);
}
bool BKE_project_contains_path(const char *path)
{
const StringRef found_root_path = bke::BlenderProject::project_root_path_find_from_path(path);
return !found_root_path.is_empty();
}
BlenderProject *BKE_project_active_load_from_path(const char *path)
{
/* Project should be unset if the path doesn't contain a project root. Unset in the beginning so

View File

@ -3152,6 +3152,16 @@ static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
const BlenderProject *active_project = CTX_wm_project();
if (active_project && !BKE_project_contains_path(path)) {
BKE_reportf(
op->reports,
RPT_WARNING,
"File saved outside of the active project's path (\"%s\"). Active project changed.",
BKE_project_root_path_get(active_project));
/* Don't cancel. Otherwise there's no way to save files outside of the active project. */
}
const int fileflags_orig = G.fileflags;
int fileflags = G.fileflags;