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

bookmark: put together the bookmark dialog

Changeset f11092eba21d

Parent 56e337034fae

by Yuki KODAMA

Changes to 2 files · Browse files at f11092eba21d Showing diff from parent 56e337034fae Diff from another changeset...

 
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
 
47
48
49
50
51
52
53
54
55
56
57
58
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
61
62
 
82
83
84
 
 
 
85
86
87
 
91
92
93
 
 
 
 
 
 
 
 
94
95
96
 
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
 
238
239
240
241
 
242
243
244
245
 
246
247
248
 
253
254
255
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
256
257
258
259
260
 
 
 
 
261
262
263
 
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
 
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
 
99
100
101
102
103
104
105
106
107
 
111
112
113
114
115
116
117
118
119
120
121
122
123
124
 
169
170
171
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
173
174
 
187
188
189
 
190
191
192
193
 
194
195
196
197
 
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
 
@@ -18,25 +18,33 @@
   from tortoisehg.hgtk import dialog, gtklib   +TYPE_ADDREMOVE = 1 +TYPE_RENAME = 2 +  RESPONSE_ADD = 1  RESPONSE_REMOVE = 2 +RESPONSE_RENAME = 3    class BookmarkAddDialog(gtk.Dialog):   """ Dialog to add bookmark to Mercurial repo """ - def __init__(self, repo, bookmark='', rev=''): + 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.connect('response', self.dialog_response)     self.repo = repo     # add buttons - self.add_button(_('Add'), RESPONSE_ADD) - self.add_button(_('Remove'), RESPONSE_REMOVE) + 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) + else: + raise _('unexpected type: %s') % type   self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)     # layout table @@ -47,16 +55,25 @@
  self._bookmarkslist = gtk.ListStore(str)   self._bookmarklistbox = gtk.ComboBoxEntry(self._bookmarkslist, 0)   self._bookmark_input = self._bookmarklistbox.get_child() - self._bookmark_input.connect('activate', - lambda w: self.response(RESPONSE_ADD))   self._bookmark_input.set_text(bookmark)   table.add_row(_('Bookmark:'), self._bookmarklistbox, padding=False)   - ## revision input - self._rev_input = gtk.Entry() - self._rev_input.set_width_chars(12) - self._rev_input.set_text(rev) - table.add_row(_('Revision:'), self._rev_input) + ## 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) + elif type == TYPE_RENAME: + self._name_input = entry + table.add_row(_('New name:'), entry) + else: + raise _('unexpected type: %s') % type + + # signal handlers + self.connect('response', self.dialog_response) + self._bookmark_input.connect('activate', self.combo_activated, type)     # prepare to show   self._refresh() @@ -82,6 +99,9 @@
  # Remove button   elif response_id == RESPONSE_REMOVE:   self._do_remove_bookmark() + # Rename button + elif response_id == RESPONSE_RENAME: + self._do_rename_bookmark()   # Close button or closed by the user   elif response_id in (gtk.RESPONSE_CLOSE, gtk.RESPONSE_DELETE_EVENT):   self.destroy() @@ -91,6 +111,14 @@
    self.run() # don't close dialog   + def combo_activated(self, entry, type): + if type == TYPE_ADDREMOVE: + self.response(RESPONSE_ADD) + elif type == TYPE_RENAME: + self.response(RESPONSE_RENAME) + else: + raise _('unexpected type: %s') % type +   def _do_add_bookmark(self):   # gather input data   name = self._bookmark_input.get_text() @@ -141,85 +169,6 @@
  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) - -class BookmarkRenameDialog(gtk.Dialog): - """ Dialog to rename a bookmark """ - def __init__(self, repo, bookmark='', rev=''): - """ Initialize the Dialog """ - gtk.Dialog.__init__(self, - buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)) - gtklib.set_tortoise_keys(self) - self.set_title(_('Bookmark - %s') % hglib.get_reponame(repo)) - self.set_resizable(False) - self.set_has_separator(False) - self.connect('response', self.dialog_response) - - self.repo = repo - - # add Rename button - renamebutton = gtk.Button(_('Rename')) - renamebutton.connect('clicked', lambda b: self._do_rename_bookmark()) - self.action_area.pack_end(renamebutton) - - # top 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.connect('activate', self._bookmarkinput_activated) - self._bookmark_input.set_text(bookmark) - table.add_row(_('Bookmark:'), self._bookmarklistbox, padding=False) - - ## revision input - self._name_input = gtk.Entry() - table.add_row(_('New name:'), self._name_input) - - # prepare to show - self._refresh() - self._bookmarklistbox.grab_focus() - - def _refresh(self): - """ update display on dialog with recent repo data """ - self.repo.invalidate() - self._bookmarkslist.clear() - self._bookmark_input.set_text('') - - # add bookmarks to drop-down list - bookmarks = hglib.get_repo_bookmarks(self.repo) - bookmarks.sort() - for bookmarkname in bookmarks: - if bookmarkname == 'tip': - continue - self._bookmarkslist.append([bookmarkname]) - - def dialog_response(self, dialog, response_id): - if response_id == gtk.RESPONSE_CLOSE \ - or response_id == gtk.RESPONSE_DELETE_EVENT: - self.destroy() - - def _bookmarkinput_activated(self, bookmarkinput): - self._do_rename_bookmark() -   def _do_rename_bookmark(self):   # gather input data   name = self._bookmark_input.get_text() @@ -238,11 +187,11 @@
  self._bookmark_input.grab_focus()   return False   - # rename bookmark + # rename bookmark   try:   self._rename_hg_bookmark(name, new_name)   dialog.info_dialog(self, _('Bookmarking completed'), - _('Bookmark "%s" has been renamed to "%s"') % + _('Bookmark "%s" has been renamed to "%s"') %   (name, new_name))   self._refresh()   except util.Abort, inst: @@ -253,11 +202,29 @@
  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, + raise util.Abort(_('a bookmark named "%s" already exists') % + new_name) + bookmarks.bookmark(ui=ui.ui(), + repo=self.repo,   mark=new_name,   rename=name) -
 
1881
1882
1883
1884
 
 
1885
1886
1887
 
1896
1897
1898
1899
 
 
1900
1901
1902
 
1881
1882
1883
 
1884
1885
1886
1887
1888
 
1897
1898
1899
 
1900
1901
1902
1903
1904
@@ -1881,7 +1881,8 @@
  oldbookmarks,   hglib.get_repo_bookmarks(self.repo))   - dialog = bookmark.BookmarkAddDialog(self.repo, rev=str(rev)) + dialog = bookmark.BookmarkAddDialog(self.repo, + type=bookmark.TYPE_ADDREMOVE, rev=str(rev))   dialog.connect('destroy', refresh)   self.show_dialog(dialog)   @@ -1896,7 +1897,8 @@
  oldbookmarks,   hglib.get_repo_bookmarks(self.repo))   - dialog = bookmark.BookmarkRenameDialog(self.repo, rev=str(rev)) + dialog = bookmark.BookmarkAddDialog(self.repo, + type=bookmark.TYPE_RENAME, rev=str(rev))   dialog.connect('destroy', refresh)   self.show_dialog(dialog)