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

commit: add a details dialog for username and date options

More work remains to be done:
* Load opts['user'] and opts['date'] when in qref mode
* Clear those two fields when leaving qref mode
* Add QNew to the dialog
* Cleanup the layout

Changeset f1a171ba9fea

Parent 9237c04bb689

by Steve Borho

Changes to one file · Browse files at f1a171ba9fea Showing diff from parent 9237c04bb689 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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
 
 
 
 
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
 
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
 
 
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
 
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
418
419
420
421
422
 
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
 
511
512
513
514
515
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
 
762
 
 
 
763
764
765
766
767
768
 
 
 
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
 # 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, error  from mercurial.node import short as short_hex    from PyQt4.QtCore import *  from PyQt4.QtGui import *    from tortoisehg.hgqt.i18n import _  from tortoisehg.util import hglib, shlib, paths  from tortoisehg.util.util import format_desc    from tortoisehg.hgqt import qtlib, status, cmdui, branchop    # Technical Debt for CommitWidget  # threaded / wrapped commit (need a CmdRunner equivalent)  # qtlib decode failure dialog (ask for retry locale, suggest HGENCODING)  # Need a unicode-to-UTF8 function  # +1 / -1 head indication (not as important with workbench integration)  # pushafterci list  # qnew/shelve-patch creation dialog (in another file)  # 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()   commitButtonName = pyqtSignal(str)   showMessage = pyqtSignal(str)   commitComplete = pyqtSignal()     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.stwidget.showMessage.connect(self.showMessage)   self.stwidget.loadBegin.connect(lambda: self.loadBegin.emit())   self.stwidget.loadComplete.connect(lambda: self.loadComplete.emit())   self.msghistory = []   self.qref = False     layout = QVBoxLayout()   layout.setContentsMargins(0, 0, 0, 0)   layout.addWidget(self.stwidget)   self.setLayout(layout)     vbox = QVBoxLayout()   vbox.setMargin(0)   vbox.setContentsMargins(*(0,)*4)     hbox = QHBoxLayout()   hbox.setMargin(0)   hbox.setContentsMargins(*(0,)*4)   branchbutton = QPushButton(_('Branch: '))   branchbutton.pressed.connect(self.branchOp)   self.branchbutton = branchbutton   self.branchop = None   hbox.addWidget(branchbutton)   self.buttonHBox = hbox     msgcombo = MessageHistoryCombo()   self.connect(msgcombo, SIGNAL('activated(int)'), self.msgSelected)   hbox.addWidget(msgcombo, 1)   hbox.addSpacing(2)   vbox.addLayout(hbox, 0)   + self.detailsbutton = QPushButton(_('Details')) + self.detailsbutton.pressed.connect(self.details) + self.buttonHBox.addWidget(self.detailsbutton) +   self.parentvbox = QVBoxLayout()   self.parentlabels = [QLabel('<b>Parent:</b>')]   self.parentvbox.addWidget(self.parentlabels[0])   vbox.addLayout(self.parentvbox, 0)   - # TODO: move to details widget - usercombo = QComboBox() - usercombo.setEditable(True) -   msgte = QPlainTextEdit()   msgte.setLineWrapMode(QPlainTextEdit.NoWrap)   msgfont = qtlib.getfont(self.stwidget.repo.ui, 'fontcomment')   msgte.setFont(msgfont.font())   msgfont.changed.connect(lambda fnt: msgte.setFont(fnt))   msgte.textChanged.connect(self.msgChanged)   msgte.setContextMenuPolicy(Qt.CustomContextMenu)   msgte.customContextMenuRequested.connect(self.menuRequested)   vbox.addWidget(msgte, 1)   upperframe = QFrame()     SP = QSizePolicy   sp = SP(SP.Expanding, SP.Expanding)   sp.setHorizontalStretch(1)   upperframe.setSizePolicy(sp)   upperframe.setLayout(vbox)     self.split = QSplitter(Qt.Vertical)   sp = SP(SP.Expanding, SP.Expanding)   sp.setHorizontalStretch(1)   sp.setVerticalStretch(0)   self.split.setSizePolicy(sp)   # 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 details(self): + dlg = DetailsDialog(self.opts, self.userhist, self) + if dlg.exec_() == QDialog.Accepted: + self.opts.update(dlg.outopts) +   def reload(self):   repo = self.stwidget.repo   repo.thginvalidate()   wctx = repo[None]     # Update qrefresh mode   if repo.changectx('.').thgmqappliedpatch():   self.commitButtonName.emit(_('QRefresh'))   if not self.qref:   self.initQRefreshMode()   else:   self.commitButtonName.emit(_('Commit'))   if self.qref:   self.endQRefreshMode()     # Update message list   self.msgcombo.reset(self.msghistory)     # Update branch operation button   cur = hglib.tounicode(wctx.branch())   if self.branchop is None:   title = _('Branch: ') + cur   elif self.branchop == False:   title = _('Close Branch: ') + cur   else:   title = _('New Branch: ') + self.branchop   self.branchbutton.setText(title)     # Update parent revision(s)   for i, ctx in enumerate(repo.parents()):   desc = format_desc(ctx.description(), 80)   fmt = "<span style='font-family:Courier'>%s(%s)</span> %s"   ptext = fmt % (ctx.rev(), short_hex(ctx.node()), desc)   ptext = _('<b>Parent: </b>') + ptext   if i > len(self.parentlabels):   lbl = QLabel(ptext)   #lbl.minimumSizeHint = lambda: QSize(0, 0)   self.parentvbox.addWidget(lbl)   self.parentlabels.append(lbl)   else:   self.parentlabels[i].setText(ptext)   while len(repo.parents()) > len(self.parentlabels):   w = self.parentlabels.pop()   self.parentvbox.removeWidget(w)     # Trigger reload of working context   self.stwidget.refreshWctx()     def initQRefreshMode(self):   'Working parent is a patch. Is it refreshable?'   repo = self.stwidget.repo   if repo['qtip'] != repo['.']:   self.showMessage.emit(_('Cannot refresh non-tip patch'))   self.commitButtonName.emit(_('N/A'))   return   self.msgte.setPlainText(hglib.tounicode(repo['qtip'].description()))   self.msgte.document().setModified(False)   self.msgte.moveCursor(QTextCursor.End)   self.qref = True     def endQRefreshMode(self):   self.msgte.clear()   self.qref = False     def msgChanged(self):   text = self.msgte.toPlainText()   self.buttonHBox.setEnabled(not text.isEmpty())   sumlen, maxlen = self.getLengths()   if not sumlen and not maxlen:   self.msgte.setExtraSelections([])   return   pos, nextpos = 0, 0   sels = []   for i, line in enumerate(text.split('\n')):   length = len(line)   pos = nextpos   nextpos += length + 1 # include \n   if i == 0:   if length < sumlen or not sumlen:   continue   pos += sumlen   elif i == 1:   if length == 0 or not sumlen:   continue   else:   if length < maxlen or not maxlen:   continue   pos += maxlen   sel = QTextEdit.ExtraSelection()   sel._bgcolor = QColor('LightSalmon')   sel._fgcolor = QColor('Black')   sel.format.setBackground(sel._bgcolor)   sel.format.setForeground(sel._fgcolor)   sel.cursor = QTextCursor(self.msgte.document())   sel.cursor.setPosition(pos)   sel.cursor.movePosition(QTextCursor.EndOfLine, QTextCursor.KeepAnchor)   sels.append(sel)   self.msgte.setExtraSelections(sels)     def msgReflow(self):   'User pressed Control-E, reflow current paragraph'   if QApplication.focusWidget() != self.msgte:   return   self.reflowBlock(self.msgte.textCursor().block())     def reflowBlock(self, block):   sumlen, maxlen = self.getLengths()   if not maxlen:   return   # In QtTextDocument land, a block is a sequence of text ending   # in (and including) a carriage return. Aka, a line of text.   while block.length() and block.previous().length() > 1:   block = block.previous()   begin = block.position()     while block.length() and block.next().length() > 1:   block = block.next()   end = block.position() + block.length() - 1     # select the contiguous lines of text under the cursor   cursor = self.msgte.textCursor()   cursor.setPosition(begin, QTextCursor.MoveAnchor)   cursor.setPosition(end, QTextCursor.KeepAnchor)   sentence = cursor.selection().toPlainText().simplified()     parts = sentence.split(' ', QString.SkipEmptyParts)   lines = QStringList()   line = QStringList()   partslen = 0   for part in parts:   if partslen + len(line) + len(part) + 1 > maxlen:   if line:   lines.append(line.join(' '))   line, partslen = QStringList(), 0   line.append(part)   partslen += len(part)   if line:   lines.append(line.join(' '))   reflow = lines.join('\n')     # Replace selection with new sentence   cursor.insertText(reflow)   return cursor.block()     def menuRequested(self, point):   cursor = self.msgte.cursorForPosition(point)   point = self.msgte.mapToGlobal(point)     def apply():   sumlen, maxlen = self.getLengths()   if not maxlen:   return   block = self.msgte.document().firstBlock()   while block != self.msgte.document().end():   if block.length() > maxlen:   block = self.reflowBlock(block)   block = block.next()   def paste():   files = self.stwidget.getChecked()   cursor.insertText(', '.join(files))   def settings():   from tortoisehg.hgqt.settings import SettingsDialog   dlg = SettingsDialog(True, focus='tortoisehg.summarylen')   if dlg.exec_() == QDialog.Accepted:   repo = self.stwidget.repo   repo.ui = hglib.reloadui(repo.root)   self.msgChanged()     menu = self.msgte.createStandardContextMenu()   for name, func in [(_('Paste &Filenames'), paste),   (_('App&ly Format'), apply),   (_('C&onfigure Format'), settings)]:   action = menu.addAction(name)   action.wrapper = lambda f=func: f()   self.connect(action, SIGNAL('triggered()'), action.wrapper)   return menu.exec_(point)     def getLengths(self):   repo = self.stwidget.repo   try:   sumlen = int(repo.ui.config('tortoisehg', 'summarylen', 0))   maxlen = int(repo.ui.config('tortoisehg', 'messagewrap', 0))   except (TypeError, ValueError):   sumlen, maxlen = 0, 0   return sumlen, maxlen     def restoreState(self, data):   return self.stwidget.restoreState(data)     def saveState(self):   return self.stwidget.saveState()     def branchOp(self):   d = branchop.BranchOpDialog(self.stwidget.repo, self.branchop)   if d.exec_() == QDialog.Accepted:   self.branchop = d.branchop   self.reload()     def canUndo(self):   'Returns undo description or None if not valid'   repo = self.stwidget.repo   if os.path.exists(repo.sjoin('undo')):   try:   args = repo.opener('undo.desc', 'r').read().splitlines()   if args[1] != 'commit':   return None   return _('Rollback commit to revision %d') % (int(args[0]) - 1)   except (IOError, IndexError, ValueError):   pass   return None     def rollback(self):   msg = self.canUndo()   if not msg:   return   d = QMessageBox.question(self, _('Confirm Undo'), msg,   QMessageBox.Ok | QMessageBox.Cancel)   if d != QMessageBox.Ok:   return   repo = self.stwidget.repo   repo.rollback()   repo.thginvalidate()   self.reload()   QTimer.singleShot(500, lambda: shlib.shell_notify([repo.root]))     def getMessage(self):   text = self.msgte.toPlainText()   try:   text = hglib.fromunicode(text, 'strict')   except UnicodeEncodeError:   pass # TODO   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 = [m for m in self.msghistory if m]   self.msgcombo.reset(self.msghistory)   self.userhist = s.value('commit/userhist').toStringList()   self.userhist = [u for u in self.userhist if u] - self.refreshUserList()   try:   curmsg = repo.opener('cur-message.txt').read()   self.msgte.setPlainText(hglib.tounicode(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())   s.setValue('commit/userhist', self.userhist)   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]   - def refreshUserList(self): - self.usercombo.clear() - l = [] - try: - repo = self.stwidget.repo - wctx = repo[None] - if self.opts.get('user'): - val = hglib.tounicode(self.opts['user']) - l.append(val) - val = hglib.tounicode(wctx.user()) - l.append(val) - except util.Abort: - pass - for name in self.userhist: - if name not in l: - l.append(name) - for name in l: - self.usercombo.addItem(name) -   def addUsernameToHistory(self, user):   if user in self.userhist:   self.userhist.remove(user)   self.userhist.insert(0, user)   self.userhist = self.userhist[:10] - self.refreshUserList() + + def getCurrentUsername(self): + # 1. Override has highest priority + user = self.opts.get('user') + if user: + return user + + # 2. Read from repository + try: + return self.stwidget.repo.ui.username() + except error.Abort: + pass + + # 3. Get a username from the user + QMessageBox.information(self, _('Please enter a username'), + _('You must identify yourself to Mercurial'), + QMessageBox.Ok) + from tortoisehg.hgqt.settings import SettingsDialog + dlg = SettingsDialog(False, focus='ui.username') + dlg.exec_() + self.stwidget.repo.ui.invalidateui() + try: + return self.stwidget.repo.ui.username() + except error.Abort: + return None     def commit(self):   repo = self.stwidget.repo   ui = repo.ui   cwd = os.getcwd()   try:   os.chdir(repo.root)   return self._commit(repo, ui)   finally:   os.chdir(cwd)     def _commit(self, repo, _ui):   msg = self.getMessage()   if not msg:   qtlib.WarningMsgBox(_('Nothing Commited'),   _('Please enter commit message'),   parent=self)   self.msgte.setFocus()   return   repo = self.stwidget.repo   if self.branchop is None:   brcmd = []   elif self.branchop == False:   brcmd = ['--close-branch']   else:   brcmd = []   # TODO: Need a unicode-to-UTF8 function   newbranch = hglib.fromunicode(self.branchop)   if newbranch in repo.branchtags():   # response: 0=Yes, 1=No, 2=Cancel   pb = [p.branch() for p in repo.parents()]   if self.nextbranch in pb:   resp = 0   else:   rev = repo[newbranch].rev()   resp = qtlib.CustomPrompt(_('Confirm Branch Change'),   _('Named branch "%s" already exists, '   'last used in revision %d\n'   'Yes\t- Make commit restarting this named branch\n'   'No\t- Make commit without changing branch\n'   'Cancel\t- Cancel this commit') % (newbranch, rev),   self, (_('&Yes'), _('&No'), _('Cancel')), 2, 2).run()   else:   resp = qtlib.CustomPrompt(_('Confirm New Branch'),   _('Create new named branch "%s" with this commit?\n'   'Yes\t- Start new branch with this commit\n'   'No\t- Make commit without branch change\n'   'Cancel\t- Cancel this commit') % newbranch,   self, (_('&Yes'), _('&No'), _('Cancel')), 2, 2).run()   if resp == 0:   repo.dirstate.setbranch(newbranch)   elif resp == 2:   return   files = self.stwidget.getChecked('MAR?!S')   if not (files or brcmd or repo[None].branch() != repo['.'].branch() \   or self.qref):   qtlib.WarningMsgBox(_('No files checked'),   _('No modified files checkmarked for commit'),   parent=self)   self.stwidget.tv.setFocus()   return   if len(repo.parents()) > 1:   files = [] - user = self.usercombo.currentText() + + user = self.getCurrentUsername() + if not user: + return   self.addUsernameToHistory(user) - user = hglib.fromunicode(user, 'strict') - if not user: - try: - QMessageBox.information(self, _('Please enter a username'), - _('You must identify yourself to Mercurial'), - QMessageBox.Ok) - from tortoisehg.hgqt.settings import SettingsDialog - dlg = SettingsDialog(False, focus='ui.username') - dlg.exec_() - user = ui.ui().username() - if user: - self.usercombo.addItem(hglib.tounicode(user)) - except util.Abort: - pass - if not user: - self.usercombo.setFocus() - return +   checkedUnknowns = self.stwidget.getChecked('?I')   if checkedUnknowns:   res = qtlib.CustomPrompt(   _('Confirm Add'),   _('Add checked untracked files?'), self,   (_('&OK'), _('Cancel')), 0, 1,   checkedUnknowns).run()   if res == 0:   dispatch._dispatch(_ui, ['add'] + checkedUnknowns)   else:   return   checkedMissing = self.stwidget.getChecked('!')   if checkedMissing:   res = qtlib.CustomPrompt(   _('Confirm Remove'),   _('Remove checked deleted files?'), self,   (_('&OK'), _('Cancel')), 0, 1,   checkedMissing).run()   if res == 0:   dispatch._dispatch(_ui, ['remove'] + checkedMissing)   else:   return   try:   date = self.opts.get('date')   if date:   util.parsedate(date)   dcmd = ['--date', date]   else:   dcmd = []   except error.Abort, e:   self.showMessage.emit(hglib.tounicode(str(e)))   dcmd = []     cmdline = ['commit', '--user', user, '--message', msg]   cmdline += dcmd + brcmd + files   if self.qref:   cmdline[0] = 'qrefresh'     for fname in repo.ui.config('tortoisehg', 'autoinc', '').split(','):   fname = fname.strip()   if fname:   cmdline.extend(['--include', fname])     ret = dispatch._dispatch(_ui, cmdline)   if not ret:   self.addMessageToHistory()   if not self.qref:   self.msgte.clear()   self.msgte.document().setModified(False)   self.commitComplete.emit()   return True   else:   return False     def keyPressEvent(self, event):   if event.key() in (Qt.Key_Return, Qt.Key_Enter):   if event.modifiers() == Qt.ControlModifier:   self.commit()   return   if event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_E:   self.msgReflow()   return super(CommitWidget, self).keyPressEvent(event)    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)   + +class DetailsDialog(QDialog): + 'Utility dialog for configuring uncommon settings' + def __init__(self, opts, userhistory, parent): + QDialog.__init__(self, parent) + self.repo = parent.stwidget.repo + + layout = QVBoxLayout() + self.setLayout(layout) + + hbox = QHBoxLayout() + self.usercb = QCheckBox(_('Set username:')) + + usercombo = QComboBox() + usercombo.setEditable(True) + usercombo.setEnabled(False) + self.usercb.toggled.connect(usercombo.setEnabled) + + l = [] + if opts.get('user'): + val = hglib.tounicode(self.opts['user']) + self.usercb.setChecked(True) + l.append(val) + try: + val = hglib.tounicode(self.repo.ui.username()) + l.append(val) + except util.Abort: + pass + for name in userhistory: + if name not in l: + l.append(name) + for name in l: + usercombo.addItem(name) + self.usercombo = usercombo + + usersaverepo = QPushButton(_('Save in Repo')) + usersaverepo.clicked.connect(self.saveInRepo) + usersaverepo.setEnabled(False) + self.usercb.toggled.connect(usersaverepo.setEnabled) + + usersaveglobal = QPushButton(_('Save Global')) + usersaveglobal.clicked.connect(self.saveGlobal) + usersaveglobal.setEnabled(False) + self.usercb.toggled.connect(usersaveglobal.setEnabled) + + hbox.addWidget(self.usercb) + hbox.addWidget(self.usercombo) + hbox.addWidget(usersaverepo) + hbox.addWidget(usersaveglobal) + layout.addLayout(hbox) + + hbox = QHBoxLayout() + self.datecb = QCheckBox(_('Set Date:')) + self.datele = QLineEdit() + self.datele.setEnabled(False) + self.datecb.toggled.connect(self.datele.setEnabled) + curdate = QPushButton(_('Update')) + curdate.setEnabled(False) + self.datecb.toggled.connect(curdate.setEnabled) + curdate.clicked.connect( lambda: self.datele.setText( + hglib.tounicode(hglib.utctime(util.makedate())))) + if opts.get('date'): + self.datele.setText(opts['date']) + self.datecb.setChecked(True) + else: + self.datecb.setChecked(False) + curdate.clicked.emit(True) + + hbox.addWidget(self.datecb) + hbox.addWidget(self.datele) + hbox.addWidget(curdate) + layout.addLayout(hbox) + + if 'mq' in self.repo.extensions(): + hbox = QHBoxLayout() + + BB = QDialogButtonBox + bb = QDialogButtonBox(BB.Ok|BB.Cancel) + self.connect(bb, SIGNAL("accepted()"), self, SLOT("accept()")) + self.connect(bb, SIGNAL("rejected()"), self, SLOT("reject()")) + self.bb = bb + layout.addWidget(bb) + + name = hglib.get_reponame(self.repo) + self.setWindowTitle('%s - commit details' % name) + + def saveInRepo(self): + fn = os.path.join(self.repo.root, '.hg', 'hgrc') + self.saveToPath([fn]) + + def saveGlobal(self): + self.saveToPath(util.user_rcpath()) + + def saveToPath(self, path): + from tortoisehg.hgqt.sync import loadIniFile + fn, cfg = loadIniFile(path, self) + if not hasattr(cfg, 'write'): + qtlib.WarningMsgBox(_('Unable to save post pull operation'), + _('Iniparse must be installed.'), parent=self) + return + if fn is None: + return + try: + user = hglib.fromunicode(self.usercombo.currentText()) + if user: + cfg.set('ui', 'username', user) + else: + try: + del cfg['ui']['username'] + except KeyError: + pass + wconfig.writefile(cfg, fn) + except IOError, e: + qtlib.WarningMsgBox(_('Unable to write configuration file'), + hglib.tounicode(e), parent=self) + + def accept(self): + outopts = {} + if self.datecb.isChecked(): + date = hglib.fromunicode(self.datele.text()) + try: + util.parsedate(date) + except error.Abort, e: + qtlib.WarningMsgBox(_('Invalid date format'), + hglib.tounicode(e), parent=self) + return + outopts['date'] = date + else: + outopts['date'] = '' + + if self.usercb.isChecked(): + user = hglib.fromunicode(self.usercombo.currentText()) + else: + user = '' + + outopts['user'] = user + if not user: + try: + self.repo.ui.username() + except util.Abort, e: + qtlib.WarningMsgBox(_('No username configured'), + hglib.tounicode(e), parent=self) + return + + self.outopts = outopts + QDialog.accept(self) +  # Technical Debt for standalone tool  # add a toolbar for refresh  # 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) - layout.setContentsMargins(0, 6, 0, 0)   - bbl = QHBoxLayout() - layout.addLayout(bbl) - layout.addSpacing(9)   BB = QDialogButtonBox   bb = QDialogButtonBox(BB.Ok|BB.Cancel|BB.Discard)   self.connect(bb, SIGNAL("accepted()"), self, SLOT("accept()"))   self.connect(bb, SIGNAL("rejected()"), self, SLOT("reject()"))   bb.button(BB.Discard).setText('Undo')   bb.button(BB.Discard).clicked.connect(commit.rollback) - bbl.addWidget(bb, alignment=Qt.AlignRight) - bbl.addSpacing(9) - self.bb = bb   bb.button(BB.Cancel).setDefault(False)   bb.button(BB.Discard).setDefault(False)   bb.button(BB.Ok).setDefault(True) + 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.showMessage.connect(self.showMessage)   commit.loadComplete.connect(self.updateUndo)   commit.commitComplete.connect(self.postcommit)   commit.commitButtonName.connect(self.setButtonName)     name = hglib.get_reponame(commit.stwidget.repo)   self.setWindowTitle('%s - commit' % name)   self.commit = commit   self.commit.reload()     def setButtonName(self, name):   self.bb.button(QDialogButtonBox.Ok).setText(name)     def updateUndo(self):   BB = QDialogButtonBox   undomsg = self.commit.canUndo()   if undomsg:   self.bb.button(BB.Discard).setEnabled(True)   self.bb.button(BB.Discard).setToolTip(undomsg)   else:   self.bb.button(BB.Discard).setEnabled(False)   self.bb.button(BB.Discard).setToolTip('')     def showMessage(self, msg):   print msg     def keyPressEvent(self, event):   if event.key() == Qt.Key_Escape:   self.reject()   return   elif event.matches(QKeySequence.Refresh):   self.commit.reload()   return super(CommitDialog, self).keyPressEvent(event)     def postcommit(self):   repo = self.commit.stwidget.repo   if repo.ui.configbool('tortoisehg', 'closeci'):   self.reject()   return   self.commit.reload()     def accept(self):   self.commit.commit()     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)