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 menusMenus 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.
(https://user-images.githubusercontent.com/83307074/117212019-49ad2000-ade9-11eb-8bc4-5fad9b359ea8.png)
(https://user-images.githubusercontent.com/83307074/117212022-4b76e380-ade9-11eb-886f-e379d0d6ac32.png)
Using this framework it would translate into this:
(https://user-images.githubusercontent.com/83307074/117212042-53368800-ade9-11eb-8d98-a238408b73d4.png)
Features- Creates menus on demand on panels without needing to create specific methods for every script, calculate IDs, etc.
- Menus are pushed to a list and created automatically on demand, linking the entries to their idx without needing a 'switch' block or leaving holes to ensure idx get enough numbers to expand the script.
- The main utility of this helper is greatly reducing coding for simple menus and having both, the menu logic creation and the menus' functions on the same place. Creation order is done following entry/menus addition.
- Can concatenate multiple menus on btn_up().
UsageFirst create the menu object. That's the main one and also includes a 'main menu' to append items to it:
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:
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:
var bSubMenu = true;
const funct = () => {return (bSubMenu) ? 'SubMenu 1' : 'SubMenu 2';};
menu.newMenu(funct);
menu.newEntry({menuName: funct, entryText: 'Change SubMenu', func: () => {bSubMenu = !bSubMenu}});
menu.newEntry({m
enuName: funct, entryText:'Hola 3', func: () => {console.log('Hola3')}, flags: () => {return (bSubMenu) ? MF_STRING : MF_GRAYED}});
Finally, lets call it with a callback:
function on_mouse_rbtn_up(x, y) {return menu.btn_up(x, y);}
(https://user-images.githubusercontent.com/83307074/117211823-081c7500-ade9-11eb-9178-f063539809a4.gif)
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.
(https://user-images.githubusercontent.com/83307074/116756215-44239480-a9fb-11eb-8489-b56a178c70f4.gif)
InstallationCopy 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.
(https://user-images.githubusercontent.com/83307074/117211962-3437f600-ade9-11eb-93d6-e5508767cf3b.png)
Download latest release (or nightly releases) at github: https://github.com/regorxxx/Menu-Framework-SMP
Just pushed a new update. Clone the repository to get the latest changes (Code/Download zip) instead of using the releases page.
### Added
- Menu framework: added bool variable (bExecute) to .btn_up(x, y, object, forcedEntry = '', bExecute = true, replaceFunc = null, flag = 0, bindArgs = null) which allows to simulate the menu without executing any related entry function.
- Menu framework: added func variable (replaceFunc) to .btn_up(x, y, object, forcedEntry = '', bExecute = true, replaceFunc = null, flag = 0, bindArgs = null) which allows to replace the related entry function with a custom one, whenever bExecute is also false. Can be used to paste to clipboard entry names easily simulating the menu usage.
- Menu framework: added flag variable (flag) to .btn_up(x, y, object, forcedEntry = '', bExecute = true, replaceFunc = null, flag = 0, bindArgs = null) which allows to set SMP TrackPopupMenu's flag.
- Menu framework: added arg variable (bindArgs) to .btn_up(x, y, object, forcedEntry = '', bExecute = true, replaceFunc = null, flag = 0, bindArgs = null) which allows to call the function associated to the entry with an additional bound argument. bindArgs = {pos: -1, args: null}, where 'pos' denotes the place where it will be added (all other arguments will be filled with void(0) to use defaults) and 'args' is passed as is.
### Changed
- Menu framework: .initMenu and .btn_up are now 2 separate functions. i.e. the menu can be recreated without having to create the UI elements using .initMenu instead of .btn_up (which also calls .initMenu).
### Fixed
- Menu framework: '&' char not showing (or making next char underscored) on created dynamic menus (when it was part of a playlist name for ex.), since they were not doubled. Now the framework automatically checks for names with '&' and doubles them ('&&' are skipped), so they are displayed right.
https://github.com/regorxxx/Menu-Framework-SMP/releases/tag/v2.0.0
### Added
- Menu framework: added bool variable (bExecute) to .btn_up(x, y, object, forcedEntry = '', bExecute = true, replaceFunc = null, flag = 0, bindArgs = null) which allows to simulate the menu without executing any related entry function.
- Menu framework: added func variable (replaceFunc) to .btn_up(x, y, object, forcedEntry = '', bExecute = true, replaceFunc = null, flag = 0, bindArgs = null) which allows to replace the related entry function with a custom one, whenever bExecute is also false. Can be used to paste to clipboard entry names easily simulating the menu usage.
- Menu framework: added flag variable (flag) to .btn_up(x, y, object, forcedEntry = '', bExecute = true, replaceFunc = null, flag = 0, bindArgs = null) which allows to set SMP TrackPopupMenu's flag.
- Menu framework: added arg variable (bindArgs) to .btn_up(x, y, object, forcedEntry = '', bExecute = true, replaceFunc = null, flag = 0, bindArgs = null) which allows to call the function associated to the entry with an additional bound argument. bindArgs = {pos: -1, args: null}, where 'pos' denotes the place where it will be added (all other arguments will be filled with void(0) to use defaults) and 'args' is passed as is.
### Changed
- Menu framework: .initMenu and .btn_up are now 2 separate functions. i.e. the menu can be recreated without having to create the UI elements using .initMenu instead of .btn_up (which also calls .initMenu).
### Removed
### Fixed
- Menu framework: '&' char not showing (or making next char underscored) on created dynamic menus (when it was part of a playlist name for ex.), since they were not doubled. Now the framework automatically checks for names with '&' and doubles them ('&&' are skipped), so they are displayed right.
- Menu framework: Menu entry checks were not being cleared properly when forcing a reset ('menu.clear(true)'), usually used on menus which are created and deleted every time they are called. This was only a problem when the menu entries' names changed on consecutive calls, for ex. when adding invisible chars at menu names.
https://github.com/regorxxx/Menu-Framework-SMP/releases/tag/v2.0.1
Added
iMaxMenuLen: menu can be initialized with a fixed entry text length for displaying purposes. Entries will be cut to such length and added '...' to the end when they are cut. ':' is also maintained at the end when edited. For ex: 'Varied Styles/Genres mix, within a decade' - > 'Varied Styles/Genres mix, ...'. 'Check errors on current playlist:' - > 'Check errors on current...:'. Internal names preserve the original full length string, and that's what's used to call the menu entry or when reporting it to console.
Changed
hasMenu: allows a second argument pointing to its main menu (subMenuFrom). Leave it blank to look for the menu at any place. hasMenu(menuName, subMenuFrom = '')
Fixed
hasMenu: not working as expected, always returning false.
https://github.com/regorxxx/Menu-Framework-SMP/releases/tag/v2.4.0
Context (https://theqwertiest.github.io/foo_spider_monkey_panel/assets/generated_files/docs/html/ContextMenuManager.html) and main menu (https://theqwertiest.github.io/foo_spider_monkey_panel/assets/generated_files/docs/html/MainMenuManager.html) managers support## [2.4.0] - 2023-03-08
### Added
- Support for [contextual menus](https://theqwertiest.github.io/foo_spider_monkey_panel/assets/generated_files/docs/html/ContextMenuManager.html) and [main menus](https://theqwertiest.github.io/foo_spider_monkey_panel/assets/generated_files/docs/html/MainMenuManager.html) at newMenu(menuName, subMenuFrom, flags, context /*{type, playlistIdx}*/, main /*{type}*/) method, by setting the 'context' or 'main' arguments. Type may be either 'handlelist', 'playlist', or 'nowplaying' in the case of contextual menus; for main menus, type must be one of the following: 'file', 'view', 'edit', 'playback', 'library', 'help'. All ids are handled under the hood. Creating a contextual menu is as easier as:
```
// If no playlistIdx is given then it uses the active playlist
menu.newMenu('Items...', void(0), void(0), {type: 'handlelist', playlistIdx: plman.FindPlaylist(pls.nameId)});
```
### Changed
### Removed
### Fixed
- Objects not properly parsed at error logging.
- Entry name not properly set -to the function name- when entryText was a function at addToMenu() method.
Unless I'm missing some detail, this now covers 100% of the native features.