Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.1.1, 2.1.2, and tip

stable commit: move MessageEntry to its own file to resolve import loop (fixes #878)

Changeset 6b128d5e32e3

Parent f4071882041d

by Steve Borho

Changes to 3 files · Browse files at 6b128d5e32e3 Showing diff from parent f4071882041d Diff from another changeset...

 
9
10
11
 
 
 
 
 
 
 
12
13
14
 
15
16
17
18
19
20
21
22
 
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
 
9
10
11
12
13
14
15
16
17
18
19
20
 
21
22
 
 
 
 
23
24
25
 
27
28
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
31
32
@@ -9,14 +9,17 @@
   from mercurial import ui, util, error   +from tortoisehg.util import hglib, shlib, wconfig, bugtraq + +from tortoisehg.hgqt.i18n import _ +from tortoisehg.hgqt.messageentry import MessageEntry +from tortoisehg.hgqt import qtlib, qscilib, status, cmdui, branchop, revpanel +from tortoisehg.hgqt import hgrcutil, mq +  from PyQt4.QtCore import *  from PyQt4.QtGui import * -from PyQt4.Qsci import QsciScintilla, QsciAPIs, QsciLexerMakefile +from PyQt4.Qsci import QsciAPIs   -from tortoisehg.hgqt.i18n import _ -from tortoisehg.util import hglib, shlib, wconfig, bugtraq -from tortoisehg.hgqt import qtlib, qscilib, status, cmdui, branchop, revpanel -from tortoisehg.hgqt import hgrcutil, mq    # Technical Debt for CommitWidget  # disable commit button while no message is entered or no files are selected @@ -24,136 +27,6 @@
 # spell check / tab completion  # in-memory patching / committing chunk selected files   -class MessageEntry(qscilib.Scintilla): - - def __init__(self, parent, getCheckedFunc=None): - super(MessageEntry, self).__init__(parent) - self.setEdgeColor(QColor('LightSalmon')) - self.setEdgeMode(QsciScintilla.EdgeLine) - self.setReadOnly(False) - self.setMarginWidth(1, 0) - self.setFont(qtlib.getfont('fontcomment').font()) - self.setCaretWidth(10) - self.setCaretLineBackgroundColor(QColor("#e6fff0")) - self.setCaretLineVisible(True) - self.setAutoIndent(True) - self.setAutoCompletionThreshold(2) - self.setAutoCompletionSource(QsciScintilla.AcsAPIs) - self.setAutoCompletionFillupsEnabled(True) - self.setLexer(QsciLexerMakefile(self)) - self.lexer().setFont(qtlib.getfont('fontcomment').font()) - self.lexer().setColor(QColor(Qt.red), QsciLexerMakefile.Error) - self.setMatchedBraceBackgroundColor(Qt.yellow) - self.setIndentationsUseTabs(False) - self.setBraceMatching(QsciScintilla.SloppyBraceMatch) - #self.setIndentationGuidesBackgroundColor(QColor("#e6e6de")) - #self.setFolding(QsciScintilla.BoxedFoldStyle) - # http://www.riverbankcomputing.com/pipermail/qscintilla/2009-February/000461.html - self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) - self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) - # default message entry widgets to word wrap, user may override - self.setWrapMode(QsciScintilla.WrapWord) - - self.getChecked = getCheckedFunc - self.setContextMenuPolicy(Qt.CustomContextMenu) - self.customContextMenuRequested.connect(self.menuRequested) - - def menuRequested(self, point): - line = self.lineAt(point) - point = self.viewport().mapToGlobal(point) - - def apply(): - line = 0 - while True: - line = self.reflowBlock(line) - if line is None: - break; - def paste(): - files = self.getChecked() - self.insert(', '.join(files)) - def settings(): - from tortoisehg.hgqt.settings import SettingsDialog - dlg = SettingsDialog(True, focus='tortoisehg.summarylen') - dlg.exec_() - - menu = self.createStandardContextMenu() - menu.addSeparator() - if self.getChecked: - action = menu.addAction(_('Paste &Filenames')) - action.triggered.connect(paste) - for name, func in [(_('App&ly Format'), apply), - (_('C&onfigure Format'), settings)]: - def add(name, func): - action = menu.addAction(name) - action.triggered.connect(func) - add(name, func) - return menu.exec_(point) - - def refresh(self, repo): - self.setEdgeColumn(repo.summarylen) - self.setIndentationWidth(repo.tabwidth) - self.setTabWidth(repo.tabwidth) - self.summarylen = repo.summarylen - - def reflowBlock(self, line): - lines = self.text().split('\n', QString.KeepEmptyParts) - if line >= len(lines): - return None - if not len(lines[line]) > 1: - return line+1 - - # find boundaries (empty lines or bounds) - b = line - while b and len(lines[b-1]) > 1: - b = b - 1 - e = line - while e+1 < len(lines) and len(lines[e+1]) > 1: - e = e + 1 - group = QStringList([lines[l].simplified() for l in xrange(b, e+1)]) - sentence = group.join(' ') - parts = sentence.split(' ', QString.SkipEmptyParts) - - outlines = QStringList() - line = QStringList() - partslen = 0 - for part in parts: - if partslen + len(line) + len(part) + 1 > self.summarylen: - if line: - outlines.append(line.join(' ')) - line, partslen = QStringList(), 0 - line.append(part) - partslen += len(part) - if line: - outlines.append(line.join(' ')) - - self.beginUndoAction() - self.setSelection(b, 0, e+1, 0) - self.removeSelectedText() - self.insertAt(outlines.join('\n')+'\n', b, 0) - self.endUndoAction() - self.setCursorPosition(b, 0) - return b + len(outlines) + 1 - - def moveCursorToEnd(self): - lines = self.lines() - if lines: - lines -= 1 - pos = self.lineLength(lines) - self.setCursorPosition(lines, pos) - self.ensureLineVisible(lines) - self.horizontalScrollBar().setSliderPosition(0) - - def keyPressEvent(self, event): - if event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_E: - line, col = self.getCursorPosition() - self.reflowBlock(line) - elif event.key() == Qt.Key_Backtab: - event.accept() - newev = QKeyEvent(event.type(), Qt.Key_Tab, Qt.ShiftModifier) - super(MessageEntry, self).keyPressEvent(newev) - else: - super(MessageEntry, self).keyPressEvent(event) -  class CommitWidget(QWidget, qtlib.TaskWidget):   'A widget that encompasses a StatusWidget and commit extras'   commitButtonEnable = pyqtSignal(bool)
Change 1 of 1 Show Entire File tortoisehg/​hgqt/​messageentry.py Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
@@ -0,0 +1,145 @@
+# messageentry.py - TortoiseHg's commit message editng widget +# +# Copyright 2011 Steve Borho <steve@borho.org> +# +# This software may be used and distributed according to the terms of the +# GNU General Public License version 2, incorporated herein by reference. + +import os + +from PyQt4.QtCore import * +from PyQt4.QtGui import * +from PyQt4.Qsci import QsciScintilla, QsciLexerMakefile + +from tortoisehg.hgqt.i18n import _ +from tortoisehg.hgqt import qtlib, qscilib + +class MessageEntry(qscilib.Scintilla): + + def __init__(self, parent, getCheckedFunc=None): + super(MessageEntry, self).__init__(parent) + self.setEdgeColor(QColor('LightSalmon')) + self.setEdgeMode(QsciScintilla.EdgeLine) + self.setReadOnly(False) + self.setMarginWidth(1, 0) + self.setFont(qtlib.getfont('fontcomment').font()) + self.setCaretWidth(10) + self.setCaretLineBackgroundColor(QColor("#e6fff0")) + self.setCaretLineVisible(True) + self.setAutoIndent(True) + self.setAutoCompletionThreshold(2) + self.setAutoCompletionSource(QsciScintilla.AcsAPIs) + self.setAutoCompletionFillupsEnabled(True) + self.setLexer(QsciLexerMakefile(self)) + self.lexer().setFont(qtlib.getfont('fontcomment').font()) + self.lexer().setColor(QColor(Qt.red), QsciLexerMakefile.Error) + self.setMatchedBraceBackgroundColor(Qt.yellow) + self.setIndentationsUseTabs(False) + self.setBraceMatching(QsciScintilla.SloppyBraceMatch) + #self.setIndentationGuidesBackgroundColor(QColor("#e6e6de")) + #self.setFolding(QsciScintilla.BoxedFoldStyle) + # http://www.riverbankcomputing.com/pipermail/qscintilla/2009-February/000461.html + self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) + self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) + # default message entry widgets to word wrap, user may override + self.setWrapMode(QsciScintilla.WrapWord) + + self.getChecked = getCheckedFunc + self.setContextMenuPolicy(Qt.CustomContextMenu) + self.customContextMenuRequested.connect(self.menuRequested) + + def menuRequested(self, point): + line = self.lineAt(point) + point = self.viewport().mapToGlobal(point) + + def apply(): + line = 0 + while True: + line = self.reflowBlock(line) + if line is None: + break; + def paste(): + files = self.getChecked() + self.insert(', '.join(files)) + def settings(): + from tortoisehg.hgqt.settings import SettingsDialog + dlg = SettingsDialog(True, focus='tortoisehg.summarylen') + dlg.exec_() + + menu = self.createStandardContextMenu() + menu.addSeparator() + if self.getChecked: + action = menu.addAction(_('Paste &Filenames')) + action.triggered.connect(paste) + for name, func in [(_('App&ly Format'), apply), + (_('C&onfigure Format'), settings)]: + def add(name, func): + action = menu.addAction(name) + action.triggered.connect(func) + add(name, func) + return menu.exec_(point) + + def refresh(self, repo): + self.setEdgeColumn(repo.summarylen) + self.setIndentationWidth(repo.tabwidth) + self.setTabWidth(repo.tabwidth) + self.summarylen = repo.summarylen + + def reflowBlock(self, line): + lines = self.text().split('\n', QString.KeepEmptyParts) + if line >= len(lines): + return None + if not len(lines[line]) > 1: + return line+1 + + # find boundaries (empty lines or bounds) + b = line + while b and len(lines[b-1]) > 1: + b = b - 1 + e = line + while e+1 < len(lines) and len(lines[e+1]) > 1: + e = e + 1 + group = QStringList([lines[l].simplified() for l in xrange(b, e+1)]) + sentence = group.join(' ') + parts = sentence.split(' ', QString.SkipEmptyParts) + + outlines = QStringList() + line = QStringList() + partslen = 0 + for part in parts: + if partslen + len(line) + len(part) + 1 > self.summarylen: + if line: + outlines.append(line.join(' ')) + line, partslen = QStringList(), 0 + line.append(part) + partslen += len(part) + if line: + outlines.append(line.join(' ')) + + self.beginUndoAction() + self.setSelection(b, 0, e+1, 0) + self.removeSelectedText() + self.insertAt(outlines.join('\n')+'\n', b, 0) + self.endUndoAction() + self.setCursorPosition(b, 0) + return b + len(outlines) + 1 + + def moveCursorToEnd(self): + lines = self.lines() + if lines: + lines -= 1 + pos = self.lineLength(lines) + self.setCursorPosition(lines, pos) + self.ensureLineVisible(lines) + self.horizontalScrollBar().setSliderPosition(0) + + def keyPressEvent(self, event): + if event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_E: + line, col = self.getCursorPosition() + self.reflowBlock(line) + elif event.key() == Qt.Key_Backtab: + event.accept() + newev = QKeyEvent(event.type(), Qt.Key_Tab, Qt.ShiftModifier) + super(MessageEntry, self).keyPressEvent(newev) + else: + super(MessageEntry, self).keyPressEvent(event)
 
18
19
20
21
22
 
 
23
24
25
 
654
655
656
657
 
658
659
660
 
856
857
858
 
859
860
861
 
18
19
20
 
 
21
22
23
24
25
 
654
655
656
 
657
658
659
660
 
856
857
858
859
860
861
862
@@ -18,8 +18,8 @@
   from tortoisehg.util import hglib, patchctx  from tortoisehg.hgqt.i18n import _ -from tortoisehg.hgqt import qtlib, cmdui, rejects, commit, qscilib, thgrepo -from tortoisehg.hgqt import qqueue, qreorder, fileview, thgimport, status +from tortoisehg.hgqt import qtlib, cmdui, rejects, qscilib, thgrepo, status +from tortoisehg.hgqt import qqueue, qreorder, fileview, thgimport, messageentry  from tortoisehg.hgqt.qtlib import geticon    # TODO @@ -654,7 +654,7 @@
  mtbarhbox.addWidget(self.newCheckBox)   mtbarhbox.addWidget(self.patchNameLE, 1)   - self.messageEditor = commit.MessageEntry(self) + self.messageEditor = messageentry.MessageEntry(self)   self.messageEditor.installEventFilter(qscilib.KeyPressInterceptor(self))   self.messageEditor.refresh(repo)   @@ -856,6 +856,7 @@
  @pyqtSlot()   def qinitOrCommit(self):   if os.path.isdir(self.repo.mq.join('.hg')): + from tortoisehg.hgqt import commit   mqrepo = thgrepo.repository(None, self.repo.mq.path)   dlg = commit.CommitDialog(mqrepo, [], {}, self)   dlg.finished.connect(dlg.deleteLater)