mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-19 01:29:49 +00:00
Add a popup_error() method in Global
Just to reduce code duplication and make error appearing easier
This commit is contained in:
parent
43d241a5c2
commit
3a852e44ff
|
@ -330,11 +330,9 @@ func export_processed_images(
|
||||||
elif project.file_format == FileFormat.JPEG:
|
elif project.file_format == FileFormat.JPEG:
|
||||||
err = processed_images[i].save_jpg(export_paths[i])
|
err = processed_images[i].save_jpg(export_paths[i])
|
||||||
if err != OK:
|
if err != OK:
|
||||||
Global.error_dialog.set_text(
|
Global.popup_error(
|
||||||
tr("File failed to save. Error code %s (%s)") % [err, error_string(err)]
|
tr("File failed to save. Error code %s (%s)") % [err, error_string(err)]
|
||||||
)
|
)
|
||||||
Global.error_dialog.popup_centered()
|
|
||||||
Global.dialog_open(true)
|
|
||||||
succeeded = false
|
succeeded = false
|
||||||
if succeeded:
|
if succeeded:
|
||||||
Global.notification_label("File(s) exported")
|
Global.notification_label("File(s) exported")
|
||||||
|
@ -379,9 +377,7 @@ func export_video(export_paths: PackedStringArray) -> bool:
|
||||||
if success < 0 or success > 1:
|
if success < 0 or success > 1:
|
||||||
var fail_text := """Video failed to export. Make sure you have FFMPEG installed
|
var fail_text := """Video failed to export. Make sure you have FFMPEG installed
|
||||||
and have set the correct path in the preferences."""
|
and have set the correct path in the preferences."""
|
||||||
Global.error_dialog.set_text(tr(fail_text))
|
Global.popup_error(tr(fail_text))
|
||||||
Global.error_dialog.popup_centered()
|
|
||||||
Global.dialog_open(true)
|
|
||||||
return false
|
return false
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
|
|
@ -218,9 +218,7 @@ class DialogAPI:
|
||||||
## Shows an alert dialog with the given [param text].
|
## Shows an alert dialog with the given [param text].
|
||||||
## Useful for displaying messages like "Incompatible API" etc...
|
## Useful for displaying messages like "Incompatible API" etc...
|
||||||
func show_error(text: String) -> void:
|
func show_error(text: String) -> void:
|
||||||
Global.error_dialog.set_text(text)
|
Global.popup_error(text)
|
||||||
Global.error_dialog.popup_centered()
|
|
||||||
Global.dialog_open(true)
|
|
||||||
|
|
||||||
## Returns the node that is the parent of dialogs used in pixelorama.
|
## Returns the node that is the parent of dialogs used in pixelorama.
|
||||||
func get_dialogs_parent_node() -> Node:
|
func get_dialogs_parent_node() -> Node:
|
||||||
|
|
|
@ -817,6 +817,12 @@ func dialog_open(open: bool) -> void:
|
||||||
tween.tween_property(control, "modulate", dim_color, 0.1)
|
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],
|
## 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.
|
## changes the cursor shape for it accordingly, and dims/brightens any textures it may have.
|
||||||
func disable_button(button: BaseButton, disable: bool) -> void:
|
func disable_button(button: BaseButton, disable: bool) -> void:
|
||||||
|
|
|
@ -62,9 +62,7 @@ func handle_loading_file(file: String) -> void:
|
||||||
var image := Image.load_from_file(file)
|
var image := Image.load_from_file(file)
|
||||||
if not is_instance_valid(image): # An error occurred
|
if not is_instance_valid(image): # An error occurred
|
||||||
var file_name: String = file.get_file()
|
var file_name: String = file.get_file()
|
||||||
Global.error_dialog.set_text(tr("Can't load file '%s'.") % [file_name])
|
Global.popup_error(tr("Can't load file '%s'.") % [file_name])
|
||||||
Global.error_dialog.popup_centered()
|
|
||||||
Global.dialog_open(true)
|
|
||||||
return
|
return
|
||||||
handle_loading_image(file, image)
|
handle_loading_image(file, image)
|
||||||
|
|
||||||
|
@ -159,11 +157,7 @@ func open_pxo_file(path: String, untitled_backup := false, replace_empty := true
|
||||||
if not success:
|
if not success:
|
||||||
return
|
return
|
||||||
elif err != OK:
|
elif err != OK:
|
||||||
Global.error_dialog.set_text(
|
Global.popup_error(tr("File failed to open. Error code %s (%s)") % [err, error_string(err)])
|
||||||
tr("File failed to open. Error code %s (%s)") % [err, error_string(err)]
|
|
||||||
)
|
|
||||||
Global.error_dialog.popup_centered()
|
|
||||||
Global.dialog_open(true)
|
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
var data_json := zip_reader.read_file("data.json").get_string_from_utf8()
|
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)
|
file = FileAccess.open(path, FileAccess.READ)
|
||||||
var err := FileAccess.get_open_error()
|
var err := FileAccess.get_open_error()
|
||||||
if err != OK:
|
if err != OK:
|
||||||
Global.error_dialog.set_text(
|
Global.popup_error(tr("File failed to open. Error code %s (%s)") % [err, error_string(err)])
|
||||||
tr("File failed to open. Error code %s (%s)") % [err, error_string(err)]
|
|
||||||
)
|
|
||||||
Global.error_dialog.popup_centered()
|
|
||||||
Global.dialog_open(true)
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
var first_line := file.get_line()
|
var first_line := file.get_line()
|
||||||
|
@ -320,19 +310,11 @@ func save_pxo_file(
|
||||||
project.name = path.get_file().trim_suffix(".pxo")
|
project.name = path.get_file().trim_suffix(".pxo")
|
||||||
var serialized_data := project.serialize()
|
var serialized_data := project.serialize()
|
||||||
if !serialized_data:
|
if !serialized_data:
|
||||||
Global.error_dialog.set_text(
|
Global.popup_error(tr("File failed to save. Converting project data to dictionary failed."))
|
||||||
tr("File failed to save. Converting project data to dictionary failed.")
|
|
||||||
)
|
|
||||||
Global.error_dialog.popup_centered()
|
|
||||||
Global.dialog_open(true)
|
|
||||||
return false
|
return false
|
||||||
var to_save := JSON.stringify(serialized_data)
|
var to_save := JSON.stringify(serialized_data)
|
||||||
if !to_save:
|
if !to_save:
|
||||||
Global.error_dialog.set_text(
|
Global.popup_error(tr("File failed to save. Converting dictionary to JSON failed."))
|
||||||
tr("File failed to save. Converting dictionary to JSON failed.")
|
|
||||||
)
|
|
||||||
Global.error_dialog.popup_centered()
|
|
||||||
Global.dialog_open(true)
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
# Check if a file with the same name exists. If it does, rename the new file temporarily.
|
# 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 err != OK:
|
||||||
if temp_path.is_valid_filename():
|
if temp_path.is_valid_filename():
|
||||||
return false
|
return false
|
||||||
Global.error_dialog.set_text(
|
Global.popup_error(tr("File failed to save. Error code %s (%s)") % [err, error_string(err)])
|
||||||
tr("File failed to save. Error code %s (%s)") % [err, error_string(err)]
|
|
||||||
)
|
|
||||||
Global.error_dialog.popup_centered()
|
|
||||||
Global.dialog_open(true)
|
|
||||||
if zip_packer: # this would be null if we attempt to save filenames such as "//\\||.pxo"
|
if zip_packer: # this would be null if we attempt to save filenames such as "//\\||.pxo"
|
||||||
zip_packer.close()
|
zip_packer.close()
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -441,11 +441,7 @@ func import_palette_from_path(path: String, make_copy := false, is_initialising
|
||||||
new_palette_imported.emit()
|
new_palette_imported.emit()
|
||||||
select_palette(palette.name)
|
select_palette(palette.name)
|
||||||
else:
|
else:
|
||||||
Global.error_dialog.set_text(
|
Global.popup_error(tr("Can't load file '%s'.\nThis is not a valid palette file.") % [path])
|
||||||
tr("Can't load file '%s'.\nThis is not a valid palette file.") % [path]
|
|
||||||
)
|
|
||||||
Global.error_dialog.popup_centered()
|
|
||||||
Global.dialog_open(true)
|
|
||||||
|
|
||||||
|
|
||||||
## Refer to app/core/gimppalette-load.c of the GNU Image Manipulation Program for the "living spec"
|
## Refer to app/core/gimppalette-load.c of the GNU Image Manipulation Program for the "living spec"
|
||||||
|
|
|
@ -248,9 +248,7 @@ func load_last_project() -> void:
|
||||||
Global.config_cache.set_value("data", "current_dir", file_path.get_base_dir())
|
Global.config_cache.set_value("data", "current_dir", file_path.get_base_dir())
|
||||||
else:
|
else:
|
||||||
# If file doesn't exist on disk then warn user about this
|
# If file doesn't exist on disk then warn user about this
|
||||||
Global.error_dialog.set_text("Cannot find last project file.")
|
Global.popup_error("Cannot find last project file.")
|
||||||
Global.error_dialog.popup_centered()
|
|
||||||
Global.dialog_open(true)
|
|
||||||
|
|
||||||
|
|
||||||
func load_recent_project_file(path: String) -> void:
|
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())
|
Global.config_cache.set_value("data", "current_dir", path.get_base_dir())
|
||||||
else:
|
else:
|
||||||
# If file doesn't exist on disk then warn user about this
|
# If file doesn't exist on disk then warn user about this
|
||||||
Global.error_dialog.set_text("Cannot find project file.")
|
Global.popup_error("Cannot find project file.")
|
||||||
Global.error_dialog.popup_centered()
|
|
||||||
Global.dialog_open(true)
|
|
||||||
|
|
||||||
|
|
||||||
func _on_OpenSprite_files_selected(paths: PackedStringArray) -> void:
|
func _on_OpenSprite_files_selected(paths: PackedStringArray) -> void:
|
||||||
|
|
|
@ -212,9 +212,7 @@ func read_extension(extension_file_or_folder_name: StringName, internal := false
|
||||||
"\n",
|
"\n",
|
||||||
"But Pixelorama's API version is: %s" % ExtensionsApi.get_api_version()
|
"But Pixelorama's API version is: %s" % ExtensionsApi.get_api_version()
|
||||||
)
|
)
|
||||||
Global.error_dialog.set_text(str(err_text, required_text))
|
Global.popup_error(str(err_text, required_text))
|
||||||
Global.error_dialog.popup_centered()
|
|
||||||
Global.dialog_open(true)
|
|
||||||
print("Incompatible API")
|
print("Incompatible API")
|
||||||
if !internal: # the file isn't created for internal extensions, no need for removal
|
if !internal: # the file isn't created for internal extensions, no need for removal
|
||||||
# Don't put it in faulty, (it's merely incompatible)
|
# Don't put it in faulty, (it's merely incompatible)
|
||||||
|
|
Loading…
Reference in a new issue