Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Menu-Framework-SMP (Read 2258 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Menu-Framework-SMP

A helper script for 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:


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().

Usage
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.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:
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: Different tools for foobar2000. The dynamic configurable menu is built using this.
 2. Playlist-Manager-SMP: A playlist manager for foobar2000. The static menus use this.
 3. World-Map-SMP: A foobar2000 UI to display current artist's country. The static menus use this.


Installation
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:
https://github.com/regorxxx/Menu-Framework-SMP

Menu-Framework-SMP 1.1.0

Reply #1
1.1.0 - 2021-05-19
Added

    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).

Changed

    Moved dependencies to main file.

Removed

    helpers_xxx.js dependency.

Re: Menu-Framework-SMP

Reply #2
## [1.2.0] - 2021-05-26
### 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.

Re: Menu-Framework-SMP

Reply #3
## [1.2.1] - 2021-05-28
### 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

Re: Menu-Framework-SMP

Reply #4
v1.2.2 - Minor update
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

Re: Menu-Framework-SMP

Reply #5
Just pushed a new update. Clone the repository to get the latest changes (Code/Download zip) instead of using the releases page.
Quote
### 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.

Re: Menu-Framework-SMP

Reply #6
https://github.com/regorxxx/Menu-Framework-SMP/releases/tag/v2.0.0
Quote
### 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.

Re: Menu-Framework-SMP

Reply #7
https://github.com/regorxxx/Menu-Framework-SMP/releases/tag/v2.0.1
Quote
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.

 

Re: Menu-Framework-SMP

Reply #8
https://github.com/regorxxx/Menu-Framework-SMP/releases/tag/v2.4.0

Context and main menu managers support
Quote
## [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.