Commits

Steve Borho  committed 16a3c8d

hggtk/thgconfig: move focus_field and new_path into class methods

This simplifies the class __init__ function and makes the behavior
easier to understand.

  • Participants
  • Parent commits 0d20d06

Comments (0)

Files changed (4)

File hggtk/hgemail.py

                 self._plain.set_sensitive(False)
 
     def _on_conf_clicked(self, button, userdata):
-        dlg = ConfigDialog(self.root, False, 'email.from')
+        dlg = ConfigDialog(self.root, False)
         dlg.show_all()
+        dlg.focus_field('email.from')
         dlg.run()
         dlg.hide()
         self._refresh()
         if self.repo.ui.config('email', 'method', 'smtp') == 'smtp':
             if not self.repo.ui.config('smtp', 'host'):
                 info_dialog('Info required', 'You must configure SMTP')
-                dlg = ConfigDialog(self.root, False, 'smtp.host')
+                dlg = ConfigDialog(self.root, False)
                 dlg.show_all()
+                dlg.focus_field('smtp.host')
                 dlg.run()
                 dlg.hide()
                 self._refresh()

File hggtk/serve.py

     def _on_conf_clicked(self, *args):
         if self.repo is None: return
         from thgconfig import ConfigDialog
-        dlg = ConfigDialog(self.repo.root, True, 'web.name')
+        dlg = ConfigDialog(self.repo.root, True)
         dlg.show_all()
+        dlg.focus_field('web.name')
         dlg.run()
         dlg.hide()
 

File hggtk/synch.py

                 newpath = None
                 break
         from thgconfig import ConfigDialog
-        dlg = ConfigDialog(self.root, True, 'paths.default', newpath)
+        dlg = ConfigDialog(self.root, True)
         dlg.show_all()
+        if newpath:
+            dlg.new_path(newpath)
+        else:
+            dlg.focus_field('paths.default')
         dlg.run()
         dlg.hide()
         self.paths = self._get_paths()

File hggtk/thgconfig.py

         hbox.pack_start(self._pathpathedit, True, True, 4)
         vbox.pack_start(hbox, False, False, 4)
         vbox.pack_start(buttonbox, False, False, 4)
+        self.refresh_path_list()
 
         self._web_info = (
                 ('Name', 'web.name', ['unknown'],
         self.fill_frame(self.hgmerge_frame, self._hgmerge_info)
         # TODO add ability to specify file extension based merge tools
 
-        if focusfield:
-            # Set page and focus to requested datum
-            for page_num, (vbox, info, widgets) in enumerate(self.pages):
-                for w, (label, cpath, values, tip) in enumerate(info):
-                    if cpath == focusfield:
-                        self.notebook.set_current_page(page_num)
-                        widgets[w].grab_focus()
-
-        if newpath:
-            self.pathlist.append(('new', newpath))
-            self.curpathrow = len(self.pathlist)-1
-            self.refresh_path_list()
-            self._pathnameedit.grab_focus()
-        else:
-            self.refresh_path_list()
-
         # Force dialog into clean state in the beginning
         self._btn_apply.set_sensitive(False)
         self.dirty = False
                 'Yes to abandon changes, No to continue') != gtk.RESPONSE_YES:
                 widget.emit_stop_by_name('response')
 
+    def focus_field(self, focusfield):
+        '''Set page and focus to requested datum'''
+        for page_num, (vbox, info, widgets) in enumerate(self.pages):
+            for w, (label, cpath, values, tip) in enumerate(info):
+                if cpath == focusfield:
+                    self.notebook.set_current_page(page_num)
+                    widgets[w].grab_focus()
+                    return
+
+    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
+        self.refresh_path_list()
+        self.notebook.set_current_page(2)
+        self._pathnameedit.grab_focus()
+
     def dirty_event(self, *args):
         if not self.dirty:
             self._btn_apply.set_sensitive(True)
         return 0
 
 def run(root='', cmdline=[], files=[], **opts):
+    dialog = ConfigDialog(root, bool(files))
+    dialog.show_all()
+    dialog.connect('response', gtk.main_quit)
     if '--focusfield' in cmdline:
         field = cmdline[cmdline.index('--focusfield')+1]
-    else:
-        field = None
-    dialog = ConfigDialog(root, bool(files), field)
-    dialog.show_all()
-    dialog.connect('response', gtk.main_quit)
+        dialog.focus_field(field)
     gtk.gdk.threads_init()
     gtk.gdk.threads_enter()
     gtk.main()