Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tab title rename logic #35

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion addons/dockable_container/dockable_container.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -446,3 +448,7 @@ 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):
_tabs_children_names[node_name] = tab_title
_resort()
11 changes: 7 additions & 4 deletions addons/dockable_container/dockable_panel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ var _leaf: DockableLayoutPanel
var _show_tabs := true
var _hide_single_tab := false


func _ready() -> void:
drag_to_rearrange_enabled = true

Expand All @@ -42,7 +41,7 @@ func _exit_tree() -> void:
tab_changed.disconnect(_on_tab_changed)


func track_nodes(nodes: Array[Control], new_leaf: DockableLayoutPanel) -> void:
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
Expand All @@ -60,11 +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)

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 get_child_rect() -> Rect2:
var control := get_current_tab_control()
return Rect2(position + control.position, control.size)
Expand Down