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

commit: add qnew/qrefresh button to commit widget

Changeset afe08b4e6fd6

Parent 52e2b36d5a62

by Phil Currier

Changes to 2 files · Browse files at afe08b4e6fd6 Showing diff from parent 52e2b36d5a62 Diff from another changeset...

 
16
17
18
19
 
20
21
22
 
157
158
159
 
160
161
162
 
172
173
174
 
 
 
 
175
176
177
 
255
256
257
 
 
 
 
 
 
 
 
 
 
 
 
 
258
259
260
 
289
290
291
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
292
293
294
 
394
395
396
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
397
398
399
 
642
643
644
645
 
 
 
646
 
647
648
649
 
651
652
653
654
 
655
656
 
657
658
659
660
661
662
663
664
665
666
667
 
 
 
 
 
 
 
 
 
668
669
670
 
16
17
18
 
19
20
21
22
 
157
158
159
160
161
162
163
 
173
174
175
176
177
178
179
180
181
182
 
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
 
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
 
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
 
803
804
805
 
806
807
808
809
810
811
812
813
 
815
816
817
 
818
819
820
821
822
823
 
 
824
825
 
 
 
 
 
826
827
828
829
830
831
832
833
834
835
836
837
@@ -16,7 +16,7 @@
 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 +from tortoisehg.hgqt import hgrcutil, mq    # Technical Debt for CommitWidget  # disable commit button while no message is entered or no files are selected @@ -157,6 +157,7 @@
 class CommitWidget(QWidget, qtlib.TaskWidget):   'A widget that encompasses a StatusWidget and commit extras'   commitButtonEnable = pyqtSignal(bool) + mqButtonEnable = pyqtSignal(bool)   linkActivated = pyqtSignal(QString)   showMessage = pyqtSignal(unicode)   commitComplete = pyqtSignal() @@ -172,6 +173,10 @@
  repo.repositoryChanged.connect(self.repositoryChanged)   repo.workingBranchChanged.connect(self.workingBranchChanged)   self.repo = repo + self.lastAction = None + self.lastCommitMsg = '' + self.currentAction = None + self.currentProgress = None     opts['ciexclude'] = repo.ui.config('tortoisehg', 'ciexclude', '')   opts['pushafter'] = repo.ui.config('tortoisehg', 'cipushafter', '') @@ -255,6 +260,19 @@
  vbox.addLayout(hbox, 0)   self.buttonHBox = hbox   + if embedded and 'mq' in self.repo.extensions(): + self.hasmqbutton = True + pnhbox = QHBoxLayout() + self.pnlabel = QLabel() + pnhbox.addWidget(self.pnlabel) + self.pnedit = mq.getPatchNameLineEdit() + self.pnedit.setMaximumWidth(250) + pnhbox.addWidget(self.pnedit) + pnhbox.addStretch() + vbox.addLayout(pnhbox) + else: + self.hasmqbutton = False +   self.pcsinfo = revpanel.ParentWidget(repo)   vbox.addWidget(self.pcsinfo, 0)   @@ -289,6 +307,131 @@
  QShortcut(QKeySequence('Ctrl+Enter'), self, self.commit).setContext(   Qt.WidgetWithChildrenShortcut)   + def mqSetupButton(self): + ispatch = lambda r: 'qtip' in r.changectx('.').tags() + notpatch = lambda r: 'qtip' not in r.changectx('.').tags() + acts = ( + ('commit', _('Commit changes'), _('Commit'), notpatch), + ('qnew', _('Create a new patch'), _('QNew'), None), + ('qref', _('Refresh current patch'), _('QRefresh'), ispatch), + ) + + class MQToolButton(QToolButton): + def styleOption(self): + opt = QStyleOptionToolButton() + opt.initFrom(self) + return opt + def menuButtonWidth(self): + style = self.style() + opt = self.styleOption() + opt.features = QStyleOptionToolButton.MenuButtonPopup + rect = style.subControlRect(QStyle.CC_ToolButton, opt, + QStyle.SC_ToolButtonMenu, self) + return rect.width() + def setBold(self): + f = self.font() + f.setWeight(QFont.Bold) + self.setFont(f) + def sizeHint(self): + # Set the desired width to keep the button from resizing + return QSize(self._width, QToolButton.sizeHint(self).height()) + + self.mqtb = mqtb = MQToolButton(self) + mqtb.setBold() + mqtb.setPopupMode(QToolButton.MenuButtonPopup) + fmk = lambda s: mqtb.fontMetrics().width(hglib.tounicode(s[2])) + mqtb._width = max(map(fmk, acts)) + 4*mqtb.menuButtonWidth() + + class MQMenu(QMenu): + def __init__(self, parent, repo): + self.repo = repo + return QMenu.__init__(self, parent) + def getActionByName(self, act): + return [a for a in self.actions() if a._name == act][0] + def showEvent(self, event): + for a in self.actions(): + if a._enablefunc: + a.setEnabled(a._enablefunc(self.repo)) + return QMenu.showEvent(self, event) + self.mqgroup = QActionGroup(self) + mqmenu = MQMenu(mqtb, self.repo) + menurefresh = lambda: self.mqSetAction(refresh=True) + for a in acts: + action = QAction(a[1], self.mqgroup) + action._name = a[0] + action._text = a[2] + action._enablefunc = a[3] + action.triggered.connect(menurefresh) + action.setCheckable(True) + if a[3] and a[3](self.repo): + action.setChecked(True) + mqmenu.addAction(action) + mqtb.setMenu(mqmenu) + mqtb.clicked.connect(self.mqPerformAction) + self.mqButtonEnable.connect(mqtb.setEnabled) + self.mqSetAction() + return mqtb + + @pyqtSlot(bool) + def mqSetAction(self, refresh=False): + curraction = self.mqgroup.checkedAction() + oldpctx = self.stwidget.pctx + pctx = self.repo.changectx('.') + if curraction._name == 'qnew': + self.pnlabel.setVisible(True) + self.pnedit.setVisible(True) + self.pnedit.setFocus() + self.pnedit.setText(mq.defaultNewPatchName(self.repo)) + self.pnedit.selectAll() + self.stwidget.setPatchContext(None) + refreshwctx = refresh and oldpctx is not None + else: + self.pnlabel.setVisible(False) + self.pnedit.setVisible(False) + ispatch = 'qtip' in pctx.tags() + def switchAction(action, name): + action.setChecked(False) + action = self.mqtb.menu().getActionByName(name) + action.setChecked(True) + return action + if curraction._name == 'qref' and not ispatch: + curraction = switchAction(curraction, 'commit') + elif curraction._name == 'commit' and ispatch: + curraction = switchAction(curraction, 'qref') + if curraction._name == 'qref': + refreshwctx = refresh + self.stwidget.setPatchContext(pctx) + elif curraction._name == 'commit': + refreshwctx = refresh and oldpctx is not None + self.stwidget.setPatchContext(None) + if curraction._name == 'qref': + if self.lastAction != 'qref': + self.lastCommitMsg = self.msgte.text() + self.setMessage(hglib.tounicode(pctx.description())) + else: + self.setMessage(self.lastCommitMsg) + if refreshwctx: + self.stwidget.refreshWctx() + self.mqtb.setText(curraction._text) + self.lastAction = curraction._name + + @pyqtSlot() + def mqPerformAction(self): + curraction = self.mqgroup.checkedAction() + if curraction._name == 'commit': + return self.commit() + olist = ('user', 'date') + cmdlines = mq.mqNewRefreshCommand(self.repo, curraction._name == 'qnew', + self.stwidget, self.pnedit, + self.msgte.text(), self.opts, olist) + self.repo.incrementBusyCount() + self.currentAction = curraction._name + self.currentProgress = _('MQ Action', 'start progress') + self.progress.emit(*cmdui.startProgress(self.currentProgress, '')) + self.commitButtonEnable.emit(False) + self.mqButtonEnable.emit(False) + self.runner.run(*cmdlines) +   @pyqtSlot(QString, QString)   def fileDisplayed(self, wfile, contents):   'Status widget is displaying a new file' @@ -394,6 +537,24 @@
  self.pcsinfo.set_revision(None)   self.pcsinfo.update()   + # This is ugly, but want pnlabel to have the same alignment/style/etc + # as pcsinfo, so extract the needed parts of pcsinfo's markup. Would + # be nicer if csinfo exposed this information, or if csinfo could hold + # widgets like pnlabel. + if self.hasmqbutton: + parent = hglib.fromunicode(_('Parent:')) + patchname = hglib.fromunicode(_('Patch name:')) + text = hglib.fromunicode(self.pcsinfo.revlabel.text()) + cellend = '</td>' + firstidx = text.find(cellend) + len(cellend) + secondidx = text[firstidx:].rfind('</tr>') + if firstidx >= 0 and secondidx >= 0: + start = text[0:firstidx].replace(parent, patchname) + self.pnlabel.setText(start + text[firstidx+secondidx:]) + else: + self.pnlabel.setText(patchname) + self.mqSetAction() +   def branchOp(self):   d = branchop.BranchOpDialog(self.repo, self.branchop, self)   d.setWindowFlags(Qt.Sheet) @@ -642,8 +803,11 @@
  commandlines.append(cmd)     repo.incrementBusyCount() - self.progress.emit(*cmdui.startProgress(_('Commit', 'start progress'), '')) + self.currentAction = 'commit' + self.currentProgress = _('Commit', 'start progress') + self.progress.emit(*cmdui.startProgress(self.currentProgress, ''))   self.commitButtonEnable.emit(False) + self.mqButtonEnable.emit(False)   self.runner.run(*commandlines)   self.stopAction.setEnabled(True)   @@ -651,20 +815,23 @@
  self.runner.cancel()     def commandFinished(self, ret): - self.progress.emit(*cmdui.stopProgress(_('Commit', 'stop progress'))) + self.progress.emit(*cmdui.stopProgress(self.currentProgress))   self.stopAction.setEnabled(False)   self.commitButtonEnable.emit(True) + self.mqButtonEnable.emit(True)   self.repo.decrementBusyCount()   if ret == 0: - # capture last message for BugTraq plugin - self.lastmessage = self.getMessage()   self.branchop = None   umsg = self.msgte.text() - if umsg: - self.addMessageToHistory(umsg) - self.msgte.clear() - self.msgte.setModified(False) - self.commitComplete.emit() + if self.currentAction != 'qref': + if self.currentAction == 'commit': + # capture last message for BugTraq plugin + self.lastmessage = self.getMessage() + if umsg: + self.addMessageToHistory(umsg) + self.setMessage('') + if self.currentAction == 'commit': + self.commitComplete.emit()    class DetailsDialog(QDialog):   'Utility dialog for configuring uncommon settings'
 
272
273
274
275
276
277
278
279
280
281
282
 
 
 
 
 
 
 
 
 
 
 
283
284
285
 
272
273
274
 
 
 
 
 
 
 
 
275
276
277
278
279
280
281
282
283
284
285
286
287
288
@@ -272,14 +272,17 @@
  pats, opts = {}, {}   cw = CommitWidget(self.repo, pats, opts, True, self)   - b = QPushButton(_('Commit', 'action button')) - b.setAutoDefault(True) - f = b.font() - f.setWeight(QFont.Bold) - b.setFont(f) - cw.buttonHBox.addWidget(b) - cw.commitButtonEnable.connect(b.setEnabled) - b.clicked.connect(cw.commit) + if cw.hasmqbutton: + cw.buttonHBox.addWidget(cw.mqSetupButton()) + else: + b = QPushButton(_('Commit', 'action button')) + b.setAutoDefault(True) + f = b.font() + f.setWeight(QFont.Bold) + b.setFont(f) + cw.buttonHBox.addWidget(b) + cw.commitButtonEnable.connect(b.setEnabled) + b.clicked.connect(cw.commit)   cw.loadSettings(QSettings(), 'workbench')     cw.output.connect(self.output)