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

commit: create a MessageHistoryCombo class

Changeset 538813d506a0

Parent 723e84514f85

by Steve Borho

Changes to one file · Browse files at 538813d506a0 Showing diff from parent 723e84514f85 Diff from another changeset...

 
53
54
55
56
57
 
 
58
59
60
 
79
80
81
 
82
83
84
 
91
92
93
94
 
95
96
 
 
 
 
 
 
 
 
 
 
97
98
99
 
105
106
107
108
 
 
109
110
111
 
 
112
113
114
 
120
121
122
123
124
 
 
125
126
127
 
136
137
138
 
139
140
141
142
143
 
 
 
 
144
145
 
 
146
147
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
149
150
 
53
54
55
 
 
56
57
58
59
60
 
79
80
81
82
83
84
85
 
92
93
94
 
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
 
116
117
118
 
119
120
121
 
 
122
123
124
125
126
 
132
133
134
 
 
135
136
137
138
139
 
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
@@ -53,8 +53,8 @@
  hbox = QHBoxLayout()   branchop = QPushButton('Branch: default')   hbox.addWidget(branchop) - msgcombo = QComboBox() - msgcombo.addItem('Recent commit messages...') + msgcombo = MessageHistoryCombo() + self.connect(msgcombo, SIGNAL('activated(int)'), self.msgSelected)   hbox.addWidget(msgcombo, 1)   vbox.addLayout(hbox, 0)   msgte = QTextEdit() @@ -79,6 +79,7 @@
  # 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) @@ -91,9 +92,19 @@
  try:   text = hglib.fromunicode(text, 'strict')   except UnicodeEncodeError: - pass # Handle decoding errors + pass # TODO: Handle decoding errors   return text   + def msgSelected(self, index): + doc = self.msgte.document() + if not doc.isEmpty() and doc.isModified(): + # TODO: get confirmation before switching + pass + 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 @@ -105,10 +116,11 @@
  repo = self.stwidget.repo   repoid = str(repo[0])   # message history is stored in unicode - self.msghistory = s.value('commit/history-'+repoid).toStringList() + self.msghistory = list(s.value('commit/history-'+repoid).toStringList()) + self.msgcombo.reset(self.msghistory)   try: - lastmsg = repo.opener('last-message.txt').read() - self.msgte.setPlainText(hglib.fromunicode(lastmsg)) + 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: @@ -120,8 +132,8 @@
  repoid = str(repo[0])   s.setValue('commit/history-'+repoid, self.msghistory)   try: - # last message is stored in local encoding - repo.opener('last-message.txt', 'w').write(self.getMessage()) + # current message is stored in local encoding + repo.opener('cur-message.txt', 'w').write(self.getMessage())   except EnvironmentError:   pass   @@ -136,15 +148,38 @@
  _('No operation to perform'),   parent=self)   return + # TODO: do something interesting here   print cmdline   umsg = self.msgte.toPlainText() - if umsg not in self.msghistory: - self.msghistory.insert(0, umsg) - self.msghistory = self.msghistory[:10] + if umsg in self.msghistory: + self.msghistory.remove(umsg) + self.msghistory.insert(0, umsg) + self.msghistory = self.msghistory[:10]   self.msgte.clear()   self.msgte.document().setModified(False) + self.msgcombo.reset(self.msghistory) + self.emit(SIGNAL('commitComplete'))   return True   +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 CommitDialog(QDialog):   'Standalone commit tool, a wrapper for CommitWidget'   def __init__(self, pats, opts, parent=None):