=== modified file 'modules/menu/menu.admin.inc'
--- modules/menu/menu.admin.inc	2007-11-17 14:25:23 +0000
+++ modules/menu/menu.admin.inc	2007-11-17 18:48:58 +0000
@@ -162,7 +162,6 @@ function theme_menu_overview_form($form)
  * Menu callback; Build the menu link editing form.
  */
 function menu_edit_item(&$form_state, $type, $item, $menu) {
-
   $form['menu'] = array(
     '#type' => 'fieldset',
     '#title' => t('Menu settings'),
@@ -233,18 +232,13 @@ function menu_edit_item(&$form_state, $t
   );
 
   // Generate a list of possible parents (not including this item or descendants).
-  $options = menu_parent_options(menu_get_menus(), $item);
   $default = $item['menu_name'] .':'. $item['plid'];
   if (!isset($options[$default])) {
     $default = 'navigation:0';
   }
-  $form['menu']['parent'] = array(
-    '#type' => 'select',
-    '#title' => t('Parent item'),
-    '#default_value' => $default,
-    '#options' => $options,
-    '#description' => t('The maximum depth for an item and all its children is fixed at !maxdepth.  Some menu items may not be available as parents if selecting them would exceed this limit.', array('!maxdepth' => MENU_MAX_DEPTH)),
-    '#attributes' => array('class' => 'menu-title-select'),
+  $form['menu']['parents'] = array(
+    '#type' => 'menu_parent_select',
+    '#mlid' => $item['mlid'],
   );
   $form['menu']['weight'] = array(
     '#type' => 'weight',
@@ -293,11 +287,19 @@ function menu_item_delete_submit($form, 
 function menu_edit_item_submit($form, &$form_state) {
   $item = $form_state['values']['menu'];
   $item['options']['attributes']['title'] = $item['description'];
-  list($item['menu_name'], $item['plid']) = explode(':', $item['parent']);
+  $max_depth = -1;
+  foreach (element_children($form['menu']['parents']) as $plid) {
+    $element = $form['menu']['parents'][$plid];
+    if (isset($element['select']) && $element['select']['#value'] > 0 && $element['#depth'] > $max_depth) {
+      $item['plid'] = $element['select']['#value'];
+      $max_depth = $element['#depth'];
+    }
+  }
   if (!menu_link_save($item)) {
     drupal_set_message(t('There was an error saving the menu link.'), 'error');
   }
   $form_state['redirect'] = 'admin/build/menu-customize/'. $item['menu_name'];
+  unset($form_state['storage']['mlid']);
 }
 
 /**

=== modified file 'modules/menu/menu.module'
--- modules/menu/menu.module	2007-11-17 14:25:23 +0000
+++ modules/menu/menu.module	2007-11-17 18:50:20 +0000
@@ -189,54 +189,106 @@ function menu_load($menu_name) {
   return db_fetch_array(db_query("SELECT * FROM {menu_custom} WHERE menu_name = '%s'", $menu_name));
 }
 
+function menu_elements() {
+  $types['menu_parent_select'] = array(
+    '#process' => array('menu_parent_select_process'),
+    '#input' => TRUE,
+    // Does not really matter but we set a #value just in case someone themes
+    // this element.
+    '#value' => '',
+  );
+  return $types;
+}
+
 /**
- * Return a list of menu items that are valid possible parents for the given menu item.
+ * Creates a parent selector fieldset for a given menu link.
  *
- * @param $menus
- *   An array of menu names and titles, such as from menu_get_menus().
- * @param $item
- *   The menu item for which to generate a list of parents.
- *   If $item['mlid'] == 0 then the complete tree is returned.
- * @return
- *   An array of menu link titles keyed on the a string containing the menu name
- *   and mlid. The list excludes the given item and its children.
+ * You need to set #mlid to the menu link id. Currently, this element
+ * is only usable in a #tree TRUE form.
  */
-function menu_parent_options($menus, $item) {
-
-  // If the item has children, there is an added limit to the depth of valid parents.
-  if (isset($item['parent_depth_limit'])) {
-    $limit = $item['parent_depth_limit'];
+function menu_parent_select_process($form, $edit, &$form_state) {
+  $original_mlid = $form['#mlid'];
+  if (isset($form_state['storage']['mlid'])) {
+    $mlid = $form_state['storage']['mlid'];
+    $collapsed = FALSE;
   }
   else {
-    $limit = _menu_parent_depth_limit($item);
+    $mlid = $original_mlid;
+    $collapsed = TRUE;
   }
-
-  foreach ($menus as $menu_name => $title) {
-    $tree = menu_tree_all_data($menu_name, NULL);
-    $options[$menu_name .':0'] = '<'. $title .'>';
-    _menu_parents_recurse($tree, $menu_name, '--', $options, $item['mlid'], $limit);
+  $item = menu_link_load($mlid);
+  $tree = menu_tree_all_data($item['menu_name'], $item);
+  if (!$form) {var_export(debug_backtrace());}
+  $form = array_merge($form, array(
+    '#type' => 'fieldset',
+    '#title' => t('Parents'),
+    '#collapsible' => TRUE,
+    '#collapsed' => $collapsed,
+  ));
+  $form += _menu_parent_select_recurse($tree, $original_mlid, TRUE);
+  $form['parent_submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Update'),
+    '#submit' => array('_menu_parent_selector_update'),
+  );
+  return $form;
+}
+
+function _menu_parent_select_recurse($tree, $original_mlid, $reset = FALSE) {
+  static $form;
+  if ($reset) {
+    $form = array();
+  }
+  foreach ($tree as $item) {
+    if (isset($item['link'])) {
+      $link = $item['link'];
+      // Skip the current element and all its children.
+      if ($link['mlid'] == $original_mlid) {
+        continue;
+      }
+      if (!$link['hidden']) {
+        $plid = $link['plid'];
+        $mlid = $link['mlid'];
+        if (!isset($form[$plid])) {
+          $form[$plid]['select'] = array(
+            '#type' => 'select',
+            '#default_value' => -1,
+          );
+          $depth = $link['depth'];
+          if ($depth > 1) {
+            $form[$plid]['select']['#options'][-1] = t('Disregard this level');
+          }
+          $form[$plid]['#depth'] = $depth;
+        }
+        $form[$plid]['select']['#options'][$mlid] = $link['title'];
+        if ($link['in_active_trail']) {
+          $form[$plid]['select']['#default_value'] = $mlid;
+        }
+      }
+    }
+    if (!empty($item['below'])) {
+      _menu_parent_select_recurse($item['below'], $original_mlid);
+    }
   }
-  return $options;
+  return $form;
 }
 
-/**
- * Recursive helper function for menu_parent_options().
- */
-function _menu_parents_recurse($tree, $menu_name, $indent, &$options, $exclude, $depth_limit) {
-  foreach ($tree as $data) {
-    if ($data['link']['depth'] > $depth_limit) {
-      // Don't iterate through any links on this level.
-      break;
-    }
-    if ($data['link']['mlid'] != $exclude && $data['link']['hidden'] >= 0) {
-      $title = $indent .' '. truncate_utf8($data['link']['title'], 30, TRUE, FALSE);
-      if ($data['link']['hidden']) {
-        $title .= ' ('. t('disabled') .')';
-      }
-      $options[$menu_name .':'. $data['link']['mlid']] = $title;
-      if ($data['below']) {
-        _menu_parents_recurse($data['below'], $menu_name, $indent .'--', $options, $exclude, $depth_limit);
-      }
+function _menu_parent_selector_update($form, &$form_state) {
+  $form_state['rebuild'] = TRUE;
+  $parents = $form_state['clicked_button']['#parents'];
+  // The last parent is the button itself.
+  array_pop($parents);
+  while ($parents) {
+    $parent = array_shift($parents);
+    $form = $form[$parent];
+  }
+  $min_depth = MENU_MAX_DEPTH + 1;
+  // We need the first element that was changed and is not "disregard this level".
+  foreach (element_children($form) as $plid) {
+    $element = $form[$plid];
+    if (isset($element['select']) && $element['select']['#default_value'] != $element['select']['#value'] && $element['select']['#value'] > 0 && $element['#depth'] < $min_depth) {
+      $form_state['storage']['mlid'] = $element['select']['#value'];
+      $min_depth = $element['#depth'];
     }
   }
 }

