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

Commit

Permalink
New File and New Folder execute in project root if there's no selecti…
Browse files Browse the repository at this point in the history
…on (#12752)

* New File and New Folder execute in project root if there's no selection

* Add ProjectManager.getSelectedFileTreeItem

* Add function to get file tree context instead
  • Loading branch information
Marcel Gerber authored and ficristo committed Jun 27, 2017
1 parent 0cb4716 commit 1b64b1e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/document/DocumentCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,10 +642,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();
selected = ProjectManager.getFileTreeContext();
if ((!selected) || (selected instanceof InMemoryFile)) {
selected = ProjectManager.getProjectRoot();
}
Expand Down
14 changes: 12 additions & 2 deletions src/project/ProjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,15 @@ 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 that was right-clicked on in the file tree menu.
* @return {?(File|Directory)}
*/
function getFileTreeContext() {
var selectedEntry = model.getContext();
return selectedEntry;
}

/**
* Returns the File or Directory corresponding to the item selected in the sidebar panel, whether in
Expand All @@ -391,8 +400,8 @@ define(function (require, exports, module) {
* @return {?(File|Directory)}
*/
function getSelectedItem() {
// Prefer file tree context, then selection, else use working set
var selectedEntry = model.getContext();
// Prefer file tree context, then file tree selection, else use working set
var selectedEntry = getFileTreeContext();
if (!selectedEntry) {
selectedEntry = model.getSelected();
}
Expand Down Expand Up @@ -1396,6 +1405,7 @@ define(function (require, exports, module) {
exports.makeProjectRelativeIfPossible = makeProjectRelativeIfPossible;
exports.shouldShow = ProjectModel.shouldShow;
exports.openProject = openProject;
exports.getFileTreeContext = getFileTreeContext;
exports.getSelectedItem = getSelectedItem;
exports.getContext = getContext;
exports.getInitialProjectPath = getInitialProjectPath;
Expand Down

0 comments on commit 1b64b1e

Please sign in to comment.