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',
)
gprefs.defaults['action-layout-toolbar-child'] = ()
gprefs.defaults['action-layout-toolbar-device'] = (
'Add Books', 'Edit Metadata', None, 'Convert Books', 'View',
'Send To Device', None, None, 'Location Manager', None, None,

View File

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

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>670</width>
<height>422</height>
<width>717</width>
<height>444</height>
</rect>
</property>
<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">
<widget class="QCheckBox" name="opt_show_child_bar">
<property name="text">
<string>&amp;Split the toolbar into two toolbars</string>
<string>Add a &amp;second toolbar</string>
</property>
</widget>
</item>

View File

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