Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.8, 0.8.1, and 0.8.2

thgconfig: allow toggle between user and repo modes

Moved the edit button to the top next to the config file combo, where
it's more obvious what you are editing.

Changeset faed9c8b5d12

Parent d2fc31ed72d9

by Steve Borho

Changes to one file · Browse files at faed9c8b5d12 Showing diff from parent d2fc31ed72d9 Diff from another changeset...

 
362
363
364
365
366
367
368
369
370
 
 
371
372
373
 
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
 
 
 
 
 
393
394
 
 
 
 
 
 
395
396
397
 
436
437
438
439
 
440
441
 
442
443
444
445
446
447
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
448
449
450
 
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
 
583
584
585
586
587
588
589
590
591
592
593
594
 
630
631
632
633
634
635
636
 
834
835
836
837
 
838
839
840
 
980
981
982
983
 
984
985
986
 
362
363
364
 
365
366
367
368
369
370
371
372
373
374
 
379
380
381
 
 
 
 
 
 
 
 
 
 
 
 
382
383
384
385
386
387
 
388
389
390
391
392
393
394
395
396
 
435
436
437
 
438
439
440
441
442
443
444
 
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
 
515
516
517
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
518
519
520
 
620
621
622
 
 
 
 
 
 
623
624
625
 
661
662
663
 
664
665
666
 
864
865
866
 
867
868
869
870
 
1010
1011
1012
 
1013
1014
1015
1016
@@ -362,12 +362,13 @@
  """ Initialize the Dialog. """   gtk.Dialog.__init__(self, parent=None, flags=0,   buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)) - self.add_button(gtk.STOCK_EDIT, gtk.RESPONSE_YES)   gtklib.set_tortoise_keys(self)     self.ui = ui.ui()   try:   repo = hg.repository(self.ui, path=paths.find_root()) + name = repo.ui.config('web', 'name') or os.path.basename(repo.root) + self.ui = repo.ui   except hglib.RepoError:   repo = None   if configrepo: @@ -378,20 +379,18 @@
  # Catch close events   self.connect('response', self.should_live)   - if configrepo: - self.ui = repo.ui - name = repo.ui.config('web', 'name') or os.path.basename(repo.root) - self.rcpath = [os.sep.join([repo.root, '.hg', 'hgrc'])] - self.set_title(_('TortoiseHg Configure Repository - ') + name) - gtklib.set_tortoise_icon(self, 'settings_repo.ico') - self.root = repo.root - else: - self.rcpath = util.user_rcpath() - self.set_title(_('TortoiseHg Configure User-Global Settings')) - gtklib.set_tortoise_icon(self, 'settings_user.ico') - self.root = None + combo = gtk.combo_box_new_text() + combo.append_text(_('User global settings')) + if repo: + combo.append_text(_('%s repository settings') % name) + combo.connect('changed', self.fileselect)   - self.ini = self.load_config(self.rcpath) + hbox = gtk.HBox() + hbox.pack_start(combo, False, False, 2) + edit = gtk.Button(_('Edit File')) + hbox.pack_start(edit, False, False, 2) + edit.connect('clicked', self.edit_clicked) + self.vbox.pack_start(hbox, False, False, 4)     # Create a new notebook, place the position of the tabs   self.notebook = notebook = gtk.Notebook() @@ -436,15 +435,78 @@
  self.diff_frame = self.add_page(notebook, _('Diff'))   self.fill_frame(self.diff_frame, _diff_info)   - if not configrepo and os.name == 'nt': + if os.name == 'nt':   self.shellframe = self.add_page(notebook, _('Shell Ext'))   self.fill_shell_frame(self.shellframe) + self.shellframe.set_sensitive(not configrepo)   self.configrepo = configrepo     # Force dialog into clean state in the beginning - self._refresh_vlist()   self._btn_apply.set_sensitive(False)   self.dirty = False + combo.set_active(configrepo and 1 or 0) + + def fileselect(self, combo): + 'select another hgrc file' + if self.dirty: + gdialog.Confirm(_('Unapplied changes'), [], self, + _('Lose changes and switch files?.')).run() + if ret != gtk.RESPONSE_YES: + return + self.configrepo = combo.get_active() and True or False + self.refresh() + + def refresh(self): + if self.configrepo: + repo = hg.repository(ui.ui(), path=paths.find_root()) + name = repo.ui.config('web', 'name') or os.path.basename(repo.root) + self.rcpath = [os.sep.join([repo.root, '.hg', 'hgrc'])] + self.set_title(_('TortoiseHg Configure Repository - ') + name) + gtklib.set_tortoise_icon(self, 'settings_repo.ico') + self.root = repo.root + else: + self.rcpath = util.user_rcpath() + self.set_title(_('TortoiseHg Configure User-Global Settings')) + gtklib.set_tortoise_icon(self, 'settings_user.ico') + self.root = None + self.shellframe.set_sensitive(not self.configrepo) + self.ini = self.load_config(self.rcpath) + self.refresh_vlist() + self.pathdata.clear() + if 'paths' in list(self.ini): + for name in self.ini['paths']: + path = self.ini['paths'][name] + safepath = hglib.toutf(url.hidepassword(path)) + self.pathdata.append([hglib.toutf(name), safepath, + hglib.toutf(path)]) + self.refresh_path_list() + self._btn_apply.set_sensitive(False) + self.dirty = False + + def edit_clicked(self, button): + def doedit(): + util.system("%s \"%s\"" % (editor, self.fn)) + # reload configs, in case they have been written since opened + if self.configrepo: + repo = hg.repository(ui.ui(), path=paths.find_root()) + u = repo.ui + else: + u = ui.ui() + editor = (u.config('tortoisehg', 'editor') or + u.config('gtools', 'editor') or + os.environ.get('HGEDITOR') or + u.config('ui', 'editor') or + os.environ.get('EDITOR', 'vi')) + if os.path.basename(editor) in ('vi', 'vim', 'hgeditor'): + gdialog.Prompt(_('No visual editor configured'), + _('Please configure a visual editor.'), self).run() + self.focus_field('tortoisehg.editor') + self.emit_stop_by_name('response') + return True + thread = threading.Thread(target=doedit, name='edit config') + thread.setDaemon(True) + thread.start() + return True     def should_live(self, *args):   if self.dirty: @@ -453,31 +515,6 @@
  if ret != gtk.RESPONSE_YES:   self.emit_stop_by_name('response')   return True - if len(args) == 2 and args[1] == gtk.RESPONSE_YES: - def doedit(): - util.system("%s \"%s\"" % (editor, self.fn)) - # reload configs, in case they have been written since opened - if self.configrepo: - repo = hg.repository(ui.ui(), path=paths.find_root()) - u = repo.ui - else: - u = ui.ui() - editor = (u.config('tortoisehg', 'editor') or - u.config('gtools', 'editor') or - os.environ.get('HGEDITOR') or - u.config('ui', 'editor') or - os.environ.get('EDITOR', 'vi')) - if os.path.basename(editor) in ('vi', 'vim', 'hgeditor'): - gdialog.Prompt(_('No visual editor configured'), - _('Please configure a visual editor.'), self).run() - self.focus_field('tortoisehg.editor') - self.emit_stop_by_name('response') - return True - thread = threading.Thread(target=doedit, name='edit config') - thread.setDaemon(True) - thread.start() - self.emit_stop_by_name('response') - return True   return False     def focus_field(self, focusfield): @@ -583,12 +620,6 @@
    # Initialize data model for 'Paths' tab   self.pathdata = gtk.ListStore(str, str, str) - if 'paths' in list(self.ini): - for name in self.ini['paths']: - path = self.ini['paths'][name] - safepath = hglib.toutf(url.hidepassword(path)) - self.pathdata.append([hglib.toutf(name), safepath, - hglib.toutf(path)])     # Define view model for 'Paths' tab   self.pathtree = gtk.TreeView(self.pathdata) @@ -630,7 +661,6 @@
  buttonbox.pack_start(self._testpathbutton)     vbox.pack_start(buttonbox, False, False, 4) - self.refresh_path_list()     def set_help(self, widget, event, buffer, tooltip):   text = ' '.join(tooltip.splitlines()) @@ -834,7 +864,7 @@
  self.pages.append((vbox, info, widgets))   return vbox   - def _refresh_vlist(self): + def refresh_vlist(self):   for vbox, info, widgets in self.pages:   for row, (label, cpath, values, tooltip) in enumerate(info):   ispw = cpath in _pwfields @@ -980,7 +1010,7 @@
  self.record_new_value(cpath, newvalue)     self.history.write() - self._refresh_vlist() + self.refresh_vlist()     try:   f = open(self.fn, "w")