Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 30be376

Browse files
committed
Merge pull request #4413 from adobe/glenn/update-drag-and-drop
Allow all files to be opened by drag and drop
2 parents 4cf8343 + e6bec22 commit 30be376

File tree

3 files changed

+21
-37
lines changed

3 files changed

+21
-37
lines changed

src/document/DocumentCommandHandlers.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,11 @@ define(function (require, exports, module) {
149149
* @private
150150
* Creates a document and displays an editor for the specified file path.
151151
* @param {!string} fullPath
152+
* @param {boolean=} silent If true, don't show error message
152153
* @return {$.Promise} a jQuery promise that will be resolved with a
153154
* document for the specified file path, or rejected if the file can not be read.
154155
*/
155-
function doOpen(fullPath) {
156+
function doOpen(fullPath, silent) {
156157
var result = new $.Deferred();
157158

158159
if (!fullPath) {
@@ -171,12 +172,18 @@ define(function (require, exports, module) {
171172
result.resolve(doc);
172173
})
173174
.fail(function (fileError) {
174-
FileUtils.showFileOpenError(fileError.name, fullPath).done(function () {
175+
function _cleanup() {
175176
// For performance, we do lazy checking of file existence, so it may be in working set
176177
DocumentManager.removeFromWorkingSet(new NativeFileSystem.FileEntry(fullPath));
177178
EditorManager.focusEditor();
178179
result.reject();
179-
});
180+
}
181+
182+
if (silent) {
183+
_cleanup();
184+
} else {
185+
FileUtils.showFileOpenError(fileError.name, fullPath).done(_cleanup);
186+
}
180187
});
181188
}
182189

@@ -194,10 +201,11 @@ define(function (require, exports, module) {
194201
* Creates a document and displays an editor for the specified file path.
195202
* If no path is specified, a file prompt is provided for input.
196203
* @param {?string} fullPath - The path of the file to open; if it's null we'll prompt for it
204+
* @param {boolean=} silent - If true, don't show error message
197205
* @return {$.Promise} a jQuery promise that will be resolved with a new
198206
* document for the specified file path, or rejected if the file can not be read.
199207
*/
200-
function _doOpenWithOptionalPath(fullPath) {
208+
function _doOpenWithOptionalPath(fullPath, silent) {
201209
var result;
202210
if (!fullPath) {
203211
// Create placeholder deferred
@@ -219,7 +227,7 @@ define(function (require, exports, module) {
219227
});
220228
DocumentManager.addListToWorkingSet(filesToOpen);
221229

222-
doOpen(paths[paths.length - 1])
230+
doOpen(paths[paths.length - 1], silent)
223231
.done(function (doc) {
224232
var url = PathUtils.parseUrl(doc.file.fullPath);
225233
//reconstruct the url but use the directory and stop there
@@ -235,7 +243,7 @@ define(function (require, exports, module) {
235243
}
236244
});
237245
} else {
238-
result = doOpen(fullPath);
246+
result = doOpen(fullPath, silent);
239247
}
240248

241249
return result.promise();
@@ -273,8 +281,9 @@ define(function (require, exports, module) {
273281
* lineNumber and columnNumber are 1-origin: the very first line is line 1, and the very first column is column 1.
274282
*/
275283
function handleFileOpen(commandData) {
276-
var fileInfo = _parseDecoratedPath(commandData ? commandData.fullPath : null);
277-
return _doOpenWithOptionalPath(fileInfo.path)
284+
var fileInfo = _parseDecoratedPath(commandData ? commandData.fullPath : null),
285+
silent = commandData ? commandData.silent : false;
286+
return _doOpenWithOptionalPath(fileInfo.path, silent)
278287
.always(function () {
279288
// If a line and column number were given, position the editor accordingly.
280289
if (fileInfo.line !== null) {

src/file/FileUtils.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -361,30 +361,6 @@ define(function (require, exports, module) {
361361
function getDirectoryPath(fullPath) {
362362
return fullPath.substr(0, fullPath.lastIndexOf("/") + 1);
363363
}
364-
365-
/**
366-
* Determine if a file is a text file. This function is only a quick best-guess.
367-
* @param {string} path Path to check
368-
* @return {boolean} True if the path is a text file, false if not.
369-
*/
370-
function isTextFile(path) {
371-
// We don't have an accurate way to quickly check if a file is a text file.
372-
// To make a good guess, start by looking at the language of the file.
373-
var language = LanguageManager.getLanguageForPath(path);
374-
375-
if (language.getId() !== "unknown") {
376-
// Language is known to Brackets, this must be a text file.
377-
return true;
378-
}
379-
380-
// All other files end up with language === "unknown", including .txt files.
381-
var extension = _getFileExtension(path),
382-
textExtensionRegEx = /^(txt|gyp[i]?)$/;
383-
384-
// If there is no extension, or the extension is known text extension, assume it is a text file.
385-
// Files with other extensions, like .png or .jpg, will return false.
386-
return (extension === path || textExtensionRegEx.test(extension.toLowerCase()));
387-
}
388364

389365
// Define public API
390366
exports.LINE_ENDINGS_CRLF = LINE_ENDINGS_CRLF;
@@ -406,5 +382,4 @@ define(function (require, exports, module) {
406382
exports.isStaticHtmlFileExt = isStaticHtmlFileExt;
407383
exports.isServerHtmlFileExt = isServerHtmlFileExt;
408384
exports.getDirectoryPath = getDirectoryPath;
409-
exports.isTextFile = isTextFile;
410385
});

src/utils/DragAndDrop.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ define(function (require, exports, module) {
5050
if (items[i].kind === "file") {
5151
var entry = items[i].webkitGetAsEntry();
5252

53-
if (entry.isFile && FileUtils.isTextFile(entry.fullPath)) {
53+
if (entry.isFile) {
5454
return true;
5555
}
5656
}
@@ -72,11 +72,11 @@ define(function (require, exports, module) {
7272
return Async.doInParallel(files, function (file) {
7373
var result = new $.Deferred();
7474

75-
// Only open text files
75+
// Only open files
7676
brackets.fs.stat(file, function (err, stat) {
77-
if (!err && stat.isFile() && FileUtils.isTextFile(file)) {
77+
if (!err && stat.isFile()) {
7878
CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET,
79-
{fullPath: file})
79+
{fullPath: file, silent: true})
8080
.done(function () {
8181
result.resolve();
8282
})

0 commit comments

Comments
 (0)