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

Remove MVM._edit, etc... #9677

Merged
merged 1 commit into from
Oct 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/LiveDevelopment/Agents/GotoAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ define(function GotoAgent(require, exports, module) {

require("utils/Global");

var Inspector = require("LiveDevelopment/Inspector/Inspector");
var DOMAgent = require("LiveDevelopment/Agents/DOMAgent");
var ScriptAgent = require("LiveDevelopment/Agents/ScriptAgent");
var RemoteAgent = require("LiveDevelopment/Agents/RemoteAgent");

var DocumentManager = require("document/DocumentManager");
var EditorManager = require("editor/EditorManager");
var MainViewManager = require("view/MainViewManager");
var Inspector = require("LiveDevelopment/Inspector/Inspector"),
DOMAgent = require("LiveDevelopment/Agents/DOMAgent"),
ScriptAgent = require("LiveDevelopment/Agents/ScriptAgent"),
RemoteAgent = require("LiveDevelopment/Agents/RemoteAgent"),
EditorManager = require("editor/EditorManager"),
CommandManager = require("command/CommandManager"),
Commands = require("command/Commands");


/** Return the URL without the query string
* @param {string} URL
Expand Down Expand Up @@ -168,9 +168,8 @@ define(function GotoAgent(require, exports, module) {
var path = url.slice(brackets.platform === "win" ? 8 : 7);
// URL-decode the path ('%20' => ' ')
path = decodeURI(path);
var promise = DocumentManager.getDocumentForPath(path);
var promise = CommandManager.execute(Commands.FILE_OPEN, {fullPath: path});
promise.done(function onDone(doc) {
MainViewManager._edit(MainViewManager.ACTIVE_PANE, doc);
if (location) {
openLocation(location, noFlash);
}
Expand Down
18 changes: 18 additions & 0 deletions src/document/DocumentManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,24 @@ define(function (require, exports, module) {
$(exports).triggerHandler("dirtyFlagChange", doc);
if (doc.isDirty) {
MainViewManager.addToWorkingSet(MainViewManager.ACTIVE_PANE, doc.file);

// We just dirtied a doc and added it to the active working set
// this may have come from an internal dirtying so if it was
// added to a working set that had no active document then
// open the document
//
// See: https://github.com/adobe/brackets/issues/9569
//
// NOTE: Adding a file to the active working set may not actually add
// it to the active working set (e.g. the document was already
// opened to the inactive working set.)
//
// Check that it was actually added to the active working set

if (!MainViewManager.getCurrentlyViewedFile() &&
MainViewManager.findInWorkingSet(MainViewManager.ACTIVE_PANE, doc.file.fullPath) !== -1) {
CommandManager.execute(Commands.FILE_OPEN, {fullPath: doc.file.fullPath});
}
}
})
.on("_documentSaved", function (event, doc) {
Expand Down
10 changes: 10 additions & 0 deletions src/search/FindUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,16 @@ define(function (require, exports, module) {
var newDoc = DocumentManager.getOpenDocumentForPath(firstPath);
// newDoc might be null if the replacement failed.
if (newDoc) {
// @todo change the `_edit` call to this:
//
/// CommandManager.execute(Commands.FILE_OPEN, {fullPath: firstPath});
//
// The problem with doing that is that the promise returned by this
// function has already been resolved by `Async.doInParallel()` and
// `CommandManager.execute` is an asynchronous operation.
// An asynchronous open can't be waited on (since the promise has been
// resolved already) so use the synchronous version so that the next `done`
// handler is blocked until the open completes
MainViewManager._edit(MainViewManager.ACTIVE_PANE, newDoc);
}
}
Expand Down
27 changes: 9 additions & 18 deletions src/view/MainViewManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -1120,28 +1120,20 @@ define(function (require, exports, module) {

/**
* Edits a document in the specified pane.
* This function is only used by Unit Tests (which construct Mock Documents),
* The Deprecated API "setCurrentDocument" and by File > New
* because there is yet to be an established File object for the Document which is required
* for the open API.
* Do not use this API unless you have a document object without a file object
* This function is only used by:
* - Unit Tests (which construct Mock Document objects),
* - by File > New because there is yet to be an established File object
* - by Find In Files which needs to open documents synchronously in some cases
* Do not use this API it is for internal use only
* @param {!string} paneId - id of the pane in which to open the document
* @param {!Document} doc - document to edit
* @param {{noPaneActivate:boolean=, noPaneRedundancyCheck:boolean=}=} optionsIn - options
* @param {{noPaneActivate:boolean=}=} optionsIn - options
* @private
*/
function _edit(paneId, doc, optionsIn) {
var options = optionsIn || {},
currentPaneId;
currentPaneId = _getPaneIdForPath(doc.file.fullPath);

if (options.noPaneRedundancyCheck) {
// This flag is for internal use only to improve performance
// Don't check for the file to have been opened in another pane pane which could be time
// consuming. should only be used when passing an actual paneId (not a special paneId)
// and the caller has already done a redundancy check.
currentPaneId = _getPaneIdForPath(doc.file.fullPath);
}

if (currentPaneId) {
// If the doc is open in another pane then switch to that pane and call open document
// which will really just show the view as it has always done we could just
Expand Down Expand Up @@ -1172,7 +1164,7 @@ define(function (require, exports, module) {
* or a document for editing. If it's a document for editing, edit is called on the document
* @param {!string} paneId - id of the pane in which to open the document
* @param {!File} file - file to open
* @param {{noPaneActivate:boolean=, noPaneRedundancyCheck:boolean=}=} optionsIn - options
* @param {{noPaneActivate:boolean=}=} optionsIn - options
* @return {jQuery.Promise} promise that resolves to a File object or
* rejects with a File error or string
*/
Expand Down Expand Up @@ -1250,8 +1242,7 @@ define(function (require, exports, module) {
DocumentManager.getDocumentForPath(file.fullPath)
.done(function (doc) {
_edit(paneId, doc, $.extend({}, options, {
noPaneActivate: true,
noPaneRedundancyCheck: true
noPaneActivate: true
}));
doPostOpenActivation();
result.resolve(doc.file);
Expand Down
19 changes: 15 additions & 4 deletions test/spec/FindInFiles-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1636,20 +1636,31 @@ define(function (require, exports, module) {
it("should select the first modified file in the working set if replacements are done in memory and no editor was open", function () {
openTestProjectCopy(defaultSourcePath);

var testFiles = ["/css/foo.css", "/foo.html", "/foo.js"];

doInMemoryTest({
queryInfo: {query: "foo"},
numMatches: 14,
replaceText: "bar",
knownGoodFolder: "unchanged",
forceFilesOpen: true,
inMemoryFiles: ["/css/foo.css", "/foo.html", "/foo.js"],
inMemoryFiles: testFiles,
inMemoryKGFolder: "simple-case-insensitive"
});


runs(function () {
var expectedFile = testPath + "/foo.html";
expect(DocumentManager.getCurrentDocument().file.fullPath).toBe(expectedFile);
expect(MainViewManager.findInWorkingSet(MainViewManager.ACTIVE_PANE, expectedFile)).not.toBe(-1);
// since nothing was opened prior to doing the
// replacements then the first file modified will be opened.
// This may not be the first item in the array above
// since the files are sorted differently in performReplacements
// and the replace is performed asynchronously.
// So, just ensure that *something* was opened
expect(DocumentManager.getCurrentDocument().file.fullPath).toBeTruthy();

testFiles.forEach(function (relPath) {
expect(MainViewManager.findInWorkingSet(MainViewManager.ACTIVE_PANE, testPath + relPath)).not.toBe(-1);
});
});
});

Expand Down