Development :  K-Meleon Web Browser Forum
K-Meleon development related discussions. 
setmenu deletions (dynamically updating them) doubts
Posted by: JohnHell
Date: April 10, 2015 06:34PM

Ok, setmenu hints please. It is still a mystery for me.

I'm thinking of a macro/script/extension that needs to update a menu set by macros.

To me, the description in the wiki doesn't tell all the story. I need examples and not just a description because isn't fully clear, at least for me.

I discovered after several trial errors that an entry, an item, can be deleted if we use the format:

setmenu(menu holder, macro or command type, name of menu entry);

Example: setmenu("Test", macro, "macro entry in test");

I blame the sentence that says that the LABEL, empty, deletes an entry, when actually is the COMMAND being empty.

Ok, great!!! I can remove entries and I can choose exactly which one!!

Now, what happens to inline and popup entries?

For popups, looks like only can be removed the popup from where a macro is called to remove it. Again, we need examples.

We have a Holder menu for a Test popup menu that holds an entry that calls a macro to remove the Test menu. So, this deletes it:

setmenu(Holder, popup);

That will delete Test popup menu BUT, you can't choose which popup!!!! what if I want to delete another. For example, lets say that Holder have another popup called Test1.

In fact, what I actually found is that it doesn't delete the popup menu from when the deletetion is called, but the first pupup menu of Holder!!!.

Looks like now, what works to delete an entry is to leave empty LABEL, but you are not telling what popup to remove. But, I haven't tested, does it work for inline too?

Also I found that the deletions don't remove the children, so, remove, in the example above, the Test popup menu, doesn't delete the entries for that menu, so, if you create Test again, it will have the same entries, and if you create entries with the same name of existing won't be replaced but added.

So looks like deletion involves deletion one by one and without choosing what exactly to remove except for macro and command entries.

What am I right and what am I wrong?

I think the new Docs project should cover a more explanatory setmenu command, as maybe is one of the most automated commands used. At least is not all clear than I thought.

Options: ReplyQuote
Re: setmenu deletions (dynamically updating them) doubts
Posted by: siria
Date: April 10, 2015 07:33PM

Whoa... no wonder you think it were horribly complicated :cool:

That said, about deleting POPUP menus I have no idea, may need some trick or perhaps not possible at all?

INLINE submenus vanish if they contain no entries anymore, as you noticed too.

I do like that menus don't need to be attached anywhere to still exist, that makes creation a lot easier, no preconditions for the first entry. No need to "create" a menu first, just act as if it were already there, insert your action line, and it IS there smiling smiley

Normal menu lines are easy to delete, just set the label empty.
For an example look at the native zoom macro, setmenu line 2+3
And I update the names ocasionally too during a session, just set the same command in the same parent menu again just with another label.

I do agree that I often greatly miss syntax *examples* in the wiki too!
Boy, what was it for an endless struggle until I finally figured out what this mysterious $ARG thing means tongue sticking out smiley While in reality it's ridiculously easy. And without examples am never sure where to put " " or not etc. In the end we all do the same, just look for already existing macro snippets and copy their ways.

But that's exactly why it's a pity most menus are created in much more complicated ways than necessary, e.g. first building inline submenus for one single command or such nonsense. And of course the next one takes this as example again and the circle continues, sigh.

====

Your discovery that menu lines can also be deleted by adding a label without an action is news to me, but why not grinning smiley And that only goes to demonstrate AGAIN just how brilliant setmenu is - you can throw at it what you want and it works!! LOL! grinning smiley



Edited 2 time(s). Last edit at 04/10/2015 07:47PM by siria.

Options: ReplyQuote
Re: setmenu deletions (dynamically updating them) doubts
Posted by: siria
Date: April 10, 2015 09:15PM

Just remembered - my linktoggle macro (in extensions forum here) creates a 4-line inline menu for selection context, each time you "toggle" a link and then highlight anything. And when clicking an item of that menu, or Ctrl+C, or after next page load the 4 lines in that inline menu are deleted again, one by one.
The inline menu itself will remain there all the time, but being empty gets invisible.
Slightly awkward the whole thing, but couldn't find a better way. The deletion-part is called "resetMenu".



Edited 1 time(s). Last edit at 04/10/2015 09:18PM by siria.

Options: ReplyQuote
Re: setmenu deletions (dynamically updating them) doubts
Posted by: JohnHell
Date: April 10, 2015 09:25PM

Quote
siria
Whoa... no wonder you think it were horribly complicated :cool:

LOL it is for me. And as I'm trying to make a quite complex macro/script/extension I have to know how it works, because looking how it works by myself it will be soooo limited, or ultra complex code, or change to a simpler way where things must be edit manually.

Quote
siria
Normal menu lines are easy to delete, just set the label empty.


[...]

Your discovery that menu lines can also be deleted by adding a label without an action is news to me, but why not grinning smiley And that only goes to demonstrate AGAIN just how brilliant setmenu is - you can throw at it what you want and it works!! LOL! grinning smiley

Mmmm there we have the problem again. How do you delete them? For me, it wasn't logic with the label empty because... what entry are you requesting to delete???

I had a look to zoom.kmm and I understand now what you mean:

setmenu(PageDisplay,command,"",ID_FONT_INCREASE);
setmenu(PageDisplay,command,"",ID_FONT_DECREASE);

I guess I tried something like this, but instead 2 double quotes I left as two commas with an empty space in the middle or two consecutive ,, and I had the error of a missing argument which drive me nuts. What is more empty than nothing?

Anyway, if there is no way to delete popups or inline, selecting as we do with entries, I think I'll go for the simpler way, also because it will need a lot of loops to update them, mmmmm, but will remove a lot of magic :/ or maybe not...,


I see what you mean by your resetMenu.

I'll think about it.

Options: ReplyQuote
Re: setmenu deletions (dynamically updating them) doubts
Posted by: siria
Date: April 10, 2015 09:38PM

Just curious, if it's no secret, what are you planning to do?

Options: ReplyQuote
Re: setmenu deletions (dynamically updating them) doubts
Posted by: JohnHell
Date: April 10, 2015 10:16PM

Quote
siria
Just curious, if it's no secret, what are you planning to do?

Surprise, you'll see if I finally make it public winking smiley

Options: ReplyQuote
Re: setmenu deletions (dynamically updating them) doubts
Posted by: JohnHell
Date: April 10, 2015 10:28PM

Better said if I finish it.

While I make things I rethink them and I have another perspective, and I leave it, and then I retake xD

Depending of the approach to accomplish something I stop myself.

Options: ReplyQuote
Re: setmenu deletions (dynamically updating them) doubts
Posted by: rodocop
Date: April 10, 2015 10:39PM

Looks promising! grinning smiley

Options: ReplyQuote
Re: setmenu deletions (dynamically updating them) doubts
Posted by: JamesD
Date: April 11, 2015 12:26AM

There may be something useful in this old (2010) project.

https://dl.dropboxusercontent.com/u/1522294/training.7z

Options: ReplyQuote
Re: setmenu deletions (dynamically updating them) doubts
Posted by: Dorian
Date: April 11, 2015 10:32AM

Does the follownig work to remove a popup menu ?

setmenu("MyMenu", "command", "MyPopupItem",0);

I know this shouldn't be done that way, but the "popup" type lack deletion feature.

Options: ReplyQuote
Re: setmenu deletions (dynamically updating them) doubts
Posted by: JohnHell
Date: April 11, 2015 03:20PM

Quote
Dorian
Does the follownig work to remove a popup menu ?

setmenu("MyMenu", "command", "MyPopupItem",0);

I know this shouldn't be done that way, but the "popup" type lack deletion feature.

Yes, that would work to the delete a targeted popup instead the first one of the popup type available.

I already was thinking in other ways to accomplish my idea, due to the madness of creation and deletion of popups and menu entries, that would be too much work checks and re-checks.

Options: ReplyQuote
Re: setmenu deletions (dynamically updating them) doubts
Posted by: siria
Date: April 11, 2015 07:21PM

Quote
Dorian
setmenu("MyMenu", "command", "MyPopupItem",0);

Hehe, neat trick grinning smiley Even works in KM1.6, and without the 0 at the end.



Edited 1 time(s). Last edit at 04/11/2015 07:33PM by siria.

Options: ReplyQuote


K-Meleon forum is powered by Phorum.