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

Already on GitHub? Sign in to your account

More fixes on tab behavior #309

Merged
merged 2 commits into from Mar 4, 2012
Jump to file or symbol
Failed to load files and symbols.
+30 −21
Split
@@ -191,23 +191,22 @@ def show_split(self, orientation):
self.actualTab = self._tabSecondary
self.setOrientation(orientation)
- def move_tab_to_next_split(self, tab):
+ def move_tab_to_next_split(self, tab_from):
if self._followMode:
return
- if tab == self._tabSecondary:
- widget = self._tabSecondary.currentWidget()
- name = self._tabSecondary.tabText(
- self._tabSecondary.currentIndex())
- self._tabMain.add_tab(widget, name)
- if widget is editor.Editor and widget.textModified:
- self._tabMain.tab_was_saved(widget)
+
+ if tab_from == self._tabSecondary:
+ tab_to = self._tabMain
else:
- widget = self._tabMain.currentWidget()
- if widget is not None:
- name = self._tabMain.tabText(self._tabMain.currentIndex())
- self._tabSecondary.add_tab(widget, name)
- if widget is editor.Editor and widget.textModified:
- self._tabSecondary.tab_was_saved(widget)
+ tab_to = self._tabSecondary
+
+ widget = tab_from.currentWidget()
+ name = tab_from.tabText(tab_from.currentIndex())
+ tab_from.remove_title(tab_from.currentIndex())
+ tab_to.add_tab(widget, name)
+ if widget is editor.Editor and widget.textModified:
+ tab_to.tab_was_saved(widget)
+ tab_from.update_current_widget()
def add_editor(self, fileName="", project=None, tabIndex=None,
content=None, syntax=None):
@@ -185,6 +185,20 @@ def move_to_open(self, identifier):
self.setCurrentIndex(i)
return
+ def remove_title(self, index):
+ """Looks for the title of the tab at index and removes it from
+ self.titles, if it's there.'"""
+ if unicode(self.tabText(index)) in self.titles:
+ self.titles.remove(unicode(self.tabText(index)))
+
+ def update_current_widget(self):
+ """Sets the focus to the current widget. If this is the last tab in the
+ current split, the allTabsClosed() signal is emitted.'"""
+ if self.currentWidget() is not None:
+ self.currentWidget().setFocus()
+ else:
+ self.emit(SIGNAL("allTabsClosed()"))
+
def removeTab(self, index):
"""Remove the Tab at the selected index and check if the
widget was modified and need to execute any saving"""
@@ -212,14 +226,10 @@ def removeTab(self, index):
elif type(widget) is editor.Editor and widget.ID:
self._add_to_last_opened(widget.ID)
- if unicode(self.tabText(index)) in self.titles:
- self.titles.remove(unicode(self.tabText(index)))
+ self.remove_title(index)
super(TabWidget, self).removeTab(index)
del widget
- if self.currentWidget() is not None:
- self.currentWidget().setFocus()
- else:
- self.emit(SIGNAL("allTabsClosed()"))
+ self.update_current_widget()
def setTabText(self, index, text):
QTabWidget.setTabText(self, index, text)
@@ -280,7 +290,7 @@ def mousePressEvent(self, event):
lambda: self._parent.move_tab_to_next_split(self))
self.connect(actionCloseSplit, SIGNAL("triggered()"),
lambda: self._parent.split_tab(
- self._parent.orientation()))
+ self._parent.orientation() == Qt.Horizontal))
else:
actionSplitH = menu.addAction(
self.tr("Split this Tab (Horizontally)"))