From 7d95c605de141f63e70e2fdb0414d7dc91bd3e9b Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 28 Jun 2024 23:04:03 +0300 Subject: [PATCH 1/2] add tab title rename logic --- addons/dockable_container/dockable_container.gd | 5 +++++ addons/dockable_container/dockable_panel.gd | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/addons/dockable_container/dockable_container.gd b/addons/dockable_container/dockable_container.gd index 3913a68..607d862 100644 --- a/addons/dockable_container/dockable_container.gd +++ b/addons/dockable_container/dockable_container.gd @@ -446,3 +446,8 @@ func _on_child_renamed(child: Node) -> void: _children_names[child] = child.name _children_names[child.name] = child _layout.rename_node(old_name, child.name) + +func set_tab_title_for_node_named(node_name: String, tab_title: String): + for panel in _panel_container.get_children(): + if panel.has_method("setup_tab_name_for_node_named"): + panel.setup_tab_name_for_node_named(node_name, tab_title) diff --git a/addons/dockable_container/dockable_panel.gd b/addons/dockable_container/dockable_panel.gd index d522027..82808df 100644 --- a/addons/dockable_container/dockable_panel.gd +++ b/addons/dockable_container/dockable_panel.gd @@ -24,6 +24,7 @@ var hide_single_tab := false: var _leaf: DockableLayoutPanel var _show_tabs := true var _hide_single_tab := false +var _tabs_children_names = {} func _ready() -> void: @@ -43,6 +44,7 @@ func _exit_tree() -> void: func track_nodes(nodes: Array[Control], new_leaf: DockableLayoutPanel) -> void: + _tabs_children_names = {} _leaf = null # avoid using previous leaf in tab_changed signals var min_size := mini(nodes.size(), get_child_count()) # remove spare children @@ -61,10 +63,17 @@ func track_nodes(nodes: Array[Control], new_leaf: DockableLayoutPanel) -> void: var ref_control := get_child(i) as DockableReferenceControl ref_control.reference_to = nodes[i] set_tab_title(i, nodes[i].name) + _tabs_children_names[nodes[i].name] = i set_leaf(new_leaf) _handle_tab_visibility() +func setup_tab_name_for_node_named(node_name: String, tab_title: String): + if !_tabs_children_names.has(node_name): + return + set_tab_title(_tabs_children_names[node_name], tab_title) + + func get_child_rect() -> Rect2: var control := get_current_tab_control() return Rect2(position + control.position, control.size) From e7122fc7c40ae694e74658ba0585ece6ab9de6bd Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 28 Jun 2024 23:45:25 +0300 Subject: [PATCH 2/2] make titles persistent --- .../dockable_container/dockable_container.gd | 9 +++++---- addons/dockable_container/dockable_panel.gd | 20 +++++++------------ 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/addons/dockable_container/dockable_container.gd b/addons/dockable_container/dockable_container.gd index 607d862..00d17a1 100644 --- a/addons/dockable_container/dockable_container.gd +++ b/addons/dockable_container/dockable_container.gd @@ -66,6 +66,8 @@ var _current_split_index := 0 var _children_names := {} var _layout_dirty := false +var _tabs_children_names = {} + func _init() -> void: child_entered_tree.connect(_child_entered_tree) @@ -352,7 +354,7 @@ func _calculate_panel_and_split_list(result: Array, layout_node: DockableLayoutN else: var panel := _get_panel(_current_panel_index) _current_panel_index += 1 - panel.track_nodes(nodes, layout_node) + panel.track_nodes(nodes, layout_node, _tabs_children_names) result.append(panel) return panel elif layout_node is DockableLayoutSplit: @@ -448,6 +450,5 @@ func _on_child_renamed(child: Node) -> void: _layout.rename_node(old_name, child.name) func set_tab_title_for_node_named(node_name: String, tab_title: String): - for panel in _panel_container.get_children(): - if panel.has_method("setup_tab_name_for_node_named"): - panel.setup_tab_name_for_node_named(node_name, tab_title) + _tabs_children_names[node_name] = tab_title + _resort() diff --git a/addons/dockable_container/dockable_panel.gd b/addons/dockable_container/dockable_panel.gd index 82808df..3c44c33 100644 --- a/addons/dockable_container/dockable_panel.gd +++ b/addons/dockable_container/dockable_panel.gd @@ -24,8 +24,6 @@ var hide_single_tab := false: var _leaf: DockableLayoutPanel var _show_tabs := true var _hide_single_tab := false -var _tabs_children_names = {} - func _ready() -> void: drag_to_rearrange_enabled = true @@ -43,8 +41,7 @@ func _exit_tree() -> void: tab_changed.disconnect(_on_tab_changed) -func track_nodes(nodes: Array[Control], new_leaf: DockableLayoutPanel) -> void: - _tabs_children_names = {} +func track_nodes(nodes: Array[Control], new_leaf: DockableLayoutPanel, tab_names_override) -> void: _leaf = null # avoid using previous leaf in tab_changed signals var min_size := mini(nodes.size(), get_child_count()) # remove spare children @@ -62,18 +59,15 @@ func track_nodes(nodes: Array[Control], new_leaf: DockableLayoutPanel) -> void: for i in nodes.size(): var ref_control := get_child(i) as DockableReferenceControl ref_control.reference_to = nodes[i] - set_tab_title(i, nodes[i].name) - _tabs_children_names[nodes[i].name] = i + + if tab_names_override.has(nodes[i].name): + set_tab_title(i, tab_names_override[nodes[i].name]) + else: + set_tab_title(i, nodes[i].name) + set_leaf(new_leaf) _handle_tab_visibility() - -func setup_tab_name_for_node_named(node_name: String, tab_title: String): - if !_tabs_children_names.has(node_name): - return - set_tab_title(_tabs_children_names[node_name], tab_title) - - func get_child_rect() -> Rect2: var control := get_current_tab_control() return Rect2(position + control.position, control.size)