diff --git a/graph_node_renderer/deck_holder_renderer.gd b/graph_node_renderer/deck_holder_renderer.gd index 82d8372..50af7ef 100644 --- a/graph_node_renderer/deck_holder_renderer.gd +++ b/graph_node_renderer/deck_holder_renderer.gd @@ -69,7 +69,7 @@ func _ready() -> void: tab_container.tab_close_requested.connect( func(tab: int): - if tab_container.get_tab_metadata(tab, "dirty"): + if tab_container.get_tab_metadata(tab, "dirty") && !tab_container.get_tab_metadata(tab, "group"): unsaved_changes_dialog_single_deck.set_meta("tab", tab) unsaved_changes_dialog_single_deck.show() return @@ -113,6 +113,7 @@ func add_empty_deck() -> void: inst.deck = deck tab_container.add_content(inst, "") tab_container.set_tab_metadata(tab_container.get_current_tab(), "id", deck.id) + tab_container.set_tab_metadata(tab_container.get_current_tab(), "group", false) tab_container.set_tab_metadata(tab_container.get_current_tab(), "path", recent_path.path_join("")) inst.group_enter_requested.connect(_on_deck_renderer_group_enter_requested) inst.dirty_state_changed.connect(_on_deck_renderer_dirty_state_changed.bind(inst)) @@ -123,13 +124,15 @@ func close_current_tab() -> void: 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 tab_container.get_tab_count(): - if tab_container.get_tab_metadata(c_tab, "id") == group: - tab_container.close_tab(tab) - await get_tree().process_frame + if !tab_container.get_tab_metadata(tab, "group"): + 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): + if tab_container.get_tab_metadata(c_tab, "id") == group: + tab_container.close_tab(tab) + await get_tree().process_frame + tab_container.close_tab(tab) ## Opens [member file_dialog] with the mode [member FileDialog.FILE_MODE_SAVE_FILE] @@ -189,6 +192,7 @@ func open_deck_at_path(path: String) -> void: inst.deck = deck tab_container.add_content(inst, path.get_file()) tab_container.set_tab_metadata(tab_container.get_current_tab(), "id", deck.id) + tab_container.set_tab_metadata(tab_container.get_current_tab(), "group", false) tab_container.set_tab_metadata(tab_container.get_current_tab(), "path", path) inst.initialize_from_deck() inst.group_enter_requested.connect(_on_deck_renderer_group_enter_requested) @@ -246,6 +250,7 @@ func _on_deck_renderer_group_enter_requested(group_id: String) -> void: deck_renderer.initialize_from_deck() tab_container.add_content(deck_renderer, "(g) %s" % group_id.left(8)) tab_container.set_tab_metadata(tab_container.get_current_tab(), "id", group_id) + tab_container.set_tab_metadata(tab_container.get_current_tab(), "group", true) deck_renderer.group_enter_requested.connect(_on_deck_renderer_group_enter_requested) @@ -380,6 +385,7 @@ 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")) + unsaved_changes_dialog_single_deck.hide() func _on_unsaved_changes_dialog_confirmed() -> void: diff --git a/graph_node_renderer/tab_container_custom.gd b/graph_node_renderer/tab_container_custom.gd index f8a7727..a2462ca 100644 --- a/graph_node_renderer/tab_container_custom.gd +++ b/graph_node_renderer/tab_container_custom.gd @@ -29,7 +29,7 @@ signal tab_rearranged(old: int, new: int) # Holds the previously active tab in the internal tab_bar var _previous_active_tab: int = -1 -var _tab_metadata: Dictionary #Dictionary[int -> tab idx, Dictionary[String -> key, Variant]] +var _tab_metadata: Array[Dictionary] #Array[Dictionary[String -> key, Variant]] func _ready() -> void: @@ -55,6 +55,10 @@ func _ready() -> void: tab_bar.active_tab_rearranged.connect( func(idx_to: int): + var old := _tab_metadata[_previous_active_tab] + var new := _tab_metadata[idx_to] + _tab_metadata[idx_to] = old + _tab_metadata[_previous_active_tab] = new tab_rearranged.emit(_previous_active_tab, idx_to) content_container.move_child(content_container.get_child(_previous_active_tab), idx_to) _previous_active_tab = idx_to @@ -65,6 +69,8 @@ func add_content(c: Node, tab_title: String) -> void: tab_bar.add_tab(tab_title) content_container.add_child(c) tab_bar.set_current_tab(tab_bar.tab_count - 1) + #_tab_metadata[tab_bar.tab_count - 1] = {} + _tab_metadata.append({}) ## Updates the tab at index [param tab_idx]'s title to [param title]. @@ -92,7 +98,7 @@ func close_tab(tab: int) -> void: if !tab_bar.select_previous_available(): tab_bar.select_next_available() tab_bar.remove_tab(tab) - _tab_metadata.erase(tab) + _tab_metadata.remove_at(tab) tab_closed.emit(tab) if tab_bar.tab_count == 0: _previous_active_tab = -1 @@ -116,13 +122,15 @@ func get_content(idx: int) -> Control: ## Sets the metadata value for the tab at index [param tab_idx] at [param key], which can be ## retrieved later using [method get_tab_metadata]. func set_tab_metadata(tab: int, key: String, value: Variant) -> void: - var m = _tab_metadata.get(tab, {}) + #var m = _tab_metadata.get(tab, {}) + #m[key] = value + #_tab_metadata[tab] = m + var m := _tab_metadata[tab] m[key] = value - _tab_metadata[tab] = m ## 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) -> Variant: - var m = _tab_metadata.get(tab, {}) + var m = _tab_metadata[tab] return m.get(key)