diff -u modules/shortcut/shortcut.module modules/shortcut/shortcut.module --- modules/shortcut/shortcut.module 23 Feb 2010 22:44:14 -0000 +++ modules/shortcut/shortcut.module 24 Feb 2010 20:40:33 -0000 @@ -18,6 +18,8 @@ * Implements hook_help(). */ function shortcut_help($path, $arg) { + global $user; + switch ($path) { case 'admin/help#shortcut': $output = '
' . t('Define which shortcut set you are using on the Shortcuts tab of your account page.', array('@userpage' => url('user'))) . '
'; - return $output; - } + case 'admin/config/user-interface/shortcut': + case 'admin/config/user-interface/shortcut/%': + if (user_access('switch shortcut sets')) { + $output = '' . t('Define which shortcut set you are using on the Shortcuts tab of your account page.', array('@shortcut-link' => url("user/{$user->uid}/shortcuts"))) . '
'; + return $output; + } } } @@ -249,8 +252,9 @@ * Access callback for switching the shortcut set assigned to a user account. * * @param object $account - * The user account whose shortcuts will be switched, or NULL to check - * permissions for switching the logged-in user's own shortcut set. + * (optional) The user account whose shortcuts will be switched. If not set, + * permissions will be checked for switching the logged-in user's own + * shortcut set. * * @return * TRUE if the current user has access to switch the shortcut set of the @@ -460,8 +464,8 @@ * Returns the current displayed shortcut set for the provided user account. * * @param $account - * The user account whose shortcuts will be returned. Defaults to the - * currently logged-in user. + * (optional) The user account whose shortcuts will be returned. Defaults to + * the currently logged-in user. * * @return * An object representing the shortcut set that should be displayed to the @@ -501,8 +505,9 @@ * Returns the default shortcut set for a given user account. * * @param object $account - * The user account whose shortcuts will be switched, or NULL to check - * permissions for the logged-in user. + * (optional) The user account whose default shortcut set will be returned. + * If not provided, the function will return the currently logged-in user's + * default shortcut set. * * @return * An object representing the default shortcut set. @@ -720,0 +726 @@ + reverted: --- modules/shortcut/shortcut.admin.js 23 Feb 2010 22:44:13 -0000 +++ modules/shortcut/shortcut.admin.js 17 Oct 2009 00:51:52 -0000 1.1 @@ -28,8 +28,8 @@ visibleLength++; } slots++; + }); + - }); - // Add a handler for when a row is swapped. tableDrag.row.prototype.onSwap = function (swappedRow) { var disabledIndex = $(table).find('tr').index($(table).find('tr.shortcut-status-disabled')) - slots - 2, @@ -84,4 +84,17 @@ } }; +/** + * Make it so when you enter text into the "New set" textfield, the + * corresponding radio button gets selected. + */ +Drupal.behaviors.newSet = { + attach: function (context, settings) { + var selectDefault = function() { + $($(this).parents('div.form-item').get(1)).find('> label > input').attr('checked', 'checked'); + }; + $('div.form-item-new input').focus(selectDefault).keyup(selectDefault); + } +}; + })(jQuery); diff -u modules/shortcut/shortcut.admin.inc modules/shortcut/shortcut.admin.inc --- modules/shortcut/shortcut.admin.inc 23 Feb 2010 22:44:13 -0000 +++ modules/shortcut/shortcut.admin.inc 24 Feb 2010 20:40:33 -0000 @@ -50,6 +50,12 @@ $options[$name] = check_plain($set->title); } + // Only administrators can add shortcut sets. + $add_access = user_access('administer shortcuts'); + if ($add_access) { + $options['new'] = t('New set'); + } + if (count($options) > 1) { $form['account'] = array( '#type' => 'value', @@ -63,6 +69,22 @@ '#default_value' => $current_set->set_name, ); + $form['new'] = array( + '#type' => 'textfield', + '#description' => t('The new set is created by copying items from your default shortcut set.'), + '#access' => $add_access, + ); + + if ($user->uid != $account->uid) { + $default_set = shortcut_default_set($account); + $form['new']['#description'] = t('The new set is created by copying items from the %default set.', array('%default' => $default_set->title)); + } + + $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', @@ -86,17 +108,41 @@ global $user; $account = $form_state['values']['account']; - // Switch to a different shortcut set. - $set = shortcut_set_load($form_state['values']['set']); - $replacements = array( - '%user' => $account->name, - '%set_name' => $set->title, - ); + if ($form_state['values']['set'] == 'new') { + // Save a new shortcut set with links copied from the user's default set. + $default_set = shortcut_default_set($account); + $set = (object) array( + 'title' => $form_state['values']['new'], + 'links' => menu_links_clone($default_set->links), + ); + shortcut_set_save($set); + $replacements = array( + '%user' => $account->name, + '%set_name' => $set->title, + '@switch-url' => url(current_path()), + ); + 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('You are now using the new %set_name shortcut set. You can edit it from this page or switch back to a different one.', $replacements)); + } + else { + drupal_set_message(t('%user is now using a new shortcut set called %set_name. You can edit it from this page.', $replacements)); + } + $form_state['redirect'] = 'admin/config/user-interface/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($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)); } /** @@ -114,7 +160,7 @@ l(t('edit set name'), "admin/config/user-interface/shortcut/$set->set_name/edit"), ); if (shortcut_set_delete_access($set)) { - $row[] = l('delete set', "admin/config/user-interface/shortcut/$set->set_name/delete"); + $row[] = l(t('delete set'), "admin/config/user-interface/shortcut/$set->set_name/delete"); } else { $row[] = ''; @@ -497,7 +543,8 @@ * @param $form_state * An associative array containing the current state of the form. * @param object $shortcut_set - * An object representing shortcut set, as returned from shortcut_set_load(). + * An object representing the shortcut set, as returned from + * shortcut_set_load(). * * @return * An array representing the form definition. @@ -506,8 +553,6 @@ * @see shortcut_set_edit_form_submit() */ function shortcut_set_edit_form($form, &$form_state, $shortcut_set) { - $default_set = shortcut_default_set(); - $form['shortcut_set'] = array( '#type' => 'value', '#value' => $shortcut_set, @@ -539,17 +584,10 @@ */ function shortcut_set_edit_form_submit($form, &$form_state) { $shortcut_set = $form_state['values']['shortcut_set']; - - if ($form_state['clicked_button']['#value'] == t('Save')) { - $shortcut_set->title = $form_state['values']['title']; - shortcut_set_save($shortcut_set); - drupal_set_message(t('Updated set name to %set-name.', array('%set-name' => $shortcut_set->title))); - $form_state['redirect'] = "admin/config/user-interface/shortcut/$shortcut_set->set_name"; - } - elseif ($form_state['clicked_button']['#value'] == t('Delete')) { - // Redirect to the delete confirmation form. - $form_state['redirect'] = "admin/config/user-interface/shortcut/$shortcut_set->set_name/delete"; - } + $shortcut_set->title = $form_state['values']['title']; + shortcut_set_save($shortcut_set); + drupal_set_message(t('Updated set name to %set-name.', array('%set-name' => $shortcut_set->title))); + $form_state['redirect'] = "admin/config/user-interface/shortcut/$shortcut_set->set_name"; } /** @@ -559,8 +597,9 @@ * 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. + * @param object $shortcut_set + * An object representing the shortcut set, as returned from + * shortcut_set_load(). * * @return * An array representing the form definition. only in patch2: unchanged: --- modules/shortcut/shortcut.admin.css 17 Oct 2009 00:51:52 -0000 1.1 +++ modules/shortcut/shortcut.admin.css 24 Feb 2010 20:40:32 -0000 @@ -1,10 +1,5 @@ /* $Id: shortcut.admin.css,v 1.1 2009/10/17 00:51:52 dries Exp $ */ -h4.shortcuts-set, -div.shortcuts-change-set { - display: inline; -} - .shortcut-slot-hidden { display: none; }