diff src/browser/sat_browser/base_widget.py @ 618:698bdb84f6a7 frontends_multi_profiles

browser_side: always display the main tab bar with a "+" button to add a new tab
author souliane <souliane@mailoo.org>
date Fri, 20 Feb 2015 19:37:54 +0100
parents 5baca9d46c34
children 11a0a32144a5
line wrap: on
line diff
--- a/src/browser/sat_browser/base_widget.py	Wed Feb 11 11:21:27 2015 +0100
+++ b/src/browser/sat_browser/base_widget.py	Fri Feb 20 19:37:54 2015 +0100
@@ -20,7 +20,10 @@
 import pyjd  # this is dummy in pyjs
 from sat.core.log import getLogger
 log = getLogger(__name__)
+
+from sat.core.i18n import _
 from sat_frontends.quick_frontend import quick_widgets
+
 from pyjamas.ui.SimplePanel import SimplePanel
 from pyjamas.ui.AbsolutePanel import AbsolutePanel
 from pyjamas.ui.VerticalPanel import VerticalPanel
@@ -804,16 +807,32 @@
         widgets_panel.addWidget(_new_panel)
 
 
-class MainTabPanel(TabPanel):
+class MainTabPanel(TabPanel, ClickHandler):
 
     def __init__(self, host):
         TabPanel.__init__(self)
+        ClickHandler.__init__(self)
         self.host = host
-        self.tabBar.setVisible(False)
         self.setStyleName('liberviaTabPanel')
         self.addStyleName('mainTabPanel')
         Window.addWindowResizeListener(self)
 
+        self.tabBar.addTab(u'✚', True)
+
+    def onTabSelected(self, sender, tabIndex):
+        if tabIndex < self.getWidgetCount():
+            TabPanel.onTabSelected(self, sender, tabIndex)
+            return
+        # user clicked the "+" tab
+        default_label = _(u'new tab')
+        try:
+            label = Window.prompt(_(u'Name of the new tab'), default_label)
+            if not label:
+                label = default_label
+        except:  # this happens when the user prevents the page to open the prompt dialog
+            label = default_label
+        self.host.addTab(label, select=True)
+
     def getCurrentPanel(self):
         """ Get the panel of the currently selected tab
 
@@ -837,17 +856,10 @@
     def add(self, widget, text=''):
         tab = DropTab(self, text)
         TabPanel.add(self, widget, tab, False)
-        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 """
+        widget_index = self.getWidgetIndex(panel)
         self.remove(panel)
         widgets_count = self.getWidgetCount()
-        if widgets_count == 1:
-            self.tabBar.setVisible(False)
-            self.host.resize()
-            self.selectTab(0)
-        else:
-            self.selectTab(widgets_count - 1)
+        self.selectTab(widget_index if widget_index < widgets_count else widgets_count - 1)