From 81cc9cbba5b6d3c4cdbdf32f6bf525958b309c30 Mon Sep 17 00:00:00 2001 From: Ty Voliter Date: Mon, 12 Dec 2011 12:08:11 -0800 Subject: [PATCH 1/7] Checking in initial fileIO.js implementation --- src/brackets.js | 67 ++++++++++++++++- src/fileIO.js | 189 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 255 insertions(+), 1 deletion(-) create mode 100644 src/fileIO.js diff --git a/src/brackets.js b/src/brackets.js index 5057bd40324..9b406775ef3 100644 --- a/src/brackets.js +++ b/src/brackets.js @@ -1,9 +1,74 @@ /* TODO: copyright notice, etc. */ $(document).ready(function() { + var myCodeMirror = CodeMirror($('#editor').get(0), { value: 'var myResponse="Yes, it will be!"\n' }); - // TODO: Write Brackets. + + + + + // Set the "inBrowser" flag + var inBrowser = !window.hasOwnProperty("brackets"); + + + // 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 + } + + + + } + }); + + }); diff --git a/src/fileIO.js b/src/fileIO.js new file mode 100644 index 00000000000..943a1386bac --- /dev/null +++ b/src/fileIO.js @@ -0,0 +1,189 @@ + + +window.ProjectManager = { + + + /** + * TODO: param docs + */ + showOpenDialog: 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 ) + return null; + + var files = brackets.file.showOpenDialog( allowMultipleSelection, + chooseDirectories, + title, + initialPath, + fileTypes ); + + + // native implemenation of brackets.file.showOpenDialog should asynchronously + // call back showOpenDialogCallback + + }, + + /** + * TODO: param docs + */ + showOpenDialogCallback: function( files ){ + showOpenDialogCallback( files ); + }, + + /** + * TODO: param docs + */ + requestNativeFileSystem: function( path, successCallback, errorCallback ){ + + // TODO: assumes path is a directory right now. Need to error check + // TODO: don't actually need to get the listing here, but should verify the directory exists + var entryList = brackets.file.getDirectoryListing(path); + var files = JSON.parse(entryList); + + + var root = new DirectoryEntry( path ); + + + return root; + } +}; + + +/** class: Entry + * + * @param {string} name + * @param {string} isFile + * @constructor + */ +Entry = function( fullPath, isDirectory) { + this.isDirectory = isDirectory; + this.isFile = !isDirectory; + // IMPLEMENT LATER void getMetadata (MetadataCallback successCallback, optional ErrorCallback errorCallback); + this.fullPath = fullPath; + + // Extract name from fullPath + this.name = null; // default if extraction fails + if( fullPath ){ + var pathParts = fullPath.split( "/" ); + if( pathParts.length > 0 ) + this.name = pathParts.pop(); + } + + // IMPLEMENT LATERvar filesystem; + // IMPLEMENT LATER void moveTo (DirectoryEntry parent, optional DOMString newName, optional EntryCallback successCallback, optional ErrorCallback errorCallback); + // IMPLEMENT LATER void copyTo (DirectoryEntry parent, optional DOMString newName, optional EntryCallback successCallback, optional ErrorCallback errorCallback); + // IMPLEMENT LATER DOMString toURL (optional DOMString mimeType); + // IMPLEMENT LATER void remove (VoidCallback successCallback, optional ErrorCallback errorCallback); + // IMPLEMENT LATER void getParent (EntryCallback successCallback, optional ErrorCallback errorCallback); +}; + + + +/** class: FileEntry + * + * @param {string} name + * @constructor + * @extends {Entry} + */ +FileEntry = function( name ) { + Entry.call(this, name, false); + + // TODO: make FileEntry actually inherit from Entry by modifying prototype. I don't know how to do this yet. + + // IMPLEMENT LATER void createWriter (FileWriterCallback successCallback, optional ErrorCallback errorCallback); + // IMPLEMENT LATER void file (FileCallback successCallback, optional ErrorCallback errorCallback); +}; + + +/** class: DirectoryEntry + * + * @param {string} name + * @constructor + * @extends {Entry} + */ +DirectoryEntry = function( name ) { + Entry.call(this, name, true); + + // TODO: make DirectoryEntry actually inherit from Entry by modifying prototype. I don't know how to do this yet. + + // IMPLEMENT LATERvoid getFile (DOMString path, optional Flags options, optional EntryCallback successCallback, optional ErrorCallback errorCallback); + // IMPLEMENT LATERvoid getDirectory (DOMString path, optional Flags options, optional EntryCallback successCallback, optional ErrorCallback errorCallback); + // IMPLEMENT LATERvoid removeRecursively (VoidCallback successCallback, optional ErrorCallback errorCallback); +}; + + +DirectoryEntry.prototype.createReader = function() { + var dirReader = new DirectoryReader(); + dirReader._directory = this; + + return dirReader; +}; + + +/** class: DirectoryReader + */ +DirectoryReader = function() { + this._directory = null; + this._successCallback = null; + this._successCallback = null; +}; + + +/** readEntires + * + * @param successCallback + * @param errorCallback + * @returns {Entry[]} + */ +DirectoryReader.prototype.readEntries = function( successCallback, errorCallback ){ + this._successCallback = successCallback; + this._errorCallback = errorCallback; + + var jsonList = brackets.file.getDirectoryListing( this._directory.fullPath); + var nameList = JSON.parse(jsonList); + var entries = []; + var rootPath = this._directory.fullPath; + + $(nameList).each(function(index, item){ + // Ignore names starting with "." + if (item.indexOf(".") != 0) { + var itemFullPath = rootPath + "/" + item; + + if( brackets.file.isDirectory( itemFullPath ) ) { + entries.push( new DirectoryEntry( itemFullPath ) ); + } + else { + entries.push( new FileEntry( itemFullPath ) ); + } + } + }); + + + + successCallback( entries ); + + // TODO: error handling +}; + + + From 489f41fc23d998a82adbd7bb841f01088d3b7014 Mon Sep 17 00:00:00 2001 From: Ty Voliter Date: Mon, 12 Dec 2011 14:23:37 -0800 Subject: [PATCH 2/7] made corrections after NJ's code review --- src/brackets.js | 99 ++++++++++++++++++++++++------------------------- src/fileIO.js | 74 +++++++++++++++--------------------- 2 files changed, 77 insertions(+), 96 deletions(-) diff --git a/src/brackets.js b/src/brackets.js index 9b406775ef3..bb680c4afa4 100644 --- a/src/brackets.js +++ b/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 ){ - + 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); + + var reader = entry.createReader(); + reader.readEntries( dirReaderSuccessCB, dirReaderErrorCB); + } + + function dirReaderSuccessCB( entries ){ + var tabs = ""; + for( i = 0; i < nestingLevel; i++ ){ + tabs += " "; } - - 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 ); } - - 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 ) - } + else if ( entry.isDirectory ){ + // create branch tree node using entry.name + console.log( tabs + entry.name ); + + nestingLevel++; + readDirectory( entry ) } } + } - - - function dirReaderErrorCB() { - // handle error - } - - - + + function dirReaderErrorCB() { + // handle error } - }); - - + } + }); diff --git a/src/fileIO.js b/src/fileIO.js index 943a1386bac..82ec97814d3 100644 --- a/src/fileIO.js +++ b/src/fileIO.js @@ -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; From 92130baedc6bea298ffb82c2307149b6ca439aac Mon Sep 17 00:00:00 2001 From: Ty Voliter Date: Mon, 12 Dec 2011 15:22:44 -0800 Subject: [PATCH 3/7] Changed tabs to spaces and changed fileIO.js to use showOpenDialog instead of showOpenPanel --- src/brackets.js | 124 +++++++++++++++++----------------- src/fileIO.js | 176 ++++++++++++++++++++++++------------------------ 2 files changed, 150 insertions(+), 150 deletions(-) diff --git a/src/brackets.js b/src/brackets.js index bb680c4afa4..bc2c7e250f3 100644 --- a/src/brackets.js +++ b/src/brackets.js @@ -2,70 +2,70 @@ $(document).ready(function() { - var myCodeMirror = CodeMirror($('#editor').get(0), { - value: 'var myResponse="Yes, it will be!"\n' - }); + var myCodeMirror = CodeMirror($('#editor').get(0), { + value: 'var myResponse="Yes, it will be!"\n' + }); - // Set the "inBrowser" flag - var inBrowser = !window.hasOwnProperty("brackets"); + // Set the "inBrowser" flag + var inBrowser = !window.hasOwnProperty("brackets"); - // Temporary button to test file directory traversa; - $("#open-folder").click(function(){ - if (!inBrowser) { - 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 ) - } - } - } + // Temporary button to test file directory traversa; + $("#open-folder").click(function(){ + if (!inBrowser) { + window.ProjectManager.showOpenDialog(false, true, "Choose a folder", null, null,showOpenDialogCallback); + } + }); + + function showOpenDialogCallback( 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 - } - } - + + function dirReaderErrorCB() { + // handle error + } + } + }); diff --git a/src/fileIO.js b/src/fileIO.js index 82ec97814d3..aa9a301bc3b 100644 --- a/src/fileIO.js +++ b/src/fileIO.js @@ -3,57 +3,57 @@ window.ProjectManager = { - /** 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 ) { - - if( !resultCallback ) - return null; - - var files = brackets.file.showOpenPanel( allowMultipleSelection, - chooseDirectories, - title, - initialPath, - fileTypes ); - - - resultCallback( files ); - - }, - - - /** requestNativeFileSystem - * - * @param {string} path + /** showOpenDialog + * + * @param {bool} allowMultipleSelection + * @param {bool} chooseDirectories + * @param {string} title + * @param {string} initialPath + * @param {string[]} fileTypes + * @param {function} resultCallback + * @constructor + */ + showOpenDialog: function ( allowMultipleSelection, + chooseDirectories, + title, + initialPath, + fileTypes, + resultCallback ) { + + if( !resultCallback ) + return null; + + var files = brackets.file.showOpenDialog( allowMultipleSelection, + chooseDirectories, + title, + initialPath, + fileTypes, + resultCallback ); + + + + }, + + + /** requestNativeFileSystem + * + * @param {string} path * @param {function} successCallback * @param {function} errorCallback */ - requestNativeFileSystem: function( path, successCallback, errorCallback ){ - - // TODO: assumes path is a directory right now. Need to error check - // TODO: don't actually need to get the listing here, but should verify the directory exists - var entryList = brackets.file.getDirectoryListing(path); - var files = JSON.parse(entryList); - - - var root = new DirectoryEntry( path ); - - - return root; - } + requestNativeFileSystem: function( path, successCallback, errorCallback ){ + + // TODO: assumes path is a directory right now. Need to error check + // TODO: don't actually need to get the listing here, but should verify the directory exists + var entryList = brackets.file.getDirectoryListing(path); + var files = JSON.parse(entryList); + + + var root = new DirectoryEntry( path ); + + + return root; + } }; @@ -72,11 +72,11 @@ Entry = function( fullPath, isDirectory) { // Extract name from fullPath this.name = null; // default if extraction fails if( fullPath ){ - var pathParts = fullPath.split( "/" ); - if( pathParts.length > 0 ) - this.name = pathParts.pop(); + var pathParts = fullPath.split( "/" ); + if( pathParts.length > 0 ) + this.name = pathParts.pop(); } - + // IMPLEMENT LATERvar filesystem; // IMPLEMENT LATER void moveTo (DirectoryEntry parent, optional DOMString newName, optional EntryCallback successCallback, optional ErrorCallback errorCallback); // IMPLEMENT LATER void copyTo (DirectoryEntry parent, optional DOMString newName, optional EntryCallback successCallback, optional ErrorCallback errorCallback); @@ -92,12 +92,12 @@ Entry = function( fullPath, isDirectory) { * @param {string} name * @constructor * @extends {Entry} - */ + */ FileEntry = function( name ) { - Entry.call(this, name, false); - - // TODO: make FileEntry actually inherit from Entry by modifying prototype. I don't know how to do this yet. - + Entry.call(this, name, false); + + // TODO: make FileEntry actually inherit from Entry by modifying prototype. I don't know how to do this yet. + // IMPLEMENT LATER void createWriter (FileWriterCallback successCallback, optional ErrorCallback errorCallback); // IMPLEMENT LATER void file (FileCallback successCallback, optional ErrorCallback errorCallback); }; @@ -108,11 +108,11 @@ FileEntry = function( name ) { * @param {string} name * @constructor * @extends {Entry} - */ + */ DirectoryEntry = function( name ) { - Entry.call(this, name, true); - - // TODO: make DirectoryEntry actually inherit from Entry by modifying prototype. I don't know how to do this yet. + Entry.call(this, name, true); + + // TODO: make DirectoryEntry actually inherit from Entry by modifying prototype. I don't know how to do this yet. // IMPLEMENT LATERvoid getFile (DOMString path, optional Flags options, optional EntryCallback successCallback, optional ErrorCallback errorCallback); // IMPLEMENT LATERvoid getDirectory (DOMString path, optional Flags options, optional EntryCallback successCallback, optional ErrorCallback errorCallback); @@ -121,17 +121,17 @@ DirectoryEntry = function( name ) { DirectoryEntry.prototype.createReader = function() { - var dirReader = new DirectoryReader(); - dirReader._directory = this; - - return dirReader; + var dirReader = new DirectoryReader(); + dirReader._directory = this; + + return dirReader; }; /** class: DirectoryReader - */ + */ DirectoryReader = function() { - + }; @@ -140,33 +140,33 @@ DirectoryReader = function() { * @param {function} successCallback * @param {function} errorCallback * @returns {Entry[]} - */ + */ DirectoryReader.prototype.readEntries = function( successCallback, errorCallback ){ var rootPath = this._directory.fullPath; var jsonList = brackets.file.getDirectoryListing( rootPath ); - var nameList = JSON.parse(jsonList); - - // Create entries for each name - var entries = []; - nameList.forEach(function(item){ + var nameList = JSON.parse(jsonList); + + // Create entries for each name + var entries = []; + nameList.forEach(function(item){ // Ignore names starting with "." - if (item.indexOf(".") != 0) { - var itemFullPath = rootPath + "/" + item; - - if( brackets.file.isDirectory( itemFullPath ) ) { - entries.push( new DirectoryEntry( itemFullPath ) ); - } - else { - entries.push( new FileEntry( itemFullPath ) ); - } - } + if (item.indexOf(".") != 0) { + var itemFullPath = rootPath + "/" + item; + + if( brackets.file.isDirectory( itemFullPath ) ) { + entries.push( new DirectoryEntry( itemFullPath ) ); + } + else { + entries.push( new FileEntry( itemFullPath ) ); + } + } }); - + - - successCallback( entries ); - - // TODO: error handling + + successCallback( entries ); + + // TODO: error handling }; From 20e327b3b7697a4cf9cc69112cc11740539b2df6 Mon Sep 17 00:00:00 2001 From: Joel Brandt Date: Mon, 12 Dec 2011 15:35:31 -0800 Subject: [PATCH 4/7] starting fileio unit tests --- test/SpecRunner.html | 3 ++- test/spec/fileIO-test.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test/spec/fileIO-test.js diff --git a/test/SpecRunner.html b/test/SpecRunner.html index e3e36ca28f6..460fe274f59 100644 --- a/test/SpecRunner.html +++ b/test/SpecRunner.html @@ -11,7 +11,8 @@ - + + diff --git a/test/spec/fileIO-test.js b/test/spec/fileIO-test.js new file mode 100644 index 00000000000..143f39fe4eb --- /dev/null +++ b/test/spec/fileIO-test.js @@ -0,0 +1,11 @@ +describe("FileIO", function(){ + + describe("Reading", function() { + + it("should run the test", function() { + // verify editor content + expect("a").toEqual("a"); + }); + }); +}); + From b1f1f4dbd2ddda413bf4c5f40f24e1626c6f1c0c Mon Sep 17 00:00:00 2001 From: Joel Brandt Date: Mon, 12 Dec 2011 15:35:51 -0800 Subject: [PATCH 5/7] binding fileio open to the menu --- src/brackets.js | 2 +- src/index.html | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/brackets.js b/src/brackets.js index bc2c7e250f3..ad783072777 100644 --- a/src/brackets.js +++ b/src/brackets.js @@ -11,7 +11,7 @@ $(document).ready(function() { // Temporary button to test file directory traversa; - $("#open-folder").click(function(){ + $("#menu-file-open").click(function(){ if (!inBrowser) { window.ProjectManager.showOpenDialog(false, true, "Choose a folder", null, null,showOpenDialogCallback); } diff --git a/src/index.html b/src/index.html index 3b321a49572..60d19fbcf26 100644 --- a/src/index.html +++ b/src/index.html @@ -18,6 +18,7 @@ + @@ -32,10 +33,10 @@ From 19cf1843c472663df49faf5470204256b4a66b9d Mon Sep 17 00:00:00 2001 From: njadbe Date: Mon, 12 Dec 2011 16:49:49 -0800 Subject: [PATCH 6/7] Code review cleanup for native file IO API --- src/{fileIO.js => NativeFileSystem.js} | 22 +++++++++------------- src/brackets.js | 19 +++++++------------ src/index.html | 2 +- test/SpecRunner.html | 1 - test/spec/fileIO-test.js | 11 ----------- 5 files changed, 17 insertions(+), 38 deletions(-) rename src/{fileIO.js => NativeFileSystem.js} (95%) delete mode 100644 test/spec/fileIO-test.js diff --git a/src/fileIO.js b/src/NativeFileSystem.js similarity index 95% rename from src/fileIO.js rename to src/NativeFileSystem.js index aa9a301bc3b..1efedc348e4 100644 --- a/src/fileIO.js +++ b/src/NativeFileSystem.js @@ -1,6 +1,4 @@ - - -window.ProjectManager = { +window.NativeFileSystem = { /** showOpenDialog @@ -29,9 +27,6 @@ window.ProjectManager = { initialPath, fileTypes, resultCallback ); - - - }, @@ -46,13 +41,14 @@ window.ProjectManager = { // TODO: assumes path is a directory right now. Need to error check // TODO: don't actually need to get the listing here, but should verify the directory exists var entryList = brackets.file.getDirectoryListing(path); - var files = JSON.parse(entryList); - - - var root = new DirectoryEntry( path ); - - - return root; + if (entryList) { + var files = JSON.parse(entryList); + var root = new DirectoryEntry( path ); + return root; + } + else { + return null; + } } }; diff --git a/src/brackets.js b/src/brackets.js index ad783072777..e18f92fe384 100644 --- a/src/brackets.js +++ b/src/brackets.js @@ -13,29 +13,25 @@ $(document).ready(function() { // Temporary button to test file directory traversa; $("#menu-file-open").click(function(){ if (!inBrowser) { - window.ProjectManager.showOpenDialog(false, true, "Choose a folder", null, null,showOpenDialogCallback); + window.NativeFileSystem.showOpenDialog(false, true, "Choose a folder", null, null, showOpenDialogCallback); } }); function showOpenDialogCallback( files ) { - - var folderName = files instanceof Array ? files[0] : files; - if (folderName != "") - var rootEntry = window.ProjectManager.requestNativeFileSystem( folderName, null, null ); // TODO: add callbacks + if (folderName != "") { + var rootEntry = window.NativeFileSystem.requestNativeFileSystem( folderName, null, null ); // TODO: add callbacks - var nestingLevel = 0; + var nestingLevel = 0; - if( rootEntry.isDirectory ) - readDirectory( rootEntry ) - + if( rootEntry.isDirectory ) + readDirectory( rootEntry ); + } // Test directory traversal function readDirectory( entry ){ - - var reader = entry.createReader(); reader.readEntries( dirReaderSuccessCB, dirReaderErrorCB); } @@ -61,7 +57,6 @@ $(document).ready(function() { } } } - function dirReaderErrorCB() { // handle error diff --git a/src/index.html b/src/index.html index 60d19fbcf26..32e8a3be90e 100644 --- a/src/index.html +++ b/src/index.html @@ -18,7 +18,7 @@ - + diff --git a/test/SpecRunner.html b/test/SpecRunner.html index 460fe274f59..88751e6932b 100644 --- a/test/SpecRunner.html +++ b/test/SpecRunner.html @@ -11,7 +11,6 @@ - diff --git a/test/spec/fileIO-test.js b/test/spec/fileIO-test.js deleted file mode 100644 index 143f39fe4eb..00000000000 --- a/test/spec/fileIO-test.js +++ /dev/null @@ -1,11 +0,0 @@ -describe("FileIO", function(){ - - describe("Reading", function() { - - it("should run the test", function() { - // verify editor content - expect("a").toEqual("a"); - }); - }); -}); - From 293c2c2e0d59b5e1b9ab64d0000edbe469270184 Mon Sep 17 00:00:00 2001 From: njadbe Date: Mon, 12 Dec 2011 16:59:17 -0800 Subject: [PATCH 7/7] Further fix to the cancel case on the Open dialog --- src/brackets.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/brackets.js b/src/brackets.js index e18f92fe384..ce60f62e3a5 100644 --- a/src/brackets.js +++ b/src/brackets.js @@ -25,7 +25,7 @@ $(document).ready(function() { var nestingLevel = 0; - if( rootEntry.isDirectory ) + if( rootEntry && rootEntry.isDirectory ) readDirectory( rootEntry ); }