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

Commit

Permalink
Add ProjectManager.getSelectedFileTreeItem
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Gerber committed Jun 13, 2017
1 parent 32f1c06 commit 6954312
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
4 changes: 1 addition & 3 deletions src/document/DocumentCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,8 @@ define(function (require, exports, module) {
// If a file is currently selected in the tree, put it next to it.
// If a directory is currently selected in the tree, put it in it.
// If an Untitled document is selected or nothing is selected in the tree, put it at the root of the project.
// (Note: 'selected' may be an item that's selected in the workingset and not the tree; but in that case
// ProjectManager.createNewItem() ignores the baseDir we give it and falls back to the project root on its own)
var baseDirEntry,
selected = ProjectManager.getSelectedItem(false);
selected = ProjectManager.getSelectedFileTreeItem();
if ((!selected) || (selected instanceof InMemoryFile)) {
selected = ProjectManager.getProjectRoot();
}
Expand Down
30 changes: 19 additions & 11 deletions src/project/ProjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,26 +382,33 @@ define(function (require, exports, module) {
* Singleton actionCreator that is used for dispatching changes to the ProjectModel.
*/
var actionCreator = new ActionCreator(model);

/**
* Returns the File or Directory corresponding to the item selected in the file tree; or null if no
* file tree item is selected.
* MAY NOT be identical to the current Document - a folder may be selected in the file tree.
* @return {?(File|Directory)}
*/
function getSelectedFileTreeItem() {
// Prefer file tree context, else use file tree selection
var selectedEntry = model.getContext();
if (!selectedEntry) {
selectedEntry = model.getSelected();
}
return selectedEntry;
}

/**
* Returns the File or Directory corresponding to the item selected in the sidebar panel, whether in
* the file tree OR in the working set; or null if no item is selected anywhere in the sidebar.
* May NOT be identical to the current Document - a folder may be selected in the sidebar, or the sidebar may not
* have the current document visible in the tree & working set.
* @param {boolean=} includeWorkingSet If true, fall back to the working set item that is selected if there's
* no selected file tree item (default behaviour)
* @return {?(File|Directory)}
*/
function getSelectedItem(includeWorkingSet) {
if (includeWorkingSet === undefined) {
includeWorkingSet = true;
}
// Prefer file tree context, then selection, else use working set
var selectedEntry = model.getContext();
function getSelectedItem() {
// Prefer file tree, else use working set
var selectedEntry = getSelectedFileTreeItem();
if (!selectedEntry) {
selectedEntry = model.getSelected();
}
if (!selectedEntry && includeWorkingSet) {
selectedEntry = MainViewManager.getCurrentlyViewedFile();
}
return selectedEntry;
Expand Down Expand Up @@ -1401,6 +1408,7 @@ define(function (require, exports, module) {
exports.makeProjectRelativeIfPossible = makeProjectRelativeIfPossible;
exports.shouldShow = ProjectModel.shouldShow;
exports.openProject = openProject;
exports.getSelectedFileTreeItem = getSelectedFileTreeItem;
exports.getSelectedItem = getSelectedItem;
exports.getContext = getContext;
exports.getInitialProjectPath = getInitialProjectPath;
Expand Down

0 comments on commit 6954312

Please sign in to comment.