From d29adb81660c7318410c11e9bdb71e6c36dcd0f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Wed, 13 Dec 2023 19:44:09 +0300 Subject: [PATCH] prompt to save all decks when closing --- graph_node_renderer/deck_holder_renderer.gd | 21 ++++++++++++++++++- graph_node_renderer/deck_holder_renderer.tscn | 6 +++++- .../unsaved_changes_dialog.tscn | 16 ++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 graph_node_renderer/unsaved_changes_dialog.tscn diff --git a/graph_node_renderer/deck_holder_renderer.gd b/graph_node_renderer/deck_holder_renderer.gd index b65eda6..bc7e501 100644 --- a/graph_node_renderer/deck_holder_renderer.gd +++ b/graph_node_renderer/deck_holder_renderer.gd @@ -35,6 +35,7 @@ enum FileMenuId { var max_recents := 4 var recent_files := [] @onready var unsaved_changes_dialog_single_deck := $UnsavedChangesDialogSingleDeck as UnsavedChangesDialogSingleDeck +@onready var unsaved_changes_dialog: ConfirmationDialog = $UnsavedChangesDialog enum ConnectionsMenuId { OBS, @@ -51,7 +52,7 @@ var _deck_to_save: WeakRef func _ready() -> void: - + get_tree().auto_accept_quit = false tab_container.add_button_pressed.connect(add_empty_deck) RendererPersistence.init_namespace(PERSISTENCE_NAMESPACE) @@ -347,6 +348,17 @@ func add_recents_to_menu() -> void: RendererPersistence.commit(PERSISTENCE_NAMESPACE) +func _notification(what: int) -> void: + if what == NOTIFICATION_WM_CLOSE_REQUEST: + if range(tab_container.get_tab_count()).any(func(x: int): return tab_container.get_content(x).dirty): + unsaved_changes_dialog.show() + else: + for i in tab_container.get_tab_count(): + close_tab(i) + + get_tree().quit() + + func _on_unsaved_changes_dialog_single_deck_confirmed() -> void: save_tab(unsaved_changes_dialog_single_deck.get_meta("tab")) close_tab(unsaved_changes_dialog_single_deck.get_meta("tab")) @@ -355,3 +367,10 @@ func _on_unsaved_changes_dialog_single_deck_confirmed() -> void: func _on_unsaved_changes_dialog_single_deck_custom_action(action: StringName) -> void: if action == &"force_close": close_tab(unsaved_changes_dialog_single_deck.get_meta("tab")) + + +func _on_unsaved_changes_dialog_confirmed() -> void: + for i in tab_container.get_tab_count(): + close_tab(i) + + get_tree().quit() diff --git a/graph_node_renderer/deck_holder_renderer.tscn b/graph_node_renderer/deck_holder_renderer.tscn index 90b3abd..2fc4952 100644 --- a/graph_node_renderer/deck_holder_renderer.tscn +++ b/graph_node_renderer/deck_holder_renderer.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=19 format=3 uid="uid://duaah5x0jhkn6"] +[gd_scene load_steps=20 format=3 uid="uid://duaah5x0jhkn6"] [ext_resource type="Script" path="res://graph_node_renderer/deck_holder_renderer.gd" id="1_67g2g"] [ext_resource type="PackedScene" uid="uid://b84f2ngtcm5b8" path="res://graph_node_renderer/tab_container_custom.tscn" id="1_s3ug2"] @@ -8,6 +8,7 @@ [ext_resource type="PackedScene" uid="uid://eioso6jb42jy" path="res://graph_node_renderer/obs_websocket_setup_dialog.tscn" id="5_uo2gj"] [ext_resource type="PackedScene" uid="uid://bq2lxmbnic4lc" path="res://graph_node_renderer/twitch_setup_dialog.tscn" id="7_7rhap"] [ext_resource type="PackedScene" uid="uid://cuwou2aa7qfc2" path="res://graph_node_renderer/unsaved_changes_dialog_single_deck.tscn" id="8_qf6ve"] +[ext_resource type="PackedScene" uid="uid://cvvkj138fg8jg" path="res://graph_node_renderer/unsaved_changes_dialog.tscn" id="9_4n0q6"] [sub_resource type="InputEventKey" id="InputEventKey_giamc"] device = -1 @@ -161,9 +162,12 @@ visible = false [node name="UnsavedChangesDialogSingleDeck" parent="." instance=ExtResource("8_qf6ve")] +[node name="UnsavedChangesDialog" parent="." instance=ExtResource("9_4n0q6")] + [connection signal="id_pressed" from="MarginContainer/VSplitContainer/VBoxContainer/MenuBar/File" to="." method="_on_file_id_pressed"] [connection signal="id_pressed" from="MarginContainer/VSplitContainer/VBoxContainer/MenuBar/Connections" to="." method="_on_connections_id_pressed"] [connection signal="id_pressed" from="MarginContainer/VSplitContainer/VBoxContainer/MenuBar/Debug" to="." method="_on_debug_id_pressed"] [connection signal="connect_button_pressed" from="OBSWebsocketSetupDialog" to="." method="_on_obs_websocket_setup_dialog_connect_button_pressed"] [connection signal="confirmed" from="UnsavedChangesDialogSingleDeck" to="." method="_on_unsaved_changes_dialog_single_deck_confirmed"] [connection signal="custom_action" from="UnsavedChangesDialogSingleDeck" to="." method="_on_unsaved_changes_dialog_single_deck_custom_action"] +[connection signal="confirmed" from="UnsavedChangesDialog" to="." method="_on_unsaved_changes_dialog_confirmed"] diff --git a/graph_node_renderer/unsaved_changes_dialog.tscn b/graph_node_renderer/unsaved_changes_dialog.tscn new file mode 100644 index 0000000..85092a2 --- /dev/null +++ b/graph_node_renderer/unsaved_changes_dialog.tscn @@ -0,0 +1,16 @@ +[gd_scene format=3 uid="uid://cvvkj138fg8jg"] + +[node name="UnsavedChangesDialog" type="ConfirmationDialog"] +initial_position = 2 +size = Vector2i(391, 206) +ok_button_text = "Quit without saving" + +[node name="Label" type="Label" parent="."] +offset_left = 8.0 +offset_top = 8.0 +offset_right = 383.0 +offset_bottom = 157.0 +text = "You have unsaved changes. Quitting now will discard them. Are you sure you want to quit?" +horizontal_alignment = 1 +vertical_alignment = 1 +autowrap_mode = 3