File browsing on OSX using openDlg() - Why are all folders greyed out?
I'm trying to setup a file and folder browsing dialog that works for both Win/OSX and with filters for restricting the dialog search to specific file types. I got a lot of help from another user on the forum (Matias Kiviniemi) in order to get the filter function working - but now I have another problem: a rather strange one.
When browsing files on OSX, all folders are greyed out!
You can still navigate (somewhat) via the Favorites -list and directory tree button at the top center, but actually clicking in the folders doesn't work at all.
I've also tried saveDlg() for browsing files but I get exactly the same problem with greyed out folders. Also, saveDlg() doesn't have the second parameter (the filter function) for restricting the dialog to a specific file type - which is something that I need.
// Utility functions for checking if the OS is Win/OSX
function isWindows(){
return app.systemInformation.indexOf("Operating System: Windows") >= 0
}
function isMac(){
return app.systemInformation.indexOf("Operating System: Mac") >= 0
}
// All params below are strings
function promptFile(dialogMessage, dialogType, extFilter, oldPath){
// Description: Opens up a file or older dialog window for browsing (Win/OSX)
// Returns: Absolute path (string) to the file or folder that was picked by the user
// File
if (dialogType == "file"){
// Create filter function for the File.saveDlg -function
var filter = null
if (isMac()){ // OSX
if (extFilter){
var filter_regex = new RegExp("[^\.]*\."+extFilter+"$")
filter = function (file_entry){
return filter_regex.test(file_entry.name)
}
}else{
filter = function(){ return true } // All and any file(s)
}
}else if (isWindows()){ // Win
if (extFilter){
filter = extFilter.charAt(0).toUpperCase() + extFilter.slice(1)+"-files:*."+extFilter
}else{
filter = "All files:*.*" // All and any file(s)
}
}else{
filter = null
}
// Create file dialog
var path = new File(oldPath);
// var dialog = path.saveDlg(dialogMessage, filter); // Same kind of error with saveDlg
var dialog = path.openDlg(dialogMessage, filter, false);
// Folder
}else if(dialogType == "folder"){
alert("folder diag:\n" + oldPath);
// Create folder dialog
var path = new Folder(oldPath);
var dialog = path.selectDlg(dialogMessage);
while (dialog.alias){
dialog = dialog.resolve.selectDlg(dialogMessage);
}
}
if (dialog){
return dialog.fsName.replace(/\\/g, "/") // Back to Front slashes
}
}
