@@ -8,7 +8,8 @@ module tab_widget |
| 8 | 8 | gtk_widget_set_size_request, g_signal_connect, & |
| 9 | 9 | gtk_widget_add_css_class, gtk_widget_remove_css_class, & |
| 10 | 10 | gtk_label_new, gtk_box_set_spacing, gtk_widget_set_hexpand, & |
| 11 | | - gtk_widget_set_halign, GTK_ALIGN_END |
| 11 | + gtk_widget_set_halign, GTK_ALIGN_END, gtk_widget_get_first_child, & |
| 12 | + gtk_widget_get_next_sibling |
| 12 | 13 | use tab_manager, only: tab_state, get_tab, num_tabs, active_tab_index, & |
| 13 | 14 | MAX_TABS, switch_to_tab, create_tab, close_tab |
| 14 | 15 | implicit none |
@@ -74,7 +75,7 @@ contains |
| 74 | 75 | |
| 75 | 76 | ! Refresh tab bar (rebuild all tab buttons) |
| 76 | 77 | subroutine refresh_tab_bar() |
| 77 | | - type(c_ptr) :: plus_btn, tab_btn |
| 78 | + type(c_ptr) :: plus_btn, tab_btn, child, next_child |
| 78 | 79 | type(tab_state), pointer :: tab |
| 79 | 80 | integer :: i |
| 80 | 81 | character(len=256) :: label_text |
@@ -86,8 +87,19 @@ contains |
| 86 | 87 | |
| 87 | 88 | print *, "Refreshing tab bar with ", num_tabs, " tabs" |
| 88 | 89 | |
| 89 | | - ! TODO: Clear existing children (need gtk_widget_get_first_child and loop) |
| 90 | | - ! For now, we'll just append - proper clearing will be added later |
| 90 | + ! Clear all existing children from tab bar |
| 91 | + child = gtk_widget_get_first_child(tab_bar_container) |
| 92 | + do while (c_associated(child)) |
| 93 | + ! Get next sibling BEFORE removing current child |
| 94 | + next_child = gtk_widget_get_next_sibling(child) |
| 95 | + call gtk_box_remove(tab_bar_container, child) |
| 96 | + child = next_child |
| 97 | + end do |
| 98 | + |
| 99 | + ! Clear button pointer array |
| 100 | + tab_buttons(:) = c_null_ptr |
| 101 | + |
| 102 | + print *, "Cleared old tab bar widgets" |
| 91 | 103 | |
| 92 | 104 | ! Create plus button first (leftmost) |
| 93 | 105 | plus_btn = gtk_button_new_with_label("+"//c_null_char) |