How To Add Your Own Top-Level Menu To Leo's Menu Bar

82 views
Skip to first unread message

tbp1...@gmail.com

unread,
Sep 24, 2021, 11:52:06 PM9/24/21
to leo-editor
I had some commands that I use often, and I didn't want to add buttons for them because some of the outlines I work with have too many buttons already.  It turns out that it's easy to add your own menus.  Maybe this is already documented somewhere, but anyway here is the way.

1. Copy the entire @menus tree from LeoSettings.leo to myLeoSettings.leo.
2. After the last @menu node, add a new @menu node with the name you want.  I call mine Local.
3. Add a new @item node under your @menu node with a command you want to invoke. You  can insert a "&" if you want to designate an accelerator key.  Use the other @menu and @item nodes as a guide.
4. Restart Leo.  Your new menu will appear after the standard menus in the menu bar.

You don't really have to put it at the end;  the new menu can go anywhere in the tree you like.  I just think it's better to keep the order of the main menus as close as possible to Leo's standard arrangement.

The commands referred to in 3) are minibuffer commands.  Example: z-open-freewin.

Edward K. Ream

unread,
Sep 25, 2021, 5:10:13 PM9/25/21
to leo-editor
On Fri, Sep 24, 2021 at 10:52 PM tbp1...@gmail.com <tbp1...@gmail.com> wrote:
I had some commands that I use often, and I didn't want to add buttons for them because some of the outlines I work with have too many buttons already.  It turns out that it's easy to add your own menus.  Maybe this is already documented somewhere, but anyway here is the way.

Thanks for this how-to.

Edward

SegundoBob

unread,
Sep 25, 2021, 5:27:41 PM9/25/21
to leo-editor
I add menus to the Leo-Editor menu bar without copying the entire @menus tree from LeoSettings.leo.  This is possible because directive @menuat exists.  See @menuat

tbp1...@gmail.com

unread,
Sep 25, 2021, 5:34:52 PM9/25/21
to leo-editor
Ahh, I have only used it to add a new item to an existing menu.  I didn't realize it could also add a new menu to the top level menu bar.  I will have to play with that.

tbp1...@gmail.com

unread,
Sep 25, 2021, 5:55:46 PM9/25/21
to leo-editor
I was able to add a new "Local" menu after Help by using the path /help,   I do get a message on the console createMenusFromConfigList no menu Local - do you know why?  The menu items are displayed and do dispatch their commands.

tbp1...@gmail.com

unread,
Sep 25, 2021, 6:03:50 PM9/25/21
to leo-editor
I see that I only get that message when myLeoSettings gets opened.  I can live with that.

Segundo Bob

unread,
Sep 25, 2021, 6:07:11 PM9/25/21
to leo-e...@googlegroups.com
On 9/25/21 2:55 PM, tbp1...@gmail.com wrote:
> I was able to add a new "Local" menu after Help by using the path
> //help/,   I do get a message on the console createMenusFromConfigList
> no menu Local - do you know why?

Not off the top of my head. Here is the node structure I use without
errors:

@settings
@menuat help before
@menu &Bob
@menu &Zxtra Editing

--
Segundo Bob
Segun...@gmail.com

tbp1...@gmail.com

unread,
Sep 25, 2021, 6:15:38 PM9/25/21
to leo-editor
Pretty much the same as what I came up with:

@settings
   @menuat /help after
      @menu &Local
         @item z-open-freewin
         ... etc

jkn

unread,
Sep 26, 2021, 2:37:14 PM9/26/21
to leo-editor
This might be a good place to re-mention my occasional IWBNI (It Would Be Nice If)...

It Would Be Nice If ... there was a way to change some of the normal Window accelerators so as to be able to use ALT-keys for alternative Leo commands.

My first use case it to have ALT-W perform File-Write (aka File Save, currently CTRL-S). This is for compatibility with my preferred CRiSP/Brief key bindings.

I did a bit of experimenting with this ages ago at the PyQt level; but at the moment I seem to be stuck with renaming the 'Window' top level menu to something else, freeing up the 'W'. Personally it would help me if there was a way to select not having top level menu accelerators at all.

(I appreciate that this is as much a PyQt issue as a Leo one)

J^n

tbp1...@gmail.com

unread,
Sep 26, 2021, 5:19:35 PM9/26/21
to leo-editor
I think you could take away the ampersand from the menu item; then it would be available for something else.  That's to be found in the menu settings in LeoSettings.leo.

jkn

unread,
Sep 26, 2021, 5:27:54 PM9/26/21
to leo-editor
On Sunday, September 26, 2021 at 10:19:35 PM UTC+1 tbp1...@gmail.com wrote:
I think you could take away the ampersand from the menu item; then it would be available for something else.  That's to be found in the menu settings in LeoSettings.leo.

IIRC that didn't work (I am used to that kind of thing from Windows/MFC decades ago).

I did look at some PyQt subclassing but didn't get very far with it, and (also IIRC; it was a couple of years ago at least) there is more stuff that you might think baked into Qt, or at least was at that time.

I would love to be proved wrong...

    J^n

tbp1...@gmail.com

unread,
Sep 26, 2021, 11:13:33 PM9/26/21
to leo-editor
I'm not sure if you would like to remap some keys Windows-wide, or just for Leo.  If it's Windows-wide, I use a key remapper called SharpKeys.  I use it to swap caps lock and left control keys.  It's fairly easy to use, and looks like it would remap any keys you like.  It remaps the keys before any applications get them, so even virtual machines get the remapped keys.

For Leo, with your particular example, I was able to make ALT-W perform the file-save command by adding an @shortcut node to the @settings tree in myLeoSettings.leo.  I also had to remove the ampersand from the "W" in the Windows menu, which I did in LeoSettings.leo.  It worked for trying it out, but to do it permanently, it would be better to copy the entire @menus  tree to myLeoSettings.leo and make the change there.

I didn't remap CNTRL-s, so presumably it still also worked as file-save.  I'm not sure how you un-assign those key assignment, or whether a shortcut in myLeoSettings.leo overrides them.

In the @shortcuts node, here is the key assignment I added to the body of the node:

file-save = ALT+w

jkn

unread,
Sep 27, 2021, 3:45:45 AM9/27/21
to leo-editor
Hi Thomas
    Thanks for your experiments. It is just for Leo that I want this (I'm on Linux actually FWIW).

I am next to certain that I tried all of that before, but it was a while ago and I will experiment again.

I definitely removed the accelerator ampersand without joy. I wonder if there is a difference between Windows and Linux in this area.

At the moment (don't laugh) I have a top level menu entry called 'Iwndow' instead of "Window', as a workaround...

I'll do a few experiments in a perhaps more-recent Leo and report back.

Oh, I think you can add a key-binding entry like "Ctrl-S = None # could be 'Nothing'" to turn off defaults.

Thanks, Jon N

jkn

unread,
Sep 27, 2021, 9:10:41 AM9/27/21
to leo-editor
Well, this is interesting ... something must have changed since I last looked at this.

I actually already have the menu entries in myLeoSettings.le, with the 'Iwndow' that I was currently using. This must have reflected my previous attempts.

I didn't have any ampersands/accelerators at all on that item, but now if I make it eg:

     w&Indow

and keep my 'file-save' binding, things seem to work as I originally expected.

Something has definitely changed, that would have been the very first thing I tried. It is just possible that there was some windows/linux behaviour difference, but I use Leo almost exclusively under Linux at the moment.

Anyway, that tweak has improved things for me. Thanks!

    Jon N

tbp1...@gmail.com

unread,
Sep 27, 2021, 10:36:40 AM9/27/21
to leo-editor
When I tried adding an @menu setting in myLeoSettings to replace one in LeoSettings.leo, it messed up the menus.  It seemed like all the toplevel menus have to be specified in one or the other set of settings, but not split between them.  (That puzzles me a bit, but whatever). Adding new menus and items can be  done in  myLeoSettings or even in an outline-specific setting.

jkn

unread,
Sep 27, 2021, 10:47:44 AM9/27/21
to leo-editor
On Monday, September 27, 2021 at 3:36:40 PM UTC+1 tbp1...@gmail.com wrote:
When I tried adding an @menu setting in myLeoSettings to replace one in LeoSettings.leo, it messed up the menus.  It seemed like all the toplevel menus have to be specified in one or the other set of settings, but not split between them.  (That puzzles me a bit, but whatever). Adding new menus and items can be  done in  myLeoSettings or even in an outline-specific setting.

I had all the menus in myLeoSettings.leo, not just one, from my previous experiments, FWIW.

Reply all
Reply to author
Forward
0 new messages