Implement bug #742686: Allow users to specify what items are shown in the second toolbar.

This commit is contained in:
John Schember 2011-03-26 18:36:46 -04:00
parent 1df045e236
commit 405ba87f8e
4 changed files with 34 additions and 40 deletions

View File

@ -29,6 +29,8 @@ gprefs.defaults['action-layout-toolbar'] = (
'Connect Share', None, 'Remove Books', None, 'Help', 'Preferences', 'Connect Share', None, 'Remove Books', None, 'Help', 'Preferences',
) )
gprefs.defaults['action-layout-toolbar-child'] = ()
gprefs.defaults['action-layout-toolbar-device'] = ( gprefs.defaults['action-layout-toolbar-device'] = (
'Add Books', 'Edit Metadata', None, 'Convert Books', 'View', 'Add Books', 'Edit Metadata', None, 'Convert Books', 'View',
'Send To Device', None, None, 'Location Manager', None, None, 'Send To Device', None, None, 'Location Manager', None, None,

View File

@ -278,11 +278,16 @@ class ToolBar(QToolBar): # {{{
pass pass
def build_bar(self): def build_bar(self):
self.child_bar.setVisible(gprefs['show_child_bar'])
self.showing_donate = False self.showing_donate = False
showing_device = self.location_manager.has_device showing_device = self.location_manager.has_device
actions = '-device' if showing_device else '' mactions = '-device' if showing_device else ''
actions = gprefs['action-layout-toolbar'+actions] mactions = gprefs['action-layout-toolbar'+mactions]
cactions = gprefs['action-layout-toolbar-child']
show_child = gprefs['show_child_bar']
if not len(cactions):
show_child = False
self.child_bar.setVisible(show_child)
for ac in self.added_actions: for ac in self.added_actions:
m = ac.menu() m = ac.menu()
@ -292,41 +297,27 @@ class ToolBar(QToolBar): # {{{
self.clear() self.clear()
self.child_bar.clear() self.child_bar.clear()
self.added_actions = [] self.added_actions = []
self.spacers = [Spacer(self.child_bar), Spacer(self.child_bar),
Spacer(self), Spacer(self)]
self.child_bar.addWidget(self.spacers[0])
if gprefs['show_child_bar']:
self.addWidget(self.spacers[2])
for what in actions: for bar, actions in ((self, mactions), (self.child_bar, cactions)):
if what is None and not gprefs['show_child_bar']: for what in actions:
self.addSeparator() if what is None:
elif what == 'Location Manager': bar.addSeparator()
for ac in self.location_manager.available_actions: elif what == 'Location Manager':
self.addAction(ac) for ac in self.location_manager.available_actions:
self.added_actions.append(ac) bar.addAction(ac)
self.setup_tool_button(ac, QToolButton.MenuButtonPopup) bar.added_actions.append(ac)
elif what == 'Donate': bar.setup_tool_button(ac, QToolButton.MenuButtonPopup)
self.d_widget = QWidget() elif what == 'Donate':
self.d_widget.setLayout(QVBoxLayout()) self.d_widget = QWidget()
self.d_widget.layout().addWidget(self.donate_button) self.d_widget.setLayout(QVBoxLayout())
self.addWidget(self.d_widget) self.d_widget.layout().addWidget(self.donate_button)
self.showing_donate = True bar.addWidget(self.d_widget)
elif what in self.gui.iactions: self.showing_donate = True
action = self.gui.iactions[what] elif what in self.gui.iactions:
bar = self action = self.gui.iactions[what]
if action.action_type == 'current' and gprefs['show_child_bar']: bar.addAction(action.qaction)
bar = self.child_bar self.added_actions.append(action.qaction)
bar.addAction(action.qaction) self.setup_tool_button(action.qaction, action.popup_type)
self.added_actions.append(action.qaction)
self.setup_tool_button(action.qaction, action.popup_type)
self.child_bar.addWidget(self.spacers[1])
if gprefs['show_child_bar']:
self.addWidget(self.spacers[3])
else:
for s in self.spacers[2:]:
s.setVisible(False)
def setup_tool_button(self, ac, menu_mode=None): def setup_tool_button(self, ac, menu_mode=None):
ch = self.widgetForAction(ac) ch = self.widgetForAction(ac)

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>670</width> <width>717</width>
<height>422</height> <height>444</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -247,7 +247,7 @@ then the tags will be displayed each on their own line.</string>
<item row="2" column="0" colspan="2"> <item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="opt_show_child_bar"> <widget class="QCheckBox" name="opt_show_child_bar">
<property name="text"> <property name="text">
<string>&amp;Split the toolbar into two toolbars</string> <string>Add a &amp;second toolbar</string>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -208,6 +208,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
LOCATIONS = [ LOCATIONS = [
('toolbar', _('The main toolbar')), ('toolbar', _('The main toolbar')),
('toolbar-child', _('The second toolbar')),
('toolbar-device', _('The main toolbar when a device is connected')), ('toolbar-device', _('The main toolbar when a device is connected')),
('context-menu', _('The context menu for the books in the ' ('context-menu', _('The context menu for the books in the '
'calibre library')), 'calibre library')),