Remove the need to special case standalone launches in the editor code

This commit is contained in:
Kovid Goyal 2013-12-06 13:55:32 +05:30
parent f31bfb749c
commit 2523138eb9
2 changed files with 13 additions and 19 deletions

View File

@ -226,12 +226,8 @@ class Editor(QMainWindow):
b.addAction(getattr(self.canvas, '%s_action' % x)) b.addAction(getattr(self.canvas, '%s_action' % x))
self.edit_bar = b = self.addToolBar(_('Edit actions tool bar')) self.edit_bar = b = self.addToolBar(_('Edit actions tool bar'))
for x in ('copy', 'paste'): for x in ('copy', 'paste'):
try: ac = actions['editor-%s' % x]
ac = actions['editor-%s' % x] setattr(self, 'action_' + x, b.addAction(ac.icon(), x, getattr(self, x)))
except KeyError:
setattr(self, 'action_' + x, b.addAction(x, getattr(self.canvas, x)))
else:
setattr(self, 'action_' + x, b.addAction(ac.icon(), x, getattr(self, x)))
self.update_clipboard_actions() self.update_clipboard_actions()
b.addSeparator() b.addSeparator()

View File

@ -126,22 +126,15 @@ class Editor(QMainWindow):
self.action_bar = b = self.addToolBar(_('File actions tool bar')) self.action_bar = b = self.addToolBar(_('File actions tool bar'))
b.setObjectName('action_bar') # Needed for saveState b.setObjectName('action_bar') # Needed for saveState
for x in ('undo', 'redo'): for x in ('undo', 'redo'):
try: b.addAction(actions['editor-%s' % x])
b.addAction(actions['editor-%s' % x])
except KeyError:
pass
self.edit_bar = b = self.addToolBar(_('Edit actions tool bar')) self.edit_bar = b = self.addToolBar(_('Edit actions tool bar'))
for x in ('cut', 'copy', 'paste'): for x in ('cut', 'copy', 'paste'):
try: b.addAction(actions['editor-%s' % x])
b.addAction(actions['editor-%s' % x])
except KeyError:
pass
self.tools_bar = b = self.addToolBar(_('Editor tools')) self.tools_bar = b = self.addToolBar(_('Editor tools'))
if actions: if self.syntax == 'html':
if self.syntax == 'html': b.addAction(actions['fix-html-current'])
b.addAction(actions['fix-html-current']) if self.syntax in {'xml', 'html', 'css'}:
if self.syntax in {'xml', 'html', 'css'}: b.addAction(actions['pretty-current'])
b.addAction(actions['pretty-current'])
def break_cycles(self): def break_cycles(self):
self.modification_state_changed.disconnect() self.modification_state_changed.disconnect()
@ -211,7 +204,12 @@ class Editor(QMainWindow):
return False return False
def launch_editor(path_to_edit, path_is_raw=False, syntax='html'): def launch_editor(path_to_edit, path_is_raw=False, syntax='html'):
from calibre.gui2.tweak_book.main import option_parser
from calibre.gui2.tweak_book.ui import Main
opts = option_parser().parse_args([])
app = QApplication([]) app = QApplication([])
# Create the actions that are placed into the editors toolbars
main = Main(opts) # noqa
if path_is_raw: if path_is_raw:
raw = path_to_edit raw = path_to_edit
else: else: