Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2019-05-16 20:43:41 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2019-05-16 20:58:52 +0300
commit4c4ac1158bca2b3286926d18f14fc44d1200a444 (patch)
tree0a7d499b7d52cdd990c820a1e4860dbba37244d3 /source/blender/editors
parent0c2add7ca3f17354c22264d20b86f243cfb30b9e (diff)
Images: more tweaks to save all modified images
Support showing warning messages before saving for cases that we can detect in advance, to be used by quit dialog.
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/include/ED_image.h2
-rw-r--r--source/blender/editors/space_image/image_ops.c92
2 files changed, 59 insertions, 35 deletions
diff --git a/source/blender/editors/include/ED_image.h b/source/blender/editors/include/ED_image.h
index a9be9598761..affe98e10f8 100644
--- a/source/blender/editors/include/ED_image.h
+++ b/source/blender/editors/include/ED_image.h
@@ -111,7 +111,7 @@ void ED_image_draw_info(struct Scene *scene,
bool ED_space_image_show_cache(struct SpaceImage *sima);
-int ED_image_save_all_modified_count(const struct bContext *C);
+int ED_image_save_all_modified_info(const struct bContext *C, struct ReportList *reports);
bool ED_image_save_all_modified(const struct bContext *C, struct ReportList *reports);
#endif /* __ED_IMAGE_H__ */
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 3dd7dd26320..a25ba6fbd9b 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -2161,32 +2161,21 @@ void IMAGE_OT_save_sequence(wmOperatorType *ot)
/********************** save all operator **********************/
-int ED_image_save_all_modified_count(const bContext *C)
-{
- Main *bmain = CTX_data_main(C);
- int num_files = 0;
-
- for (Image *ima = bmain->images.first; ima; ima = ima->id.next) {
- if (ELEM(ima->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE)) {
- continue;
- }
- else if (BKE_image_is_dirty(ima)) {
- if (ima->source == IMA_SRC_FILE && !BKE_image_has_packedfile(ima)) {
- num_files++;
- }
- }
- }
-
- return num_files;
-}
-
-bool ED_image_save_all_modified(const bContext *C, ReportList *reports)
+static int image_save_all_modified(const bContext *C,
+ ReportList *reports,
+ int *num_files,
+ const bool dry_run,
+ const bool ignore_dry_run_warnings)
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
GSet *unique_paths = BLI_gset_str_new(__func__);
bool ok = true;
+ if (num_files) {
+ *num_files = 0;
+ }
+
for (Image *ima = bmain->images.first; ima; ima = ima->id.next) {
if (ELEM(ima->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE)) {
/* Don't save render results automatically. */
@@ -2195,15 +2184,22 @@ bool ED_image_save_all_modified(const bContext *C, ReportList *reports)
if (BKE_image_has_packedfile(ima)) {
if (ima->id.lib == NULL) {
/* Re-pack. */
- BKE_image_memorypack(ima);
+ if (!dry_run) {
+ BKE_image_memorypack(ima);
+ }
+
+ if (num_files) {
+ (*num_files)++;
+ }
}
- else {
+ else if (!ignore_dry_run_warnings) {
/* Can't pack to library data. */
BKE_reportf(reports,
- RPT_ERROR,
+ RPT_WARNING,
"Packed library image: %s from library %s can't be saved",
ima->id.name,
ima->id.lib->name);
+ ok = false;
}
}
else {
@@ -2217,28 +2213,36 @@ bool ED_image_save_all_modified(const bContext *C, ReportList *reports)
if (image_save_options_init(bmain, &opts, ima, NULL, false, false)) {
if (!BLI_gset_haskey(unique_paths, opts.filepath)) {
- const bool save_ok = BKE_image_save(reports, bmain, ima, NULL, &opts);
+ if (!dry_run) {
+ const bool save_ok = BKE_image_save(reports, bmain, ima, NULL, &opts);
+
+ if (save_ok) {
+ BLI_gset_insert(unique_paths, BLI_strdup(opts.filepath));
+ }
- if (save_ok) {
- BLI_gset_insert(unique_paths, BLI_strdup(opts.filepath));
+ ok = ok && save_ok;
}
- ok = ok && save_ok;
+ if (num_files) {
+ (*num_files)++;
+ }
}
- else {
+ else if (!ignore_dry_run_warnings) {
BKE_reportf(reports,
RPT_WARNING,
"File path used by more than one saved image: %s",
opts.filepath);
+ ok = false;
}
}
}
- else {
+ else if (!ignore_dry_run_warnings) {
BKE_reportf(reports,
- RPT_ERROR,
+ RPT_WARNING,
"Image %s can't be saved, no valid file path: %s",
ima->id.name,
ima->name);
+ ok = false;
}
}
}
@@ -2249,15 +2253,35 @@ bool ED_image_save_all_modified(const bContext *C, ReportList *reports)
return ok;
}
-static int image_save_all_modified_exec(bContext *C, wmOperator *op)
+int ED_image_save_all_modified_info(const bContext *C, ReportList *reports)
{
- ED_image_save_all_modified(C, op->reports);
- return OPERATOR_FINISHED;
+ /* Dry run to get number of files, and any warnings we can detect in advance. */
+ int num_files;
+ image_save_all_modified(C, reports, &num_files, true, false);
+ return num_files;
+}
+
+bool ED_image_save_all_modified(const bContext *C, ReportList *reports)
+{
+ /* Save, and ignore any warnings that we already detected in
+ * ED_image_save_all_modified_info. */
+ return image_save_all_modified(C, reports, NULL, false, true);
}
static bool image_save_all_modified_poll(bContext *C)
{
- return (ED_image_save_all_modified_count(C) > 0);
+ /* Let operator run if there are any files to saved, or any warnings to
+ * report about files that we can't save. */
+ int num_files;
+ bool ok = image_save_all_modified(C, NULL, &num_files, true, false);
+ return (num_files > 0) || !ok;
+}
+
+static int image_save_all_modified_exec(bContext *C, wmOperator *op)
+{
+ /* Save, and show all warnings. */
+ image_save_all_modified(C, op->reports, NULL, false, false);
+ return OPERATOR_FINISHED;
}
void IMAGE_OT_save_all_modified(wmOperatorType *ot)