mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Implement context menu for comments editor
This commit is contained in:
parent
8abe395507
commit
b7e57597a3
@ -222,6 +222,7 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
|
|||||||
('remove_format', 'edit-clear', _('Remove formatting'), ),
|
('remove_format', 'edit-clear', _('Remove formatting'), ),
|
||||||
('copy', 'edit-copy', _('Copy'), ),
|
('copy', 'edit-copy', _('Copy'), ),
|
||||||
('paste', 'edit-paste', _('Paste'), ),
|
('paste', 'edit-paste', _('Paste'), ),
|
||||||
|
('paste_and_match_style', 'edit-paste', _('Paste and match style'), ),
|
||||||
('cut', 'edit-cut', _('Cut'), ),
|
('cut', 'edit-cut', _('Cut'), ),
|
||||||
('indent', 'format-indent-more', _('Increase indentation'), ),
|
('indent', 'format-indent-more', _('Increase indentation'), ),
|
||||||
('outdent', 'format-indent-less', _('Decrease indentation'), ),
|
('outdent', 'format-indent-less', _('Decrease indentation'), ),
|
||||||
@ -429,6 +430,11 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
|
|||||||
self.paste()
|
self.paste()
|
||||||
self.focus_self()
|
self.focus_self()
|
||||||
|
|
||||||
|
def do_paste_and_match_style(self):
|
||||||
|
text = QApplication.instance().clipboard().text()
|
||||||
|
if text:
|
||||||
|
self.setText(text)
|
||||||
|
|
||||||
def do_cut(self):
|
def do_cut(self):
|
||||||
self.cut()
|
self.cut()
|
||||||
self.focus_self()
|
self.focus_self()
|
||||||
@ -708,18 +714,18 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
|
|||||||
return self.textCursor().selectedText()
|
return self.textCursor().selectedText()
|
||||||
|
|
||||||
def setText(self, text):
|
def setText(self, text):
|
||||||
c = self.textCursor()
|
with self.editing_cursor() as c:
|
||||||
c.insertText(text)
|
c.insertText(text)
|
||||||
self.setTextCursor(c)
|
|
||||||
|
|
||||||
def contextMenuEvent(self, ev):
|
def contextMenuEvent(self, ev):
|
||||||
raise NotImplementedError('TODO')
|
|
||||||
menu = self.createStandardContextMenu()
|
menu = self.createStandardContextMenu()
|
||||||
# paste = self.pageAction(QWebPage.Paste)
|
|
||||||
for action in menu.actions():
|
for action in menu.actions():
|
||||||
pass
|
parts = action.text().split('\t')
|
||||||
# if action == paste:
|
if len(parts) == 2 and QKeySequence(QKeySequence.Paste).toString(QKeySequence.NativeText) in parts[-1]:
|
||||||
# menu.insertAction(action, self.pageAction(QWebPage.PasteAndMatchStyle))
|
menu.insertAction(action, self.action_paste_and_match_style)
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
menu.addAction(self.action_paste_and_match_style)
|
||||||
st = self.text()
|
st = self.text()
|
||||||
if st and st.strip():
|
if st and st.strip():
|
||||||
self.create_change_case_menu(menu)
|
self.create_change_case_menu(menu)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user