Skip to content

Menus defined in boards.txt have no defined ordering #7955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sleemanj opened this issue Aug 31, 2018 · 4 comments
Closed

Menus defined in boards.txt have no defined ordering #7955

sleemanj opened this issue Aug 31, 2018 · 4 comments
Milestone

Comments

@sleemanj
Copy link

sleemanj commented Aug 31, 2018

If one defines menus in a boards.txt there is no defined or even reliable or repeatable ordering for how those menus are sorted in the Tools menu

Example, if one defines menus thusly

menu.version    = Processor Version
menu.clock      = Processor Speed
menu.boot       = Use Bootloader
menu.core       = Millis, Tone Support
menu.millis_ppm  = Millis Accuracy
menu.print      = Print Support
menu.serial     = Serial Support
menu.lto        = Link Time Optimisation (1.6.11+ only)
menu.bodlevel   = Brown-out Detection Level
menu.advclk     = Override Clock Source
menu.advfrq     = Override Frequency
menu.advups     = Override Upload Speed

then one might reasonably expect them to be shown in this order (where a variant has that menu), however the actual results appear largely at-random with no discernible pattern I can see, not alpha, not first appearance in the file... I think it's just pretty much random.

a2

@facchinm
Copy link
Member

Hi @sleemanj,
this is due to HashSet not being intrinsically ordered in Java.
I've created a very simple PR to test this #7956 ; let me know if it fixes the issue so we can merge it safely, thanks!

@facchinm facchinm added this to the Release 1.8.7 milestone Aug 31, 2018
@sleemanj
Copy link
Author

Compiled and tested Linux x64 Java 8.

The ordering is now alpha by menu title and seems to work without issue.

That's certainly an improvement over random - core authors can easily fudge menu titles with a prefixed index number "01. Blah Menu", "02. Foo Menu", or they can also be a bit kludgy and use a sequences of zero width space characters before each menu whichseems to work (1 zero-width space = 1st item, 2 zero-width spaces = 2nd item...) also, just a bit hard to see what you're doing when coding it :-)

Ideally of course instead of alpha it would just preserve the order the menus were defined in boards.txt, but that might be more complicated.

cmaglie added a commit to facchinm/Arduino that referenced this issue Sep 3, 2018
@cmaglie
Copy link
Member

cmaglie commented Sep 4, 2018

@sleemanj could you try this build #7956 (comment)? I've used a LinkedHashSet instead of a TreeSet and it seems to work as intended. Java magics :-)

@sleemanj
Copy link
Author

sleemanj commented Sep 4, 2018

Compiled and tested Linux x64 Java 8.

Perfect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants