docsforadobe / aequery

MIT License
41 stars 8 forks source link

Integrate & adapt selectFiles function #31

Closed runegan closed 6 years ago

runegan commented 7 years ago

Original report by Zack Lovatt (Bitbucket: zlovatt, GitHub: zlovatt).


Based on this by @rafikhan, adapted from something by @rendertom

Needs to be aequery-ified, and implemented as aeq.file.selectFiles();

var myFiles = selectFiles(["jsx", "theme", "someOtherExtension"], true);

function selectFiles(extensionList, multiSelect)
{
    var message = multiSelect ? "Please select multiple files" : "Please select file";

    var getFilterForFiles = function ()
    {
        var isWindows = ($.os.indexOf("Windows") != -1);

        if (isWindows) {
            return '*.' + extensionList.join(';*.');
        } else {
            var extensionListRe = '\.(' + extensionList.join('|') + ')$';
            var re = new RegExp(extensionListRe, "i");

            return function (file) {
                return file.name.match(re) || file.constructor.name === "Folder";
            };
        }
    }

    return File.openDialog(message, getFilterForFiles(), multiSelect);
}
runegan commented 7 years ago

Original comment by renderTom - (Bitbucket: [Tomas Sinkunas](https://bitbucket.org/Tomas Sinkunas), ).


Add third optional 'message' parameter to the function, so you can prompt for custom message when dialog appears.

runegan commented 6 years ago

Original comment by Zack Lovatt (Bitbucket: zlovatt, GitHub: zlovatt).


Adds selectFiles to aeq.file (resolve #31)