Yuya Nishihara avatar Yuya Nishihara committed b148e39

scintilla patch

Comments (0)

Files changed (4)

scintilla-compat.diff

+# HG changeset patch
+# Date 1378302212 -32400
+# Parent 194021797cc0406e757995ced966e9685540bff4
+qscilib: introduce super class of Scintilla just contains compatibility fixes
+
+diff --git a/tortoisehg/hgqt/qscilib.py b/tortoisehg/hgqt/qscilib.py
+--- a/tortoisehg/hgqt/qscilib.py
++++ b/tortoisehg/hgqt/qscilib.py
+@@ -119,32 +119,10 @@ class _SciImSupport(object):
+                                 self.PREEDIT_INDIC_ID,
+                                 QsciScintilla.INDIC_PLAIN)
+ 
+-class Scintilla(QsciScintilla):
+-    def __init__(self, parent=None):
+-        super(Scintilla, self).__init__(parent)
+-        self.autoUseTabs = True
+-        self.setUtf8(True)
+-        self.setWrapVisualFlags(QsciScintilla.WrapFlagByBorder)
+-        self.textChanged.connect(self._resetfindcond)
+-        self._resetfindcond()
+-        self.highlightLines = set()
+-        self._setMultipleSelectionOptions()
+-        unbindConflictedKeys(self)
+ 
+-    def _setMultipleSelectionOptions(self):
+-        if hasattr(QsciScintilla, 'SCI_SETMULTIPLESELECTION'):
+-            self.SendScintilla(QsciScintilla.SCI_SETMULTIPLESELECTION, True)
+-            self.SendScintilla(QsciScintilla.SCI_SETADDITIONALSELECTIONTYPING,
+-                               True)
+-            self.SendScintilla(QsciScintilla.SCI_SETMULTIPASTE,
+-                               QsciScintilla.SC_MULTIPASTE_EACH)
+-            self.SendScintilla(QsciScintilla.SCI_SETVIRTUALSPACEOPTIONS,
+-                               QsciScintilla.SCVS_RECTANGULARSELECTION)
+-
+-    def read(self, f):
+-        result = super(Scintilla, self).read(f)
+-        self.setDefaultEolMode()
+-        return result
++# give better name if any
++class ScintillaCompat(QsciScintilla):
++    """Scintilla widget with compatibility patches"""
+ 
+     def inputMethodQuery(self, query):
+         if query == Qt.ImMicroFocus:
+@@ -172,15 +150,6 @@ class Scintilla(QsciScintilla):
+     def _imsupport(self):
+         return _SciImSupport(self)
+ 
+-    def cursorRect(self):
+-        """Return a rectangle (in viewport coords) including the cursor"""
+-        l, i = self.getCursorPosition()
+-        p = self.positionFromLineIndex(l, i)
+-        x = self.SendScintilla(QsciScintilla.SCI_POINTXFROMPOSITION, 0, p)
+-        y = self.SendScintilla(QsciScintilla.SCI_POINTYFROMPOSITION, 0, p)
+-        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)
+@@ -208,10 +177,100 @@ class Scintilla(QsciScintilla):
+         a = menu.addAction(_('Select &All'), self.selectAll)
+         a.setShortcuts(QKeySequence.SelectAll)
+ 
++        return menu
++
++    # compability mode with QScintilla from Ubuntu 10.04
++    if not hasattr(QsciScintilla, 'HiddenIndicator'):
++        HiddenIndicator = QsciScintilla.INDIC_HIDDEN
++    if not hasattr(QsciScintilla, 'PlainIndicator'):
++        PlainIndicator = QsciScintilla.INDIC_PLAIN
++    if not hasattr(QsciScintilla, 'StrikeIndicator'):
++        StrikeIndicator = QsciScintilla.INDIC_STRIKE
++
++    if not hasattr(QsciScintilla, 'indicatorDefine'):
++        def indicatorDefine(self, style, indicatorNumber=-1):
++            # compatibility layer allows only one indicator to be defined
++            if indicatorNumber == -1:
++                indicatorNumber = 1
++            self.SendScintilla(self.SCI_INDICSETSTYLE, indicatorNumber, style)
++            return indicatorNumber
++
++    if not hasattr(QsciScintilla, 'setIndicatorDrawUnder'):
++        def setIndicatorDrawUnder(self, under, indicatorNumber):
++            self.SendScintilla(self.SCI_INDICSETUNDER, indicatorNumber, under)
++
++    if not hasattr(QsciScintilla, 'setIndicatorForegroundColor'):
++        def setIndicatorForegroundColor(self, color, indicatorNumber):
++            self.SendScintilla(self.SCI_INDICSETFORE, indicatorNumber, color)
++            self.SendScintilla(self.SCI_INDICSETALPHA, indicatorNumber,
++                               color.alpha())
++
++    if not hasattr(QsciScintilla, 'clearIndicatorRange'):
++        def clearIndicatorRange(self, lineFrom, indexFrom, lineTo, indexTo,
++                                indicatorNumber):
++            start = self.positionFromLineIndex(lineFrom, indexFrom)
++            finish = self.positionFromLineIndex(lineTo, indexTo)
++
++            self.SendScintilla(self.SCI_SETINDICATORCURRENT, indicatorNumber)
++            self.SendScintilla(self.SCI_INDICATORCLEARRANGE,
++                               start, finish - start)
++
++    if not hasattr(QsciScintilla, 'fillIndicatorRange'):
++        def fillIndicatorRange(self, lineFrom, indexFrom, lineTo, indexTo,
++                               indicatorNumber):
++            start = self.positionFromLineIndex(lineFrom, indexFrom)
++            finish = self.positionFromLineIndex(lineTo, indexTo)
++
++            self.SendScintilla(self.SCI_SETINDICATORCURRENT, indicatorNumber)
++            self.SendScintilla(self.SCI_INDICATORFILLRANGE,
++                               start, finish - start)
++
++
++class Scintilla(ScintillaCompat):
++    """Scintilla widget for file view or editor"""
++
++    def __init__(self, parent=None):
++        super(Scintilla, self).__init__(parent)
++        self.autoUseTabs = True
++        self.setUtf8(True)
++        self.setWrapVisualFlags(QsciScintilla.WrapFlagByBorder)
++        self.textChanged.connect(self._resetfindcond)
++        self._resetfindcond()
++        self.highlightLines = set()
++        self._setMultipleSelectionOptions()
++        unbindConflictedKeys(self)
++
++    def _setMultipleSelectionOptions(self):
++        if hasattr(QsciScintilla, 'SCI_SETMULTIPLESELECTION'):
++            self.SendScintilla(QsciScintilla.SCI_SETMULTIPLESELECTION, True)
++            self.SendScintilla(QsciScintilla.SCI_SETADDITIONALSELECTIONTYPING,
++                               True)
++            self.SendScintilla(QsciScintilla.SCI_SETMULTIPASTE,
++                               QsciScintilla.SC_MULTIPASTE_EACH)
++            self.SendScintilla(QsciScintilla.SCI_SETVIRTUALSPACEOPTIONS,
++                               QsciScintilla.SCVS_RECTANGULARSELECTION)
++
++    def read(self, f):
++        result = super(Scintilla, self).read(f)
++        self.setDefaultEolMode()
++        return result
++
++    def cursorRect(self):
++        """Return a rectangle (in viewport coords) including the cursor"""
++        l, i = self.getCursorPosition()
++        p = self.positionFromLineIndex(l, i)
++        x = self.SendScintilla(QsciScintilla.SCI_POINTXFROMPOSITION, 0, p)
++        y = self.SendScintilla(QsciScintilla.SCI_POINTYFROMPOSITION, 0, p)
++        w = self.SendScintilla(QsciScintilla.SCI_GETCARETWIDTH)
++        return QRect(x, y, w, self.textHeight(l))
++
++    # TODO: shouldn't override non-virtual method
++    def createStandardContextMenu(self):
++        """Create standard context menu; ownership is transferred to caller"""
++        menu = super(Scintilla, self).createStandardContextMenu()
+         menu.addSeparator()
+         editoptsmenu = menu.addMenu(_('&Editor Options'))
+         self._buildEditorOptionsMenu(editoptsmenu)
+-
+         return menu
+ 
+     def _buildEditorOptionsMenu(self, editoptsmenu):
+@@ -437,52 +496,6 @@ class Scintilla(QsciScintilla):
+                                    point.x(), point.y())
+         return self.SendScintilla(self.SCI_LINEFROMPOSITION, chpos)
+ 
+-    # compability mode with QScintilla from Ubuntu 10.04
+-    if not hasattr(QsciScintilla, 'HiddenIndicator'):
+-        HiddenIndicator = QsciScintilla.INDIC_HIDDEN
+-    if not hasattr(QsciScintilla, 'PlainIndicator'):
+-        PlainIndicator = QsciScintilla.INDIC_PLAIN
+-    if not hasattr(QsciScintilla, 'StrikeIndicator'):
+-        StrikeIndicator = QsciScintilla.INDIC_STRIKE
+-
+-    if not hasattr(QsciScintilla, 'indicatorDefine'):
+-        def indicatorDefine(self, style, indicatorNumber=-1):
+-            # compatibility layer allows only one indicator to be defined
+-            if indicatorNumber == -1:
+-                indicatorNumber = 1
+-            self.SendScintilla(self.SCI_INDICSETSTYLE, indicatorNumber, style)
+-            return indicatorNumber
+-
+-    if not hasattr(QsciScintilla, 'setIndicatorDrawUnder'):
+-        def setIndicatorDrawUnder(self, under, indicatorNumber):
+-            self.SendScintilla(self.SCI_INDICSETUNDER, indicatorNumber, under)
+-
+-    if not hasattr(QsciScintilla, 'setIndicatorForegroundColor'):
+-        def setIndicatorForegroundColor(self, color, indicatorNumber):
+-            self.SendScintilla(self.SCI_INDICSETFORE, indicatorNumber, color)
+-            self.SendScintilla(self.SCI_INDICSETALPHA, indicatorNumber,
+-                               color.alpha())
+-
+-    if not hasattr(QsciScintilla, 'clearIndicatorRange'):
+-        def clearIndicatorRange(self, lineFrom, indexFrom, lineTo, indexTo,
+-                                indicatorNumber):
+-            start = self.positionFromLineIndex(lineFrom, indexFrom)
+-            finish = self.positionFromLineIndex(lineTo, indexTo)
+-
+-            self.SendScintilla(self.SCI_SETINDICATORCURRENT, indicatorNumber)
+-            self.SendScintilla(self.SCI_INDICATORCLEARRANGE,
+-                               start, finish - start)
+-
+-    if not hasattr(QsciScintilla, 'fillIndicatorRange'):
+-        def fillIndicatorRange(self, lineFrom, indexFrom, lineTo, indexTo,
+-                               indicatorNumber):
+-            start = self.positionFromLineIndex(lineFrom, indexFrom)
+-            finish = self.positionFromLineIndex(lineTo, indexTo)
+-
+-            self.SendScintilla(self.SCI_SETINDICATORCURRENT, indicatorNumber)
+-            self.SendScintilla(self.SCI_INDICATORFILLRANGE,
+-                               start, finish - start)
+-
+ 
+ class SearchToolBar(QToolBar):
+     conditionChanged = pyqtSignal(unicode, bool, bool)

scintilla-stdmenu.diff

+# HG changeset patch
+# Date 1378302215 -32400
+# Parent 5595a5b610bea4c0f4d3e113c7211b03ca01bebc
+qscilib: patch createStandardContextMenu only if necessary
+
+diff --git a/tortoisehg/hgqt/qscilib.py b/tortoisehg/hgqt/qscilib.py
+--- a/tortoisehg/hgqt/qscilib.py
++++ b/tortoisehg/hgqt/qscilib.py
+@@ -150,34 +150,36 @@ class ScintillaCompat(QsciScintilla):
+     def _imsupport(self):
+         return _SciImSupport(self)
+ 
+-    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)
++            a = menu.addAction(_('Select &All'), self.selectAll)
++            a.setShortcuts(QKeySequence.SelectAll)
+ 
+-        return menu
++            return menu
+ 
+     # compability mode with QScintilla from Ubuntu 10.04
+     if not hasattr(QsciScintilla, 'HiddenIndicator'):
+scintilla-compat.diff
+scintilla-stdmenu.diff
 win32sigpipe.diff
 win32sigpipe-use.diff
 win32sigpipe-dirtyhack.diff

win32sigpipe-use.diff

 # Parent 4705e3459975558c80bc1e87ae18c5b84d29096d
 cmdcore: implement graceful abort on process-based command executor
 
+XXX maybe this can be implemented as mixin of CmdProc?
+
 diff --git a/tortoisehg/hgqt/cmdcore.py b/tortoisehg/hgqt/cmdcore.py
 --- a/tortoisehg/hgqt/cmdcore.py
 +++ b/tortoisehg/hgqt/cmdcore.py
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.