src/utils/DragAndDrop.js
function openDroppedFiles(paths) {
        var errorFiles = [],
            ERR_MULTIPLE_ITEMS_WITH_DIR = {};

        return Async.doInParallel(paths, function (path, idx) {
            var result = new $.Deferred();

            // Only open files.
            FileSystem.resolve(path, function (err, item) {
                if (!err && item.isFile) {
                    // If the file is already open, and this isn't the last
                    // file in the list, return. If this *is* the last file,
                    // always open it so it gets selected.
                    if (idx < paths.length - 1) {
                        if (MainViewManager.findInWorkingSet(MainViewManager.ALL_PANES, path) !== -1) {
                            result.resolve();
                            return;
                        }
                    }

                    CommandManager.execute(Commands.CMD_ADD_TO_WORKINGSET_AND_OPEN,
                                           {fullPath: path, silent: true})
                        .done(function () {
                            result.resolve();
                        })
                        .fail(function (openErr) {
                            errorFiles.push({path: path, error: openErr});
                            result.reject();
                        });
                } else if (!err && item.isDirectory && paths.length === 1) {
                    // One folder was dropped, open it.
                    ProjectManager.openProject(path)
                        .done(function () {
                            result.resolve();
                        })
                        .fail(function () {
                            // User was already notified of the error.
                            result.reject();
                        });
                } else {
                    errorFiles.push({path: path, error: err || ERR_MULTIPLE_ITEMS_WITH_DIR});
                    result.reject();
                }
            });

            return result.promise();
        }, false)
            .fail(function () {
                function errorToString(err) {
                    if (err === ERR_MULTIPLE_ITEMS_WITH_DIR) {
                        return Strings.ERROR_MIXED_DRAGDROP;
                    } else {
                        return FileUtils.getFileErrorString(err);
                    }
                }

                if (errorFiles.length > 0) {
                    var message = Strings.ERROR_OPENING_FILES;

                    message += "<ul class='dialog-list'>";
                    errorFiles.forEach(function (info) {
                        message += "<li><span class='dialog-filename'>" +
                            StringUtils.breakableUrl(ProjectManager.makeProjectRelativeIfPossible(info.path)) +
                            "</span> - " + errorToString(info.error) +
                            "</li>";
                    });
                    message += "</ul>";

                    Dialogs.showModalDialog(
                        DefaultDialogs.DIALOG_ID_ERROR,
                        Strings.ERROR_OPENING_FILE_TITLE,
                        message
                    );
                }
            });
    }
function openDroppedFiles(paths) {
        var errorFiles = [],
            ERR_MULTIPLE_ITEMS_WITH_DIR = {};

        return Async.doInParallel(paths, function (path, idx) {
            var result = new $.Deferred();

            // Only open files.
            FileSystem.resolve(path, function (err, item) {
                if (!err && item.isFile) {
                    // If the file is already open, and this isn't the last
                    // file in the list, return. If this *is* the last file,
                    // always open it so it gets selected.
                    if (idx < paths.length - 1) {
                        if (MainViewManager.findInWorkingSet(MainViewManager.ALL_PANES, path) !== -1) {
                            result.resolve();
                            return;
                        }
                    }

                    CommandManager.execute(Commands.CMD_ADD_TO_WORKINGSET_AND_OPEN,
                                           {fullPath: path, silent: true})
                        .done(function () {
                            result.resolve();
                        })
                        .fail(function (openErr) {
                            errorFiles.push({path: path, error: openErr});
                            result.reject();
                        });
                } else if (!err && item.isDirectory && paths.length === 1) {
                    // One folder was dropped, open it.
                    ProjectManager.openProject(path)
                        .done(function () {
                            result.resolve();
                        })
                        .fail(function () {
                            // User was already notified of the error.
                            result.reject();
                        });
                } else {
                    errorFiles.push({path: path, error: err || ERR_MULTIPLE_ITEMS_WITH_DIR});
                    result.reject();
                }
            });

            return result.promise();
        }, false)
            .fail(function () {
                function errorToString(err) {
                    if (err === ERR_MULTIPLE_ITEMS_WITH_DIR) {
                        return Strings.ERROR_MIXED_DRAGDROP;
                    } else {
                        return FileUtils.getFileErrorString(err);
                    }
                }

                if (errorFiles.length > 0) {
                    var message = Strings.ERROR_OPENING_FILES;

                    message += "<ul class='dialog-list'>";
                    errorFiles.forEach(function (info) {
                        message += "<li><span class='dialog-filename'>" +
                            StringUtils.breakableUrl(ProjectManager.makeProjectRelativeIfPossible(info.path)) +
                            "</span> - " + errorToString(info.error) +
                            "</li>";
                    });
                    message += "</ul>";

                    Dialogs.showModalDialog(
                        DefaultDialogs.DIALOG_ID_ERROR,
                        Strings.ERROR_OPENING_FILE_TITLE,
                        message
                    );
                }
            });
    }
function openDroppedFiles ( paths ) { var errorFiles = [ ] , ERR_MULTIPLE_ITEMS_WITH_DIR = { } ; return Async . doInParallel ( paths , function ( path , idx ) { var result = new $ . Deferred ( ) ; // Only open files. FileSystem . resolve ( path , function ( err , item ) { if ( ! err && item . isFile ) { // If the file is already open, and this isn't the last // file in the list, return. If this *is* the last file, // always open it so it gets selected. if ( idx < paths . length - 1 ) { if ( MainViewManager . findInWorkingSet ( MainViewManager . ALL_PANES , path ) !== - 1 ) { result . resolve ( ) ; return ; } } CommandManager . execute ( Commands . CMD_ADD_TO_WORKINGSET_AND_OPEN , { fullPath : path , silent : true } ) . done ( function ( ) { result . resolve ( ) ; } ) . fail ( function ( openErr ) { errorFiles . push ( { path : path , error : openErr } ) ; result . reject ( ) ; } ) ; } else if ( ! err && item . isDirectory && paths . length === 1 ) { // One folder was dropped, open it. ProjectManager . openProject ( path ) . done ( function ( ) { result . resolve ( ) ; } ) . fail ( function ( ) { // User was already notified of the error. result . reject ( ) ; } ) ; } else { errorFiles . push ( { path : path , error : err || ERR_MULTIPLE_ITEMS_WITH_DIR } ) ; result . reject ( ) ; } } ) ; return result . promise ( ) ; } , false ) . fail ( function ( ) { function errorToString ( err ) { if ( err === ERR_MULTIPLE_ITEMS_WITH_DIR ) { return Strings . ERROR_MIXED_DRAGDROP ; } else { return FileUtils . getFileErrorString ( err ) ; } } if ( errorFiles . length > 0 ) { var message = Strings . ERROR_OPENING_FILES ; message += "<ul class='dialog-list'>" ; errorFiles . forEach ( function ( info ) { message += "<li><span class='dialog-filename'>" + StringUtils . breakableUrl ( ProjectManager . makeProjectRelativeIfPossible ( info . path ) ) + "</span> - " + errorToString ( info . error ) + "</li>" ; } ) ; message += "</ul>" ; Dialogs . showModalDialog ( DefaultDialogs . DIALOG_ID_ERROR , Strings . ERROR_OPENING_FILE_TITLE , message ) ; } } ) ; }
Open dropped files
@param {Array.<string>} files Array of files dropped on the application.
@return {Promise} Promise that is resolved if all files are opened, or rejected
if there was an error.
Open dropped files