Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.6, 0.7, and 0.7.1

thgconfig: Switch to in-place editing model for "paths" page

The old editing model showed a list of aliases where you could
select an alias. You would then have to edit the alias in a
field in the bottom of the page.

In addition to this you would have to actively "Refresh" your
change to the list, in addition to committing it with the
"Apply" button.

The new editing model has only one level of commit: the "Apply"
button.

The patch also simplifies the internal data structures.
By relying more on gtk.ListStore and gtk.TreeView some
synchronization code could be removed.

Changeset 3f550f36b564

Parent 6ab1df0a7b5e

by Peer Sommerlund

Changes to one file · Browse files at 3f550f36b564 Showing diff from parent 6ab1df0a7b5e Diff from another changeset...

 
127
128
129
 
 
 
 
 
 
 
 
 
 
 
 
 
130
131
132
133
134
135
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
 
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
 
317
318
319
320
 
 
 
 
 
 
 
 
 
 
 
 
 
321
322
323
324
 
 
 
 
325
 
326
327
328
329
330
 
333
334
335
336
337
338
339
340
341
342
343
 
344
345
346
347
348
 
 
 
 
 
 
 
 
 
 
349
350
351
352
 
 
 
353
354
355
356
357
 
 
358
359
360
 
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
 
 
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
 
 
 
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
 
558
559
560
561
562
 
563
564
 
 
 
565
566
567
 
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
 
172
173
174
 
 
 
 
175
176
177
178
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
180
181
 
313
314
315
 
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
 
 
331
332
333
334
335
336
337
 
338
339
340
 
343
344
345
 
 
 
 
 
 
 
 
346
347
348
 
 
 
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
 
370
371
372
373
374
 
378
379
380
 
 
 
 
 
 
 
 
 
 
 
 
 
 
381
382
383
 
 
 
 
 
 
 
 
 
 
 
384
385
 
 
 
 
 
 
 
 
 
 
 
 
 
 
386
387
388
389
390
 
391
392
393
 
 
 
 
 
 
 
394
395
396
 
530
531
532
 
 
533
534
 
535
536
537
538
539
540
@@ -127,24 +127,42 @@
  self.paths_frame = self.add_page(notebook, 'Paths')   vbox = self.fill_frame(self.paths_frame, self._paths_info)   + # Initialize data model for 'Paths' tab + self.pathdata = gtk.ListStore( + gobject.TYPE_STRING, + gobject.TYPE_STRING) + if 'paths' in list(self.ini): + for name in self.ini['paths']: + if name in ('default', 'default-push'): continue + path = self.ini['paths'][name] + iter = self.pathdata.insert_before(None, None) + self.pathdata.set_value(iter, 0, "%s" % name) + self.pathdata.set_value(iter, 1, "%s" % path) + + # Define view model for 'Paths' tab   self.pathtree = gtk.TreeView() - self.pathsel = self.pathtree.get_selection() - self.pathsel.connect("changed", self._pathlist_rowchanged) - column = gtk.TreeViewColumn('Peer Repository Paths', - gtk.CellRendererText(), text=2) - self.pathtree.append_column(column) + self.pathtree.set_model(self.pathdata) + self.pathtree.connect("cursor-changed", self._pathtree_changed) + + renderer = gtk.CellRendererText() + renderer.set_property('editable', True) + renderer.connect('edited', self.on_alias_edit) + column = gtk.TreeViewColumn('Alias', + renderer, text=0) + self.pathtree.append_column(column) + + renderer = gtk.CellRendererText() + renderer.set_property('editable', True) + renderer.connect('edited', self.on_path_edit) + column = gtk.TreeViewColumn('Repository Path', + renderer, text=1) + self.pathtree.append_column(column) +   scrolledwindow = gtk.ScrolledWindow()   scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)   scrolledwindow.add(self.pathtree)   vbox.add(scrolledwindow)   - self.pathlist = [] - if 'paths' in list(self.ini): - for name in self.ini['paths']: - if name in ('default', 'default-push'): continue - self.pathlist.append((name, self.ini['paths'][name])) - self.curpathrow = 0 -   buttonbox = gtk.HBox()   self.addButton = gtk.Button("Add")   self.addButton.connect('clicked', self._add_path) @@ -154,32 +172,10 @@
  self._delpathbutton.connect('clicked', self._remove_path)   buttonbox.pack_start(self._delpathbutton)   - self._refreshpathbutton = gtk.Button("Refresh") - self._refreshpathbutton.connect('clicked', self._refresh_path) - buttonbox.pack_start(self._refreshpathbutton) -   self._testpathbutton = gtk.Button("Test")   self._testpathbutton.connect('clicked', self._test_path)   buttonbox.pack_start(self._testpathbutton)   - table = gtk.Table(2, 2, False) - lbl = gtk.Label('Name:') - lbl.set_alignment(1.0, 0.0) - self._pathnameedit = gtk.Entry() - self._pathnameedit.set_sensitive(False) - table.attach(lbl, 0, 1, 0, 1, gtk.FILL, 0, 4, 3) - table.attach(self._pathnameedit, 1, 2, 0, 1, - gtk.FILL|gtk.EXPAND, 0, 4, 3) - - lbl = gtk.Label('Path:') - lbl.set_alignment(1.0, 0.0) - self._pathpathedit = gtk.Entry() - self._pathpathedit.set_sensitive(False) - table.attach(lbl, 0, 1, 1, 2, gtk.FILL, 0, 4, 3) - table.attach(self._pathpathedit, 1, 2, 1, 2, - gtk.FILL|gtk.EXPAND, 0, 4, 3) - - vbox.pack_start(table, False, False, 4)   vbox.pack_start(buttonbox, False, False, 4)   self.refresh_path_list()   @@ -317,14 +313,28 @@
  self.notebook.set_current_page(page_num)   widgets[w].grab_focus()   return - + + def on_alias_edit(self, cell, path, new_text): + dirty = self.pathdata[path][0] != new_text + self.pathdata[path][0] = new_text + if dirty: + self.dirty_event() + + def on_path_edit(self, cell, path, new_text): + dirty = self.pathdata[path][1] != new_text + self.pathdata[path][1] = new_text + if dirty: + self.dirty_event() +   def new_path(self, newpath):   '''Add a new path to [paths], give default name, focus''' - self.pathlist.append(('new', newpath)) - self.curpathrow = len(self.pathlist)-1 + iter = self.pathdata.insert_before(None, None) + self.pathdata.set_value(iter, 0, 'new') + self.pathdata.set_value(iter, 1, '%s' % newpath) + self.pathtree.get_selection().select_iter(iter)   self.refresh_path_list() + # This method may be called from hggtk.sync, so ensure page is visible   self.notebook.set_current_page(2) - self._pathnameedit.grab_focus()   self.dirty_event()     def dirty_event(self, *args): @@ -333,28 +343,32 @@
  self.dirty = True     def _add_path(self, *args): - if len(self.pathlist): - self.pathlist.append(self.pathlist[self.curpathrow]) - else: - self.pathlist.append(('new', 'http://')) - self.curpathrow = len(self.pathlist)-1 - self.refresh_path_list() - self._pathnameedit.grab_focus() - self.dirty_event() + self.new_path('http://')     def _remove_path(self, *args): - del self.pathlist[self.curpathrow] - if self.curpathrow > len(self.pathlist)-1: - self.curpathrow = len(self.pathlist)-1 + selection = self.pathtree.get_selection() + if not selection.count_selected_rows(): + return + model, iter = selection.get_selected() + next_iter = self.pathdata.iter_next(iter) + del self.pathdata[iter] + if next_iter: + selection.select_iter(next_iter) + elif len(self.pathdata): + selection.select_path(len(self.pathdata) - 1)   self.refresh_path_list()   self.dirty_event()     def _test_path(self, *args): + selection = self.pathtree.get_selection() + if not selection.count_selected_rows(): + return   if not self.root:   error_dialog(self, 'No Repository Found',   'Path testing cannot work without a repository')   return - testpath = self._pathpathedit.get_text() + model, iter = selection.get_selected() + testpath = model[iter][1]   if not testpath:   return   if testpath[0] == '~': @@ -364,61 +378,19 @@
  dlg = CmdDialog(cmdline)   dlg.run()   dlg.hide() - - def _refresh_path(self, *args): - name, path = (self._pathnameedit.get_text(), - self._pathpathedit.get_text()) - if name == 'default': - vbox, info, widgets = self.pages[2] - widgets[0].child.set_text(path) - del self.pathlist[self.curpathrow] - elif name == 'default-push': - vbox, info, widgets = self.pages[2] - widgets[1].child.set_text(path) - del self.pathlist[self.curpathrow] - else: - self.pathlist[self.curpathrow] = (name, path) + + def _pathtree_changed(self, sel):   self.refresh_path_list() - self.dirty_event() - - def _pathlist_rowchanged(self, sel): - model, iter = sel.get_selected() - if not iter: - return - self._pathnameedit.set_text(model.get(iter, 0)[0]) - self._pathpathedit.set_text(model.get(iter, 1)[0]) - self._pathnameedit.set_sensitive(True) - self._pathpathedit.set_sensitive(True) - self.curpathrow = model.get(iter, 3)[0]     def refresh_path_list(self): - model = gtk.ListStore(gobject.TYPE_PYOBJECT, - gobject.TYPE_PYOBJECT, - gobject.TYPE_STRING, - gobject.TYPE_PYOBJECT) - row = 0 - for (name, path) in self.pathlist: - iter = model.insert_before(None, None) - model.set_value(iter, 0, name) - model.set_value(iter, 1, path) - model.set_value(iter, 2, "%s = %s" % (name, path)) - model.set_value(iter, 3, row) - row += 1 - self.pathtree.set_model(model) - if len(self.pathlist): + """Update sensitivity of buttons""" + if ( len(self.pathdata) + and self.pathtree.get_selection().count_selected_rows() ):   self._delpathbutton.set_sensitive(True)   self._testpathbutton.set_sensitive(True) - self._refreshpathbutton.set_sensitive(True)   else:   self._delpathbutton.set_sensitive(False)   self._testpathbutton.set_sensitive(False) - self._refreshpathbutton.set_sensitive(False) - self._pathnameedit.set_text('') - self._pathpathedit.set_text('') - self._pathnameedit.set_sensitive(False) - self._pathpathedit.set_sensitive(False) - if self.curpathrow >= 0 and self.curpathrow < len(self.pathlist): - self.pathsel.select_path(self.curpathrow)     def fill_frame(self, frame, info):   widgets = [] @@ -558,10 +530,11 @@
  self.history.read()     # flush changes on paths page - if len(self.pathlist): - self._refresh_path(None) + if len(self.pathdata):   refreshlist = [] - for (name, path) in self.pathlist: + for row in self.pathdata: + name = row[0] + path = row[1]   cpath = '.'.join(['paths', name])   self.record_new_value(cpath, path, False)   refreshlist.append(name)