This repository has been archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
"Show in Tree" command #1823
Merged
Merged
"Show in Tree" command #1823
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ define(function (require, exports, module) { | |
FileViewController = require("project/FileViewController"), | ||
PerfUtils = require("utils/PerfUtils"), | ||
ViewUtils = require("utils/ViewUtils"), | ||
CollectionUtils = require("utils/CollectionUtils"), | ||
FileUtils = require("file/FileUtils"), | ||
Urls = require("i18n!nls/urls"), | ||
KeyEvent = require("utils/KeyEvent"); | ||
|
@@ -765,7 +766,75 @@ define(function (require, exports, module) { | |
|
||
return result.promise(); | ||
} | ||
|
||
|
||
|
||
/** | ||
* Returns the tree node corresponding to the given file/folder. Returns null if the path lies | ||
* outside the project, or if it doesn't exist. | ||
* | ||
* @param {!Entry} entry FileEntry of DirectoryEntry to show | ||
* @return {$.Promise} Resolved with jQ obj for the jsTree tree node; or rejected if not found | ||
*/ | ||
function _findTreeNode(entry) { | ||
var projRelativePath = makeProjectRelativeIfPossible(entry.fullPath); | ||
var treeAPI = $.jstree._reference(_projectTree); | ||
var result = new $.Deferred(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no need to get treeAPI or to create a Deferred object until after you have verified that the file is within the project. |
||
|
||
// If path not within project, ignore | ||
if (projRelativePath === entry.fullPath) { | ||
return null; | ||
} | ||
|
||
// We're going to traverse from root of tree, one segment at a time | ||
var pathSegments = projRelativePath.split("/"); | ||
|
||
function findInSubtree($nodes, segmentI) { | ||
var seg = pathSegments[segmentI]; | ||
var match = CollectionUtils.indexOf($nodes, function (node, i) { | ||
var nodeName = $(node).data("entry").name; | ||
return nodeName === seg; | ||
}); | ||
|
||
if (match === -1) { | ||
result.reject(); // path doesn't exist | ||
} else { | ||
var $node = $nodes.eq(match); | ||
if (segmentI === pathSegments.length - 1) { | ||
result.resolve($node); // done searching! | ||
} else { | ||
// Search next level down | ||
var subChildren = treeAPI._get_children($node); | ||
if (subChildren.length > 0) { | ||
findInSubtree(subChildren, segmentI + 1); | ||
} else { | ||
// Subtree not loaded yet: force async load & try again | ||
treeAPI.load_node($node, function (data) { | ||
subChildren = treeAPI._get_children($node); | ||
findInSubtree(subChildren, segmentI + 1); | ||
}, function (err) { | ||
result.reject(); // includes case where folder is empty | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Begin searching from root | ||
var topLevelNodes = treeAPI._get_children(-1); // -1 means top level in jsTree-ese | ||
findInSubtree(topLevelNodes, 0); | ||
|
||
return result.promise(); | ||
} | ||
|
||
function showInTree(fileEntry) { | ||
_findTreeNode(fileEntry) | ||
.done(function ($node) { | ||
// jsTree will automatically expand parent nodes to ensure visible | ||
_projectTree.jstree("select_node", $node, false); | ||
}); | ||
} | ||
|
||
|
||
/** | ||
* Open a new project. Currently, Brackets must always have a project open, so | ||
* this method handles both closing the current project and opening a new project. | ||
|
@@ -1194,4 +1263,5 @@ define(function (require, exports, module) { | |
exports.createNewItem = createNewItem; | ||
exports.renameSelectedItem = renameSelectedItem; | ||
exports.forceFinishRename = forceFinishRename; | ||
exports.showInTree = showInTree; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */ | ||
/*global define, $ */ | ||
|
||
/** | ||
* Utilities functions related to data collections (arrays & maps) | ||
*/ | ||
define(function (require, exports, module) { | ||
"use strict"; | ||
|
||
/** | ||
* Returns the first index in 'array' for which isMatch() returns true, or -1 if none | ||
* @param {!Array.<*>|jQueryObject} array | ||
* @param {!function(*, Number):boolean} isMatch Passed (item, index), same as with forEach() | ||
*/ | ||
function indexOf(array, isMatch) { | ||
// Old-fashioned loop, instead of Array.some, to support jQuery "arrays" | ||
var i; | ||
for (i = 0; i < array.length; i++) { | ||
if (isMatch(array[i], i)) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
} | ||
|
||
|
||
// Define public API | ||
exports.indexOf = indexOf; | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a little generic. Maybe "Show in Project Tree" or "Show in Project Panel"?