Hosted Forums => foobar2000 => 3rd Party Plugins - (fb2k) => Topic started by: regor on 2021-05-13 12:08:52

Title: Menu-Framework-SMP
Post by: regor on 2021-05-13 12:08:52
Menu-Framework-SMP (https://github.com/regorxxx/Menu-Framework-SMP)
(https://img.shields.io/github/release/regorxxx/Menu-Framework-SMP.svg?include_prereleases) (https://github.com/regorxxx/Menu-Framework-SMP/blob/main/CHANGELOG.md)(https://www.codefactor.io/repository/github/regorxxx/Menu-Framework-SMP/badge/main) (https://www.codefactor.io/repository/github/regorxxx/Menu-Framework-SMP/overview/main)(https://api.codacy.com/project/badge/Grade/3e59f8dccd204721a7801197d6c336ed) (https://www.codacy.com/gh/regorxxx/Menu-Framework-SMP/dashboard?utm_source=github.com&utm_medium=referral&utm_content=regorxxx/Menu-Framework-SMP&utm_campaign=Badge_Grade)(https://img.shields.io/github/license/regorxxx/Menu-Framework-SMP) (https://github.com/regorxxx/Menu-Framework-SMP/blob/main/LICENSE)
A helper script for Spider Monkey Panel (https://theqwertiest.github.io/foo_spider_monkey_panel) and foobar2000 which allows to easily create customizable menus on demand which can be easily refactored, moved or edited without working with static ids. A lifesaver.

The problem with current SMP menus
Menus are usually coded at multiple places which must be linked by ID, storing and sharing the different variables for menus and submenus when you have multiple objects using them, etc. It leads to 2 clear problems: non readability and maintenance nightmare.


Using this framework it would translate into this:



First create the menu object. That's the main one and also includes a 'main menu' to append items to it:
Code: [Select]
const menu = new _menu();
menu.newEntry({menu, entryText: 'hello', func: () => {console.log('hello')}}); // Shorthand notation
menu.newEntry({entryText: 'hello2', func: () => {console.log('hello2')}}); // Or omit the menu, to append directly to main one
menu.newEntry({entryText: 'sep'}); // You can also add a separator
Then, you may want to create sub-menus linked to it. To do that, just create a new menu entry within the object:
Code: [Select]
const subMenu = menu.newMenu('This is a submenu'); // It will be added just after the last declared entry!
menu.newEntry({menuName: subMenu, entryText: 'This is my func', func: yourFunc);
Sub-menus can also be dynamically created:
Code: [Select]
var bSubMenu = true;
const funct = () => {return (bSubMenu) ? 'SubMenu 1' : 'SubMenu 2';};
menu.newEntry({menuName: funct, entryText: 'Change SubMenu', func: () => {bSubMenu = !bSubMenu}});
enuName: funct, entryText:'Hola 3', func: () => {console.log('Hola3')}, flags: () => {return (bSubMenu) ? MF_STRING : MF_GRAYED}});
Finally, lets call it with a callback:
Code: [Select]
function on_mouse_rbtn_up(x, y) {return menu.btn_up(x, y);}


There are more usage examples and full documentation on the header of 'menu_xxx.js'.

Other implementations
 1. Playlist-Tools-SMP (https://github.com/regorxxx/Playlist-Tools-SMP): Different tools for foobar2000. The dynamic configurable menu is built using this.
 2. Playlist-Manager-SMP (https://github.com/regorxxx/Playlist-Manager-SMP): A playlist manager for foobar2000. The static menus use this.
 3. World-Map-SMP (https://github.com/regorxxx/World-Map-SMP): A foobar2000 UI to display current artist's country. The static menus use this.


Copy all files from the zip into YOUR_FOOBAR_PROFILE_PATH\scripts\SMP\xxx-scripts
Any other path WILL NOT work without editing the scripts. (see images_Installation_*jpg)
Since the framework only requires 2 files, i.e. the main one and the helper... it's pretty easy to adjust the include paths to whatever it's preferred.


Download latest release (or nightly releases) at github:
Title: Menu-Framework-SMP 1.1.0
Post by: regor on 2021-05-19 16:41:32
1.1.0 - 2021-05-19 (https://github.com/regorxxx/Menu-Framework-SMP)

    New examples.
    Allows calling a forced menu entry routine even without using mouse tracking. If it fails, logs to console. btn_up(x, y, [object], forcedEntry).
    Multiple menu concatenation using btn_up(x, y, [object], forcedEntry), where [object] may be another menu object or an array of menus. It should allow sharing the same menu code in multiple scripts easily (or optional menus).


    Moved dependencies to main file.


    helpers_xxx.js dependency.
Title: Re: Menu-Framework-SMP
Post by: regor on 2021-05-26 21:04:40
## [1.2.0] - 2021-05-26 (https://github.com/regorxxx/Menu-Framework-SMP)
### Added
- Macros: This.lastCall stores the last menu entry name clicked on. (Meant to be used with macros or forced entries)
### Changed
- Macros: entryMap now contains entries named according to the menu they reside (menu + '\\' + entryName). That allows to call entries with same name but placed on different submenus at the same time. (Meant to be used with macros or forced entries)
- This.clear() has as default argument bForce = false; i.e. to totally clear all set menus, must be set to true.
- This.newCheckMenu(menuName, entryTextA, entryTextB, idxFun) translates into CheckMenuItem(entryTextA, idxFun) when entryTextB is undefined and into CheckMenuRadioItem(entryTextA, entryTextB, idxFun) when both are defined, thus allowing both checking behaviour in the framework. (previously only the second one was allowed). Any checkMenu added with previous versions works without changes.
### Removed
### Fixed
- Check menus ids not being updated if entries are removed/added on every call. Now entry/menu arrays are cleared on every call (not only the entry list), which should prevent any possible error at other points too.
Title: Re: Menu-Framework-SMP
Post by: regor on 2021-05-28 21:57:06
## [1.2.1] - 2021-05-28 (https://github.com/regorxxx/Menu-Framework-SMP)
### Added
- This.getMenus() returns the entire list of menus attached to the menu instance (useful to swith menus on/off on demand).
- This.lastCall is sent to console on every menu call.
### Changed
- Macros: This.lastCall now omits ('main\' or the main menu name) when the entry resides on the main menu. i.e. just use the entry name for main menu entries, and submenu\entry name for the rest.รง
- Minor code cleanup.
### Removed
### Fixed
Title: Re: Menu-Framework-SMP
Post by: regor on 2021-06-07 19:31:14
v1.2.2 - Minor update (https://github.com/regorxxx/Menu-Framework-SMP)
Better compatibility with right tabbed text at menu entries. See changelog.

## [1.2.2] - 2021-06-07
### Added
### Changed
- 'entryMap' now stores menu names with anything after tabs '\t' stripped. i.e. you can add extra variable info tabbed to the right (like shortcuts) to the menu names without it being reflected on .lastCall. Makes easier to work with macros or shortcuts, since changing that part of the string will still output the same "entry name". menu.btn_up(void(0), void(0), void(0), 'Playlist History\\Previous playlist') and menu.btn_up(void(0), void(0), void(0), 'Playlist History\\Previous playlist\tCtrl + R') would be equivalent.
### Removed
- helpers_xxx.js file.
### Fixed
SimplePortal 1.0.0 RC1 © 2008-2021