|
|
@@ -3442,6 +3442,19 @@ class _ExpandableTextEdit(QTextEdit):
|
|
|
self.completer.insertText.connect(self.insertCompletion)
|
|
|
self.completer.popup().clicked.connect(self.insert_completion_click)
|
|
|
|
|
|
+ self.menu = None
|
|
|
+ self.undo_flag = False
|
|
|
+ self.redo_flag = False
|
|
|
+
|
|
|
+ self.undoAvailable.connect(self.on_undo_available)
|
|
|
+ self.redoAvailable.connect(self.on_redo_available)
|
|
|
+
|
|
|
+ def on_undo_available(self, val):
|
|
|
+ self.undo_flag = val
|
|
|
+
|
|
|
+ def on_redo_available(self, val):
|
|
|
+ self.redo_flag = val
|
|
|
+
|
|
|
def set_model_data(self, keyword_list):
|
|
|
self.model.setStringList(keyword_list)
|
|
|
|
|
|
@@ -3528,6 +3541,89 @@ class _ExpandableTextEdit(QTextEdit):
|
|
|
else:
|
|
|
self.completer.popup().hide()
|
|
|
|
|
|
+ def contextMenuEvent(self, event):
|
|
|
+ self.menu = QtWidgets.QMenu()
|
|
|
+ tcursor = self.textCursor()
|
|
|
+ txt = tcursor.selectedText()
|
|
|
+
|
|
|
+ # UNDO
|
|
|
+ undo_action = QAction('%s\t%s' % (_("Undo"), _('Ctrl+Z')), self)
|
|
|
+ self.menu.addAction(undo_action)
|
|
|
+ undo_action.triggered.connect(self.undo)
|
|
|
+ if self.undo_flag is False:
|
|
|
+ undo_action.setDisabled(True)
|
|
|
+
|
|
|
+ # REDO
|
|
|
+ redo_action = QAction('%s\t%s' % (_("Redo"), _('Ctrl+Y')), self)
|
|
|
+ self.menu.addAction(redo_action)
|
|
|
+ redo_action.triggered.connect(self.redo)
|
|
|
+ if self.redo_flag is False:
|
|
|
+ redo_action.setDisabled(True)
|
|
|
+
|
|
|
+ self.menu.addSeparator()
|
|
|
+
|
|
|
+ # CUT
|
|
|
+ cut_action = QAction('%s\t%s' % (_("Cut"), _('Ctrl+X')), self)
|
|
|
+ self.menu.addAction(cut_action)
|
|
|
+ cut_action.triggered.connect(self.cut_text)
|
|
|
+ if txt == '':
|
|
|
+ cut_action.setDisabled(True)
|
|
|
+
|
|
|
+ # COPY
|
|
|
+ copy_action = QAction('%s\t%s' % (_("Copy"), _('Ctrl+C')), self)
|
|
|
+ self.menu.addAction(copy_action)
|
|
|
+ copy_action.triggered.connect(self.copy_text)
|
|
|
+ if txt == '':
|
|
|
+ copy_action.setDisabled(True)
|
|
|
+
|
|
|
+ # PASTE
|
|
|
+ paste_action = QAction('%s\t%s' % (_("Paste"), _('Ctrl+V')), self)
|
|
|
+ self.menu.addAction(paste_action)
|
|
|
+ paste_action.triggered.connect(self.paste_text)
|
|
|
+
|
|
|
+ # DELETE
|
|
|
+ delete_action = QAction('%s\t%s' % (_("Delete"), _('Del')), self)
|
|
|
+ self.menu.addAction(delete_action)
|
|
|
+ delete_action.triggered.connect(self.delete_text)
|
|
|
+
|
|
|
+ self.menu.addSeparator()
|
|
|
+
|
|
|
+ # SELECT ALL
|
|
|
+ sel_all_action = QAction('%s\t%s' % (_("Select All"), _('Ctrl+A')), self)
|
|
|
+ self.menu.addAction(sel_all_action)
|
|
|
+ sel_all_action.triggered.connect(self.selectAll)
|
|
|
+
|
|
|
+ self.menu.exec_(event.globalPos())
|
|
|
+
|
|
|
+ def cut_text(self):
|
|
|
+ tcursor = self.textCursor()
|
|
|
+ clipboard = QtWidgets.QApplication.clipboard()
|
|
|
+
|
|
|
+ txt = tcursor.selectedText()
|
|
|
+ clipboard.clear()
|
|
|
+ clipboard.setText(txt)
|
|
|
+
|
|
|
+ tcursor.deleteChar()
|
|
|
+
|
|
|
+ def copy_text(self):
|
|
|
+ tcursor = self.textCursor()
|
|
|
+ clipboard = QtWidgets.QApplication.clipboard()
|
|
|
+
|
|
|
+ txt = tcursor.selectedText()
|
|
|
+ clipboard.clear()
|
|
|
+ clipboard.setText(txt)
|
|
|
+
|
|
|
+ def paste_text(self):
|
|
|
+ tcursor = self.textCursor()
|
|
|
+ clipboard = QtWidgets.QApplication.clipboard()
|
|
|
+
|
|
|
+ txt = clipboard.text()
|
|
|
+ tcursor.insertText(txt)
|
|
|
+
|
|
|
+ def delete_text(self):
|
|
|
+ tcursor = self.textCursor()
|
|
|
+ tcursor.deleteChar()
|
|
|
+
|
|
|
def sizeHint(self):
|
|
|
"""
|
|
|
QWidget sizeHint impelemtation
|