Show warning when saving files outside the active project
This commit is contained in:
parent
525f24f1ba
commit
2578c0ba92
|
@ -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();
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue