Implement context menu for comments editor

This commit is contained in:
Kovid Goyal 2019-07-03 09:50:35 +05:30
parent 8abe395507
commit b7e57597a3
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -222,6 +222,7 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
('remove_format', 'edit-clear', _('Remove formatting'), ),
('copy', 'edit-copy', _('Copy'), ),
('paste', 'edit-paste', _('Paste'), ),
('paste_and_match_style', 'edit-paste', _('Paste and match style'), ),
('cut', 'edit-cut', _('Cut'), ),
('indent', 'format-indent-more', _('Increase indentation'), ),
('outdent', 'format-indent-less', _('Decrease indentation'), ),
@ -429,6 +430,11 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
self.paste()
self.focus_self()
def do_paste_and_match_style(self):
text = QApplication.instance().clipboard().text()
if text:
self.setText(text)
def do_cut(self):
self.cut()
self.focus_self()
@ -708,18 +714,18 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
return self.textCursor().selectedText()
def setText(self, text):
c = self.textCursor()
with self.editing_cursor() as c:
c.insertText(text)
self.setTextCursor(c)
def contextMenuEvent(self, ev):
raise NotImplementedError('TODO')
menu = self.createStandardContextMenu()
# paste = self.pageAction(QWebPage.Paste)
for action in menu.actions():
pass
# if action == paste:
# menu.insertAction(action, self.pageAction(QWebPage.PasteAndMatchStyle))
parts = action.text().split('\t')
if len(parts) == 2 and QKeySequence(QKeySequence.Paste).toString(QKeySequence.NativeText) in parts[-1]:
menu.insertAction(action, self.action_paste_and_match_style)
break
else:
menu.addAction(self.action_paste_and_match_style)
st = self.text()
if st and st.strip():
self.create_change_case_menu(menu)