Tracks whether a "currentFileChange" notification occured due to a call to openAndSelectDocument.
var _curDocChangedDueToMe = false;
var WORKING_SET_VIEW = "WorkingSetView";
var PROJECT_MANAGER = "ProjectManager";
function _activatePane(paneId) {
if (paneId) {
MainViewManager.setActivePaneId(paneId);
} else {
MainViewManager.focusActivePane();
}
// If fullPath corresonds to the current doc being viewed then opening the file won't
// trigger a currentFileChange event, so we need to trigger a documentSelectionFocusChange
// in this case to signify the selection focus has changed even though the current document has not.
exports.trigger("documentSelectionFocusChange");
}
Opens the specified document if it's not already open, adds it to the working set, and selects it in the WorkingSetView
function addToWorkingSetAndSelect(fullPath) {
DeprecationWarning.deprecationWarning("Use FileViewController.openFileAndAddToWorkingSet() instead of FileViewController.addToWorkingSetAndSelect().", true);
var result = new $.Deferred();
openFileAndAddToWorkingSet(fullPath)
.done(function (file) {
var doc;
if (file) {
doc = DocumentManager.getOpenDocumentForPath(file.fullPath);
}
result.resolve(doc);
})
.fail(function (err) {
result.reject(err);
});
return result.promise();
}
returns either WORKING_SET_VIEW or PROJECT_MANAGER
function getFileSelectionFocus() {
return _fileSelectionFocus;
}
EventDispatcher.makeEventDispatcher(exports);
// Deprecated
exports.addToWorkingSetAndSelect = addToWorkingSetAndSelect;
// Define public API
exports.getFileSelectionFocus = getFileSelectionFocus;
exports.openAndSelectDocument = openAndSelectDocument;
exports.openFileAndAddToWorkingSet = openFileAndAddToWorkingSet;
exports.setFileViewFocus = setFileViewFocus;
exports.WORKING_SET_VIEW = WORKING_SET_VIEW;
exports.PROJECT_MANAGER = PROJECT_MANAGER;
});
Opens a document if it's not open and selects the file in the UI corresponding to fileSelectionFocus
function openAndSelectDocument(fullPath, fileSelectionFocus, paneId) {
var result,
curDocChangedDueToMe = _curDocChangedDueToMe;
function _getDerivedPaneContext() {
function _secondPaneContext() {
return (window.event.ctrlKey || window.event.metaKey) && window.event.altKey ? MainViewManager.SECOND_PANE : null;
}
function _firstPaneContext() {
return (window.event.ctrlKey || window.event.metaKey) ? MainViewManager.FIRST_PANE : null;
}
return window.event && (_secondPaneContext() || _firstPaneContext());
}
if (fileSelectionFocus !== PROJECT_MANAGER && fileSelectionFocus !== WORKING_SET_VIEW) {
console.error("Bad parameter passed to FileViewController.openAndSelectDocument");
return;
}
// Opening files are asynchronous and we want to know when this function caused a file
// to open so that _fileSelectionFocus is set appropriatly. _curDocChangedDueToMe is set here
// and checked in the currentFileChange handler
_curDocChangedDueToMe = true;
_fileSelectionFocus = fileSelectionFocus;
paneId = (paneId || _getDerivedPaneContext() || MainViewManager.ACTIVE_PANE);
// If fullPath corresonds to the current doc being viewed then opening the file won't
// trigger a currentFileChange event, so we need to trigger a documentSelectionFocusChange
// in this case to signify the selection focus has changed even though the current document has not.
var currentPath = MainViewManager.getCurrentlyViewedPath(paneId);
if (currentPath === fullPath) {
_activatePane(paneId);
result = (new $.Deferred()).resolve().promise();
} else {
result = CommandManager.execute(Commands.FILE_OPEN, {fullPath: fullPath,
paneId: paneId});
}
// clear after notification is done
result.always(function () {
_curDocChangedDueToMe = curDocChangedDueToMe;
});
return result;
}
Opens the specified document if it's not already open, adds it to the working set, and selects it in the WorkingSetView
function openFileAndAddToWorkingSet(fullPath, paneId) {
var result = new $.Deferred(),
promise = CommandManager.execute(Commands.CMD_ADD_TO_WORKINGSET_AND_OPEN, {fullPath: fullPath,
paneId: paneId});
// This properly handles sending the right nofications in cases where the document
// is already the current one. In that case we will want to notify with
// documentSelectionFocusChange so the views change their selection
promise.done(function (file) {
// CMD_ADD_TO_WORKINGSET_AND_OPEN command sets the current document. Update the
// selection focus only if doc is not null. When double-clicking on an
// image file, we get a null doc here but we still want to keep _fileSelectionFocus
// as PROJECT_MANAGER. Regardless of doc is null or not, call _activatePane
// to trigger documentSelectionFocusChange event.
_fileSelectionFocus = WORKING_SET_VIEW;
_activatePane(paneId);
result.resolve(file);
}).fail(function (err) {
result.reject(err);
});
return result.promise();
}
Modifies the selection focus in the project side bar. A file can either be selected in the working set (the open files) or in the file tree, but not both.
function setFileViewFocus(fileSelectionFocus) {
if (fileSelectionFocus !== PROJECT_MANAGER && fileSelectionFocus !== WORKING_SET_VIEW) {
console.error("Bad parameter passed to FileViewController.setFileViewFocus");
return;
}
if (_fileSelectionFocus !== fileSelectionFocus) {
_fileSelectionFocus = fileSelectionFocus;
exports.trigger("fileViewFocusChange");
}
}