mirror of
https://github.com/adobe/brackets.git
synced 2024-11-20 09:53:00 +01:00
Merge branch 'master' into initial-fileio-work
This commit is contained in:
commit
7a61508dc1
@ -34,7 +34,10 @@ ProjectManager.openProject = function() {
|
||||
ProjectManager.loadProject( files[0] );
|
||||
},
|
||||
function(error) {
|
||||
console.log(error); // TODO: real error handling
|
||||
brackets.showErrorDialog(
|
||||
brackets.strings.ERROR_LOADING_PROJECT
|
||||
, brackets.strings.format(brackets.strings.OPEN_DIALOG_ERROR, error.code)
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -86,7 +89,10 @@ ProjectManager.loadProject = function(rootPath) {
|
||||
ProjectManager._renderTree(ProjectManager._treeDataProvider);
|
||||
},
|
||||
function(error) {
|
||||
console.log(error); // TODO: real error handling
|
||||
brackets.showErrorDialog(
|
||||
brackets.strings.ERROR_LOADING_PROJECT
|
||||
, brackets.strings.format(brackets.strings.REQUEST_NATIVE_FILE_SYSTEM_ERROR, rootPath, error.code)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
@ -120,7 +126,10 @@ ProjectManager._treeDataProvider = function(treeNode, jsTreeCallback) {
|
||||
jsTreeCallback(subtreeJSON);
|
||||
},
|
||||
function(error) {
|
||||
console.log(error); // TODO: real error handling
|
||||
brackets.showErrorDialog(
|
||||
brackets.strings.ERROR_LOADING_PROJECT
|
||||
, brackets.strings.format(brackets.strings.READ_DIRECTORY_ENTRIES_ERROR, dirEntry.fullPath, error.code)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -10,25 +10,51 @@ brackets.inBrowser = !brackets.hasOwnProperty("fs");
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
/**
|
||||
* General purpose modal error dialog.
|
||||
*
|
||||
* @param {string} title The title of the error dialog. Can contain HTML markup.
|
||||
* @param {string} message The message to display in the error dialog. Can contain HTML markup.
|
||||
*/
|
||||
brackets.showErrorDialog = function(title, message) {
|
||||
var dlg = $("#error-dialog");
|
||||
|
||||
// Set title and message
|
||||
$("#error-dialog-title").html(title);
|
||||
$("#error-dialog-message").html(message);
|
||||
|
||||
// Click handler for OK button
|
||||
dlg.delegate("#error-dialog-ok", "click", function(e) {
|
||||
dlg.modal(true).hide();
|
||||
});
|
||||
|
||||
// Run the dialog
|
||||
dlg.modal(
|
||||
{ backdrop: "static"
|
||||
, show: true
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
var myCodeMirror = CodeMirror($('#editor').get(0), {
|
||||
value: 'var myResponse="Yes, it will be!"\n'
|
||||
});
|
||||
|
||||
// Load a default project into the tree
|
||||
if (brackets.inBrowser) {
|
||||
// In browser: dummy folder tree (hardcoded in ProjectManager)
|
||||
ProjectManager.loadProject("DummyProject");
|
||||
} else {
|
||||
// In app shell: load Brackets itself
|
||||
var loadedPath = window.location.pathname;
|
||||
var bracketsSrc = loadedPath.substr(0, loadedPath.lastIndexOf("/"));
|
||||
ProjectManager.loadProject(bracketsSrc);
|
||||
}
|
||||
|
||||
// Open project button
|
||||
$("#btn-open-project").click(function() {
|
||||
ProjectManager.openProject();
|
||||
});
|
||||
// Load a default project into the tree
|
||||
if (brackets.inBrowser) {
|
||||
// In browser: dummy folder tree (hardcoded in ProjectManager)
|
||||
ProjectManager.loadProject("DummyProject");
|
||||
} else {
|
||||
// In app shell: load Brackets itself
|
||||
var loadedPath = window.location.pathname;
|
||||
var bracketsSrc = loadedPath.substr(0, loadedPath.lastIndexOf("/"));
|
||||
ProjectManager.loadProject(bracketsSrc);
|
||||
}
|
||||
|
||||
// Open project button
|
||||
$("#btn-open-project").click(function() {
|
||||
ProjectManager.openProject();
|
||||
});
|
||||
|
||||
|
||||
// Implements the 'Run Tests' menu to bring up the Jasmine unit test window
|
||||
@ -48,7 +74,7 @@ $(document).ready(function() {
|
||||
}
|
||||
});
|
||||
|
||||
// Ty test code hooked up to "new" menu. Test reads a file and prints its constents to the log.
|
||||
// Ty test code hooked up to "new" menu. Test reads a file and prints its constents to the log.
|
||||
// uncomment to test
|
||||
/*$("#menu-file-new").click(function(){
|
||||
var fileEntry = new NativeFileSystem.FileEntry( "/Users/tvoliter/github/brackets-app/README.md" );
|
||||
|
@ -17,11 +17,13 @@
|
||||
|
||||
<script src="thirdparty/jquery-1.7.min.js"></script>
|
||||
<script src="widgets/bootstrap-dropdown.js"></script>
|
||||
<script src="widgets/bootstrap-modal.js"></script>
|
||||
<script src="thirdparty/jstree_pre1.0_fix_1/jquery.jstree.js"></script>
|
||||
|
||||
<script src="NativeFileSystem.js"></script>
|
||||
<script src="brackets.js"></script>
|
||||
<script src="ProjectManager.js"></script>
|
||||
<script src="strings.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- TODO: LESS won't work directly from Chrome when run locally (unless you launch it with -allow-file-access-from-files)
|
||||
@ -76,5 +78,19 @@
|
||||
<div id="editor"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal Windows -->
|
||||
<div id="error-dialog" class="modal hide fade">
|
||||
<div class="modal-header">
|
||||
<a href="#" class="close">×</a>
|
||||
<h3 id="error-dialog-title">Error</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p id="error-dialog-message">Message goes here</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a id="error-dialog-ok" href="#" class="btn primary">OK</a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
38
src/strings.js
Normal file
38
src/strings.js
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
|
||||
*/
|
||||
|
||||
if (!brackets.strings)
|
||||
brackets.strings = {};
|
||||
|
||||
(function() {
|
||||
var s = brackets.strings;
|
||||
|
||||
/**
|
||||
* Format a string by replacing placeholder symbols with passed in arguments.
|
||||
*
|
||||
* Example: var formatted = brackets.strings.format("Hello {0}", "World");
|
||||
*
|
||||
* @param {string} str The base string
|
||||
* @param {string} ... Arguments to be substituted into the string
|
||||
*
|
||||
* @return {string} Formatted string
|
||||
*/
|
||||
s.format = function(str) {
|
||||
var args = arguments;
|
||||
return str.replace(/{(\d+)}/g, function(match, num) {
|
||||
// args[0] is the string, so we need to adjust index values here
|
||||
// "num" is a string
|
||||
var i = Number(num);
|
||||
return typeof args[i + 1] !== 'undefined' ? args[i + 1] : match;
|
||||
});
|
||||
}
|
||||
|
||||
// General file io error strings
|
||||
|
||||
// Project error strings
|
||||
s.ERROR_LOADING_PROJECT = "Error loading project";
|
||||
s.OPEN_DIALOG_ERROR = "An error occurred when showing the open file dialog. (error {0})";
|
||||
s.REQUEST_NATIVE_FILE_SYSTEM_ERROR = "An error occurred when trying to load the directory '{0}'. (error {1})";
|
||||
s.READ_DIRECTORY_ENTRIES_ERROR = "An error occurred when reading the contents of the directory '{0}'. (error {1})";
|
||||
})();
|
@ -130,6 +130,12 @@ describe("LowLevelFileIO", function() {
|
||||
expect(err).toBe(brackets.fs.ERR_INVALID_PARAMS);
|
||||
});
|
||||
});
|
||||
|
||||
it ("should return an error if trying to read a directory", function() {
|
||||
brackets.fs.readFile(baseDir, "utf8", function(err, contents) {
|
||||
expect(err).toBe(brackets.fs.ERR_CANT_READ);
|
||||
});
|
||||
})
|
||||
}); // describe("readFile")
|
||||
|
||||
describe("writeFile", function() {
|
||||
@ -157,5 +163,12 @@ describe("LowLevelFileIO", function() {
|
||||
expect(err).toBe(brackets.fs.ERR_INVALID_PARAMS);
|
||||
});
|
||||
});
|
||||
|
||||
it ("should return an error if trying to write a directory", function() {
|
||||
brackets.fs.writeFile(baseDir, contents, "utf8", function(err, contents) {
|
||||
// Ideally we would get ERR_CANT_WRITE, but as long as we get some sort of error it's fine.
|
||||
expect(err).toBeTruthy();
|
||||
});
|
||||
})
|
||||
}); // describe("writeFile")
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user