Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #8816 > unrolled thread

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

Started byJohn Fultz <jfultz@wolfram.com>
First post2012-03-01 10:39 +0000
Last post2012-03-04 09:33 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: How add a menu item with a menu key using an init.m John Fultz <jfultz@wolfram.com> - 2012-03-01 10:39 +0000
    Re: How add a menu item with a menu key using an init.m Chris Degnen <degnen@cwgsy.net> - 2012-03-04 09:33 +0000

#8816 — Re: How add a menu item with a menu key using an init.m

FromJohn Fultz <jfultz@wolfram.com>
Date2012-03-01 10:39 +0000
SubjectRe: How add a menu item with a menu key using an init.m
Message-ID<jinjlj$d33$1@smc.vnet.net>
On Sat, 25 Feb 2012 01:58:51 -0500 (EST), Chris Degnen wrote:
> 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"}]]}]];

No, you have this backwards.  AddMenuCommands can only *position* a menu 
relative to one with a simple front end token.  The command that you're adding 
can be any menu command.

Sincerely,

John Fultz
jfultz@wolfram.com
User Interface Group
Wolfram Research, Inc.

>
>
> 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


[toc] | [next] | [standalone]


#8860

FromChris Degnen <degnen@cwgsy.net>
Date2012-03-04 09:33 +0000
Message-ID<jivcsh$n34$1@smc.vnet.net>
In reply to#8816
On Thursday, March 1, 2012 10:39:47 AM UTC, John Fultz wrote:
> On Sat, 25 Feb 2012 01:58:51 -0500 (EST), Chris Degnen wrote:
> > 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"}]]}]];
> 
> No, you have this backwards.  AddMenuCommands can only *position* a menu 
> relative to one with a simple front end token.  The command that you're adding 
> can be any menu command.

Thanks for the clarification, but in that case should KernelExecute
menu items also work?

I have made three examples to illustrate the question.

(For readers, these menu modifications only persist for the current
front end session.)

The first one adds a MathGroup link to the Help menu, and works
fine, (at least with Chrome).

FrontEndExecute[
 AddMenuCommands[
  "SelectionHelpDialog", {Delimiter, 
   MenuItem["&MathGroup Archive", 
    FrontEndExecute[{FrontEnd`NotebookLocate[{URL[
         "http://forums.wolfram.com/mathgroup"], None}]}], 
    MenuKey["M", Modifiers -> {"Control", "Shift"}]]}]]


The second example adds a custom function at the same location on
the Help menu.  The MenuItem works if it is included in MenuSetup.tr
but when added through AddMenuCommands it produces the message
"Could not process unknown packet "CreateDialog"."
 
FrontEndExecute[
 AddMenuCommands[
  "SelectionHelpDialog", {Delimiter, 
   MenuItem["Custom Function version 1",
    KernelExecute[
     CreateDialog[{TextCell["Click OK to close"],
       DefaultButton[]}]],
    MenuEvaluator -> Automatic]}]]


The third example is a roundabout way to achieve what the second
example attempts.  It works for the function demonstrated, but it
would not work for OptionsExplorer[] which need to access the
current front end selection.  (OptionsExplorer seems to have some
obsolescence problems, by the way, before anyone spends time.)


FrontEndExecute[
 AddMenuCommands[
  "SelectionHelpDialog", {Delimiter, 
   MenuItem["Custom Function version 2",
    FrontEndExecute[
     {FrontEnd`NotebookWrite[FrontEnd`NotebookCreate[], 
       RowBox[{RowBox[{"CreateDialog", "[", RowBox[{"{",
             RowBox[
              {RowBox[
                {"TextCell",
                 "[", "\"\<Click OK to close\>\"", "]"}], ",",
               RowBox[{"DefaultButton", "[", "]"}]}],
             "}"}], "]"}], ";",
         RowBox[{"NotebookClose", "[", "]"}]}]],
      FrontEndToken["EvaluateCells"]}], 
    MenuKey["F", Modifiers -> {"Control", "Shift"}]]}]]

Is there some way to run KernelExecute with AddMenuCommands?

Thanks, Chris

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web