Edit Book: When re-arranging the toolbars inside an individual file editor, save the new toolbar layout so that it is re-used in the future. Also apply the changed layout to all open editors of the same type. See #1346913 (Edit Books - Toolbars)

This commit is contained in:
Kovid Goyal 2014-07-22 22:48:59 +05:30
parent d05e88293f
commit 7573a62754
3 changed files with 56 additions and 3 deletions

View File

@ -14,7 +14,7 @@ from PyQt4.Qt import (
QDialog, QSpinBox, QCheckBox, QDialogButtonBox, QToolButton, QMenu, QInputDialog)
from calibre.gui2 import error_dialog
from calibre.gui2.tweak_book import actions
from calibre.gui2.tweak_book import actions, tprefs, editors
from calibre.gui2.tweak_book.editor.canvas import Canvas
class ResizeDialog(QDialog): # {{{
@ -164,6 +164,17 @@ class Editor(QMainWindow):
def go_to_line(self, *args, **kwargs):
pass
def save_state(self):
for bar in self.bars:
if bar.isFloating():
return
tprefs['image-editor-state'] = bytearray(self.saveState())
def restore_state(self):
state = tprefs.get('image-editor-state', None)
if state is not None:
self.restoreState(state)
def set_focus(self):
self.canvas.setFocus(Qt.OtherFocusReason)
@ -234,6 +245,7 @@ class Editor(QMainWindow):
for x in ('undo', 'redo'):
b.addAction(getattr(self.canvas, '%s_action' % x))
self.edit_bar = b = self.addToolBar(_('Edit actions tool bar'))
b.setObjectName('edit-actions-bar')
for x in ('copy', 'paste'):
ac = actions['editor-%s' % x]
setattr(self, 'action_' + x, b.addAction(ac.icon(), x, getattr(self, x)))
@ -254,11 +266,24 @@ class Editor(QMainWindow):
m.addAction(_('De-speckle image'), self.canvas.despeckle_image)
self.info_bar = b = self.addToolBar(_('Image information bar'))
b.setObjectName('image_info_bar')
self.fmt_label = QLabel('')
b.addWidget(self.fmt_label)
b.addSeparator()
self.size_label = QLabel('')
b.addWidget(self.size_label)
self.bars = [self.action_bar, self.edit_bar, self.info_bar]
for x in self.bars:
x.setFloatable(False)
x.topLevelChanged.connect(self.toolbar_floated)
self.restore_state()
def toolbar_floated(self, floating):
if not floating:
self.save_state()
for ed in editors.itervalues():
if ed is not self:
ed.restore_state()
def update_clipboard_actions(self, *args):
if self.canvas.has_selection:

View File

@ -17,7 +17,7 @@ from calibre import prints
from calibre.constants import DEBUG
from calibre.ebooks.chardet import replace_encoding_declarations
from calibre.gui2 import error_dialog, open_url
from calibre.gui2.tweak_book import actions, current_container, tprefs, dictionaries, editor_toolbar_actions, editor_name
from calibre.gui2.tweak_book import actions, current_container, tprefs, dictionaries, editor_toolbar_actions, editor_name, editors
from calibre.gui2.tweak_book.editor import SPELL_PROPERTY, LINK_PROPERTY, TAG_NAME_PROPERTY, CSS_PROPERTY
from calibre.gui2.tweak_book.editor.help import help_url
from calibre.gui2.tweak_book.editor.text import TextEdit
@ -259,11 +259,34 @@ class Editor(QMainWindow):
b.setObjectName('action_bar') # Needed for saveState
self.tools_bar = b = self.addToolBar(_('Editor tools'))
b.setObjectName('tools_bar')
self.bars = [self.action_bar, self.tools_bar]
if self.syntax == 'html':
self.format_bar = b = self.addToolBar(_('Format text'))
b.setObjectName('html_format_bar')
self.bars.append(self.format_bar)
self.insert_tag_menu = QMenu(self)
self.populate_toolbars()
for x in self.bars:
x.setFloatable(False)
x.topLevelChanged.connect(self.toolbar_floated)
def toolbar_floated(self, floating):
if not floating:
self.save_state()
for ed in editors.itervalues():
if ed is not self:
ed.restore_state()
def save_state(self):
for bar in self.bars:
if bar.isFloating():
return
tprefs['%s-editor-state' % self.syntax] = bytearray(self.saveState())
def restore_state(self):
state = tprefs.get('%s-editor-state' % self.syntax, None)
if state is not None:
self.restoreState(state)
def populate_toolbars(self):
self.action_bar.clear(), self.tools_bar.clear()
@ -302,6 +325,7 @@ class Editor(QMainWindow):
self.format_bar.clear()
for name in tprefs['editor_format_toolbar']:
add_action(name, self.format_bar)
self.restore_state()
def break_cycles(self):
for x in ('modification_state_changed', 'word_ignored', 'link_clicked'):

View File

@ -22,7 +22,7 @@ from calibre.gui2 import elided_text, open_url
from calibre.gui2.keyboard import Manager as KeyboardManager
from calibre.gui2.main_window import MainWindow
from calibre.gui2.throbber import ThrobbingButton, create_donate_widget
from calibre.gui2.tweak_book import current_container, tprefs, actions, capitalize, toolbar_actions
from calibre.gui2.tweak_book import current_container, tprefs, actions, capitalize, toolbar_actions, editors
from calibre.gui2.tweak_book.file_list import FileListWidget
from calibre.gui2.tweak_book.job import BlockingJob
from calibre.gui2.tweak_book.boss import Boss
@ -146,6 +146,10 @@ class Central(QStackedWidget): # {{{
def save_state(self):
tprefs.set('search-panel-visible', self.search_panel.isVisible())
self.search_panel.save_state()
for ed in editors.itervalues():
ed.save_state()
if self.current_editor is not None:
self.current_editor.save_state() # Ensure the current editor saves it state last
def restore_state(self):
self.search_panel.setVisible(tprefs.get('search-panel-visible', False))