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

Commit

Permalink
Bug: 12766 - Now language mode can be changed for unsaved Untitled Do…
Browse files Browse the repository at this point in the history
…cuments (#13086)
  • Loading branch information
saurabh95 authored and swmitra committed Feb 16, 2017
1 parent 74c5306 commit 7883b01
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 59 deletions.
11 changes: 5 additions & 6 deletions src/document/DocumentManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,13 @@ define(function (require, exports, module) {
// use existing document
return new $.Deferred().resolve(doc).promise();
} else {
var result = new $.Deferred(),
promise = result.promise();

// Should never get here if the fullPath refers to an Untitled document
// return null in case of untitled documents
if (fullPath.indexOf(_untitledDocumentPath) === 0) {
console.error("getDocumentForPath called for non-open untitled document: " + fullPath);
return new $.Deferred().reject().promise();
result.resolve(null);
return promise;
}

var file = FileSystem.getFileForPath(fullPath),
Expand All @@ -346,9 +348,6 @@ define(function (require, exports, module) {
// wait for the result of a previous request
return pendingPromise;
} else {
var result = new $.Deferred(),
promise = result.promise();

// log this document's Promise as pending
getDocumentForPath._pendingDocumentPromises[file.id] = promise;

Expand Down
2 changes: 0 additions & 2 deletions src/editor/EditorStatusBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ define(function (require, exports, module) {

// Ensure width isn't left locked by a previous click of the dropdown (which may not have resulted in a "change" event at the time)
languageSelect.$button.css("width", "auto");
// Setting Untitled documents to non-text mode isn't supported yet, so disable the switcher in that case for now
languageSelect.$button.prop("disabled", doc.isUntitled());
// Show the current language as button title
languageSelect.$button.text(lang.getName());
}
Expand Down
95 changes: 51 additions & 44 deletions src/extensions/default/JavaScriptCodeHints/ScopeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ define(function (require, exports, module) {
PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
ProjectManager = brackets.getModule("project/ProjectManager"),
Strings = brackets.getModule("strings"),
StringUtils = brackets.getModule("utils/StringUtils");
StringUtils = brackets.getModule("utils/StringUtils"),
InMemoryFile = brackets.getModule("document/InMemoryFile");

var HintUtils = require("HintUtils"),
MessageIds = require("MessageIds"),
Expand Down Expand Up @@ -1168,59 +1169,65 @@ define(function (require, exports, module) {

ensurePreferences();
deferredPreferences.done(function () {
FileSystem.resolve(dir, function (err, directory) {
if (err) {
console.error("Error resolving", dir);
addFilesDeferred.resolveWith(null);
return;
}

directory.getContents(function (err, contents) {
if (!file instanceof InMemoryFile) {
FileSystem.resolve(dir, function (err, directory) {
if (err) {
console.error("Error getting contents for", directory);
console.error("Error resolving", dir);
addFilesDeferred.resolveWith(null);
return;
}

var files = contents
.filter(function (entry) {
return entry.isFile && !isFileExcluded(entry);
})
.map(function (entry) {
return entry.fullPath;
});
directory.getContents(function (err, contents) {
if (err) {
console.error("Error getting contents for", directory);
addFilesDeferred.resolveWith(null);
return;
}

initTernServer(dir, files);

var hintsPromise = primePump(path);
hintsPromise.done(function () {
if (!usingModules()) {
// Read the subdirectories of the new file's directory.
// Read them first in case there are too many files to
// read in the project.
addAllFilesAndSubdirectories(dir, function () {
// If the file is in the project root, then read
// all the files under the project root.
var currentDir = (dir + "/");
if (projectRoot && currentDir !== projectRoot &&
currentDir.indexOf(projectRoot) === 0) {
addAllFilesAndSubdirectories(projectRoot, function () {
// prime the pump again but this time don't wait
// for completion.
primePump(path);
var files = contents
.filter(function (entry) {
return entry.isFile && !isFileExcluded(entry);
})
.map(function (entry) {
return entry.fullPath;
});

initTernServer(dir, files);

var hintsPromise = primePump(path);
hintsPromise.done(function () {
if (!usingModules()) {
// Read the subdirectories of the new file's directory.
// Read them first in case there are too many files to
// read in the project.
addAllFilesAndSubdirectories(dir, function () {
// If the file is in the project root, then read
// all the files under the project root.
var currentDir = (dir + "/");
if (projectRoot && currentDir !== projectRoot &&
currentDir.indexOf(projectRoot) === 0) {
addAllFilesAndSubdirectories(projectRoot, function () {
// prime the pump again but this time don't wait
// for completion.
primePump(path);

addFilesDeferred.resolveWith(null, [_ternWorker]);
});
} else {
addFilesDeferred.resolveWith(null, [_ternWorker]);
});
} else {
addFilesDeferred.resolveWith(null, [_ternWorker]);
}
});
} else {
addFilesDeferred.resolveWith(null, [_ternWorker]);
}
}
});
} else {
addFilesDeferred.resolveWith(null, [_ternWorker]);
}
});
});
});
});
} else {
initTernServer(pr, []);
primePump(path);
addFilesDeferred.resolveWith(null, [_ternWorker]);
}
});
}

Expand Down
6 changes: 4 additions & 2 deletions src/search/FindInFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,11 +452,13 @@ define(function (require, exports, module) {
*/
function _updateDocumentInNode(docPath) {
DocumentManager.getDocumentForPath(docPath).done(function (doc) {
var updateObject = {
if (doc) {
var updateObject = {
"filePath": docPath,
"docContents": doc.getText()
};
searchDomain.exec("documentChanged", updateObject);
searchDomain.exec("documentChanged", updateObject);
}
});
}

Expand Down
14 changes: 9 additions & 5 deletions src/view/MainViewManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -1273,11 +1273,15 @@ define(function (require, exports, module) {
} else {
DocumentManager.getDocumentForPath(file.fullPath)
.done(function (doc) {
_edit(paneId, doc, $.extend({}, options, {
noPaneActivate: true
}));
doPostOpenActivation();
result.resolve(doc.file);
if (doc) {
_edit(paneId, doc, $.extend({}, options, {
noPaneActivate: true
}));
doPostOpenActivation();
result.resolve(doc.file);
} else {
result.resolve(null);
}
})
.fail(function (fileError) {
result.reject(fileError);
Expand Down

0 comments on commit 7883b01

Please sign in to comment.