home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.1 / 7.1.285 < prev    next >
Encoding:
Internet Message Format  |  2008-03-19  |  5.7 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 7.1.285 (extra)
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=ISO-8859-1
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 7.1.285 (extra)
  11. Problem:    Mac: dialog hotkeys don't work.
  12. Solution:   Add hotkey support. (Dan Sandler)
  13. Files:        src/gui_mac.c
  14.  
  15.  
  16. *** ../vim-7.1.284/src/gui_mac.c    Wed Mar 12 21:47:31 2008
  17. --- src/gui_mac.c    Sun Mar 16 15:25:13 2008
  18. ***************
  19. *** 153,158 ****
  20. --- 153,161 ----
  21.   /* Keeping track of which scrollbar is being dragged */
  22.   static ControlHandle dragged_sb = NULL;
  23.   
  24. + /* Vector of char_u --> control index for hotkeys in dialogs */
  25. + static short *gDialogHotKeys;
  26.   static struct
  27.   {
  28.       FMFontFamily family;
  29. ***************
  30. *** 5519,5524 ****
  31. --- 5522,5570 ----
  32.       SetDialogItemText(itemHandle, itemName);
  33.   }
  34.   
  35. + /* ModalDialog() handler for message dialogs that have hotkey accelerators.
  36. +  * Expects a mapping of hotkey char to control index in gDialogHotKeys;
  37. +  * setting gDialogHotKeys to NULL disables any hotkey handling.
  38. +  */
  39. +     static pascal Boolean
  40. + DialogHotkeyFilterProc (
  41. +     DialogRef        theDialog,
  42. +     EventRecord        *event,
  43. +     DialogItemIndex *itemHit)
  44. + {
  45. +     char_u keyHit;
  46. +     if (event->what == keyDown || event->what == autoKey)
  47. +     {
  48. +     keyHit = (event->message & charCodeMask);
  49. +     if (gDialogHotKeys && gDialogHotKeys[keyHit])
  50. +     {
  51. + #ifdef DEBUG_MAC_DIALOG_HOTKEYS
  52. +         printf("user pressed hotkey '%c' --> item %d\n", keyHit, gDialogHotKeys[keyHit]);
  53. + #endif
  54. +         *itemHit = gDialogHotKeys[keyHit];
  55. +         /* When handing off to StdFilterProc, pretend that the user
  56. +          * clicked the control manually. Note that this is also supposed
  57. +          * to cause the button to hilite briefly (to give some user
  58. +          * feedback), but this seems not to actually work (or it's too
  59. +          * fast to be seen).
  60. +          */
  61. +         event->what = kEventControlSimulateHit;
  62. +         return true; /* we took care of it */
  63. +     }
  64. +     /* Defer to the OS's standard behavior for this event.
  65. +      * This ensures that Enter will still activate the default button. */
  66. +     return StdFilterProc(theDialog, event, itemHit);
  67. +     }
  68. +     return false;      /* Let ModalDialog deal with it */
  69. + }
  70.   /* TODO: There have been some crashes with dialogs, check your inbox
  71.    * (Jussi)
  72.    */
  73. ***************
  74. *** 5544,5549 ****
  75. --- 5590,5597 ----
  76.       GrafPtr    oldPort;
  77.       short    itemHit;
  78.       char_u    *buttonChar;
  79. +     short    hotKeys[256];        /* map of hotkey -> control ID */
  80. +     char_u    aHotKey;
  81.       Rect    box;
  82.       short    button;
  83.       short    lastButton;
  84. ***************
  85. *** 5571,5576 ****
  86. --- 5619,5626 ----
  87.   
  88.       WindowRef    theWindow;
  89.   
  90. +     ModalFilterUPP dialogUPP;
  91.       /* Check 'v' flag in 'guioptions': vertical button placement. */
  92.       vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL);
  93.   
  94. ***************
  95. *** 5610,5615 ****
  96. --- 5660,5668 ----
  97.       buttonChar = buttons;
  98.       button = 0;
  99.   
  100. +     /* initialize the hotkey mapping */
  101. +     memset(hotKeys, 0, sizeof(hotKeys));
  102.       for (;*buttonChar != 0;)
  103.       {
  104.       /* Get the name of the button */
  105. ***************
  106. *** 5619,5625 ****
  107. --- 5672,5689 ----
  108.       {
  109.           if (*buttonChar != DLG_HOTKEY_CHAR)
  110.           name[++len] = *buttonChar;
  111. +         else
  112. +         {
  113. +         aHotKey = (char_u)*(buttonChar+1);
  114. +         if (aHotKey >= 'A' && aHotKey <= 'Z')
  115. +             aHotKey = (char_u)((int)aHotKey + (int)'a' - (int)'A');
  116. +         hotKeys[aHotKey] = button;
  117. + #ifdef DEBUG_MAC_DIALOG_HOTKEYS
  118. +         printf("### hotKey for button %d is '%c'\n", button, aHotKey);
  119. + #endif
  120. +         }
  121.       }
  122.       if (*buttonChar != 0)
  123.         buttonChar++;
  124.       name[0] = len;
  125. ***************
  126. *** 5688,5694 ****
  127. --- 5752,5764 ----
  128.       (void) C2PascalString(textfield, &name);
  129.       SetDialogItemText(itemHandle, name);
  130.       inputItm.width = StringWidth(name);
  131. +     /* Hotkeys don't make sense if there's a text field */
  132. +     gDialogHotKeys = NULL;
  133.       }
  134. +     else
  135. +     /* Install hotkey table */
  136. +     gDialogHotKeys = (short *)&hotKeys;
  137.   
  138.       /* Set the <ENTER> and <ESC> button. */
  139.       SetDialogDefaultItem(theDialog, dfltbutton);
  140. ***************
  141. *** 5777,5786 ****
  142.       dialog_busy = TRUE;
  143.   #endif
  144.   
  145.       /* Hang until one of the button is hit */
  146.       do
  147.       {
  148. !     ModalDialog(nil, &itemHit);
  149.       } while ((itemHit < 1) || (itemHit > lastButton));
  150.   
  151.   #ifdef USE_CARBONKEYHANDLER
  152. --- 5847,5859 ----
  153.       dialog_busy = TRUE;
  154.   #endif
  155.   
  156. +     /* Prepare the shortcut-handling filterProc for handing to the dialog */
  157. +     dialogUPP = NewModalFilterUPP(DialogHotkeyFilterProc);
  158.       /* Hang until one of the button is hit */
  159.       do
  160.       {
  161. !     ModalDialog(dialogUPP, &itemHit);
  162.       } while ((itemHit < 1) || (itemHit > lastButton));
  163.   
  164.   #ifdef USE_CARBONKEYHANDLER
  165. ***************
  166. *** 5803,5808 ****
  167. --- 5876,5884 ----
  168.       /* Restore the original graphical port */
  169.       SetPort(oldPort);
  170.   
  171. +     /* Free the modal filterProc */
  172. +     DisposeRoutineDescriptor(dialogUPP);
  173.       /* Get ride of th edialog (free memory) */
  174.       DisposeDialog(theDialog);
  175.   
  176. *** ../vim-7.1.284/src/version.c    Thu Mar 20 13:22:47 2008
  177. --- src/version.c    Thu Mar 20 14:38:06 2008
  178. ***************
  179. *** 668,669 ****
  180. --- 668,671 ----
  181.   {   /* Add new patch number below this line */
  182. + /**/
  183. +     285,
  184.   /**/
  185.  
  186. -- 
  187. hundred-and-one symptoms of being an internet addict:
  188. 163. You go outside for the fresh air (at -30 degrees) but open the
  189.      window first to hear new mail arrive.
  190.  
  191.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  192. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  193. \\\        download, build and distribute -- http://www.A-A-P.org        ///
  194.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  195.