[Bf-blender-cvs] [2578c0ba924] blender-projects-basics: Show warning when saving files outside the active project
Julian Eisel
noreply at git.blender.org
Thu Oct 6 17:45:21 CEST 2022
Commit: 2578c0ba924b970ba558fb9b4c57562c6fdeae59
Author: Julian Eisel
Date: Thu Oct 6 17:35:05 2022 +0200
Branches: blender-projects-basics
https://developer.blender.org/rB2578c0ba924b970ba558fb9b4c57562c6fdeae59
Show warning when saving files outside the active project
===================================================================
M source/blender/blenkernel/BKE_blender_project.h
M source/blender/blenkernel/intern/blender_project.cc
M source/blender/windowmanager/intern/wm_files.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_blender_project.h b/source/blender/blenkernel/BKE_blender_project.h
index 8241747a93a..6eb7cca19fb 100644
--- a/source/blender/blenkernel/BKE_blender_project.h
+++ b/source/blender/blenkernel/BKE_blender_project.h
@@ -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();
diff --git a/source/blender/blenkernel/intern/blender_project.cc b/source/blender/blenkernel/intern/blender_project.cc
index 146f3f0bef6..339ec71dd4c 100644
--- a/source/blender/blenkernel/intern/blender_project.cc
+++ b/source/blender/blenkernel/intern/blender_project.cc
@@ -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
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index ef16a91fef5..f0e95285451 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -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;
More information about the Bf-blender-cvs
mailing list