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

commit: begin development on a Qt commit tool

commit.py will house a CommitWidget, which holds most of the commit tool logic.
It is essentially a wrapper for a StatusWidget plus the commit extras.

It will also house a CommitDialog, a lightweight QDialog wrapper for a Commit
Widget, providing all the framework for preserving geometry, progress/status
bar, running commands, and handling events. Everyone who begged for 'ESC' to
close the commit tool will finally be happy. The CommitDialog will have no
toolbar, and will have a typical dialog button bar on the bottom.

The CommitWidget is also intended to be embedded in the WorkBench app, so it
will present a generic SIGNAL/SLOT interface to its parent application. The
WorkBench app may place the commit button wherever it likes.

Changeset 266fd331ee06

Parent 7c9018c7df02

by Steve Borho

Changes to 2 files · Browse files at 266fd331ee06 Showing diff from parent 7c9018c7df02 Diff from another changeset...

Change 1 of 1 Show Entire File tortoisehg/​hgqt/​commit.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
@@ -0,0 +1,144 @@
+# 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 + +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 + +class CommitWidget(QWidget): + '''A widget that encompasses a StatusWidget and commit extras + SIGNALS: + loadBegin() - for progress bar + loadComplete() - for progress bar + errorMessage(QString) - for status bar + titleTextChanged(QString) - for window title + commitComplete(QString) - refresh notification + ''' + 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) + layout = QVBoxLayout() + layout.addWidget(self.stwidget) + self.setLayout(layout) + # TODO add commit widgets + # branchop dialog + # message history selection widget + # username entry + # message entry + # parent text + # Yuki's Mockup: http://bitbucket.org/kuy/thg-qt/wiki/Home + + def restoreState(self, data): + return self.stwidget.restoreState(data) + + def saveState(self): + return self.stwidget.saveState() + + def getChecked(self): + return self.stwidget.getChecked() + +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 + + cmd = cmdui.Widget() + cmd.commandStarted.connect(self.commandStarted) + cmd.commandFinished.connect(self.commandFinished) + cmd.commandCanceling.connect(self.commandCanceled) + layout.addWidget(cmd) + cmd.setHidden(True) + self.cmd = cmd + + s = QSettings() + commit.restoreState(s.value('commit/state').toByteArray()) + self.restoreGeometry(s.value('commit/geom').toByteArray()) + self.commit = commit + + self.connect(self.commit, SIGNAL('errorMessage'), + self.errorMessage) + + def errorMessage(self, msg): + # TODO: Does not appear to work + self.cmd.pmon.set_text(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 commandStarted(self): + self.cmd.setShown(True) + self.bb.button(QDialogButtonBox.Ok).setEnabled(False) + + def commandFinished(self, wrapper): + self.bb.button(QDialogButtonBox.Ok).setEnabled(True) + if wrapper.data is not 0: + self.cmd.show_output(True) + else: + self.reject() + + def commandCanceled(self): + self.bb.button(QDialogButtonBox.Ok).setEnabled(True) + + def accept(self): + cmdline = ['commit'] + files = self.stwidget.getChecked() + if files: + cmdline.extend(files) + else: + qtlib.WarningMsgBox(_('No files selected'), + _('No operation to perform'), + parent=self) + return + print cmdline + #self.cmd.run(cmdline) + + def reject(self): + if self.cmd.core.is_running(): + self.cmd.core.cancel() + else: + s = QSettings() + s.setValue('commit/state', self.commit.saveState()) + s.setValue('commit/geom', self.saveGeometry()) + QDialog.reject(self) + +def run(ui, *pats, **opts): + return CommitDialog(hglib.canonpaths(pats), opts)
 
347
348
349
 
 
 
 
 
350
351
352
 
636
637
638
 
 
 
 
639
640
641
 
347
348
349
350
351
352
353
354
355
356
357
 
641
642
643
644
645
646
647
648
649
650
@@ -347,6 +347,11 @@
  from tortoisehg.hgqt.clone import run   qtrun(run, ui, *pats, **opts)   +def commit(ui, *pats, **opts): + """commit tool""" + from tortoisehg.hgqt.commit import run + qtrun(run, ui, *pats, **opts) +  def email(ui, *pats, **opts):   """send changesets by email"""   from tortoisehg.hgqt.hgemail import run @@ -636,6 +641,10 @@
  ('', 'uncompressed', None,   _('use uncompressed transfer (fast over LAN)')),],   _('thg clone [OPTION]... SOURCE [DEST]')), + "^commit|ci": (commit, + [('u', 'user', '', _('record user as committer')), + ('d', 'date', '', _('record datecode as commit date'))], + _('thg commit [OPTIONS] [FILE]...')),   "^grep|search": (grep, [], _('thg grep')),   "^email":   (email,