prompt to save all decks when closing

This commit is contained in:
Lera Elvoé 2023-12-13 19:44:09 +03:00
parent bf9af8c996
commit d29adb8166
No known key found for this signature in database
3 changed files with 41 additions and 2 deletions

View file

@ -35,6 +35,7 @@ enum FileMenuId {
var max_recents := 4 var max_recents := 4
var recent_files := [] var recent_files := []
@onready var unsaved_changes_dialog_single_deck := $UnsavedChangesDialogSingleDeck as UnsavedChangesDialogSingleDeck @onready var unsaved_changes_dialog_single_deck := $UnsavedChangesDialogSingleDeck as UnsavedChangesDialogSingleDeck
@onready var unsaved_changes_dialog: ConfirmationDialog = $UnsavedChangesDialog
enum ConnectionsMenuId { enum ConnectionsMenuId {
OBS, OBS,
@ -51,7 +52,7 @@ var _deck_to_save: WeakRef
func _ready() -> void: func _ready() -> void:
get_tree().auto_accept_quit = false
tab_container.add_button_pressed.connect(add_empty_deck) tab_container.add_button_pressed.connect(add_empty_deck)
RendererPersistence.init_namespace(PERSISTENCE_NAMESPACE) RendererPersistence.init_namespace(PERSISTENCE_NAMESPACE)
@ -347,6 +348,17 @@ func add_recents_to_menu() -> void:
RendererPersistence.commit(PERSISTENCE_NAMESPACE) 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: func _on_unsaved_changes_dialog_single_deck_confirmed() -> void:
save_tab(unsaved_changes_dialog_single_deck.get_meta("tab")) save_tab(unsaved_changes_dialog_single_deck.get_meta("tab"))
close_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: func _on_unsaved_changes_dialog_single_deck_custom_action(action: StringName) -> void:
if action == &"force_close": if action == &"force_close":
close_tab(unsaved_changes_dialog_single_deck.get_meta("tab")) 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()

View file

@ -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="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"] [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://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://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://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"] [sub_resource type="InputEventKey" id="InputEventKey_giamc"]
device = -1 device = -1
@ -161,9 +162,12 @@ visible = false
[node name="UnsavedChangesDialogSingleDeck" parent="." instance=ExtResource("8_qf6ve")] [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/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/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="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="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="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="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"]

View file

@ -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