Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.0.1, 2.0.2, and 2.0.3

stable bookmarks: add a move command, general cleanups (closes #177)

Since thgrepo objects monitor bookmark state, there's no need to manually
update the combos or other fields. This simplifies and improves the button
state refresh logic.

Changeset f59fe6408cb4

Parent 5e1f43414529

by Steve Borho

Changes to 2 files · Browse files at f59fe6408cb4 Showing diff from parent 5e1f43414529 Diff from another changeset...

 
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
 
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
 
185
186
187
 
 
188
189
190
191
192
193
 
194
195
196
 
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
 
228
229
230
231
 
232
233
234
 
235
236
 
237
238
239
 
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
 
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
 
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
 
151
152
153
154
155
156
 
 
157
158
 
159
160
161
162
 
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
 
203
204
205
 
206
207
208
 
209
210
 
211
212
213
214
 
218
219
220
 
 
 
221
222
 
223
224
225
226
227
 
 
 
 
@@ -29,83 +29,67 @@
  self.setWindowFlags(self.windowFlags() & \   ~Qt.WindowContextHelpButtonHint)   self.repo = repo + self.rev = rev + self.node = repo[rev].node()     # base layout box   base = QVBoxLayout()   base.setSpacing(0)   base.setContentsMargins(*(0,)*4) + base.setSizeConstraint(QLayout.SetFixedSize) + self.setLayout(base)   - # main layout box   box = QVBoxLayout() - box.setSpacing(6) - box.setContentsMargins(*(6,)*4) - base.addLayout(box) + box.setSpacing(8) + box.setContentsMargins(*(8,)*4) + self.layout().addLayout(box)     ## main layout grid - grid = QGridLayout() - grid.setSpacing(6) - box.addLayout(grid) + form = QFormLayout(fieldGrowthPolicy=QFormLayout.AllNonFixedFieldsGrow) + box.addLayout(form) + + form.addRow(_('Revision:'), QLabel(str(rev)))     ### bookmark combo - self.bookmark_combo = QComboBox() - self.bookmark_combo.setEditable(True) - self.bookmark_combo.setMinimumWidth(180) - self.bookmark_combo.setEditText('') - grid.addWidget(QLabel(_('Bookmark:')), 0, 0) - grid.addWidget(self.bookmark_combo, 0, 1) + self.bookmarkCombo = QComboBox() + self.bookmarkCombo.setEditable(True) + self.bookmarkCombo.currentIndexChanged.connect(self.bookmarkTextChanged) + self.bookmarkCombo.editTextChanged.connect(self.bookmarkTextChanged) + form.addRow(_('Bookmark:'), self.bookmarkCombo)     ### Rename input - self.new_name_text = QLineEdit() - self.new_name_text.setMaximumWidth(100) - self.new_name_text.textEdited.connect(self.new_bookmark_changed) - self.new_name_label = QLabel(_('New name:')) - grid.addWidget(self.new_name_label, 1, 0) - grid.addWidget(self.new_name_text, 1, 1) - self.enable_new_name(False) - - ### revision input - self.initial_rev = str(rev) - self.rev_text = QLineEdit() - self.rev_text.setMaximumWidth(100) - self.rev_text.setText(rev) - self.rev_text.setReadOnly(True) - #self.rev_text.textEdited.connect(self.update_sensitives) - grid.addWidget(QLabel(_('Revision:')), 2, 0) - grid.addWidget(self.rev_text, 2, 1) + self.newNameEdit = QLineEdit() + self.newNameEdit.textEdited.connect(self.bookmarkTextChanged) + form.addRow(_('New Name:'), self.newNameEdit)     ## bottom buttons - buttons = QDialogButtonBox() - self.close_btn = buttons.addButton(QDialogButtonBox.Close) - self.close_btn.clicked.connect(self.reject) - self.add_btn = buttons.addButton(_('&Add'), - QDialogButtonBox.ActionRole) - self.add_btn.clicked.connect(self.add_bookmark) - self.rename_btn = buttons.addButton(_('&Rename'), - QDialogButtonBox.ActionRole) - self.rename_btn.clicked.connect(self.rename_bookmark) - self.remove_btn = buttons.addButton(_('&Remove'), - QDialogButtonBox.ActionRole) - self.remove_btn.clicked.connect(self.remove_bookmark) - box.addWidget(buttons) + BB = QDialogButtonBox + bbox = QDialogButtonBox() + self.addBtn = bbox.addButton(_('&Add'), BB.ActionRole) + self.renameBtn = bbox.addButton(_('Re&name'), BB.ActionRole) + self.removeBtn = bbox.addButton(_('&Remove'), BB.ActionRole) + self.moveBtn = bbox.addButton(_('&Move'), BB.ActionRole) + bbox.addButton(BB.Close) + bbox.rejected.connect(self.reject) + box.addWidget(bbox)   - # add signals - self.bookmark_combo.currentIndexChanged.connect(self.toggle_new_bookmark) - self.bookmark_combo.editTextChanged.connect(self.update_sensitives) + self.addBtn.clicked.connect(self.add_bookmark) + self.renameBtn.clicked.connect(self.rename_bookmark) + self.removeBtn.clicked.connect(self.remove_bookmark) + self.moveBtn.clicked.connect(self.move_bookmark)     ## horizontal separator   self.sep = QFrame()   self.sep.setFrameShadow(QFrame.Sunken)   self.sep.setFrameShape(QFrame.HLine) - base.addWidget(self.sep) + self.layout().addWidget(self.sep)     ## status line   self.status = qtlib.StatusLabel()   self.status.setContentsMargins(4, 2, 4, 4) - base.addWidget(self.status) + self.layout().addWidget(self.status)     # dialog setting - self.setLayout(base) - self.layout().setSizeConstraint(QLayout.SetFixedSize)   self.setWindowTitle(_('Bookmark - %s') % self.repo.displayname)   self.setWindowIcon(qtlib.geticon('hg-bookmarks'))   @@ -117,61 +101,43 @@
    # prepare to show   self.clear_status() - self.update_bookmark_combo(clear=False) - self.update_sensitives() - self.rename_btn.setVisible(False) - self.rename_btn.setEnabled(False) - self.enable_new_name(False) - self.bookmark_combo.setFocus() + self.refresh() + self.repo.repositoryChanged.connect(self.refresh) + self.bookmarkCombo.setFocus() + self.bookmarkTextChanged()   - ### Private Methods ### - def enable_new_name(self, enabled): - self.new_name_text.setEnabled(enabled) - self.new_name_label.setEnabled(enabled) - - def update_bookmark_combo(self, clear=True): + def refresh(self):   """ update display on dialog with recent repo data """ - bookmark_name = self.bookmark_combo.currentText() - self.bookmark_combo.clear() -   # add bookmarks to drop-down list   marks = self.repo._bookmarks.keys()[:]   marks.sort()   marks.reverse() + cur = self.bookmarkCombo.currentText() + self.bookmarkCombo.clear()   for bookmark in marks: - self.bookmark_combo.addItem(hglib.tounicode(bookmark)) - self.bookmark_combo.clearEditText() - - # restore tag name - if not clear and bookmark_name: - self.bookmark_combo.setEditText(bookmark_name) - - def toggle_new_bookmark(self): - bookmark = self.bookmark_combo.currentText() - bookmarklocal = hglib.fromunicode(bookmark) - is_new = bookmarklocal not in self.repo._bookmarks - self.add_btn.setVisible(is_new) - self.add_btn.setDisabled(not is_new) - self.remove_btn.setVisible(not is_new) - self.rename_btn.setVisible(not is_new) - self.enable_new_name(not is_new) + self.bookmarkCombo.addItem(hglib.tounicode(bookmark)) + if cur: + self.bookmarkCombo.setEditText(cur) + else: + self.bookmarkTextChanged()     @pyqtSlot() - def update_sensitives(self): - """ update bottom button sensitives based on rev and bookmark """ - self.toggle_new_bookmark() - revstr = self.rev_text.text() - if not revstr or not self.bookmark_combo.currentText(): - self.add_btn.setDisabled(True) - return - - try: - # check if valid revision, tag, or branch - self.repo[hglib.fromunicode(revstr)] - except (error.LookupError, error.RepoError): - self.add_btn.setDisabled(True) - self.remove_btn.setDisabled(True) - self.rename_btn.setDisabled(True) + def bookmarkTextChanged(self): + bookmark = self.bookmarkCombo.currentText() + bookmarklocal = hglib.fromunicode(bookmark) + if bookmarklocal in self.repo._bookmarks: + curnode = self.repo._bookmarks[bookmarklocal] + self.addBtn.setEnabled(False) + self.newNameEdit.setEnabled(True) + self.removeBtn.setEnabled(True) + self.renameBtn.setEnabled(bool(self.newNameEdit.text())) + self.moveBtn.setEnabled(self.node != curnode) + else: + self.addBtn.setEnabled(bool(bookmark)) + self.removeBtn.setEnabled(False) + self.moveBtn.setEnabled(False) + self.renameBtn.setEnabled(False) + self.newNameEdit.setEnabled(False)     def set_status(self, text, icon=None):   self.status.setShown(True) @@ -185,12 +151,12 @@
    def commandFinished(self, ret):   if ret is 0: + self.bookmarkCombo.clearEditText() + self.newNameEdit.setText('')   self.finishfunc() - self.repo.incrementBusyCount() - self.repo.decrementBusyCount()     def add_bookmark(self): - bookmark = self.bookmark_combo.currentText() + bookmark = self.bookmarkCombo.currentText()   bookmarklocal = hglib.fromunicode(bookmark)   if bookmarklocal in self.repo._bookmarks:   self.set_status(_('A bookmark named "%s" already exists') % @@ -198,29 +164,38 @@
  return     def finished(): - self.bookmark_combo.addItem(bookmark)   self.set_status(_("Bookmark '%s' has been added") % bookmark, True) - self.toggle_new_bookmark() - self.bookmark_combo.clearEditText()     cmdline = ['bookmark', '--repository', self.repo.root, - '--rev', self.initial_rev, bookmarklocal] + '--rev', str(self.rev), bookmarklocal]   self.cmd.run(cmdline)   self.finishfunc = finished   + def move_bookmark(self): + bookmark = self.bookmarkCombo.currentText() + bookmarklocal = hglib.fromunicode(bookmark) + if bookmarklocal not in self.repo._bookmarks: + self.set_status(_('Bookmark named "%s" does not exist') % + bookmark, False) + return + + def finished(): + self.set_status(_("Bookmark '%s' has been moved") % bookmark, True) + + cmdline = ['bookmark', '--repository', self.repo.root, + '--rev', str(self.rev), '--force', bookmarklocal] + self.cmd.run(cmdline) + self.finishfunc = finished     def remove_bookmark(self): - bookmark = self.bookmark_combo.currentText() + bookmark = self.bookmarkCombo.currentText()   bookmarklocal = hglib.fromunicode(bookmark) - if not bookmarklocal in self.repo._bookmarks: + if bookmarklocal not in self.repo._bookmarks:   self.set_status(_("Bookmark '%s' does not exist") % bookmark, False)   return     def finished(): - self.bookmark_combo.removeItem(self.bookmark_combo.currentIndex()) - self.new_name_text.setText("")   self.set_status(_("Bookmark '%s' has been removed") % bookmark, True) - self.update_sensitives()     cmdline = ['bookmark', '--repository', self.repo.root,   '--delete', bookmarklocal] @@ -228,12 +203,12 @@
  self.finishfunc = finished     def rename_bookmark(self): - name = self.bookmark_combo.currentText() + name = self.bookmarkCombo.currentText()   namelocal = hglib.fromunicode(name)   - newname = self.new_name_text.text() + newname = self.newNameEdit.text()   newnamelocal = hglib.fromunicode(newname) - if not namelocal in self.repo._bookmarks: + if namelocal not in self.repo._bookmarks:   self.set_status(_("Bookmark '%s' does not exist") % name, False)   return   @@ -243,18 +218,10 @@
  return     def finished(): - self.bookmark_combo.removeItem(self.bookmark_combo.currentIndex()) - self.bookmark_combo.addItem(newname) - self.new_name_text.setText("")   self.set_status(_("Bookmark '%s' has been renamed to '%s'") %   (name, newname), True) - self.update_sensitives()     cmdline = ['bookmark', '--repository', self.repo.root,   '--rename', namelocal, newnamelocal]   self.cmd.run(cmdline)   self.finishfunc = finished - - @pyqtSlot(QString) - def new_bookmark_changed(self, value): - self.rename_btn.setDisabled(not value)
 
1199
1200
1201
1202
 
1203
1204
1205
 
1199
1200
1201
 
1202
1203
1204
1205
@@ -1199,7 +1199,7 @@
  dlg.exec_()     def bookmarkRevision(self): - dlg = bookmark.BookmarkDialog(self.repo, str(self.rev), self) + dlg = bookmark.BookmarkDialog(self.repo, self.rev, self)   dlg.showMessage.connect(self.showMessage)   dlg.output.connect(self.output)   dlg.makeLogVisible.connect(self.makeLogVisible)