Index: template.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/themes/rootcandy/template.php,v
retrieving revision 1.36.2.24
diff -u -p -r1.36.2.24 template.php
--- template.php	19 Apr 2009 08:51:15 -0000	1.36.2.24
+++ template.php	3 May 2009 16:28:02 -0000
@@ -41,23 +41,14 @@ function _rootcandy_admin_navigation() {
   $path = base_path() . path_to_theme();
   $base = path_to_theme();
 
-  /**
-   *
-   */
   // get users role
   global $user;
 
   if ($user->uid != 1) {
     // get sorted roles
-    $role_weights = theme_get_setting('role-weight');
-    if ($role_weights) {
-      $filter_out = array_keys($user->roles);
-      $roles = array_intersect(array_flip($role_weights), $filter_out);
-      ksort($roles);
-      $keys = array_keys($roles);
-      $role = $roles[$keys[0]];
-
-      $rootcandy_navigation = theme_get_setting('rootcandy_navigation_source_'. $role);
+    $role_menu = _rootcandy_init_role_menu();
+    if ($role_menu) {
+      $rootcandy_navigation = theme_get_setting('rootcandy_navigation_source_'. $role_menu);
     }
   }
   else {
@@ -446,4 +437,64 @@ function _rootcandy_countmatches($arrayo
     if ($arrayone[$i] == $part) $matches = $i+1;
   }
   return $matches;
+}
+
+// TODO: we need to check if only the rootcandy theme and its subthemes are selected!
+function rootcandy_system_settings_form($form) {
+  if ($form['#id'] == 'system-theme-settings') {
+
+    foreach($form['theme_specific']['rows'] as $rid => $row) {
+      //we are only interested in numeric keys
+      if (intval($rid)){
+        $this_row = $row['data']['#value'];
+        //Add the weight field to the row
+        $weight = $form['theme_specific']['rows'][$rid]['role-weight-'.$rid]['#value'];
+        $this_row[] = drupal_render($form['theme_specific']['navigation']['nav-by-role']['rootcandy_navigation_source_'.$rid]);
+        $this_row[] = drupal_render($form['theme_specific']['rows'][$rid]['role-weight-'.$rid]);
+        //Add the row to the array of rows
+        $table_rows[$weight] = array('data'=>$this_row, 'class'=>'draggable');
+      }
+    }
+    ksort($table_rows);
+
+    $header = array(
+      "Role", "Navigation menu", "Order"
+    );
+
+    $form['theme_specific']['navigation']['role-weights']['content']['#value'] = theme('table', $header, $table_rows, array('id'=>'rootcandy-settings-table'));
+    $output .= drupal_render($form);
+
+    drupal_add_tabledrag('rootcandy-settings-table', 'order', 'sibling', 'weight');
+  }
+  else {
+    $output = drupal_render($form);
+  }
+  return $output;
+}
+
+function rootcandy_theme() {
+  return array(
+    'system_settings_form' => array(
+      'arguments' => array('form' => NULL),
+    ),
+  );
+}
+
+function _rootcandy_init_role_menu() {
+  global $theme_key;
+  global $user;
+  $i = 100;
+  $settings = theme_get_settings($theme_key);
+  $menu = array();
+
+  $roles = user_roles(FALSE);
+
+  foreach ($user->roles as $rid => $role) {
+    if (!$weight = $settings['role-weight-'.$rid]) {
+      $settings['role-weight-'.$rid] = $i++;
+    }
+    $menu[$settings['role-weight-'.$rid]] = $rid;
+  }
+  ksort($menu);
+  return $menu[key($menu)];
 }
\ No newline at end of file
Index: theme-settings.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/themes/rootcandy/theme-settings.php,v
retrieving revision 1.6.2.10
diff -u -p -r1.6.2.10 theme-settings.php
--- theme-settings.php	19 Apr 2009 08:48:14 -0000	1.6.2.10
+++ theme-settings.php	3 May 2009 16:28:02 -0000
@@ -91,9 +91,9 @@ function rootcandy_settings($saved_setti
     '#default_value' => $settings['rootcandy_navigation_icons_size'],
   );
 
-  $form['navigation']['nav-by-role'] = array(
+  $form['navigation']['role-weights'] = array(
     '#type' => 'fieldset',
-    '#title' => t('Menu source by role'),
+    '#title' => t('Menu by role and weights'),
     '#weight' => 1,
     '#collapsible' => TRUE,
     '#collapsed' => TRUE,
@@ -103,34 +103,15 @@ function rootcandy_settings($saved_setti
     NULL => t('None'),
     '_rootcandy_default_navigation' => t('default navigation'),
   );
+
   $primary_options = array_merge($primary_options, menu_get_menus());
   $roles = user_roles(FALSE);
   foreach ($roles as $rid => $role) {
     $form['navigation']['nav-by-role']['rootcandy_navigation_source_'. $rid] = array(
       '#type' => 'select',
-      '#title' => t('@role navigation', array('@role' => $role)),
       '#default_value' => $settings['rootcandy_navigation_source_'. $rid],
       '#options' => $primary_options,
       '#tree' => FALSE,
-      '#description' => t('Select what should be displayed as the navigation menu for role @role.', array('@role' => $role)),
-    );
-  }
-
-  $form['navigation']['role-weight'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Role weight'),
-    '#weight' => 1,
-    '#collapsible' => TRUE,
-    '#collapsed' => TRUE,
-    '#tree' => TRUE,
-  );
-
-  foreach ($roles as $rid => $role) {
-    $form['navigation']['role-weight'][$rid] = array(
-      '#type' => 'weight',
-      '#delta' => 5,
-      '#title' => $role,
-      '#default_value' => $settings['role-weight'][$rid],
     );
   }
 
@@ -150,6 +131,23 @@ function rootcandy_settings($saved_setti
     '#required' => FALSE
   );
 
+// EXPERIMENTAL CODE - ALMOST WORKING
+  $i = 100;
+  foreach ($roles as $rid => $role) {
+    if (!$weight = $settings['role-weight-'.$rid]) {
+      $weight = $i++;
+    }
+    $data = array($role);
+    $form['rows'][$rid]['data'] = array('#type' => 'value', '#value' => $data);
+    $form['rows'][$rid]['role-weight-'.$rid] = array(
+      '#type'=>'textfield',
+      '#size'=>5,
+      '#default_value' => $weight,
+      '#attributes' => array('class'=>'weight'),
+    );
+  }
+// EXPERIMENTAL CODE
+
   // Return the additional form widgets
   return $form;
 }
\ No newline at end of file
