Directory list sample FUNCTION B

This function to select directories does the same as Directory list sample function A. The only difference is in the implementation. In function A, a stand-alone Input box is used to present the sub-directories; the function below makes use of a Dialog instead, where the drop-down box (in QSA called "ComboBox") with subdirectory names is added to a dialog. In Qt, these graphical components are called widgets. The obvious advantage to use a Dialog, is that other components can be added as well, like CheckBoxes, RadioButtons, LineEdits, etc. Also, there is more control over the appearance of the dialog by changing the properties of the components.

 

function Get_directories() {

 

BrainVoyagerQX.TimeOutMessageBox("With this function you can select as many directories as you like.\nPlease first select a main directory...", 4);

var maindirname = FileDialog.getExistingDirectory();

var maindir = new Dir(maindirname);

var subdirnames = maindir.entryList("*", maindir.Dirs);

var subdirarray = new Array();

 

BrainVoyagerQX.TimeOutMessageBox("Please now select subdirectories. To stop, press 'cancel'.", 4); // show timeoutmessagebox for 4 seconds

var dialog = new Dialog;

var subdirbox = new ComboBox;

subdirbox.label = "Please select a directory:\nTo stop, press 'cancel'.";

subdirbox.itemList = subdirnames;

dialog.add(subdirbox);

 

BrainVoyagerQX.ShowLogTab();

var selectedsubdir;

BrainVoyagerQX.PrintToLog("\nStart selecting directories...");

while (dialog.exec()) {

selectedsubdir = subdirbox.currentItem;

BrainVoyagerQX.PrintToLog("Selected subdirectory: " + selectedsubdir);

subdirarray.unshift(maindir.path + "/" + selectedsubdir); // add the whole pathname to the subdirectory

}

BrainVoyagerQX.PrintToLog("Finished.");

return subdirarray; // returns the array to another function that invokes this function Get_directories()

}

 

The function in real-time

Invoke the function 'Get directories':

 

 

A time out message box shows the purpose of the function:

 

 

Select a main directory:

 

 

 

Select the first directory, in this example 'RM':

 

 

Select another directory, in this case 'RY':

 

 

All directories have been selected. Now press 'Cancel':

 

 

The function will indicate on the Log tab that it is finished: