1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

Add a popup_error() method in Global

Just to reduce code duplication and make error appearing easier
This commit is contained in:
Emmanouil Papadeas 2024-01-24 02:27:57 +02:00
parent 43d241a5c2
commit 3a852e44ff
7 changed files with 19 additions and 51 deletions

View file

@ -330,11 +330,9 @@ func export_processed_images(
elif project.file_format == FileFormat.JPEG:
err = processed_images[i].save_jpg(export_paths[i])
if err != OK:
Global.error_dialog.set_text(
Global.popup_error(
tr("File failed to save. Error code %s (%s)") % [err, error_string(err)]
)
Global.error_dialog.popup_centered()
Global.dialog_open(true)
succeeded = false
if succeeded:
Global.notification_label("File(s) exported")
@ -379,9 +377,7 @@ func export_video(export_paths: PackedStringArray) -> bool:
if success < 0 or success > 1:
var fail_text := """Video failed to export. Make sure you have FFMPEG installed
and have set the correct path in the preferences."""
Global.error_dialog.set_text(tr(fail_text))
Global.error_dialog.popup_centered()
Global.dialog_open(true)
Global.popup_error(tr(fail_text))
return false
return true

View file

@ -218,9 +218,7 @@ class DialogAPI:
## Shows an alert dialog with the given [param text].
## Useful for displaying messages like "Incompatible API" etc...
func show_error(text: String) -> void:
Global.error_dialog.set_text(text)
Global.error_dialog.popup_centered()
Global.dialog_open(true)
Global.popup_error(text)
## Returns the node that is the parent of dialogs used in pixelorama.
func get_dialogs_parent_node() -> Node:

View file

@ -817,6 +817,12 @@ func dialog_open(open: bool) -> void:
tween.tween_property(control, "modulate", dim_color, 0.1)
func popup_error(text: String) -> void:
error_dialog.set_text(text)
error_dialog.popup_centered()
dialog_open(true)
## sets the [member BaseButton.disabled] property of the [param button] to [param disable],
## changes the cursor shape for it accordingly, and dims/brightens any textures it may have.
func disable_button(button: BaseButton, disable: bool) -> void:

View file

@ -62,9 +62,7 @@ func handle_loading_file(file: String) -> void:
var image := Image.load_from_file(file)
if not is_instance_valid(image): # An error occurred
var file_name: String = file.get_file()
Global.error_dialog.set_text(tr("Can't load file '%s'.") % [file_name])
Global.error_dialog.popup_centered()
Global.dialog_open(true)
Global.popup_error(tr("Can't load file '%s'.") % [file_name])
return
handle_loading_image(file, image)
@ -159,11 +157,7 @@ func open_pxo_file(path: String, untitled_backup := false, replace_empty := true
if not success:
return
elif err != OK:
Global.error_dialog.set_text(
tr("File failed to open. Error code %s (%s)") % [err, error_string(err)]
)
Global.error_dialog.popup_centered()
Global.dialog_open(true)
Global.popup_error(tr("File failed to open. Error code %s (%s)") % [err, error_string(err)])
return
else:
var data_json := zip_reader.read_file("data.json").get_string_from_utf8()
@ -253,11 +247,7 @@ func open_v0_pxo_file(path: String, new_project: Project) -> bool:
file = FileAccess.open(path, FileAccess.READ)
var err := FileAccess.get_open_error()
if err != OK:
Global.error_dialog.set_text(
tr("File failed to open. Error code %s (%s)") % [err, error_string(err)]
)
Global.error_dialog.popup_centered()
Global.dialog_open(true)
Global.popup_error(tr("File failed to open. Error code %s (%s)") % [err, error_string(err)])
return false
var first_line := file.get_line()
@ -320,19 +310,11 @@ func save_pxo_file(
project.name = path.get_file().trim_suffix(".pxo")
var serialized_data := project.serialize()
if !serialized_data:
Global.error_dialog.set_text(
tr("File failed to save. Converting project data to dictionary failed.")
)
Global.error_dialog.popup_centered()
Global.dialog_open(true)
Global.popup_error(tr("File failed to save. Converting project data to dictionary failed."))
return false
var to_save := JSON.stringify(serialized_data)
if !to_save:
Global.error_dialog.set_text(
tr("File failed to save. Converting dictionary to JSON failed.")
)
Global.error_dialog.popup_centered()
Global.dialog_open(true)
Global.popup_error(tr("File failed to save. Converting dictionary to JSON failed."))
return false
# Check if a file with the same name exists. If it does, rename the new file temporarily.
@ -346,11 +328,7 @@ func save_pxo_file(
if err != OK:
if temp_path.is_valid_filename():
return false
Global.error_dialog.set_text(
tr("File failed to save. Error code %s (%s)") % [err, error_string(err)]
)
Global.error_dialog.popup_centered()
Global.dialog_open(true)
Global.popup_error(tr("File failed to save. Error code %s (%s)") % [err, error_string(err)])
if zip_packer: # this would be null if we attempt to save filenames such as "//\\||.pxo"
zip_packer.close()
return false

View file

@ -441,11 +441,7 @@ func import_palette_from_path(path: String, make_copy := false, is_initialising
new_palette_imported.emit()
select_palette(palette.name)
else:
Global.error_dialog.set_text(
tr("Can't load file '%s'.\nThis is not a valid palette file.") % [path]
)
Global.error_dialog.popup_centered()
Global.dialog_open(true)
Global.popup_error(tr("Can't load file '%s'.\nThis is not a valid palette file.") % [path])
## Refer to app/core/gimppalette-load.c of the GNU Image Manipulation Program for the "living spec"

View file

@ -248,9 +248,7 @@ func load_last_project() -> void:
Global.config_cache.set_value("data", "current_dir", file_path.get_base_dir())
else:
# If file doesn't exist on disk then warn user about this
Global.error_dialog.set_text("Cannot find last project file.")
Global.error_dialog.popup_centered()
Global.dialog_open(true)
Global.popup_error("Cannot find last project file.")
func load_recent_project_file(path: String) -> void:
@ -266,9 +264,7 @@ func load_recent_project_file(path: String) -> void:
Global.config_cache.set_value("data", "current_dir", path.get_base_dir())
else:
# If file doesn't exist on disk then warn user about this
Global.error_dialog.set_text("Cannot find project file.")
Global.error_dialog.popup_centered()
Global.dialog_open(true)
Global.popup_error("Cannot find project file.")
func _on_OpenSprite_files_selected(paths: PackedStringArray) -> void:

View file

@ -212,9 +212,7 @@ func read_extension(extension_file_or_folder_name: StringName, internal := false
"\n",
"But Pixelorama's API version is: %s" % ExtensionsApi.get_api_version()
)
Global.error_dialog.set_text(str(err_text, required_text))
Global.error_dialog.popup_centered()
Global.dialog_open(true)
Global.popup_error(str(err_text, required_text))
print("Incompatible API")
if !internal: # the file isn't created for internal extensions, no need for removal
# Don't put it in faulty, (it's merely incompatible)