Skip to main content
Kasyan Servetsky
Legend
February 9, 2016
Answered

Wanna select multiple folders in the open dialog box, but it’s impossible, isn’t it?

  • February 9, 2016
  • 1 reply
  • 1430 views

Hi forum,

The File and Folder objects have openDlg() method. The former has also the multiSelect parameter, the latter doesn’t.

I wish I could also have it for the Folder so I could ctrl/shift select multiple folders instead of picking up a folder and processing all its subfolders.

Maybe I’m missing something obvious or there’s an workaround to make such a dialog box.

Regards,

Kasyan

This topic has been closed for replies.
Correct answer Loic.Aigon

As suggested, a possible approach :

Folder.prototype.selectMultipleDialog = function (prompt,multiselect){

  var w = new Window('dialog','MultipleSelectDialog'),

  st,

  ls,

  btnGp,

    koBtn,

    okBtn,

    folderFilter = function(f){

        return (f instanceof Folder)

    },

    u,

    folders = this.getFiles(folderFilter),

    getFolderNames = function(foldersObjectArray){

        var n = foldersObjectArray.length,

        namesArray = [];

        while ( n--){

            namesArray = decodeURI(foldersObjectArray.name);

        }

        return namesArray;

    },

    folderListItems = getFolderNames(folders),

    n = 0;

  

 

  

    st = w.add('statictext',u,prompt);

    ls = w.add('listbox',undefined, folderListItems, {multiselect:multiselect} );

    btnGp = w.add('group');

  

    koBtn = btnGp.add('button',u,'Cancel');

    okBtn = btnGp.add('button',u,'Select');

    koBtn.onClick = function(){

  w.close(0);

  }

  okBtn.onClick = function(){

  w.close(1);

  }

  

    ls.onChange = function() {

        okBtn.enabled = ls.selection!==null;

    }

  

    w.preferredSize.width = 450;

    w.alignChildren = ["fill","top"];

    ls.preferredSize.height = 200;

    btnGp.alignChildren = ["right","top"];

  okBtn.enabled = false;

    if ( w.show()==1 ){

  if ( ls.selection instanceof Array ) {

  n = ls.selection.length;

            while ( n-- ) folders[ls.selection.index].execute();

  }

  else {

  folders[ls.selection.index].execute();

  }

  }

}

var fo = Folder.desktop;

fo.selectMultipleDialog("test", true)

HTH

Loic

www.ozalto.com

1 reply

Loic.Aigon
Legend
February 9, 2016

Hi Kasyan,

I am a bit confused by you assumption. As far as I can see in the DOM, although a Folder object can bederivated from a generic File object, the openDialog and by extension openDlg are Files instance methods only. The Folder instance on the contrary has a selectDialog() and selectDlg() method.

I tried just in case to call openDialog and openDlg on both the Folder class and Folder instance, and it throwed an error quite unsurprisingly.

So I guess the only workaround would be to build your own folder selection window.

FWIW,

Loïc

Loic.Aigon
Loic.AigonCorrect answer
Legend
February 9, 2016

As suggested, a possible approach :

Folder.prototype.selectMultipleDialog = function (prompt,multiselect){

  var w = new Window('dialog','MultipleSelectDialog'),

  st,

  ls,

  btnGp,

    koBtn,

    okBtn,

    folderFilter = function(f){

        return (f instanceof Folder)

    },

    u,

    folders = this.getFiles(folderFilter),

    getFolderNames = function(foldersObjectArray){

        var n = foldersObjectArray.length,

        namesArray = [];

        while ( n--){

            namesArray = decodeURI(foldersObjectArray.name);

        }

        return namesArray;

    },

    folderListItems = getFolderNames(folders),

    n = 0;

  

 

  

    st = w.add('statictext',u,prompt);

    ls = w.add('listbox',undefined, folderListItems, {multiselect:multiselect} );

    btnGp = w.add('group');

  

    koBtn = btnGp.add('button',u,'Cancel');

    okBtn = btnGp.add('button',u,'Select');

    koBtn.onClick = function(){

  w.close(0);

  }

  okBtn.onClick = function(){

  w.close(1);

  }

  

    ls.onChange = function() {

        okBtn.enabled = ls.selection!==null;

    }

  

    w.preferredSize.width = 450;

    w.alignChildren = ["fill","top"];

    ls.preferredSize.height = 200;

    btnGp.alignChildren = ["right","top"];

  okBtn.enabled = false;

    if ( w.show()==1 ){

  if ( ls.selection instanceof Array ) {

  n = ls.selection.length;

            while ( n-- ) folders[ls.selection.index].execute();

  }

  else {

  folders[ls.selection.index].execute();

  }

  }

}

var fo = Folder.desktop;

fo.selectMultipleDialog("test", true)

HTH

Loic

www.ozalto.com

Kasyan Servetsky
Legend
February 10, 2016

Thank you very much for your quick reply, Loic!

Regards,
Kasyan