comparison 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
comparison
equal deleted inserted replaced
617:5baca9d46c34 618:698bdb84f6a7
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 import pyjd # this is dummy in pyjs 20 import pyjd # this is dummy in pyjs
21 from sat.core.log import getLogger 21 from sat.core.log import getLogger
22 log = getLogger(__name__) 22 log = getLogger(__name__)
23
24 from sat.core.i18n import _
23 from sat_frontends.quick_frontend import quick_widgets 25 from sat_frontends.quick_frontend import quick_widgets
26
24 from pyjamas.ui.SimplePanel import SimplePanel 27 from pyjamas.ui.SimplePanel import SimplePanel
25 from pyjamas.ui.AbsolutePanel import AbsolutePanel 28 from pyjamas.ui.AbsolutePanel import AbsolutePanel
26 from pyjamas.ui.VerticalPanel import VerticalPanel 29 from pyjamas.ui.VerticalPanel import VerticalPanel
27 from pyjamas.ui.HorizontalPanel import HorizontalPanel 30 from pyjamas.ui.HorizontalPanel import HorizontalPanel
28 from pyjamas.ui.ScrollPanel import ScrollPanel 31 from pyjamas.ui.ScrollPanel import ScrollPanel
802 805
803 widgets_panel = self.tab_panel.getWidget(self._getIndex()) 806 widgets_panel = self.tab_panel.getWidget(self._getIndex())
804 widgets_panel.addWidget(_new_panel) 807 widgets_panel.addWidget(_new_panel)
805 808
806 809
807 class MainTabPanel(TabPanel): 810 class MainTabPanel(TabPanel, ClickHandler):
808 811
809 def __init__(self, host): 812 def __init__(self, host):
810 TabPanel.__init__(self) 813 TabPanel.__init__(self)
814 ClickHandler.__init__(self)
811 self.host = host 815 self.host = host
812 self.tabBar.setVisible(False)
813 self.setStyleName('liberviaTabPanel') 816 self.setStyleName('liberviaTabPanel')
814 self.addStyleName('mainTabPanel') 817 self.addStyleName('mainTabPanel')
815 Window.addWindowResizeListener(self) 818 Window.addWindowResizeListener(self)
819
820 self.tabBar.addTab(u'✚', True)
821
822 def onTabSelected(self, sender, tabIndex):
823 if tabIndex < self.getWidgetCount():
824 TabPanel.onTabSelected(self, sender, tabIndex)
825 return
826 # user clicked the "+" tab
827 default_label = _(u'new tab')
828 try:
829 label = Window.prompt(_(u'Name of the new tab'), default_label)
830 if not label:
831 label = default_label
832 except: # this happens when the user prevents the page to open the prompt dialog
833 label = default_label
834 self.host.addTab(label, select=True)
816 835
817 def getCurrentPanel(self): 836 def getCurrentPanel(self):
818 """ Get the panel of the currently selected tab 837 """ Get the panel of the currently selected tab
819 838
820 @return: WidgetsPanel 839 @return: WidgetsPanel
835 self.setHeight("%s%s" % (ideal_height, "px")) 854 self.setHeight("%s%s" % (ideal_height, "px"))
836 855
837 def add(self, widget, text=''): 856 def add(self, widget, text=''):
838 tab = DropTab(self, text) 857 tab = DropTab(self, text)
839 TabPanel.add(self, widget, tab, False) 858 TabPanel.add(self, widget, tab, False)
840 if self.getWidgetCount() > 1:
841 self.tabBar.setVisible(True)
842 self.host.resize()
843 859
844 def onWidgetPanelRemove(self, panel): 860 def onWidgetPanelRemove(self, panel):
845 """ Called when a child WidgetsPanel is empty and need to be removed """ 861 """ Called when a child WidgetsPanel is empty and need to be removed """
862 widget_index = self.getWidgetIndex(panel)
846 self.remove(panel) 863 self.remove(panel)
847 widgets_count = self.getWidgetCount() 864 widgets_count = self.getWidgetCount()
848 if widgets_count == 1: 865 self.selectTab(widget_index if widget_index < widgets_count else widgets_count - 1)
849 self.tabBar.setVisible(False)
850 self.host.resize()
851 self.selectTab(0)
852 else:
853 self.selectTab(widgets_count - 1)