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

bookmark: option to make a new bookmark current

If the track.current setting is on, then a checkbox
is added to the Add/Remove Bookmark dialog, which when checked and
enabled, will make newly-created bookmarks the current one.

The option will be disabled if the revision is set to one other
than the working directory parent.

Changeset 52799c003972

Parent e319b7311c28

by paulm

Changes to 2 files · Browse files at 52799c003972 Showing diff from parent e319b7311c28 Diff from another changeset...

 
14
15
16
17
 
18
19
20
 
40
41
42
 
 
 
43
44
45
 
69
70
71
 
72
73
74
 
79
80
81
82
 
 
 
 
 
 
 
83
84
85
86
87
88
 
 
89
90
 
91
92
93
 
112
113
114
 
 
 
 
 
 
 
 
 
 
 
 
115
116
117
 
130
131
132
 
133
134
135
 
150
151
152
 
 
 
 
153
154
155
 
180
181
182
 
 
 
 
183
184
185
 
14
15
16
 
17
18
19
20
 
40
41
42
43
44
45
46
47
48
 
72
73
74
75
76
77
78
 
83
84
85
 
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
 
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
 
155
156
157
158
159
160
161
 
176
177
178
179
180
181
182
183
184
185
 
210
211
212
213
214
215
216
217
218
219
@@ -14,7 +14,7 @@
 from hgext import bookmarks    from tortoisehg.util.i18n import _ -from tortoisehg.util import hglib, i18n +from tortoisehg.util import hglib, i18n, settings    from tortoisehg.hgtk import dialog, gtklib   @@ -40,6 +40,9 @@
    self.repo = repo   + # persistent settings + self.settings = settings.Settings('bookmark') +   # add buttons   if type == TYPE_ADDREMOVE:   self._button_add = self.add_button(_('Add'), RESPONSE_ADD) @@ -69,6 +72,7 @@
  table.add_row(label, self._bookmarklistbox, padding=False)     ## add entry + trackcurrent = self.repo.ui.configbool('bookmarks', 'track.current')   entry = gtk.Entry()   if type == TYPE_ADDREMOVE:   self._rev_input = entry @@ -79,15 +83,24 @@
  self._name_input = entry   label = _('New Name:')   table.add_row(label, entry, padding=False) - + # Option to make new bookmark the active one + if type == TYPE_ADDREMOVE and trackcurrent: + check = gtk.CheckButton(_('Make new bookmark current')) + self.opt_newcurrent = check + check.set_sensitive(hglib.is_rev_current(self.repo, rev)) + table.add_row(None, check) +   # signal handlers   self.connect('response', self.dialog_response)   self._bookmark_input.connect('activate', self.entry_activated, type)   entry.connect('activate', self.entry_activated, type)   if type == TYPE_ADDREMOVE:   self._bookmark_input.connect('changed', self.bookmark_changed) + if trackcurrent: + self._rev_input.connect('changed', self.rev_changed)     # prepare to show + self.load_settings()   if type == TYPE_ADDREMOVE:   self.set_add_move_button_sensitivity()   self._refresh(clear=False) @@ -112,6 +125,18 @@
  if clear:   self._bookmark_input.set_text('')   + def load_settings(self): + if hasattr(self, 'opt_newcurrent'): + newcurrent = self.settings.get_value('newcurrent', False) + self.opt_newcurrent.set_active(newcurrent) + + def store_settings(self): + if hasattr(self, 'opt_newcurrent'): + newcurrent = self.opt_newcurrent.get_active() + self.settings.set_value('newcurrent', newcurrent) + + self.settings.write() +   def dialog_response(self, dialog, response_id):   # Add button   if response_id == RESPONSE_ADD: @@ -130,6 +155,7 @@
  self._do_current_bookmark()   # Close button or closed by the user   elif response_id in (gtk.RESPONSE_CLOSE, gtk.RESPONSE_DELETE_EVENT): + self.store_settings()   self.destroy()   return # close dialog   else: @@ -150,6 +176,10 @@
  else:   raise _('unexpected type: %s') % type   + def rev_changed(self, rev_input): + rev = rev_input.get_text() + self.opt_newcurrent.set_sensitive(hglib.is_rev_current(self.repo, rev)) +   def bookmark_changed(self, bookmark_widget):   self.set_add_move_button_sensitivity()   @@ -180,6 +210,10 @@
  self._add_hg_bookmark(name, rev)   dialog.info_dialog(self, _('Bookmarking completed'),   _('Bookmark "%s" has been added') % name) + if (hasattr(self, 'opt_newcurrent') and + self.opt_newcurrent.get_property('sensitive') and + self.opt_newcurrent.get_active()): + self._current_hg_bookmark(name)   self._refresh()   except util.Abort, inst:   dialog.error_dialog(self, _('Error in bookmarking'), str(inst))
 
240
241
242
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
 
@@ -240,3 +240,20 @@
  return dict(repo._bookmarks)   else:   return repo._bookmarks.keys() + +def is_rev_current(repo, rev): + ''' + Returns True if the revision indicated by 'rev' is the current + working directory parent. + + If rev is '' or None, it is assumed to mean 'tip'. + ''' + if rev in ('', None): + rev = 'tip' + rev = repo.lookup(rev) + parents = repo.parents() + + if len(parents) > 1: + return False + + return rev == parents[0].node() \ No newline at end of file