Commits

Peter Suter  committed 822b61a

Extend `IPreferencePanelProvider` extension point to support child panels.

  • Participants
  • Parent commits 158e97e

Comments (0)

Files changed (4)

File trac/htdocs/css/prefs.css

  vertical-align: middle;
  white-space: nowrap;
 }
+
+#content.prefs div.prefs_child {
+ margin-bottom: 4em;
+ margin-top: 4em;
+}
+#content.prefs div.prefs_child  h2 {
+ background: #f7f7f7;
+ border-bottom: 1px solid #d7d7d7;
+ box-shadow: 1px 1px .5em 0 #ccc;
+ border-radius: .1em;
+ padding: .2em .4em;
+}

File trac/prefs/api.py

         """Return a list of available preference panels.
 
         The items returned by this function must be tuple of the form
-        `(panel, label)`.
+        `(panel, label)`, or `(panel, label, parent_panel)` for child panels.
         """
 
     def render_preference_panel(req, panel):

File trac/prefs/templates/prefs.html

       <div id="tabcontent" py:with="has_forms = list(select('.//form'))">
         <form id="userprefs" action="" method="post" py:strip="has_forms">
           ${select("*|text()")}
+          <div py:for="(name, title, child) in child_panels">
+            <div class="prefs_child">
+              <h2 id="${name}">${title}</h2>
+              ${child}
+            </div>
+          </div>
           <div class="buttons" py:if="not has_forms">
             <input type="hidden" name="action" value="save" />
             <input type="submit" value="${_('Save changes')}" />

File trac/prefs/web_ui.py

 from trac.util.datefmt import all_timezones, get_timezone, localtz
 from trac.util.translation import _, get_available_locales
 from trac.web import HTTPNotFound, IRequestHandler
-from trac.web.chrome import add_notice, add_stylesheet, \
+from trac.web.chrome import add_notice, add_stylesheet, Chrome, \
                             INavigationContributor, ITemplateProvider
 
 
         panel_id = req.args['panel_id']
 
         panels = []
+        child_panels = []
         chosen_provider = None
-
+        chrome = Chrome(self.env)
+        
         for provider in self.panel_providers:
-            for name, label in provider.get_preference_panels(req) or []:
-                if name == panel_id or None:
-                    chosen_provider = provider
-                panels.append((name, label))
+            for panel in provider.get_preference_panels(req) or []:
+                if len(panel) == 3:
+                    name, label, parent = panel
+                    if parent == panel_id:
+                        template, data = \
+                            provider.render_preference_panel(req, name)
+                        child_panels.append((name, label,
+                            chrome.render_template(req, template, data,
+                                                   fragment=True)))
+                else:
+                    name, label = panel
+                    if name == panel_id or None:
+                        chosen_provider = provider
+                    panels.append(panel)
         if not chosen_provider:
             self.log.warn('Unknown preference panel %r', panel_id)
             raise HTTPNotFound(_('Unknown preference panel'))
 
         template, data = chosen_provider.render_preference_panel(req, panel_id)
-        data.update({'active_panel': panel_id, 'panels': panels})
+        data.update({'active_panel': panel_id, 
+                     'panels': panels, 
+                     'child_panels': child_panels})
 
         add_stylesheet(req, 'common/css/prefs.css')
         return template, data, None