Index: modules/menu.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/menu.module,v
retrieving revision 1.31
diff -u -r1.31 menu.module
--- modules/menu.module 5 May 2005 22:22:46 -0000 1.31
+++ modules/menu.module 24 Jun 2005 21:36:41 -0000
@@ -92,6 +92,47 @@
 }

 /**
+ * Implementation of hook_nodeapi().
+ */
+function menu_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
+
+  if (user_access('administer menu')) {
+    switch ($op) {
+      case 'form post':
+        $edit = $_POST['edit'];
+        $edit['nid'] = $node->nid;
+        return menu_node_form($edit);
+        break;
+
+      case 'insert':
+      case 'update':
+        if ($node->menu[delete]) {
+          menu_node_form_delete($node);
+          menu_rebuild();
+        }
+        elseif ($node->menu[title]) {
+          $edit['title'] = $node->menu[title];
+          $edit['description'] = '';
+          $edit['path'] = ($node->menu[path]) ? $node->menu[path] : "node/$node->nid";
+          $edit['pid'] = $node->menu[pid];
+          $edit['weight'] = $node->menu[weight];
+          $edit['mid'] = $node->menu[mid];
+          $edit['type'] = $node->menu[type];
+
+          menu_edit_item_save($edit);
+          menu_rebuild();
+        }
+        break;
+
+      case 'delete':
+        menu_node_form_delete($node);
+        menu_rebuild();
+        break;
+    }
+  }
+}
+
+/**
  * Implementation of hook_perm().
  */
 function menu_perm() {
@@ -99,6 +140,16 @@
 }

 /**
+ * Implementation of hook_settings().
+ */
+function menu_settings() {
+  $options = menu_parent_options(0);
+  $group .= form_select(t('Default parent item'), 'menu_pid_preset', variable_get('menu_pid_preset', 1), $options, t('Choose a parent to be selected by default in the menu \'quick item\' form.'));
+  $output = form_group(t('Menu node form options'), $group);
+  return $output;
+}
+
+/**
  * Menu callback; present the main menu management page.
  */
 function menu_overview() {
@@ -502,4 +553,44 @@
   return $options;
 }

+/**
+ * Build the form for quickly adding a menu item for a given node.
+ */
+function menu_node_form($edit = array()) {
+  $item = array();
+  if ($edit['nid'] > 0) {
+    $item = db_fetch_array(db_query("SELECT * FROM {menu} WHERE path = 'node/%d'", $edit['nid']));
+    if (!$item['path']) {
+      // I don't really have to set this, but it's probably good practice.
+      $item['path'] = 'node/'. $edit['nid'];
+    }
+  }
+  $item = ($_POST['op'] == t('Preview')) ? array_merge($item, $edit['menu']) : array_merge($edit['menu'], $item);
+
+  $group = form_textfield(t('Menu item title'), 'menu][title', $item['title'], 60, 128, t('The name to display for this link.'), NULL, TRUE);
+  // Generate a list of possible parents (not including this item or descendants).
+  $options = menu_parent_options($edit['mid']);
+  $group .= form_select(t('Parent item'), 'menu][pid', ($item['pid']) ? $item['pid'] : variable_get('menu_pid_preset', 1), $options);
+  $group .= form_hidden('menu][description', $item['description']);
+  $group .= form_hidden('menu][path', $item['path']);
+  $group .= form_hidden('menu][weight', ($item['weight']) ? $item['weight'] : 0);
+  $group .= form_hidden('menu][mid', ($item['mid']) ? $item['mid'] : 0);
+  $group .= form_hidden('menu][type', ($item['type']) ? $item['type'] : MENU_CUSTOM_ITEM);
+
+  if ($item['mid'] > 0) {
+    $group .= form_checkbox(t('Check to delete this menu item.'), 'menu][delete', 1, $item['delete'], null);
+  }
+  $form = form_group_collapsible(t('Menu item settings'), $group, TRUE);
+
+  return $form;
+}
+
+/**
+ * Remove the menu item.
+ */
+function menu_node_form_delete($node) {
+  if (db_query("DELETE FROM {menu} WHERE path = 'node/%s'", $node->nid)) {
+    drupal_set_message(t('Menu item deleted.'));
+  }
+}
 ?>
 ul {
