Commits

Yuya Nishihara committed 2ff415a

qscilib: patch createStandardContextMenu only if necessary

  • Participants
  • Parent commits df6de5f

Comments (0)

Files changed (1)

tortoisehg/hgqt/qscilib.py

         w = self.SendScintilla(QsciScintilla.SCI_GETCARETWIDTH)
         return QRect(x, y, w, self.textHeight(l))
 
-    def createStandardContextMenu(self):
-        """Create standard context menu; ownership is transferred to caller"""
-        menu = QMenu(self)
-        if not self.isReadOnly():
-            a = menu.addAction(_('&Undo'), self.undo)
-            a.setShortcuts(QKeySequence.Undo)
-            a.setEnabled(self.isUndoAvailable())
-            a = menu.addAction(_('&Redo'), self.redo)
-            a.setShortcuts(QKeySequence.Redo)
-            a.setEnabled(self.isRedoAvailable())
+    if not hasattr(QsciScintilla, 'createStandardContextMenu'):
+        def createStandardContextMenu(self):
+            """Create standard context menu; ownership is transferred to
+            caller"""
+            menu = QMenu(self)
+            if not self.isReadOnly():
+                a = menu.addAction(_('&Undo'), self.undo)
+                a.setShortcuts(QKeySequence.Undo)
+                a.setEnabled(self.isUndoAvailable())
+                a = menu.addAction(_('&Redo'), self.redo)
+                a.setShortcuts(QKeySequence.Redo)
+                a.setEnabled(self.isRedoAvailable())
+                menu.addSeparator()
+                a = menu.addAction(_('Cu&t'), self.cut)
+                a.setShortcuts(QKeySequence.Cut)
+                a.setEnabled(self.hasSelectedText())
+            a = menu.addAction(_('&Copy'), self.copy)
+            a.setShortcuts(QKeySequence.Copy)
+            a.setEnabled(self.hasSelectedText())
+            if not self.isReadOnly():
+                a = menu.addAction(_('&Paste'), self.paste)
+                a.setShortcuts(QKeySequence.Paste)
+                a = menu.addAction(_('&Delete'), self.removeSelectedText)
+                a.setShortcuts(QKeySequence.Delete)
+                a.setEnabled(self.hasSelectedText())
             menu.addSeparator()
-            a = menu.addAction(_('Cu&t'), self.cut)
-            a.setShortcuts(QKeySequence.Cut)
-            a.setEnabled(self.hasSelectedText())
-        a = menu.addAction(_('&Copy'), self.copy)
-        a.setShortcuts(QKeySequence.Copy)
-        a.setEnabled(self.hasSelectedText())
-        if not self.isReadOnly():
-            a = menu.addAction(_('&Paste'), self.paste)
-            a.setShortcuts(QKeySequence.Paste)
-            a = menu.addAction(_('&Delete'), self.removeSelectedText)
-            a.setShortcuts(QKeySequence.Delete)
-            a.setEnabled(self.hasSelectedText())
-        menu.addSeparator()
-        a = menu.addAction(_('Select &All'), self.selectAll)
-        a.setShortcuts(QKeySequence.SelectAll)
-        return menu
+            a = menu.addAction(_('Select &All'), self.selectAll)
+            a.setShortcuts(QKeySequence.SelectAll)
+            return menu
 
 
 class Scintilla(ScintillaCompat):
         self.setDefaultEolMode()
         return result
 
+    # TODO: shouldn't override non-virtual method
     def createStandardContextMenu(self):
         """Create standard context menu; ownership is transferred to caller"""
         menu = super(Scintilla, self).createStandardContextMenu()