From 5e90b740e79792a0222de738d6664cd7656ad307 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas Date: Fri, 2 Dec 2022 02:11:23 +0200 Subject: [PATCH] Only popup a single files dialog for multiple files - implements #585 This replaces the previous behavior, which used to popup multiple dialogs for each existing file, making the users click "OK" for each exported image. --- Translations/Translations.pot | 3 ++- src/Autoload/Export.gd | 35 ++++++++++++++++++---------------- src/UI/Dialogs/ExportDialog.gd | 10 +++++----- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/Translations/Translations.pot b/Translations/Translations.pot index adfb56dce452..e77ec864e5fb 100644 --- a/Translations/Translations.pot +++ b/Translations/Translations.pot @@ -376,7 +376,8 @@ msgstr "" msgid "File Exists, Overwrite?" msgstr "" -msgid "File %s already exists. Overwrite?" +msgid "The following files already exist. Do you wish to overwrite them?\n" +"%s" msgstr "" msgid "Directory path is not valid!" diff --git a/src/Autoload/Export.gd b/src/Autoload/Export.gd index e0caa67bd950..8f5b8b9b756d 100644 --- a/src/Autoload/Export.gd +++ b/src/Autoload/Export.gd @@ -34,7 +34,7 @@ var was_exported := false # Export coroutine signal var stop_export := false -var file_exists_alert := "File %s already exists. Overwrite?" +var file_exists_alert := "The following files already exist. Do you wish to overwrite them?\n%s" # Export progress variables var export_progress_fraction := 0.0 @@ -165,34 +165,37 @@ func export_processed_images( multiple_files = true if processed_images.size() > 1 else false # Check export paths var export_paths := [] + var paths_of_existing_files := "" for i in range(processed_images.size()): stop_export = false var export_path := create_export_path(multiple_files, project, i + 1) - # If user want to create new directory for each animation tag then check - # if directories exist and create them if not + # If the user wants to create a new directory for each animation tag then check + # if directories exist, and create them if not if multiple_files and new_dir_for_each_frame_tag: var frame_tag_directory := Directory.new() if not frame_tag_directory.dir_exists(export_path.get_base_dir()): frame_tag_directory.open(directory_path) frame_tag_directory.make_dir(export_path.get_base_dir().get_file()) - # Check if the file already exists - var file_check: File = File.new() - if file_check.file_exists(export_path): - # Ask user if they want to overwrite the file - if not was_exported or (was_exported and not ignore_overwrites): - # Overwrite existing file? - export_dialog.open_file_exists_alert_popup(file_exists_alert % export_path) - # Stops the function until the user decides if they want to overwrite - yield(export_dialog, "resume_export_function") - if stop_export: - # User decided to stop export - return + + if not ignore_overwrites: # Check if the files already exist + var file_check: File = File.new() + if file_check.file_exists(export_path): + if not paths_of_existing_files.empty(): + paths_of_existing_files += "\n" + paths_of_existing_files += export_path export_paths.append(export_path) # Only get one export path if single file animated image is exported if is_single_file_format(): break - # Scale images that are to export + if not paths_of_existing_files.empty(): # If files already exist + # Ask user if they want to overwrite the files + export_dialog.open_file_exists_alert_popup(tr(file_exists_alert) % paths_of_existing_files) + # Stops the function until the user decides if they want to overwrite + yield(export_dialog, "resume_export_function") + if stop_export: # User decided to stop export + return + scale_processed_images() if is_single_file_format(): diff --git a/src/UI/Dialogs/ExportDialog.gd b/src/UI/Dialogs/ExportDialog.gd index 905706863bef..f81b222daded 100644 --- a/src/UI/Dialogs/ExportDialog.gd +++ b/src/UI/Dialogs/ExportDialog.gd @@ -213,13 +213,14 @@ func update_dimensions_label() -> void: func open_path_validation_alert_popup(path_or_name: int = -1) -> void: # 0 is invalid path, 1 is invalid name + var error_text := "Directory path and file name are not valid!" if path_or_name == 0: - path_validation_alert_popup.dialog_text = "Directory path is not valid!" + error_text = "Directory path is not valid!" elif path_or_name == 1: - path_validation_alert_popup.dialog_text = "File name is not valid!" - else: - path_validation_alert_popup.dialog_text = "Directory path and file name are not valid!" + error_text = "File name is not valid!" + path_validation_alert_popup.dialog_text = error_text + print(error_text) path_validation_alert_popup.popup_centered() @@ -260,7 +261,6 @@ func _on_ExportDialog_about_to_show() -> void: file_format_options.selected = Export.file_format show_tab() - Export.file_exists_alert = tr("File %s already exists. Overwrite?") # Update translation # Set the size of the preview checker checker.rect_size = checker.get_parent().rect_size