From 9411f37a471e2a519a492ab2429dedbde30264e3 Mon Sep 17 00:00:00 2001 From: Manolis Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Fri, 18 Mar 2022 04:21:38 +0200 Subject: [PATCH] Add a confirmation dialog when deleting a layout --- Translations/Translations.pot | 3 +++ src/UI/Dialogs/ManageLayouts.gd | 19 ++++++++++++------- src/UI/Dialogs/ManageLayouts.tscn | 6 ++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Translations/Translations.pot b/Translations/Translations.pot index b587725cf..afbf664f1 100644 --- a/Translations/Translations.pot +++ b/Translations/Translations.pot @@ -196,6 +196,9 @@ msgstr "" msgid "Edit Layout" msgstr "" +msgid "Are you sure you want to delete this layout?" +msgstr "" + msgid "Auto" msgstr "" diff --git a/src/UI/Dialogs/ManageLayouts.gd b/src/UI/Dialogs/ManageLayouts.gd index 877137849..f07c001db 100644 --- a/src/UI/Dialogs/ManageLayouts.gd +++ b/src/UI/Dialogs/ManageLayouts.gd @@ -8,6 +8,7 @@ onready var edit_layout: Button = find_node("EditLayout") onready var delete_layout: Button = find_node("DeleteLayout") onready var layout_settings: ConfirmationDialog = $LayoutSettings onready var layout_name: LineEdit = $LayoutSettings/LayoutName +onready var delete_confirmation: ConfirmationDialog = $DeleteConfirmation func _on_ManageLayouts_about_to_show() -> void: @@ -50,13 +51,7 @@ func _on_EditLayout_pressed() -> void: func _on_DeleteLayout_pressed() -> void: - delete_layout_file(layout_list.get_item_text(layout_selected) + ".tres") - Global.top_menu_container.layouts.remove(layout_selected) - layout_list.remove_item(layout_selected) - Global.top_menu_container.populate_layouts_submenu() - layout_selected = -1 - edit_layout.disabled = true - delete_layout.disabled = true + delete_confirmation.popup_centered() func _on_LayoutSettings_confirmed() -> void: @@ -88,3 +83,13 @@ func _on_LayoutSettings_confirmed() -> void: func delete_layout_file(file_name: String) -> void: var dir := Directory.new() dir.remove("user://layouts/".plus_file(file_name)) + + +func _on_DeleteConfirmation_confirmed() -> void: + delete_layout_file(layout_list.get_item_text(layout_selected) + ".tres") + Global.top_menu_container.layouts.remove(layout_selected) + layout_list.remove_item(layout_selected) + Global.top_menu_container.populate_layouts_submenu() + layout_selected = -1 + edit_layout.disabled = true + delete_layout.disabled = true diff --git a/src/UI/Dialogs/ManageLayouts.tscn b/src/UI/Dialogs/ManageLayouts.tscn index 46c8b9403..86c283b64 100644 --- a/src/UI/Dialogs/ManageLayouts.tscn +++ b/src/UI/Dialogs/ManageLayouts.tscn @@ -83,6 +83,11 @@ margin_bottom = 50.5 size_flags_horizontal = 3 placeholder_text = "Insert name" +[node name="DeleteConfirmation" type="ConfirmationDialog" parent="."] +margin_right = 200.0 +margin_bottom = 70.0 +dialog_text = "Are you sure you want to delete this layout?" + [connection signal="about_to_show" from="." to="." method="_on_ManageLayouts_about_to_show"] [connection signal="popup_hide" from="." to="." method="_on_ManageLayouts_popup_hide"] [connection signal="item_activated" from="VBoxContainer/SavedLayouts" to="." method="_on_SavedLayouts_item_activated"] @@ -92,3 +97,4 @@ placeholder_text = "Insert name" [connection signal="pressed" from="VBoxContainer/ButtonsContainer/EditLayout" to="." method="_on_EditLayout_pressed"] [connection signal="pressed" from="VBoxContainer/ButtonsContainer/DeleteLayout" to="." method="_on_DeleteLayout_pressed"] [connection signal="confirmed" from="LayoutSettings" to="." method="_on_LayoutSettings_confirmed"] +[connection signal="confirmed" from="DeleteConfirmation" to="." method="_on_DeleteConfirmation_confirmed"]