How add a menu item with a menu key using an init.m

  • Follow


I want to add an item to the Insert menu that executes a particular 
kernel command and is activated by a particular shortcut key. And I want 
to do this _without_ modifying and of the .tr files in
$InstallationDirectory/SystemFiles/FrontEnd/TextResources but only by 
modifying files in the $UserBaseDirectory tree. (So that such changes 
will be preserved across version updates.)

I know that in principle one can do this by creating (or editing an 
existing) file:

   Autoload`PacletManagerConfiguration``FrontEnd``init.m

Here's what I put there:

   FrontEnd`AddMenuCommands["Input from Above",
      {Delimiter,Item["Options &Explorer",
       KernelExecute[ToExpression["OptionsExplorer[]"]],
       MenuKey["o",Modifiers->{Control,Command}],
       MenuEvaluator->Automatic]}];

But nothing happens after a restart of Mathematica with clean cache.

What's wrong? Did I err in indicating the Insert menu's entry "Item from 
Above" referenced there? Or something else.

Note that the corresponding modification, instead, to MenuSetup.tr would be:

   Item["Options &Explorer",
      KernelExecute[ToExpression["OptionsExplorer[]"]],
      MenuKey["o", Modifiers->{Control,Command}],
      MenuEvaluator->Automatic]

(This is specifically to invoke Yuri Kandrashkin's OptionsExplorer 
package. But of course my question has more general applicability.)

-- 
Murray Eisenberg                     murray@math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305

0
Reply murray (1874) 2/21/2012 11:17:18 AM

Murray Eisenberg wrote:
>
> Here's what I put there:
>
>    FrontEnd`AddMenuCommands["Input from Above",
>       {Delimiter,Item["Options &Explorer",
>        KernelExecute[ToExpression["OptionsExplorer[]"]],
>        MenuKey["o",Modifiers->{Control,Command}],
>        MenuEvaluator->Automatic]}];
>
> But nothing happens after a restart of Mathematica with clean cache.
> What's wrong? Did I err in indicating the Insert menu's entry "Item from
> Above" referenced there? Or something else.

There are two problems: the front end token for the Insert
menu position would be "DuplicatePreviousOutput", and, more
problematically, AddMenuCommands can only add simple
front end tokens like "OptionsDialog" (as demonstrated by
Andy Ross).

FrontEndExecute[AddMenuCommands["DuplicatePreviousOutput",
   {Delimiter, MenuItem["Options &Explorer", "OptionsDialog",
     MenuKey["O", Modifiers -> {"Control", "Shift"}]]}]];



On Feb 21, 11:17 am, Murray Eisenberg <mur...@math.umass.edu> wrote:
> I want to add an item to the Insert menu that executes a particular
> kernel command and is activated by a particular shortcut key. And I want
> to do this _without_ modifying and of the .tr files in
> $InstallationDirectory/SystemFiles/FrontEnd/TextResources but only by
> modifying files in the $UserBaseDirectory tree. (So that such changes
> will be preserved across version updates.)
>
> I know that in principle one can do this by creating (or editing an
> existing) file:
>
>    Autoload`PacletManagerConfiguration``FrontEnd``init.m
>
> Here's what I put there:
>
>    FrontEnd`AddMenuCommands["Input from Above",
>       {Delimiter,Item["Options &Explorer",
>        KernelExecute[ToExpression["OptionsExplorer[]"]],
>        MenuKey["o",Modifiers->{Control,Command}],
>        MenuEvaluator->Automatic]}];
>
> But nothing happens after a restart of Mathematica with clean cache.
>
> What's wrong? Did I err in indicating the Insert menu's entry "Item from
> Above" referenced there? Or something else.
>
> Note that the corresponding modification, instead, to MenuSetup.tr would be:
>
>    Item["Options &Explorer",
>       KernelExecute[ToExpression["OptionsExplorer[]"]],
>       MenuKey["o", Modifiers->{Control,Command}],
>       MenuEvaluator->Automatic]
>
> (This is specifically to invoke Yuri Kandrashkin's OptionsExplorer
> package. But of course my question has more general applicability.)
>
> --
> Murray Eisenberg                     mur...@math.umass.edu
> Mathematics & Statistics Dept.
> Lederle Graduate Research Tower      phone413 549-1020begin_of_the_skype_highlighting            413 549-1020   (H)
> University of Massachusetts                413 545-2859begin_of_the_skype_highlighting            413 545-2859      (W)
> 710 North Pleasant Street            fax   413 545-1801
> Amherst, MA 01003-9305

0
Reply degnen (96) 2/25/2012 7:02:25 AM


1 Replies
56 Views

(page loaded in 0.081 seconds)

Similiar Articles:













7/17/2012 8:58:48 AM


Reply: