PDA

View Full Version : fileDialog replacement beta


chips__
10-23-2003, 04:51 PM
hola people!

well, i'm writing a new filebrowser, since the one under linux is cr*p, and theres all this about some os's supporting different things. so this one should be universal.
please have a look at my first beta

// filebrowser for all operating systems beta 0.1
// (c) peter hartwig 2003 / peter@hartwig.dk

/* usage : phFileBrowse (window title, ok button title, cancel button title,
start dir)

When the ok button is pressed, the optionVar phBrowseFile is updated.
a quick example would be:

phFileBrowse("Select outputfile","OK","Cancel","/net/homes/phartwig/");

scriptJob -uiDeleted phBrowseWindow " phUpdateOut " ;
proc phUpdateOut()
{
string $x = `optionVar -q phBrowseFile`;
print $x;
}

*/

/*
updates to come, hopefully
-sorting by name, date etc.
-history
-if possible, and if people want it, some way of returning the filename directly
-a nicer interface?
*/


global proc phFileBrowse(string $phBrowseWinTitle, string $phBrowseOkBtn,
string $phBrowseCnlBtn, string $phBrowseDir)
{
chdir $phBrowseDir;
string $window = `window -title $phBrowseWinTitle -width 300 -height 500 phBrowseWindow`;
string $form = `formLayout -numberOfDivisions 100`;
string $b1 = `textScrollList -dcc updatelist DirList`;
string $b2 = `textScrollList -sc updatetextfield FileList`;
string $b3 = `textField FileText`;
string $column = `columnLayout -adjustableColumn true`;
button -label $phBrowseOkBtn -c phBrowseOk; button -label $phBrowseCnlBtn -c phBrowseCancel;

formLayout -edit
-attachForm $b1 "top" 2
-attachForm $b1 "left" 2
-attachControl $b1 "bottom" 2 $b2
-attachPosition $b1 "right" 2 75

-attachControl $b3 "top" 2 $b2
-attachForm $b3 "left" 2
-attachForm $b3 "right" 2
-attachForm $b3 "bottom" 2

-attachForm $b2 "top" 200
-attachForm $b2 "left" 2
-attachForm $b2 "bottom" 30
-attachForm $b2 "right" 2

-attachForm $column "top" 2
-attachPosition $column "left" 0 75
-attachControl $column "bottom" 2 $b2
-attachForm $column "right" 2
$form;
showWindow $window;

phBrowseUpdateDirs;
}

global proc phBrowseUpdateDirs()
{
textScrollList -e -ra DirList;
$currentDir = (`pwd`+"/");

string $dirs[] = `getFileList -folder $currentDir`;
string $dir;
int $dirTest=0;
int $dirNo = 0;
textScrollList -e -append ".." DirList;
for ($dir in $dirs)
{
$dirTest = `filetest -d $dirs[$dirNo]`;
if ($dirTest == true)
{
textScrollList -e -append $dirs[$dirNo] DirList;
};
$dirNo = $dirNo +1;
};

}

global proc updatelist()
{
textScrollList -e -ra FileList;
string $selectedItem[] = `textScrollList -query -selectItem DirList`;
chdir ($selectedItem[0]+"/");
string $currentDir = (`pwd`+"/");
string $b[] = `getFileList -folder ($currentDir)`;
string $x;
string $fileTest = 0;
int $i = 0;
for ($x in $b)
{
$fileTest = `filetest -f $b[$i]`;
if ($fileTest == 1)
{
textScrollList -e -append $b[$i] FileList;
}
$i=$i+1;
};
phBrowseUpdateDirs;
}

global proc updatetextfield()
{
string $selectedFile[] = `textScrollList -q -selectItem FileList`;
textField -e -tx $selectedFile[0] FileText;
}

global proc phBrowseOk()
{
string $phBrowseFile = ((`pwd`+"/")+ `textField -q -tx FileText`);
optionVar -stringValue phBrowseFile $phBrowseFile;
deleteUI -window phBrowseWindow;
}

global proc phBrowseCancel()
{
deleteUI -window phBrowseWindow;
}

CGTalk Moderation
01-16-2006, 12:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.