Skip to content

Commit 4689565

Browse files
committed
Refactor GroupTab closing
1 parent 321d038 commit 4689565

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

activity_browser/ui/widgets/central.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,19 @@ def connect_signals(self):
118118
self.tabCloseRequested.connect(self.tabClosed)
119119
signals.project.changed.connect(self.deleteLater)
120120

121+
def addTab(self, widget, *args, **kwargs):
122+
super().addTab(widget, *args, **kwargs)
123+
widget.destroyed.connect(self.checkEmpty)
124+
125+
def checkEmpty(self):
126+
"""
127+
Check if the GroupTabWidget is empty (i.e., has no tabs).
128+
129+
If it is empty, delete the widget.
130+
"""
131+
if self.count() == 1:
132+
self.deleteLater()
133+
121134
def tabClosed(self, index):
122135
"""
123136
Handle the closing of a tab.
@@ -129,7 +142,4 @@ def tabClosed(self, index):
129142
index (int): The index of the tab to be closed.
130143
"""
131144
self.widget(index).deleteLater() # Delete the widget associated with the tab.
132-
self.removeTab(index) # Remove the tab from the widget.
133145

134-
if self.count() == 0: # If no tabs remain, delete the entire widget.
135-
self.deleteLater()

0 commit comments

Comments
 (0)