Create View menu

This commit is contained in:
Kovid Goyal 2013-11-09 11:18:56 +05:30
parent aa0d4f1b71
commit f97b799456
3 changed files with 40 additions and 17 deletions

View File

@ -24,5 +24,12 @@ def set_current_container(container):
global _current_container global _current_container
_current_container = container _current_container = container
actions = {} class NonReplaceDict(dict):
editors = {}
def __setitem__(self, k, v):
if k in self:
raise ValueError('The key %s is already present' % k)
dict.__setitem__(self, k, v)
actions = NonReplaceDict()
editors = NonReplaceDict()

View File

@ -120,6 +120,8 @@ class Editor(QMainWindow):
'There is no suitable text in the clipboard to paste.'), show=True) 'There is no suitable text in the clipboard to paste.'), show=True)
self.editor.paste() self.editor.paste()
def contextMenuEvent(self, ev):
ev.ignore()
def launch_editor(path_to_edit, path_is_raw=False, syntax='html'): def launch_editor(path_to_edit, path_is_raw=False, syntax='html'):
if path_is_raw: if path_is_raw:

View File

@ -109,9 +109,9 @@ class Main(MainWindow):
self.keyboard = KeyboardManager() self.keyboard = KeyboardManager()
self.create_actions() self.create_actions()
self.create_menubar() self.create_toolbars()
self.create_toolbar()
self.create_docks() self.create_docks()
self.create_menubar()
self.status_bar = self.statusBar() self.status_bar = self.statusBar()
self.status_bar.addPermanentWidget(self.boss.save_manager.status_widget) self.status_bar.addPermanentWidget(self.boss.save_manager.status_widget)
@ -224,20 +224,31 @@ class Main(MainWindow):
e.addAction(self.action_subset_fonts) e.addAction(self.action_subset_fonts)
e.addAction(self.action_smarten_punctuation) e.addAction(self.action_smarten_punctuation)
def create_toolbar(self): e = b.addMenu(_('&View'))
self.global_bar = b = self.addToolBar(_('Book tool bar')) t = e.addMenu(_('Tool&bars'))
b.setObjectName('global_bar') # Needed for saveState e.addSeparator()
b.addAction(self.action_open_book) for name, ac in actions.iteritems():
b.addAction(self.action_global_undo) if name.endswith('-dock'):
b.addAction(self.action_global_redo) e.addAction(ac)
b.addAction(self.action_save) elif name.endswith('-bar'):
b.addAction(self.action_toc) t.addAction(ac)
self.polish_bar = b = self.addToolBar(_('Polish book tool bar')) def create_toolbars(self):
b.setObjectName('polish_bar') # Needed for saveState def create(text, name):
b.addAction(self.action_embed_fonts) name += '-bar'
b.addAction(self.action_subset_fonts) b = self.addToolBar(text)
b.addAction(self.action_smarten_punctuation) b.setObjectName(name) # Needed for saveState
setattr(self, name.replace('-', '_'), b)
actions[name] = b.toggleViewAction()
return b
a = create(_('Book tool bar'), 'global').addAction
for x in ('open_book', 'global_undo', 'global_redo', 'save', 'toc'):
a(getattr(self, 'action_' + x))
a = create(_('Polish book tool bar'), 'polish').addAction
for x in ('embed_fonts', 'subset_fonts', 'smarten_punctuation'):
a(getattr(self, 'action_' + x))
def create_docks(self): def create_docks(self):
@ -302,3 +313,6 @@ class Main(MainWindow):
self.restoreState(state, self.STATE_VERSION) self.restoreState(state, self.STATE_VERSION)
# We never want to start with the inspector showing # We never want to start with the inspector showing
self.inspector_dock.close() self.inspector_dock.close()
def contextMenuEvent(self, ev):
ev.ignore()