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	14 Jan 2010 02:35:29 -0000
@@ -19,82 +19,128 @@ 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();
+  $query['token'] = drupal_get_token('shortcuts-switch-link');
+  $query['destination'] = $_GET['q'];
+  
+  foreach ($shortcut_sets as $set) {
+    //is the the user's current set?
+    $is_current_set = $set->set_name == shortcut_current_displayed_set($user)->set_name;
+    //skip this set if the user can't switch to it or edit it
+    if ($user && !shortcut_set_switch_access($user) && !$is_current_set) {
+      continue;
+    }
+    $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 ($is_current_set) {
+        $cols[2] = t('active');
+      } else {
+          $cols[2] =l(t('set active'), "shortcuts/switch/{$user->uid}/{$set->set_name}", array('query' => $query));
+      }
+    }
+    //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,
-  );
-
-  $form['#attached'] = array(
-    'css' => array(drupal_get_path('module', 'shortcut') . '/shortcut.admin.css'),
-    'js' => array(drupal_get_path('module', 'shortcut') . '/shortcut.admin.js'),
+    '#title' => t('Set name'),
+    '#description' => t('The new set is created by copying items from the default set.'),
   );
 
-  $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 +148,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 +175,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 +470,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	14 Jan 2010 02:35:29 -0000
@@ -18,22 +18,35 @@ define('SHORTCUT_DEFAULT_SET_NAME', 'sho
  * Implements hook_help().
  */
 function shortcut_help($path, $arg) {
+
+  $choose_message = '<p>' . t('You can choose which shortcut set to use from the Shortcuts tab of your <a href="@user">user account page</a>', array('@user' => url('user'))) . '</p>';
+
   switch ($path) {
     case 'admin/help#shortcut':
       $output = '<h3>' . t('About') . '</h3>';
-      $output .= '<p>' . t('The Shortcut module allows users to create sets of <em>shortcut</em> links to commonly-visited pages of the site. Shortcuts are contained within <em>sets</em>, and each user with <em>Select own shortcut set</em> permission can select a preferred set of shortcuts. For more information, see the online handbook entry for <a href="@shortcut">Shortcut module</a>.', array('@shortcut' => 'http://drupal.org/handbook/modules/shortcut/')) . '</p>';
+      $output .= '<p>' . t('The Shortcut module allows users to create sets of <em>shortcut</em> links to commonly-visited pages of the site. Shortcuts are contained within <em>sets</em>, and each user with the <em>Select own shortcut set</em> permission can select a preferred set of shortcuts. For more information, see the online handbook entry for <a href="@shortcut">Shortcut module</a>.', array('@shortcut' => 'http://drupal.org/handbook/modules/shortcut/')) . '</p>';
       $output .= '<h3>' . t('Uses') . '</h3>';
       $output .= '<dl><dt>' . t('Creating and modifying shortcuts and sets') . '</dt>';
-      $output .= '<dd>' . t('Users with the appropriate permissions can manage shortcut sets, choose a preferred shortcut set, and edit the shortcuts within sets from the <a href="@shortcuts">Shortcuts administration page</a>.', array('@shortcuts' => url('admin/config/system/shortcut'))) . '</dd>';
+      $output .= '<dd>' . t('Users with the appropriate permissions can manage shortcut sets and edit the shortcuts within sets from the <a href="@shortcuts">Shortcuts administration page</a>.', array('@shortcuts' => url('admin/config/system/shortcut'))) . '</dd>';
       $output .= '<dt>' . t('Adding and removing shortcuts') . '</dt>';
-      $output .= '<dd>' . t('The Shortcut module creates an add/remove link for each page on your site; the link lets you add or remove the current page from the currently-enabled set of shortcuts (if your theme displays it). The core Seven administration theme displays this link next to the page title, as a small + or - sign. If you click on the + sign, you will add that page to your preferred set of shortcuts. If the page is already part of your shortcut set, the link will be a - sign, and will allow you to remove the current page from your shortcut set.') . '</dd>';
+      $output .= '<dd>' . t('The Shortcut module creates an add/remove link for each page on your site. If your theme displays the link, it lets you add or remove the current page from your shortcut set. The core Seven administration theme displays this link next to the page title, as a small + or - sign. If you click on the + sign, you will add that page to your shortcut set. If the page is already part of your shortcut set, the link will be a - sign, and will allow you to remove the current page from your shortcut set.') . '</dd>';
       $output .= '<dt>' . t('Displaying shortcuts') . '</dt>';
       $output .= '<dd>' . t('You can display your shortcuts by enabling the Shortcuts block on the <a href="@blocks">Blocks administration page</a>. Certain administrative modules also display your shortcuts; for example, the core <a href="@toolbar-help">Toolbar module</a> displays them near the top of the page, along with an <em>Edit shortcuts</em> link.', array('@blocks' => url('admin/structure/block'), '@toolbar-help' => url('admin/help/toolbar'))) . '</dd>';
+      $output .= '<dt>' . t('Choosing a shortcut set') . '</dt>';
+      $output .= '<dd>' . t('Users with the <em>Select own shortcut set</em> permission can choose which shortcut set to use from the Shortcuts tab of their <a href="@user">user account page</a>', array('@user' => url('user'))) . '</dd>';
       $output .= '</dl>';
+
       return $output;
+
+    case 'admin/config/system/shortcut/%':
+      return $choose_message;
+
+    case 'admin/config/system/shortcut':
+      return $choose_message;
   }
 }
 
+
 /**
  * Implements hook_permission().
  */
@@ -58,9 +71,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 +110,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 +138,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 +162,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 +196,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 +226,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;
 }
