Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.0, 1.0.1, and 1.0.2

bookmark: new dialog to set the current bookmark

Changeset 73e6d5bf66df

Parent a7252818d702

by paulm

Changes to 2 files · Browse files at 73e6d5bf66df Showing diff from parent a7252818d702 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
 
 
 
 
 
 
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
 # bookmark.py - TortoiseHg dialog to add/remove/rename bookmarks  #  # Copyright 2007 TK Soh <teekaysoh@gmail.com>  # Copyright 2007 Steve Borho <steve@borho.org>  # Copyright 2009 Emmanuel Rosa <goaway1000@gmail.com>  #  # This software may be used and distributed according to the terms of the  # GNU General Public License version 2, incorporated herein by reference.    import gtk  import traceback    from mercurial import ui, util  from hgext import bookmarks    from tortoisehg.util.i18n import _  from tortoisehg.util import hglib, i18n    from tortoisehg.hgtk import dialog, gtklib    TYPE_ADDREMOVE = 1  TYPE_RENAME = 2 +TYPE_CURRENT = 3   -RESPONSE_ADD = 1 -RESPONSE_REMOVE = 2 -RESPONSE_RENAME = 3 +RESPONSE_ADD = 1 +RESPONSE_REMOVE = 2 +RESPONSE_RENAME = 3 +RESPONSE_CURRENT = 4    class BookmarkDialog(gtk.Dialog):   """ Dialog to add bookmark to Mercurial repo """   def __init__(self, repo, type, bookmark='', rev=''):   """ Initialize the Dialog """   gtk.Dialog.__init__(self)   gtklib.set_tortoise_keys(self)   self.set_title(_('Bookmark - %s') % hglib.get_reponame(repo))   self.set_resizable(False)   self.set_has_separator(False)     self.repo = repo     # add buttons   if type == TYPE_ADDREMOVE:   self.add_button(_('Add'), RESPONSE_ADD)   self.add_button(_('Remove'), RESPONSE_REMOVE)   elif type == TYPE_RENAME:   self.add_button(_('Rename'), RESPONSE_RENAME) + elif type == TYPE_CURRENT: + self.add_button(_('Set Current'), RESPONSE_CURRENT)   else:   raise _('unexpected type: %s') % type   self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)     # layout table   table = gtklib.LayoutTable()   self.vbox.pack_start(table, True, True, 2)     ## bookmark name input   self._bookmarkslist = gtk.ListStore(str)   self._bookmarklistbox = gtk.ComboBoxEntry(self._bookmarkslist, 0)   self._bookmark_input = self._bookmarklistbox.get_child()   self._bookmark_input.set_text(bookmark)   table.add_row(_('Bookmark:'), self._bookmarklistbox, padding=False)     ## add entry   entry = gtk.Entry()   if type == TYPE_ADDREMOVE:   self._rev_input = entry   entry.set_width_chars(12)   entry.set_text(rev)   table.add_row(_('Revision:'), entry) - else: + elif type == TYPE_RENAME:   self._name_input = entry   table.add_row(_('New name:'), entry)     # signal handlers   self.connect('response', self.dialog_response)   self._bookmark_input.connect('activate', self.entry_activated, type)   entry.connect('activate', self.entry_activated, type)     # prepare to show   self._refresh(clear=False) - if type == TYPE_ADDREMOVE: + if type == TYPE_RENAME: + self._name_input.grab_focus() + else:   self._bookmarklistbox.grab_focus() - else: - self._name_input.grab_focus()     def _refresh(self, clear=True):   """ update display on dialog with recent repo data """   self.repo.invalidate()   self._bookmarkslist.clear()     # add bookmarks to drop-down list   bookmarks = hglib.get_repo_bookmarks(self.repo)   bookmarks.sort()   for bookmarkname in bookmarks:   if bookmarkname != 'tip':   self._bookmarkslist.append([bookmarkname])     # clear bookmark name input   if clear:   self._bookmark_input.set_text('')     def dialog_response(self, dialog, response_id):   # Add button   if response_id == RESPONSE_ADD:   self._do_add_bookmark()   # Remove button   elif response_id == RESPONSE_REMOVE:   self._do_remove_bookmark()   # Rename button   elif response_id == RESPONSE_RENAME:   self._do_rename_bookmark() + # Set Current button + elif response_id == RESPONSE_CURRENT: + self._do_current_bookmark()   # Close button or closed by the user   elif response_id in (gtk.RESPONSE_CLOSE, gtk.RESPONSE_DELETE_EVENT):   self.destroy()   return # close dialog   else:   raise _('unexpected response id: %s') % response_id     self.run() # don't close dialog     def entry_activated(self, entry, type):   if type == TYPE_ADDREMOVE:   self.response(RESPONSE_ADD)   elif type == TYPE_RENAME:   self.response(RESPONSE_RENAME) + elif type == TYPE_CURRENT: + self.response(RESPONSE_CURRENT)   else:   raise _('unexpected type: %s') % type     def _do_add_bookmark(self):   # gather input data   name = self._bookmark_input.get_text()   rev = self._rev_input.get_text()     # verify input   if name == '':   dialog.error_dialog(self, _('Bookmark input is empty'),   _('Please enter bookmark name'))   self._bookmark_input.grab_focus()   return False     # add bookmark to repo   try:   self._add_hg_bookmark(name, rev)   dialog.info_dialog(self, _('Bookmarking completed'),   _('Bookmark "%s" has been added') % name)   self._refresh()   except util.Abort, inst:   dialog.error_dialog(self, _('Error in bookmarking'), str(inst))   return False   except:   dialog.error_dialog(self, _('Error in bookmarking'),   traceback.format_exc())   return False     def _do_remove_bookmark(self):   # gather input data   name = self._bookmark_input.get_text()     # verify input   if name == '':   dialog.error_dialog(self, _('Bookmark name is empty'),   _('Please select bookmark name to remove'))   self._bookmark_input.grab_focus()   return False     try:   self._remove_hg_bookmark(name)   dialog.info_dialog(self, _('Bookmarking completed'),   _('Bookmark "%s" has been removed') % name)   self._refresh()   except util.Abort, inst:   dialog.error_dialog(self, _('Error in bookmarking'), str(inst))   return False   except:   dialog.error_dialog(self, _('Error in bookmarking'),   traceback.format_exc())   return False     def _do_rename_bookmark(self):   # gather input data   name = self._bookmark_input.get_text()   new_name = self._name_input.get_text()     # verify input   if name == '':   dialog.error_dialog(self, _('Bookmark input is empty'),   _('Please enter bookmark name'))   self._bookmark_input.grab_focus()   return False     if new_name == '':   dialog.error_dialog(self, _('Bookmark new name input is empty'),   _('Please enter new bookmark name'))   self._bookmark_input.grab_focus()   return False     # rename bookmark   try:   self._rename_hg_bookmark(name, new_name)   dialog.info_dialog(self, _('Bookmarking completed'),   _('Bookmark "%s" has been renamed to "%s"') %   (name, new_name))   self._refresh()   except util.Abort, inst:   dialog.error_dialog(self, _('Error in bookmarking'), str(inst))   return False   except:   dialog.error_dialog(self, _('Error in bookmarking'),   traceback.format_exc())   return False   + def _do_current_bookmark(self): + # gather input data + name = self._bookmark_input.get_text() + + # verify input + if name == '': + dialog.error_dialog(self, _('Bookmark input is empty'), + _('Please enter bookmark name')) + self._bookmark_input.grab_focus() + return False + + # set current bookmark + try: + self._current_hg_bookmark(name) + dialog.info_dialog(self, _('Bookmarking completed'), + _('Bookmark "%s" has been made current') % + name) + self._refresh() + except util.Abort, inst: + dialog.error_dialog(self, _('Error in bookmarking'), str(inst)) + return False + except: + dialog.error_dialog(self, _('Error in bookmarking'), + traceback.format_exc()) + return False +   def _add_hg_bookmark(self, name, revision):   if name in hglib.get_repo_bookmarks(self.repo):   raise util.Abort(_('a bookmark named "%s" already exists') % name)     bookmarks.bookmark(ui=ui.ui(),   repo=self.repo,   rev=revision,   mark=name)     def _remove_hg_bookmark(self, name):   if not name in hglib.get_repo_bookmarks(self.repo):   raise util.Abort(_("Bookmark '%s' does not exist") % name)     bookmarks.bookmark(ui=ui.ui(),   repo=self.repo,   mark=name,   delete=True)     def _rename_hg_bookmark(self, name, new_name):   if new_name in hglib.get_repo_bookmarks(self.repo):   raise util.Abort(_('a bookmark named "%s" already exists') %   new_name)   bookmarks.bookmark(ui=ui.ui(),   repo=self.repo,   mark=new_name,   rename=name) + + def _current_hg_bookmark(self, name): + if name not in hglib.get_repo_bookmarks(self.repo): + raise util.Abort(_('no bookmark named "%s" exists') % + name) + bookmarks.setcurrent(self.repo, name)
 
876
877
878
 
 
 
879
880
881
 
1214
1215
1216
 
 
 
 
 
 
 
 
 
 
 
 
1217
1218
1219
 
1906
1907
1908
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1909
1910
1911
 
876
877
878
879
880
881
882
883
884
 
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
 
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
@@ -876,6 +876,9 @@
  self.add_bookmark))   m.append(create_menu(_('Rename Bookmark...'),   self.rename_bookmark)) + if self.repo.ui.configbool('bookmarks', 'track.current'): + m.append(create_menu(_('Set Current Bookmark...'), + self.current_bookmark))   return m.create_menu()     def mq_context_menu(self): @@ -1214,6 +1217,18 @@
  else:   if newmarkers != oldmarkers:   self.refresh_model() + + def refresh_on_current_marker_change(self, oldlen, oldmarkers, + oldcurrent, newmarkers, + newcurrent): + self.repo.invalidate() + self.changeview.clear_cache() + if len(self.repo) != oldlen: + self.reload_log() + else: + if newmarkers != oldmarkers or \ + oldcurrent != newcurrent: + self.refresh_model()     def apply_clicked(self, button):   combo = self.ppullcombo @@ -1906,6 +1921,27 @@
  bmark, rev)   dialog.connect('destroy', refresh)   self.show_dialog(dialog) + + def current_bookmark(self, menuitem): + # save current bookmark info for detecting current bookmark changed + bookmarks = extensions.find('bookmarks') + # Note that the dialog shouldn't change the repo len, or # of bookmarks, + # etc, but check in case they've been modified by something else... + oldbookmarks = hglib.get_repo_bookmarks(self.repo) + oldlen = len(self.repo) + oldcurrent = bookmarks.current(self.repo) + rev = str(self.currevid) + bmark = self.get_rev_tag(rev, include=oldbookmarks) + + def refresh(*args): + self.refresh_on_current_marker_change(oldlen, oldbookmarks, oldcurrent, + hglib.get_repo_bookmarks(self.repo), + bookmarks.current(self.repo)) + + dialog = bookmark.BookmarkDialog(self.repo, bookmark.TYPE_CURRENT, + bmark, rev) + dialog.connect('destroy', refresh) + self.show_dialog(dialog)     def bisect_reset(self, menuitem):   commands.bisect(ui=self.ui,