Dialog().choices - popup list seperators

Using the new OrderedMap() makes life easier when making popup lists.
Convert OrderedMap() to Vector() and pass to the Dialog() object.

There is one problem - the list can only have one separator - as the OrderedMap() needs unique keys.


Is it therefore possible to change the seperator slightly and allow for a unique description in brackets after the seperator ?
something like
Use a single hyphen with optional description in brackets "- (sep1)"

In the meantime this request is studied by the Opus team, you can do that (EDIT: meaning use something like "- (sep1)") in your OrderedMap, and once it is transformed in a vector, make a small pass through all items in vector, search for a regexp like ^- \([^\)]*\)$ and replace it with simple -.
EDIT : Note that any pattern used to make it a separator will not be available anymore as a menu entry label, so that choice will restrain the possibilities for the menu items (or an espace mechanism has to be provided).

You could also save the Opus team the work and just put in your map an entry with the hyphen containing a vector with the positions where you want a separator. Then you simply insert the hyphen into your menu in the positions indicated in said vector.

Thanks for response.
Using @PassThePeas suggestion as it makes for easier re-ordering (select line and just drag to desired position). Although the regex is not needed, a simple charAt(0) == '-' will do.

Since you're the one specifying the entries in the Dialog().choices, you're definitely in the best place to know what is sufficient to match your inputs :slight_smile: . I was trying to match as closely as possible what you suggested, but if charAt(0) == '-' is enough, it's easier to code and more readable !

For people interested in learning to write a simple popup list here is the finished product, no resources needed, adapt to your own needs, can be bound to the double/middle click events in prefs or put in a button, no resources required, copy and paste the JScript below into a new script and you will have a new command called popupList

// Popup List for middle-click button
// Ⓒ 2023
// D.Barnes


// Initialize script
function OnInit(initData)
{
  initData.name             = 'Popup List';     // name shown in Script Add-Ins list
  initData.version          = '1.1';
  initData.copyright        = 'Ⓒ 2023';
  initData.url              = 'https://resource.dopus.com/t/how-to-use-buttons-and-scripts-from-this-forum/3546/3';
  initData.desc             = 'Simple popup list called as a command, can be bound to mouse background events';
  initData.group            = 'Commands';
  initData.default_enable   = true;
  initData.min_version      = '13.0';

  // Add a command to Opus
  var cmd                   = initData.AddCommand();
  cmd.name                  = 'popupList';		// command name
  cmd.method                = cmd.name;		    // function called
  cmd.desc                  = initData.desc;
  cmd.label                 = initData.name;	// name shown in commands list in customize dialog
  cmd.noprogress            = true;
}


// command method set in OnInit()
function popupList(clickData)
{
    // set logging true or false
    var log = false;
    if (log) DOpus.Output('Popup List');


    // menu items and commands - easier to re-order due to using an OrderedMap()
    // note: separators start with a hyphen and have a unique key and the value must be 'separator'
    var menu = DOpus.Create.OrderedMap();

    menu('▶  Menu					(Ctrl + Shift + M)')            = 'Toolbar \"Menu\" TOGGLE LINE=0';

    menu('- sep1')                                                  = 'separator';

    menu('▶  Main Toolbar			(Ctrl + Shift + T)')            = 'Toolbar \"Main\" STATE=top TOGGLE';
    menu('▶  Images Toolbar			(Ctrl + Shift + I)')            = 'Toolbar \"Images\" STATE=bottom TOGGLE LINE=0';
    menu('▶  Applications Toolbar	(Ctrl + Shift + A)')            = 'Toolbar \"Applications\" STATE=center TOGGLE';
    menu('▶  Favorites				(Ctrl + Shift + B)')            = 'Toolbar NAME=\"Favorites Bar\" STATE=tree TOGGLE';
    menu('▶  Labels					(Ctrl + Shift + L)')            = 'Toolbar \"Labels\" STATE=left LINE=0 TOGGLE';

    menu('- sep2')                                                  = 'separator';
    
    menu('▷  Status Bar				(Ctrl + B)')                    = 'Set STATUSBAR=Toggle';
    menu('▷  Preferences')                                          = 'Prefs';

    menu('- sep3')                                                  = 'separator';

    menu('⧉  Toggle Thumbnails / Details')                          = 'Set VIEW=Thumbnails*,Details*';
    menu('⧉  Toggle Thumbnail Labels')                              = 'Set THUMBNAILLABELS=toggle';
    menu('⧉  Toggle Tooltips')                                      = 'Set INFOTIPS=toggle';

    menu('- sep4')                                                   = 'separator';

    menu('⧉  Thumbnail Size 64px')                                  = 'Show THUMBNAILSIZE=64';
    menu('⧉  Thumbnail Size 96px')                                  = 'Show THUMBNAILSIZE=96';
    menu('⧉  Thumbnail Size 128px')                                 = 'Show THUMBNAILSIZE=128';
    menu('⧉  Thumbnail Size 196px')                                 = 'Show THUMBNAILSIZE=196';
    menu('⧉  Thumbnail Size 512px')                                 = 'Show THUMBNAILSIZE=512';

    menu('- sep5')                                                   = 'separator';

    menu('⧉  Thumbnails Fit')                                       = 'Set THUMBSTRETCH=FitSmooth';
    menu('⧉  Thumbnails Fill (square)')                             = 'Set THUMBSTRETCH=FillCropSmooth';

    menu('- sep6')                                                   = 'separator';

    menu('▢  Bottom-Half of Screen	(Shift + F6)')                   = 'SET LISTERPOS=5,1100 LISTERSIZE 3830,1000 DUAL=Toggle,Remember';
    menu('▢  Bottom-Left of Screen	(Ctrl + F6)')                    = 'SET LISTERPOS=5,1100 LISTERSIZE 1895,1000 DUAL=off,Remember';

    menu('- sep7')                                                   = 'separator';

    menu('⛬  BBC News')                                             = 'https://www.bbc.co.uk/';
    menu('⛬  Sky News')                                             = 'https://news.sky.com/uk/';
    menu('⛬  Amazon')                                               = 'https://www.amazon.co.uk/';
    menu('⛬  eBay')                                                 = 'https://www.ebay.co.uk/';
    menu('⛬  Steam Deck')                                           = 'https://store.steampowered.com/steamdeck';


    // vectors for passing to dialog object and command object
    var menu_items      = DOpus.Create.Vector();
    var menu_commands   = DOpus.Create.Vector();
    var index = 0;

    for (var e = new Enumerator(menu); !e.atEnd(); e.moveNext())
    {
        var key                 = e.item();
        // check for separator
        if (key.charAt(0) == '-')
            menu_items(index)   = '-';
        else
            menu_items(index)   = key;

        var value               = menu(key);
        menu_commands(index)    = value;

        index++;
    }


    // log menu items and commands
    if (log) DOpus.Output('count: ' + menu.count);
    if (log) DOpus.Output('');
    if (log) DOpus.Output('ITEMS: ');
    for (var loop = 0; loop < menu.count; loop++)
    {
        if (log) DOpus.Output(menu_items(loop));
    }
    if (log) DOpus.Output('');
    if (log) DOpus.Output('COMMANDS: ');
    for (var loop = 0; loop < menu.count; loop++)
    {
        if (log) DOpus.Output(menu_commands(loop));
    }


    // show popup list
    var cmd = clickData.func.command;
    var dlg = clickData.func.Dlg;
    dlg.choices = menu_items;
    dlg.menu = 0;
    dlg.Show();


    // run command
    if (dlg.result && menu_commands[dlg.result - 1] != 'separator') 
    {
        if (log) DOpus.Output('Command called');
        cmd.RunCommand(menu_commands[dlg.result - 1]);
    }


    // log results
    if (log) DOpus.Output('');
    if (log) DOpus.Output('Return code = ' + dlg.result);
    if (log) { if (dlg.result) DOpus.Output('Command = ' + menu_commands[dlg.result - 1]); }
}
3 Likes