mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Store layout of toolbar and context menus in a config file
This commit is contained in:
parent
c2364a6b87
commit
ff827175f7
@ -11,22 +11,8 @@ from PyQt4.Qt import QWidget, QAbstractListModel, Qt, QIcon, \
|
|||||||
QVariant, QItemSelectionModel
|
QVariant, QItemSelectionModel
|
||||||
|
|
||||||
from calibre.gui2.dialogs.config.toolbar_ui import Ui_Form
|
from calibre.gui2.dialogs.config.toolbar_ui import Ui_Form
|
||||||
from calibre.gui2.layout import TOOLBAR_NO_DEVICE, TOOLBAR_DEVICE
|
|
||||||
from calibre.gui2.init import LIBRARY_CONTEXT_MENU, DEVICE_CONTEXT_MENU
|
|
||||||
from calibre.gui2 import gprefs, NONE, warning_dialog
|
from calibre.gui2 import gprefs, NONE, warning_dialog
|
||||||
|
|
||||||
DEFAULTS = {
|
|
||||||
'toolbar': TOOLBAR_NO_DEVICE,
|
|
||||||
'toolbar-device': TOOLBAR_DEVICE,
|
|
||||||
'context-menu': LIBRARY_CONTEXT_MENU,
|
|
||||||
'context-menu-device': DEVICE_CONTEXT_MENU,
|
|
||||||
}
|
|
||||||
|
|
||||||
UNREMOVABLE = {
|
|
||||||
'toolbar': ['Preferences'],
|
|
||||||
'toolbar-device': ['Send To Device', 'Location Manager'],
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class FakeAction(object):
|
class FakeAction(object):
|
||||||
|
|
||||||
@ -86,7 +72,7 @@ class AllModel(BaseModel):
|
|||||||
|
|
||||||
def __init__(self, key, gui):
|
def __init__(self, key, gui):
|
||||||
BaseModel.__init__(self)
|
BaseModel.__init__(self)
|
||||||
current = gprefs.get('action-layout-'+key, DEFAULTS[key])
|
current = gprefs['action-layout-'+key]
|
||||||
all = list(gui.iactions.keys()) + ['Donate']
|
all = list(gui.iactions.keys()) + ['Donate']
|
||||||
all = [x for x in all if x not in current] + [None]
|
all = [x for x in all if x not in current] + [None]
|
||||||
all = [self.name_to_action(x, gui) for x in all]
|
all = [self.name_to_action(x, gui) for x in all]
|
||||||
@ -125,7 +111,7 @@ class CurrentModel(BaseModel):
|
|||||||
|
|
||||||
def __init__(self, key, gui):
|
def __init__(self, key, gui):
|
||||||
BaseModel.__init__(self)
|
BaseModel.__init__(self)
|
||||||
current = gprefs.get('action-layout-'+key, DEFAULTS[key])
|
current = gprefs['action-layout-'+key]
|
||||||
self._data = [self.name_to_action(x, gui) for x in current]
|
self._data = [self.name_to_action(x, gui) for x in current]
|
||||||
self.key = key
|
self.key = key
|
||||||
self.gui = gui
|
self.gui = gui
|
||||||
|
@ -13,7 +13,7 @@ from PyQt4.Qt import Qt, QStackedWidget, QMenu, \
|
|||||||
from calibre.utils.config import prefs
|
from calibre.utils.config import prefs
|
||||||
from calibre.constants import isosx, __appname__, preferred_encoding, \
|
from calibre.constants import isosx, __appname__, preferred_encoding, \
|
||||||
__version__
|
__version__
|
||||||
from calibre.gui2 import config, is_widescreen
|
from calibre.gui2 import config, is_widescreen, gprefs
|
||||||
from calibre.gui2.library.views import BooksView, DeviceBooksView
|
from calibre.gui2.library.views import BooksView, DeviceBooksView
|
||||||
from calibre.gui2.widgets import Splitter
|
from calibre.gui2.widgets import Splitter
|
||||||
from calibre.gui2.tag_view import TagBrowserWidget
|
from calibre.gui2.tag_view import TagBrowserWidget
|
||||||
@ -27,14 +27,15 @@ def partial(*args, **kwargs):
|
|||||||
_keep_refs.append(ans)
|
_keep_refs.append(ans)
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
LIBRARY_CONTEXT_MENU = (
|
gprefs.defaults['action-layout-context-menu'] = (
|
||||||
'Edit Metadata', 'Send To Device', 'Save To Disk',
|
'Edit Metadata', 'Send To Device', 'Save To Disk',
|
||||||
'Connect Share', 'Copy To Library', None,
|
'Connect Share', 'Copy To Library', None,
|
||||||
'Convert Books', 'View', 'Open Folder', 'Show Book Details',
|
'Convert Books', 'View', 'Open Folder', 'Show Book Details',
|
||||||
'Similar Books', None, 'Remove Books',
|
'Similar Books', None, 'Remove Books',
|
||||||
)
|
)
|
||||||
|
|
||||||
DEVICE_CONTEXT_MENU = ('View', 'Save To Disk', None, 'Remove Books', None,
|
gprefs.defaults['action-layout-context-menu-device'] = (
|
||||||
|
'View', 'Save To Disk', None, 'Remove Books', None,
|
||||||
'Add To Library', 'Edit Collections',
|
'Add To Library', 'Edit Collections',
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -48,9 +49,9 @@ class LibraryViewMixin(object): # {{{
|
|||||||
m.addSeparator()
|
m.addSeparator()
|
||||||
elif what in self.iactions:
|
elif what in self.iactions:
|
||||||
m.addAction(self.iactions[what].qaction)
|
m.addAction(self.iactions[what].qaction)
|
||||||
populate_menu(lm, LIBRARY_CONTEXT_MENU)
|
populate_menu(lm, gprefs['action-layout-context-menu'])
|
||||||
dm = QMenu(self)
|
dm = QMenu(self)
|
||||||
populate_menu(dm, DEVICE_CONTEXT_MENU)
|
populate_menu(dm, gprefs['action-layout-context-menu-device'])
|
||||||
ec = self.iactions['Edit Collections'].qaction
|
ec = self.iactions['Edit Collections'].qaction
|
||||||
self.library_view.set_context_menu(lm, ec)
|
self.library_view.set_context_menu(lm, ec)
|
||||||
for v in (self.memory_view, self.card_a_view, self.card_b_view):
|
for v in (self.memory_view, self.card_a_view, self.card_b_view):
|
||||||
|
@ -19,13 +19,13 @@ from calibre.gui2 import config, gprefs
|
|||||||
from calibre.gui2.widgets import ComboBoxWithHelp
|
from calibre.gui2.widgets import ComboBoxWithHelp
|
||||||
from calibre import human_readable
|
from calibre import human_readable
|
||||||
|
|
||||||
TOOLBAR_NO_DEVICE = (
|
gprefs.defaults['action-layout-toolbar'] = (
|
||||||
'Add Books', 'Edit Metadata', None, 'Convert Books', 'View', None,
|
'Add Books', 'Edit Metadata', None, 'Convert Books', 'View', None,
|
||||||
'Choose Library', 'Donate', None, 'Fetch News', 'Save To Disk',
|
'Choose Library', 'Donate', None, 'Fetch News', 'Save To Disk',
|
||||||
'Connect Share', None, 'Remove Books', None, 'Help', 'Preferences',
|
'Connect Share', None, 'Remove Books', None, 'Help', 'Preferences',
|
||||||
)
|
)
|
||||||
|
|
||||||
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,
|
||||||
'Fetch News', 'Save To Disk', 'Connect Share', None,
|
'Fetch News', 'Save To Disk', 'Connect Share', None,
|
||||||
@ -248,7 +248,8 @@ class ToolBar(QToolBar): # {{{
|
|||||||
|
|
||||||
def build_bar(self):
|
def build_bar(self):
|
||||||
showing_device = self.location_manager.has_device
|
showing_device = self.location_manager.has_device
|
||||||
actions = TOOLBAR_DEVICE if showing_device else TOOLBAR_NO_DEVICE
|
actions = '-device' if showing_device else ''
|
||||||
|
actions = gprefs['action-layout-toolbar'+actions]
|
||||||
|
|
||||||
self.clear()
|
self.clear()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user