mirror of
https://github.com/adobe/brackets.git
synced 2024-11-20 18:02:54 +01:00
made corrections after NJ's code review
This commit is contained in:
parent
81cc9cbba5
commit
489f41fc23
105
src/brackets.js
105
src/brackets.js
@ -6,10 +6,6 @@ $(document).ready(function() {
|
||||
value: 'var myResponse="Yes, it will be!"\n'
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Set the "inBrowser" flag
|
||||
var inBrowser = !window.hasOwnProperty("brackets");
|
||||
|
||||
@ -17,58 +13,59 @@ $(document).ready(function() {
|
||||
// Temporary button to test file directory traversa;
|
||||
$("#open-folder").click(function(){
|
||||
if (!inBrowser) {
|
||||
var foldername = "/Users/tvoliter/github/brackets-app/brackets"; // brackets.file.showOpenPanel(false, true, "Choose a folder");
|
||||
|
||||
if (foldername != "")
|
||||
var rootEntry = window.ProjectManager.requestNativeFileSystem( foldername, null, null ); // TODO: add callbacks
|
||||
|
||||
var nestingLevel = 0;
|
||||
|
||||
if( rootEntry.isDirectory )
|
||||
readDirectory( rootEntry )
|
||||
|
||||
|
||||
|
||||
// Test directory traversal
|
||||
function readDirectory( entry ){
|
||||
|
||||
|
||||
var reader = entry.createReader();
|
||||
reader.readEntries( dirReaderSuccessCB, dirReaderErrorCB);
|
||||
}
|
||||
|
||||
function dirReaderSuccessCB( entries ){
|
||||
var tabs = "";
|
||||
for( i = 0; i < nestingLevel; i++ ){
|
||||
tabs += " ";
|
||||
}
|
||||
|
||||
for ( var entryI in entries ){
|
||||
var entry = entries[entryI];
|
||||
if( entry.isFile ){
|
||||
// create leaf tree node using entry.name
|
||||
console.log( tabs+ entry.name );
|
||||
}
|
||||
else if ( entry.isDirectory ){
|
||||
// create branch tree node using entry.name
|
||||
console.log( tabs + entry.name );
|
||||
|
||||
nestingLevel++;
|
||||
readDirectory( entry )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function dirReaderErrorCB() {
|
||||
// handle error
|
||||
}
|
||||
|
||||
|
||||
|
||||
window.ProjectManager.showOpenPanel(false, true, "Choose a folder", null, "[*]",showOpenPanelCallback);
|
||||
}
|
||||
});
|
||||
|
||||
function showOpenPanelCallback( files ) {
|
||||
|
||||
|
||||
var folderName = files instanceof Array ? files[0] : files;
|
||||
|
||||
if (folderName != "")
|
||||
var rootEntry = window.ProjectManager.requestNativeFileSystem( folderName, null, null ); // TODO: add callbacks
|
||||
|
||||
var nestingLevel = 0;
|
||||
|
||||
if( rootEntry.isDirectory )
|
||||
readDirectory( rootEntry )
|
||||
|
||||
|
||||
|
||||
// Test directory traversal
|
||||
function readDirectory( entry ){
|
||||
|
||||
|
||||
var reader = entry.createReader();
|
||||
reader.readEntries( dirReaderSuccessCB, dirReaderErrorCB);
|
||||
}
|
||||
|
||||
function dirReaderSuccessCB( entries ){
|
||||
var tabs = "";
|
||||
for( i = 0; i < nestingLevel; i++ ){
|
||||
tabs += " ";
|
||||
}
|
||||
|
||||
for ( var entryI in entries ){
|
||||
var entry = entries[entryI];
|
||||
if( entry.isFile ){
|
||||
// create leaf tree node using entry.name
|
||||
console.log( tabs+ entry.name );
|
||||
}
|
||||
else if ( entry.isDirectory ){
|
||||
// create branch tree node using entry.name
|
||||
console.log( tabs + entry.name );
|
||||
|
||||
nestingLevel++;
|
||||
readDirectory( entry )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function dirReaderErrorCB() {
|
||||
// handle error
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -3,55 +3,43 @@
|
||||
window.ProjectManager = {
|
||||
|
||||
|
||||
/**
|
||||
* TODO: param docs
|
||||
*/
|
||||
showOpenDialog: function ( allowMultipleSelection,
|
||||
/** showOpenPanel
|
||||
*
|
||||
* @param {bool} allowMultipleSelection
|
||||
* @param {bool} chooseDirectories
|
||||
* @param {string} title
|
||||
* @param {string} initialPath
|
||||
* @param {string[]} fileTypes
|
||||
* @param {function} resultCallback
|
||||
* @constructor
|
||||
*/
|
||||
showOpenPanel: function ( allowMultipleSelection,
|
||||
chooseDirectories,
|
||||
title,
|
||||
initialPath,
|
||||
fileTypes,
|
||||
resultCallback ) {
|
||||
|
||||
var showOpenDialogCallback = resultCallback;
|
||||
|
||||
// Default parameter values
|
||||
if( allowMultipleSelection == undefined )
|
||||
allowMultipleSelection = false;
|
||||
if( chooseDirectories == undefined )
|
||||
chooseDirectories = false;
|
||||
if( title == undefined )
|
||||
title = "Choose File";
|
||||
if( initialPath == undefined )
|
||||
initialPath = null;
|
||||
if( fileTypes == undefined || fileTypes.length == 0 )
|
||||
fileTypes = ["*"];
|
||||
|
||||
// TODO: errow when callback is null
|
||||
if( resultCallback )
|
||||
|
||||
if( !resultCallback )
|
||||
return null;
|
||||
|
||||
var files = brackets.file.showOpenDialog( allowMultipleSelection,
|
||||
var files = brackets.file.showOpenPanel( allowMultipleSelection,
|
||||
chooseDirectories,
|
||||
title,
|
||||
initialPath,
|
||||
fileTypes );
|
||||
|
||||
|
||||
// native implemenation of brackets.file.showOpenDialog should asynchronously
|
||||
// call back showOpenDialogCallback
|
||||
resultCallback( files );
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* TODO: param docs
|
||||
*/
|
||||
showOpenDialogCallback: function( files ){
|
||||
showOpenDialogCallback( files );
|
||||
},
|
||||
|
||||
/**
|
||||
* TODO: param docs
|
||||
|
||||
/** requestNativeFileSystem
|
||||
*
|
||||
* @param {string} path
|
||||
* @param {function} successCallback
|
||||
* @param {function} errorCallback
|
||||
*/
|
||||
requestNativeFileSystem: function( path, successCallback, errorCallback ){
|
||||
|
||||
@ -143,28 +131,24 @@ DirectoryEntry.prototype.createReader = function() {
|
||||
/** class: DirectoryReader
|
||||
*/
|
||||
DirectoryReader = function() {
|
||||
this._directory = null;
|
||||
this._successCallback = null;
|
||||
this._successCallback = null;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/** readEntires
|
||||
*
|
||||
* @param successCallback
|
||||
* @param errorCallback
|
||||
* @param {function} successCallback
|
||||
* @param {function} errorCallback
|
||||
* @returns {Entry[]}
|
||||
*/
|
||||
DirectoryReader.prototype.readEntries = function( successCallback, errorCallback ){
|
||||
this._successCallback = successCallback;
|
||||
this._errorCallback = errorCallback;
|
||||
|
||||
var jsonList = brackets.file.getDirectoryListing( this._directory.fullPath);
|
||||
var rootPath = this._directory.fullPath;
|
||||
var jsonList = brackets.file.getDirectoryListing( rootPath );
|
||||
var nameList = JSON.parse(jsonList);
|
||||
var entries = [];
|
||||
var rootPath = this._directory.fullPath;
|
||||
|
||||
$(nameList).each(function(index, item){
|
||||
// Create entries for each name
|
||||
var entries = [];
|
||||
nameList.forEach(function(item){
|
||||
// Ignore names starting with "."
|
||||
if (item.indexOf(".") != 0) {
|
||||
var itemFullPath = rootPath + "/" + item;
|
||||
|
Loading…
Reference in New Issue
Block a user