To: vim-dev@vim.org Subject: Patch 6.0.251 (extra) Fcc: outbox From: Bram Moolenaar MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.0.251 (extra) Problem: Macintosh: menu shortcuts are not very clear. Solution: Show the shortcut with the Mac clover symbol. (raindog) Files: src/gui_mac.c *** ../vim60.250/src/gui_mac.c Thu Feb 21 19:20:14 2002 --- src/gui_mac.c Thu Feb 21 19:23:43 2002 *************** *** 3756,3761 **** --- 3756,3762 ---- { char_u *name; vimmenu_T *parent = menu->parent; + int menu_inserted; /* Cannot add item, if the menu have not been created */ if (parent->submenu_id == 0) *************** *** 3777,3786 **** idx += gui.MacOSHelpItems; #endif /* Call InsertMenuItem followed by SetMenuItemText * to avoid special character recognition by InsertMenuItem */ ! InsertMenuItem(parent->submenu_handle, "\p ", idx); /* afterItem */ SetMenuItemText(parent->submenu_handle, idx+1, name); #if 0 --- 3778,3856 ---- idx += gui.MacOSHelpItems; #endif + menu_inserted = 0; + if (menu->actext) + { + /* If the accelerator text for the menu item looks like it describes + * a command key (e.g., "" or ""), display it as the + * item's command equivalent. + */ + int key = 0; + int modifiers = 0; + char_u *p_actext; + p_actext = menu->actext; + key = find_special_key(&p_actext, &modifiers, /*keycode=*/0); + if (*p_actext != 0) + key = 0; /* error: trailing text */ + /* find_special_key() returns a keycode with as many of the + * specified modifiers as appropriate already applied (e.g., for + * "" it returns Ctrl-X as the keycode and MOD_MASK_CMD + * as the only modifier). Since we want to display all of the + * modifiers, we need to convert the keycode back to a printable + * character plus modifiers. + * TODO: Write an alternative find_special_key() that doesn't + * apply modifiers. + */ + if (key > 0 && key < 32) + { + /* Convert a control key to an uppercase letter. Note that + * by this point it is no longer possible to distinguish + * between, e.g., Ctrl-S and Ctrl-Shift-S. + */ + modifiers |= MOD_MASK_CTRL; + key += '@'; + } + /* If the keycode is an uppercase letter, set the Shift modifier. + * If it is a lowercase letter, don't set the modifier, but convert + * the letter to uppercase for display in the menu. + */ + else if (key >= 'A' && key <= 'Z') + modifiers |= MOD_MASK_SHIFT; + else if (key >= 'a' && key <= 'z') + key += 'A' - 'a'; + /* Note: keycodes below 0x22 are reserved by Apple. */ + if (key >= 0x22 && vim_isprintc_strict(key)) + { + int valid = 1; + char_u mac_mods = kMenuNoModifiers; + /* Convert Vim modifier codes to Menu Manager equivalents. */ + if (modifiers & MOD_MASK_SHIFT) + mac_mods |= kMenuShiftModifier; + if (modifiers & MOD_MASK_CTRL) + mac_mods |= kMenuControlModifier; + if (!(modifiers & MOD_MASK_CMD)) + mac_mods |= kMenuNoCommandModifier; + if (modifiers & MOD_MASK_ALT || modifiers & MOD_MASK_MULTI_CLICK) + valid = 0; /* TODO: will Alt someday map to Option? */ + if (valid) + { + char_u item_txt[10]; + /* Insert the menu item after idx, with its command key. */ + item_txt[0] = 3; item_txt[1] = ' '; item_txt[2] = '/'; + item_txt[3] = key; + InsertMenuItem(parent->submenu_handle, item_txt, idx); + /* Set the modifier keys. */ + SetMenuItemModifiers(parent->submenu_handle, idx+1, mac_mods); + menu_inserted = 1; + } + } + } /* Call InsertMenuItem followed by SetMenuItemText * to avoid special character recognition by InsertMenuItem */ ! if (!menu_inserted) ! InsertMenuItem(parent->submenu_handle, "\p ", idx); /* afterItem */ ! /* Set the menu item name. */ SetMenuItemText(parent->submenu_handle, idx+1, name); #if 0 *** ../vim60.250/src/version.c Thu Feb 21 19:20:14 2002 --- src/version.c Thu Feb 21 19:24:32 2002 *************** *** 608,609 **** --- 608,611 ---- { /* Add new patch number below this line */ + /**/ + 251, /**/ -- Engineers are always delighted to share wisdom, even in areas in which they have no experience whatsoever. Their logic provides them with inherent insight into any field of expertise. This can be a problem when dealing with the illogical people who believe that knowledge can only be derived through experience. (Scott Adams - The Dilbert principle) /// Bram Moolenaar -- Bram@moolenaar.net -- http://www.moolenaar.net \\\ /// Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim \\\ \\\ Project leader for A-A-P -- http://www.a-a-p.org /// \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///