Mercurial > libervia-web
diff browser_side/panels.py @ 177:ba95cd824e06
browser side: tab is removed if it doesn't contain widget anymore.
bug 8
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 25 Jan 2013 00:38:06 +0100 |
parents | d97b0cba8b04 |
children | 7a349be99a77 |
line wrap: on
line diff
--- a/browser_side/panels.py Mon Jan 14 00:28:56 2013 +0100 +++ b/browser_side/panels.py Fri Jan 25 00:38:06 2013 +0100 @@ -172,13 +172,17 @@ self.host.registerWidget(self) def _getWidgetsPanel(self): - return self.getParent().getParent().getParent() + current = self + while current is not None and current.__class__ != WidgetsPanel: + current = current.getParent() + if current is None: + print "Error: can't find WidgetsPanel" + return current def onClick(self, sender): self.host.select(self) def onClose(self, sender): - print "onClose:", sender _widgetspanel = self._getWidgetsPanel() _widgetspanel.removeWidget(self) @@ -901,6 +905,18 @@ if _max_cols != self._max_cols: self._max_cols = _max_cols self._sizesAdjust() + current = self + + blank_page = not [wid for wid in self.flextable if isinstance(wid, LiberviaWidget)] # do we still have widgets on the page ? + + if blank_page and not isinstance(self.getParent(), MainDiscussionPanel): + #we now notice the MainTabPanel that the WidgetsPanel is empty and need to be removed + while current is not None: + if isinstance(current, MainTabPanel): + current.onWidgetPanelRemove(self) + return + current = current.getParent() + print "Error: no MainTabPanel found !" def getIndex(self, wid): return self.flextable.getIndex(wid) @@ -953,7 +969,7 @@ tab_panel_elt = self.getElement() _elts = doc().getElementsByClassName('gwt-TabBar') if not _elts.length: - print ("ERROR: not TabBar found, it should exist !") + print ("ERROR: no TabBar found, it should exist !") tab_bar_h = 0 else: tab_bar_h = _elts.item(0).offsetHeight @@ -966,6 +982,14 @@ if self.getWidgetCount()>1: self.tabBar.setVisible(True) self.host.resize() + + def onWidgetPanelRemove(self, panel): + """ Called when a child WidgetsPanel is empty and need to be removed """ + self.remove(panel) + if self.getWidgetCount() == 1: + self.tabBar.setVisible(False) + self.host.resize() + self.selectTab(0) class MainPanel(AbsolutePanel):