Dialog().choices - popup list seperators

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]); }
}
4 Likes