fix close crash (#40)

closes #39

Reviewed-on: https://codeberg.org/Eroax/StreamGraph/pulls/40
Co-authored-by: Lera Elvoé <yagich@poto.cafe>
Co-committed-by: Lera Elvoé <yagich@poto.cafe>
This commit is contained in:
Lera Elvoé 2024-01-15 07:23:47 +00:00 committed by yagich
parent b8e65edcef
commit 49582126c4
2 changed files with 19 additions and 15 deletions

View file

@ -99,7 +99,7 @@ func _ready() -> void:
unsaved_changes_dialog_single_deck.set_meta("tab", tab)
unsaved_changes_dialog_single_deck.show()
return
close_tab(tab)
await close_tab(tab)
)
file_dialog.canceled.connect(disconnect_file_dialog_signals)
@ -161,9 +161,9 @@ func close_tab(tab: int) -> void:
var groups := DeckHolder.close_deck(tab_container.get_tab_metadata(tab, "id"))
# close tabs associated with this deck's groups
for group in groups:
for c_tab in range(tab_container.get_tab_count() - 1, 0, -1):
for c_tab in range(tab_container.get_tab_count() - 1, -1, -1):
if tab_container.get_tab_metadata(c_tab, "id") == group:
tab_container.close_tab(tab)
tab_container.close_tab(c_tab)
await get_tree().process_frame
tab_container.close_tab(tab)
@ -419,27 +419,28 @@ func _notification(what: int) -> void:
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)
#for i in tab_container.get_tab_count():
#close_tab(i)
for i in range(tab_container.get_tab_count() - 1, -1, -1):
await 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"))
await close_tab(unsaved_changes_dialog_single_deck.get_meta("tab"))
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"))
await close_tab(unsaved_changes_dialog_single_deck.get_meta("tab"))
unsaved_changes_dialog_single_deck.hide()
func _on_unsaved_changes_dialog_confirmed() -> void:
for i in tab_container.get_tab_count():
close_tab(i)
for i in range(tab_container.get_tab_count() - 1, -1, -1):
await close_tab(i)
get_tree().quit()

View file

@ -98,10 +98,10 @@ func is_empty() -> bool:
## Closes a tab at the index [param tab].
func close_tab(tab: int) -> void:
content_container.get_child(tab).queue_free()
_tab_metadata.remove_at(tab)
tab_bar.remove_tab(tab)
if !tab_bar.select_previous_available():
tab_bar.select_next_available()
tab_bar.remove_tab(tab)
_tab_metadata.remove_at(tab)
tab_closed.emit(tab)
if tab_bar.tab_count == 0:
_previous_active_tab = -1
@ -135,7 +135,10 @@ func set_tab_metadata(tab: int, key: String, value: Variant) -> void:
## Returns the metadata value set to the tab at index [param tab_idx] using [method set_tab_metadata].
## If no metadata was previously set, returns [code]null[/code] by default.
func get_tab_metadata(tab: int, key: String, default: Variant = null) -> Variant:
if _tab_metadata.size() - 1 < tab:
return default
#if _tab_metadata.size() - 1 < tab:
#return default
#if tab < _tab_metadata.size():
#return default
assert(tab < _tab_metadata.size())
var m = _tab_metadata[tab]
return m.get(key, default)