Integrate & adapt selectFiles function

Issue #31 resolved
Zack Lovatt
created an issue

Based on this by @Rafi Khan, adapted from something by @Tomas Sinkunas

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);
}

Comments (2)

  1. Log in to comment