Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

commit: handle character encoding of user combo box

Changeset 3e8b47b86254

Parent 8b840103709d

by André Sintzoff

Changes to one file · Browse files at 3e8b47b86254 Showing diff from parent 8b840103709d Diff from another changeset...

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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
 # commit.py - TortoiseHg's commit widget and standalone dialog  #  # Copyright 2010 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 mercurial import hg, ui, cmdutil, util, dispatch    from PyQt4.QtCore import *  from PyQt4.QtGui import *    from tortoisehg.hgqt.i18n import _  from tortoisehg.util import hglib, shlib, paths    from tortoisehg.hgqt import qtlib, status, cmdui    # Technical Debt for CommitWidget  # qrefresh support  # threaded / wrapped commit (need a CmdRunner equivalent)  # qctlib decode failure dialog (ask for locale, suggest HGENCODING)  # auto-add unknown files  # auto-rem missing files  # add rollback function with prompt  # +1 / -1 head indication (not as important with workbench integration)  # hook up username from command line to username combo  # recent committers history  # pushafterci, autoincludes list  # use username and date options  # implement a branchop dialog (in another file)  # qnew/shelve-patch creation dialog (in another file)  # reflow / auto-wrap / message format checks / paste filenames  # spell check / tab completion  # in-memory patching / committing chunk selected files    class CommitWidget(QWidget):   'A widget that encompasses a StatusWidget and commit extras'   loadBegin = pyqtSignal()   loadComplete = pyqtSignal()   errorMessage = pyqtSignal(QString)   commitComplete = pyqtSignal()   commit = pyqtSlot()     def __init__(self, pats, opts, root=None, parent=None):   QWidget.__init__(self, parent)     self.opts = opts # user, date   self.stwidget = status.StatusWidget(pats, opts, root, self)   self.connect(self.stwidget, SIGNAL('errorMessage'),   lambda m: self.emit(SIGNAL('errorMessage'), m))   self.msghistory = []     layout = QVBoxLayout()   layout.addWidget(self.stwidget)   self.setLayout(layout)   form = QFormLayout()   usercombo = QComboBox() - usercombo.addItem(self.stwidget.repo[None].user()) + usercombo.addItem(hglib.tounicode(self.stwidget.repo[None].user()))   usercombo.setEditable(True)   form.addRow(_('Changeset:'), QLabel(_('Working Copy')))   form.addRow(_('User:'), usercombo)   form.addRow(_('Parent:'), QLabel('Description of ' +   str(self.stwidget.repo['.'])))   frame = QFrame()   frame.setLayout(form)   frame.setFrameStyle(QFrame.StyledPanel)     vbox = QVBoxLayout()   vbox.addWidget(frame, 0)   vbox.setMargin(0)   hbox = QHBoxLayout()   branchop = QPushButton('Branch: default')   hbox.addWidget(branchop)   msgcombo = MessageHistoryCombo()   self.connect(msgcombo, SIGNAL('activated(int)'), self.msgSelected)   hbox.addWidget(msgcombo, 1)   vbox.addLayout(hbox, 0)   msgte = QTextEdit()   msgte.setAcceptRichText(False)   vbox.addWidget(msgte, 1)   upperframe = QFrame()   upperframe.setLayout(vbox)     self.split = QSplitter(Qt.Vertical)   # Add our widgets to the top of our splitter   self.split.addWidget(upperframe)   # Add status widget document frame below our splitter   # this reparents the docf from the status splitter   self.split.addWidget(self.stwidget.docf)     # add our splitter where the docf used to be   self.stwidget.split.addWidget(self.split)   msgte.setFocus()   # Yuki's Mockup: http://bitbucket.org/kuy/thg-qt/wiki/Home   self.usercombo = usercombo   self.msgte = msgte   self.msgcombo = msgcombo     def restoreState(self, data):   return self.stwidget.restoreState(data)     def saveState(self):   return self.stwidget.saveState()     def getMessage(self):   text = self.msgte.toPlainText()   try:   text = hglib.fromunicode(text, 'strict')   except UnicodeEncodeError:   pass   return text     def msgSelected(self, index):   doc = self.msgte.document()   if not doc.isEmpty() and doc.isModified():   d = QMessageBox.question(self, _('Confirm Discard Message'),   _('Discard current commit message?'),   QMessageBox.Ok | QMessageBox.Cancel)   if d != QMessageBox.Ok:   return   self.msgte.setPlainText(self.msghistory[index])   self.msgte.document().setModified(False)   self.msgte.moveCursor(QTextCursor.End)   self.msgte.setFocus()     def canExit(self):   # Usually safe to exit, since we're saving messages implicitly   # We'll ask the user for confirmation later, if they have any   # files partially selected.   return True     def loadConfigs(self, s):   'Load history, etc, from QSettings instance'   repo = self.stwidget.repo   repoid = str(repo[0])   # message history is stored in unicode   self.split.restoreState(s.value('commit/split').toByteArray())   self.msghistory = list(s.value('commit/history-'+repoid).toStringList())   self.msghistory = [s for s in self.msghistory if s]   self.msgcombo.reset(self.msghistory)   try:   curmsg = repo.opener('cur-message.txt').read()   self.msgte.setPlainText(hglib.fromunicode(curmsg))   self.msgte.document().setModified(False)   self.msgte.moveCursor(QTextCursor.End)   except EnvironmentError:   pass     def storeConfigs(self, s):   'Save history, etc, in QSettings instance'   repo = self.stwidget.repo   repoid = str(repo[0])   s.setValue('commit/history-'+repoid, self.msghistory)   s.setValue('commit/split', self.split.saveState())   try:   # current message is stored in local encoding   repo.opener('cur-message.txt', 'w').write(self.getMessage())   except EnvironmentError:   pass     def addMessageToHistory(self):   umsg = self.msgte.toPlainText()   if not umsg:   return   if umsg in self.msghistory:   self.msghistory.remove(umsg)   self.msghistory.insert(0, umsg)   self.msghistory = self.msghistory[:10]   self.msgcombo.reset(self.msghistory)     def commit(self):   msg = self.getMessage()   if not msg:   qtlib.WarningMsgBox(_('Nothing Commited'),   _('Please enter commit message'),   parent=self)   self.msgte.setFocus()   return   files = self.stwidget.getChecked()   if not files:   qtlib.WarningMsgBox(_('No files selected'),   _('No operation to perform'),   parent=self)   self.stwidget.tv.setFocus()   return   cmdline = ['commit', '--message', msg] + files   ret = dispatch._dispatch(self.stwidget.repo.ui, cmdline)   if not ret:   self.addMessageToHistory()   self.msgte.clear()   self.msgte.document().setModified(False)   self.emit(SIGNAL('commitComplete'))   return True   else:   return False    class MessageHistoryCombo(QComboBox):   def __init__(self, parent=None):   QComboBox.__init__(self, parent)   self.reset([])     def reset(self, msgs):   self.clear()   self.addItem(_('Recent commit messages...'))   self.loaded = False   self.msgs = msgs     def showPopup(self):   if not self.loaded:   self.clear()   for s in self.msgs:   self.addItem(s.split('\n', 1)[0][:70])   self.loaded = True   QComboBox.showPopup(self)    # Technical Debt for standalone tool  # add a toolbar for refresh, undo, etc  # add a statusbar and simple progressbar    class CommitDialog(QDialog):   'Standalone commit tool, a wrapper for CommitWidget'   def __init__(self, pats, opts, parent=None):   QDialog.__init__(self, parent)   self.pats = pats   self.opts = opts     layout = QVBoxLayout()   self.setLayout(layout)     commit = CommitWidget(pats, opts, None, self)   layout.addWidget(commit, 1)     BB = QDialogButtonBox   bb = QDialogButtonBox(BB.Ok|BB.Cancel)   self.connect(bb, SIGNAL("accepted()"), self, SLOT("accept()"))   self.connect(bb, SIGNAL("rejected()"), self, SLOT("reject()"))   bb.button(BB.Ok).setDefault(True)   bb.button(BB.Ok).setText('Commit')   layout.addWidget(bb)   self.bb = bb     s = QSettings()   commit.restoreState(s.value('commit/state').toByteArray())   self.restoreGeometry(s.value('commit/geom').toByteArray())   commit.loadConfigs(s)   commit.errorMessage.connect(self.errorMessage)     name = hglib.get_reponame(commit.stwidget.repo)   self.setWindowTitle('%s - commit' % name)   self.commit = commit     def errorMessage(self, msg):   print msg     def keyPressEvent(self, event):   if event.key() in (Qt.Key_Return, Qt.Key_Enter):   if event.modifiers() == Qt.ControlModifier:   self.accept() # Ctrl+Enter   return   elif event.key() == Qt.Key_Escape:   self.reject()   return   return super(QDialog, self).keyPressEvent(event)     def accept(self):   if self.commit.commit():   self.reject()   else:   self.commit.stwidget.refreshWctx()     def reject(self):   if self.commit.canExit():   s = QSettings()   s.setValue('commit/state', self.commit.saveState())   s.setValue('commit/geom', self.saveGeometry())   self.commit.storeConfigs(s)   QDialog.reject(self)    def run(ui, *pats, **opts):   return CommitDialog(hglib.canonpaths(pats), opts)