Index: modules/shortcut/shortcut.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/shortcut/shortcut.admin.inc,v
retrieving revision 1.4
diff -u -p -r1.4 shortcut.admin.inc
--- modules/shortcut/shortcut.admin.inc	3 Jan 2010 21:01:04 -0000	1.4
+++ modules/shortcut/shortcut.admin.inc	13 Jan 2010 23:46:04 -0000
@@ -19,82 +19,123 @@ function shortcut_max_slots() {
 }
 
 /**
- * Menu callback; Build the form for switching shortcut sets.
+ * Menu callback; Build the table for administering shortcut sets.
  *
- * @param $form
- *   An associative array containing the structure of the form.
- * @param $form_state
- *   An associative array containing the current state of the form.
- * @param $account
- *   (optional) The user account whose shortcuts will be switched. Defaults to
- *   the current logged-in user.
- * @return
- *   An array representing the form definition.
+ * @param $user
+ *   (optional) User object for the user whose shortcuts will be administered
  *
- * @ingroup forms
- * @see shortcut_set_switch_submit()
+ * @see theme_shortcut_set_admin()
  */
-function shortcut_set_switch($form, &$form_state, $account = NULL) {
-  global $user;
-  if (!isset($account)) {
-    $account = $user;
+function shortcut_set_admin($user = NULL) {
+  $shortcut_sets = shortcut_sets();
+  $rows = array();
+  foreach ($shortcut_sets as $set) {
+    $cols = array();
+    $cols[0] = check_plain($set->title);
+    //Add an edit link, if the user has permission
+    $cols[1] = shortcut_set_edit_access($set) ? l('edit', "admin/config/system/shortcut/$set->set_name") : NULL;
+    //if we're on the user page, add a link to set the user's default set
+    if ($user) {
+      if ($set->set_name == shortcut_current_displayed_set($user)->set_name) {
+        $cols[2] = t('active');
+      } elseif (shortcut_set_switch_access($user)) {
+          $query['token'] = drupal_get_token('shortcuts-switch-link');
+          $query['destination'] = $_GET['q'];
+          $cols[2] =l(t('set active'), "shortcuts/switch/{$user->uid}/{$set->set_name}", array('query' => $query));
+      } else {
+        $cols[2] = NULL;
+      }
+    }
+    //Add a delete link if it's not the default set
+    $cols[3] = user_access('administer shortcuts') && $set->set_name != shortcut_default_set($user)->set_name ? l('delete', "admin/config/system/shortcut/$set->set_name/delete") : NULL;
+    
+    $rows[] = $cols;
   }
+  return theme('shortcut_set_admin', $rows);
+}
 
-  // Prepare the list of shortcut sets.
-  $sets = shortcut_sets();
-  $current_set = shortcut_current_displayed_set($account);
-  $default_set = shortcut_default_set($account);
-  $options = array();
-  foreach ($sets as $name => $set) {
-    $options[$name] = check_plain($set->title);
-  }
+/**
+ * Menu callback; Set the default shortcut set.
+ *
+ * @see shortcut_set_admin()
+ */
+function shortcut_switch_current_set($account, $shortcut_set) {
+  if (isset($_REQUEST['token']) && drupal_valid_token($_REQUEST['token'], 'shortcuts-switch-link')) {
 
-  // Only administrators can add shortcut sets.
-  $add_access = user_access('administer shortcuts');
-  if ($add_access) {
-    $options['new'] = t('New set');
+    // Check if the specified set exists.
+    if (isset($shortcut_set->set_name)) {
+      // Set the default set.
+      shortcut_set_assign_user($shortcut_set, $account);
+      $replacements = array(
+        '%user' => $account->name,
+        '%set_name' => $shortcut_set->title,
+      );
+      global $user;
+      drupal_set_message($account->uid == $user->uid ? t('You are now using the %set_name shortcut set.', $replacements) : t('%user is now using the %set_name shortcut set.', $replacements));
+    }
+    else {
+      drupal_set_message(t('The requested shortcut set was not found.'), 'error');
+    }
+    drupal_goto($_REQUEST['destination']);
   }
+  return drupal_access_denied();
+}
 
-  $form['account'] = array(
-    '#type' => 'value',
-    '#value' => $account,
-  );
 
-  $form['set'] = array(
-    '#type' => 'radios',
-    '#title' => $user->uid == $account->uid ? t('Choose a set of shortcuts to use') : t('Choose a set of shortcuts for this user'),
-    '#options' => $options,
-    '#default_value' => $current_set->set_name,
-  );
+/**
+ * Theme function for the shortcut set admin form.
+ *
+ * @param $rows
+ *   An associative array containing a row for each Shortcut set with
+ *   - Shortcut title
+ *   - Edit link
+ *   - Delete link, if available
+ *   
+ * @return
+ *   A themed HTML string representing the content of the form.
+ *
+ * @ingroup themeable
+ * @see shortcut_set_admin()
+ */
+function theme_shortcut_set_admin($rows) {
+  $output = '';
+  $header = array(t('Name'), array('data' => t('Operations'), 'colspan' => 3));
+  $output .= theme('table', array('header' => $header, 'rows' => $rows));
+  return $output;
+}
 
+/**
+ * Menu callback; Build the form for adding a shortcut set.
+ *
+ * @param $form
+ *   An associative array containing the structure of the form.
+ * @param $form_state
+ *   An associative array containing the current state of the form.
+ * @return
+ *   An array representing the form definition.
+ *
+ * @ingroup forms
+ * @see shortcut_set_add_form_submit()
+ */
+function shortcut_set_add_form($form, &$form_state) {
   $form['new'] = array(
     '#type' => 'textfield',
-    '#description' => t('The new set is created by copying items from the @default set.', array('@default' => $default_set->title)),
-    '#access' => $add_access,
+    '#title' => t('Set name'),
+    '#description' => t('The new set is created by copying items from the default set.'),
   );
 
-  $form['#attached'] = array(
-    'css' => array(drupal_get_path('module', 'shortcut') . '/shortcut.admin.css'),
-    'js' => array(drupal_get_path('module', 'shortcut') . '/shortcut.admin.js'),
-  );
-
-  $form['actions'] = array('#type' => 'container', '#attributes' => array('class' => array('form-actions')));
   $form['actions']['submit'] = array(
-    '#type' => 'submit', 
-    '#value' => t('Save configuration'),
+    '#type' => 'submit',
+    '#value' => t('Create new set'),
   );
 
   return $form;
 }
 
 /**
- * Submit handler for the form that switches shortcut sets.
+ * Submit handler for the form that adds a new shortcut set.
  */
-function shortcut_set_switch_submit($form, &$form_state) {
-  global $user;
-  $account = $form_state['values']['account'];
-
-  if ($form_state['values']['set'] == 'new') {
+function shortcut_set_add_form_submit($form, &$form_state) {
     // Save a new shortcut set with links copied from the default set.
     $default_set = shortcut_default_set();
     $set = (object) array(
@@ -102,35 +143,14 @@ function shortcut_set_switch_submit($for
       'links' => menu_links_clone($default_set->links),
     );
     shortcut_set_save($set);
+
     $replacements = array(
-      '%user' => $account->name,
-      '%set_name' => $set->title,
-      // This form can be displayed on more than one page, so make sure we link
-      // back to the correct one.
-      '@switch-url' => url($_GET['q']),
-    );
-    if ($account->uid == $user->uid) {
-      // Only administrators can create new shortcut sets, so we know they have
-      // access to switch back.
-      drupal_set_message(t('Your are now using the new %set_name shortcut set. You can customize it from this page or <a href="@switch-url">switch back to a different one.</a>', $replacements));
-    }
-    else {
-      drupal_set_message(t('%user is now using a new shortcut set called %set_name. You can customize it from this page.', $replacements));
-    }
-    $form_state['redirect'] = 'admin/config/system/shortcut/' . $set->set_name;
-  }
-  else {
-    // Switch to a different shortcut set.
-    $set = shortcut_set_load($form_state['values']['set']);
-    $replacements = array(
-      '%user' => $account->name,
       '%set_name' => $set->title,
     );
-    drupal_set_message($account->uid == $user->uid ? t('You are now using the %set_name shortcut set.', $replacements) : t('%user is now using the %set_name shortcut set.', $replacements));
-  }
 
-  // Assign the shortcut set to the provided user account.
-  shortcut_set_assign_user($set, $account);
+    drupal_set_message(t('The new %set_name shortcut set has been created. You can customize it from this page.', $replacements));
+
+    $form_state['redirect'] = 'admin/config/system/shortcut/' . $set->set_name;
 }
 
 /**
@@ -150,22 +170,12 @@ function shortcut_set_switch_submit($for
  */
 function shortcut_set_customize($form, &$form_state, $shortcut_set) {
   $form['set'] = array(
-    '#markup' => t('Using set "@set"', array('@set' => $shortcut_set->title)),
+    '#markup' => t('Editing set "@set"', array('@set' => $shortcut_set->title)),
     '#prefix' => '<h4 class="shortcuts-set">',
     '#suffix' => '</h4>',
     '#weight' => -100,
   );
 
-  $form['change_set'] = array(
-    '#type' => 'link',
-    '#title' => t('Change set'),
-    '#href' => 'admin/config/system/shortcut',
-    '#prefix' => '<div class="shortcuts-change-set"> (',
-    '#suffix' => ')</div>',
-    '#weight' => -99,
-    '#access' => shortcut_set_switch_access(),
-  );
-
   $form['shortcuts']['#tree'] = TRUE;
   $form['shortcuts']['enabled'] = $form['shortcuts']['disabled'] = array();
   foreach ($shortcut_set->links as $link) { 
@@ -455,6 +465,47 @@ function shortcut_admin_add_link($shortc
 }
 
 /**
+ * Menu callback; Build the form for deleting a shortcut set.
+ *
+ * @param $form
+ *   An associative array containing the structure of the form.
+ * @param $form_state
+ *   An associative array containing the current state of the form.
+ * @param $set_name
+ *   The unique name of the set that will be deleted.
+ * @return
+ *   An array representing the form definition.
+ *
+ * @ingroup forms
+ * @see shortcut_set_delete_form_submit()
+ */
+function shortcut_set_delete_form($form, &$form_state, $shortcut_set) {
+  $form['shortcut_set'] = array(
+    '#type' => 'value',
+    '#value' => $shortcut_set->set_name,
+  );
+
+  return confirm_form(
+    $form,
+    t('Are you sure you want to delete the shortcut set %title?', array('%title' => $shortcut_set->title)),
+    'admin/config/system/shortcut/' . $shortcut_set->set_name,
+    t('This action cannot be undone.'),
+    t('Delete'),
+    t('Cancel')
+  );
+}
+
+/**
+ * Submit handler for the shortcut link deletion form.
+ */
+function shortcut_set_delete_form_submit($form, &$form_state) {
+  $shortcut_set = shortcut_set_load($form_state['values']['shortcut_set']);
+  shortcut_set_delete($shortcut_set);
+  $form_state['redirect'] = 'admin/config/system/shortcut/';
+  drupal_set_message(t('The shortcut set %title has been deleted.', array('%title' => $shortcut_set->title)));
+}
+
+/**
  * Menu callback; Build the form for deleting a shortcut link.
  *
  * @param $form
Index: modules/shortcut/shortcut.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/shortcut/shortcut.module,v
retrieving revision 1.17
diff -u -p -r1.17 shortcut.module
--- modules/shortcut/shortcut.module	11 Jan 2010 00:06:58 -0000	1.17
+++ modules/shortcut/shortcut.module	13 Jan 2010 23:46:05 -0000
@@ -58,9 +58,16 @@ function shortcut_menu() {
   $items['admin/config/system/shortcut'] = array(
     'title' => 'Shortcuts',
     'description' => 'List the available shortcut sets and switch between them.',
+    'page callback' => 'shortcut_set_admin',
+    'access arguments' => array('administer shortcuts'),
+    'file' => 'shortcut.admin.inc',
+  );
+  $items['admin/config/system/shortcut/add-set'] = array(
+    'title' => 'Add shortcut set',
     'page callback' => 'drupal_get_form',
-    'page arguments' => array('shortcut_set_switch'),
+    'page arguments' => array('shortcut_set_add_form'),
     'access arguments' => array('administer shortcuts'),
+    'type' => MENU_LOCAL_ACTION,
     'file' => 'shortcut.admin.inc',
   );
   $items['admin/config/system/shortcut/%shortcut_set'] = array(
@@ -90,6 +97,14 @@ function shortcut_menu() {
     'type' => MENU_CALLBACK,
     'file' => 'shortcut.admin.inc',
   );
+  $items['admin/config/system/shortcut/%shortcut_set/delete'] = array(
+    'title' => 'Delete this shortcut set',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('shortcut_set_delete_form', 4),
+    'access arguments' => array('administer shortcuts'),
+    'type' => MENU_CALLBACK,
+    'file' => 'shortcut.admin.inc',
+  );
   $items['admin/config/system/shortcut/link/%menu_link'] = array(
     'title' => 'Edit shortcut',
     'page callback' => 'drupal_get_form',
@@ -110,13 +125,22 @@ function shortcut_menu() {
   );
   $items['user/%user/shortcuts'] = array(
     'title' => 'Shortcuts',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('shortcut_set_switch', 1),
-    'access callback' => 'shortcut_set_switch_access',
+    'page callback' => 'shortcut_set_admin',
+    'page arguments' => array(1),
+    'access callback' => 'shortcut_user_access',
     'access arguments' => array(1),
     'type' => MENU_LOCAL_TASK,
     'file' => 'shortcut.admin.inc',
   );
+  $items['shortcuts/switch/%user/%shortcut_set'] = array(
+    'title' => 'Set Current Shortcut Set',
+    'page callback' => 'shortcut_switch_current_set',
+    'page arguments' => array(2, 3),
+    'access callback' => 'shortcut_set_switch_access',
+    'access arguments' => array(2),
+    'type' => MENU_CALLBACK,
+    'file' => 'shortcut.admin.inc',
+  );
   return $items;
 }
 
@@ -125,6 +149,9 @@ function shortcut_menu() {
  */
 function shortcut_theme() {
   return array(
+    'shortcut_set_admin' => array(
+      'file' => 'shortcut.admin.inc',
+    ),
     'shortcut_set_customize' => array(
       'render element' => 'form',
       'file' => 'shortcut.admin.inc',
@@ -156,6 +183,20 @@ function shortcut_block_view($delta = ''
 }
 
 /**
+ * Access callback for accessing the shortcut management tab for a given user.
+ *
+ * @param $account
+ *   The user account whose shortcuts will be administered.
+ * @return
+ *   TRUE if the current user has access to administer shortcuts for the
+ *   provided account, FALSE otherwise.
+ */
+function shortcut_user_access($account) {
+  global $user;
+  return shortcut_set_switch_access($account) || ($account->uid == $user->uid && shortcut_set_edit_access());
+}
+
+/**
  * Access callback for editing a shortcut set.
  *
  * @param $shortcut_set
@@ -172,7 +213,7 @@ function shortcut_set_edit_access($short
     return TRUE;
   }
   if (user_access('customize shortcut links')) {
-    return !isset($shortcut_set) || $shortcut_set == shortcut_current_displayed_set();
+    return !isset($shortcut_set) || $shortcut_set->set_name == shortcut_current_displayed_set()->set_name;
   }
   return FALSE;
 }
