fortrangoingonforty/sniffly / 0a91afe

Browse files

fix widget duplication bug in refresh_tab_bar

Authored by espadonne
SHA
0a91afe99523b6a61eaf27c2b0e2dc7e8715081f
Parents
387d0a1
Tree
ede21ce

1 changed file

StatusFile+-
M src/gui/tab_widget.f90 16 4
src/gui/tab_widget.f90modified
@@ -8,7 +8,8 @@ module tab_widget
88
                  gtk_widget_set_size_request, g_signal_connect, &
99
                  gtk_widget_add_css_class, gtk_widget_remove_css_class, &
1010
                  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
1213
   use tab_manager, only: tab_state, get_tab, num_tabs, active_tab_index, &
1314
                          MAX_TABS, switch_to_tab, create_tab, close_tab
1415
   implicit none
@@ -74,7 +75,7 @@ contains
7475
 
7576
   ! Refresh tab bar (rebuild all tab buttons)
7677
   subroutine refresh_tab_bar()
77
-    type(c_ptr) :: plus_btn, tab_btn
78
+    type(c_ptr) :: plus_btn, tab_btn, child, next_child
7879
     type(tab_state), pointer :: tab
7980
     integer :: i
8081
     character(len=256) :: label_text
@@ -86,8 +87,19 @@ contains
8687
 
8788
     print *, "Refreshing tab bar with ", num_tabs, " tabs"
8889
 
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"
91103
 
92104
     ! Create plus button first (leftmost)
93105
     plus_btn = gtk_button_new_with_label("+"//c_null_char)