Permalink
Browse files

Initial commit. Super pre-beta version go!

  • Loading branch information...
0 parents commit bdb05525df93e30dedb1790ecf77c5e4ab566d6d @andrewrabon andrewrabon committed Aug 26, 2011
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,46 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Release Checklist</title>
+ <link rel="stylesheet" href="filesystem:chrome-extension://lcdlhpohidhdgicfpinplmiabadbncpc/persistent/style.css">
+ <style>
+ body {
+ padding: 25px 25%;
+ font-family: "Verdana", "Arial", sans-serif;
+ font-size: 16px;
+ }
+ h1 {
+ text-align: center;
+ }
+ ul {
+ margin-bottom: 50px;
+ }
+ </style>
+ </head>
+ <body>
+ <h1>Release Checklist</h1>
+
+ <h2>Initial features</h2>
+ <ul>
+ <li>File reading/writing/listing</li>
+ <li>New/save/rename/launch/delete files</li>
+ <li>Syntax highlighting</li>
+ <li>FILEWRITER replacement</li>
+ <li>Tab space preservation (line-to-line)</li>
+ <li>Ctrl key bindings (Save, New, Launch, Duplicate line)</li>
+ <li>Line/column position updating</li>
+ </ul>
+
+ <h2>Lacking features</h2>
+ <ul>
+ <li>Subdirectories</li>
+ <li>Importing external files</li>
+ <li>Exporting the project</li>
+ <li>Multiple projects</li>
+ <li>Animations</li>
+ <li>Syncing between Chrome installations</li>
+ <li>Replace (find will always be Chrome-native)</li>
+ </ul>
+ </body>
+</html>
@@ -0,0 +1,15 @@
+
+ <!--<li><span class="active">index.html <a class="launch" href="#" target="_blank">Launch</a></span></li>
+ <li><span>style.css</span></li>
+ <li class="folder">/folder/
+ <ul>
+ <li><span>image.png</span></li>
+ <li><span>icon.png</span></li>
+ </ul>
+ </li>
+ <li class="folder">/folder2/
+ <ul>
+ <li><span>image.png</span></li>
+ <li><span>icon.png</span></li>
+ </ul>
+ </li>-->
@@ -0,0 +1,30 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>FileWriter</title>
+
+ <link rel="stylesheet" href="style.css">
+ <link rel="stylesheet" href="scripts/jquery.contextMenu.css">
+ <script src="scripts/jquery.min.js"></script>
+ <script src="scripts/jquery.contextMenu.js"></script>
+ <script src="scripts/ace.js"></script>
+ <script src="scripts/theme-monokai.js"></script>
+ <script src="scripts/mode-html.js"></script>
+
+ <script src="scripts/filewriter.js"></script>
+ <script src="scripts/app.js"></script>
+ </head>
+ <body>
+ <section id="sidebar">
+ <div id="commands">
+ <button id="new">New File</button>
+ <!--<button id="add">Add Files</button>-->
+ <button id="save">Save File</button>
+ </div>
+ <ul id="files"></ul>
+ </section>
+ <div id="editor"></div>
+ <!--<div id="status">Line 2, Column 42</div>-->
+ </body>
+</html>
@@ -0,0 +1,19 @@
+{
+ "name": "FileWriter",
+ "description": "Edit and view local files with this text editor geared towards web development.",
+ "version": "1.0",
+ "app": {
+ "launch": {
+ "local_path": "index.html"
+ }
+ },
+ "icons": {
+ "16": "images/16.png",
+ "48": "images/48.png",
+ "128": "images/128.png"
+ },
+ "permissions": [
+ "notifications",
+ "unlimitedStorage"
+ ]
+}
@@ -0,0 +1,9 @@
+# Alert!
+This project isn't anywhere near 1.0 yet, use at your own peril. Current builds of FileWriter are known to corrupt files.
+Use at your own risk.
+
+# Credits
+- Most of the File API code comes straight from [HTML5Rocks](http://www.html5rocks.com/en/tutorials/file/filesystem/). Super kudos to those guys.
+- Ace code editor by [Ajax.org](https://github.com/ajaxorg/ace), used under a LGPL license.
+- Pencil icon by [Brightmix](http://www.brightmix.com/), used under a WTFPL license.
+- contextMenu jQuery plugin by [Rodney Rehm](https://github.com/medialize/jQuery-contextMenu), used under an MIT license.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,58 @@
+$(function () {
+ var editor, HTMLMode;
+
+ editor = FileWriter.editor = ace.edit('editor');
+ HTMLMode = require("ace/mode/html").Mode;
+ editor.getSession().setUseSoftTabs(false);
+ editor.getSession().setMode(new HTMLMode());
+ //editor.setTheme('ace/theme/monokai');
+ editor.getSession().setTabSize(8);
+ editor.getSession().setUseWrapMode(false);
+ editor.setShowPrintMargin(false);
+
+ $('#new').click(function () {
+ var name = prompt('File name? (include extension)', '*.txt');
+ FileWriter.files.newFile(name);
+ });
+
+ $('#add').click(function () {
+ // Coming soon.
+ });
+
+ $('#save').click(function () {
+ FileWriter.files.saveFile();
+ });
+
+ $.contextMenu({
+ selector: 'li',
+ items: {
+ edit: { name: 'Edit' },
+ launch: { name: 'Launch (Open in new tab)' },
+ rename: { name: 'Rename' },
+ separator: '---------',
+ 'delete': { name: 'Delete' }
+ },
+ callback: function(key, opt){
+ switch (key) {
+ case 'edit':
+ $(this).click();
+ break;
+ case 'launch':
+ window.open(FileWriter.files.getFileEntry($(this).find('span').data('filename')).toURL());
+ break;
+ case 'rename':
+ var newName = prompt('New name?', '*.txt');
+
+ FileWriter.files.getFileEntry($(this).find('span').data('filename')).moveTo(filesystem.root, newName);
+ FileWriter.helpers.refreshList();
+ break;
+ case 'delete':
+ FileWriter.files.getFileEntry($(this).find('span').data('filename')).remove();
+ FileWriter.helpers.refreshList();
+ break;
+ }
+ }
+ });
+
+ window.webkitRequestFileSystem(window.PERSISTENT, 10*1024*1024, FileWriter.helpers.init, FileWriter.helpers.errorHandler);
+});
@@ -0,0 +1,170 @@
+/* Attempt at a semi-professional library for this stuff. */
+(function () {
+ var filesystem, fileList = [], currentFile;
+
+ var FileWriter = {
+ editor: null,
+
+ /* File control functions */
+ files: {
+ loadFile: function (filename) {
+ filesystem.root.getFile(filename, { create: true }, function (fileEntry) {
+ currentFile = fileEntry;
+
+ fileEntry.file(function (file) {
+ var reader = new FileReader();
+
+ reader.onloadend = function (e) {
+ FileWriter.editor.getSession().setValue(this.result);
+ };
+
+ reader.readAsText(file);
+ }, FileWriter.helpers.errorHandler);
+ }, FileWriter.helpers.errorHandler);
+
+ $('#editor').keypress(function () {
+ // Update the title/name with an asterisk signifying it's unsaved.
+ });
+ },
+
+ newFile: function (n) {
+ filesystem.root.getFile(n, { create: true });
+ FileWriter.helpers.refreshList();
+ },
+
+ addFiles: function () {
+ // Import functionality to be added later.
+ },
+
+ saveFile: function () {
+ currentFile.createWriter(function (fileWriter) {
+ var bb = new WebKitBlobBuilder();
+ FileWriter.editor.getSession().setValue(FileWriter.editor.getSession()
+ .getValue().replace('[FILEWRITER]', filesystem.root.toURL()));
+ bb.append(FileWriter.editor.getSession().getValue());
+ fileWriter.write(bb.getBlob(FileWriter.helpers.getMime(currentFile)));
+ console.log(FileWriter.helpers.getMime(currentFile));
+ }, FileWriter.helpers.errorHandler);
+ },
+
+ getFileEntry: function (n) {
+ var i, matched;
+ for (i = 0; i < fileList.length; i = i + 1) {
+ if (fileList[i].name === n) {
+ matched = fileList[i];
+ }
+ }
+ return matched;
+ }
+ },
+
+ /* Helper functions */
+ helpers: {
+ init: function (fs) {
+ filesystem = fs;
+ FileWriter.helpers.refreshList();
+ },
+
+ listResults: function (entries) {
+ var fragment = document.createDocumentFragment();
+
+ entries.forEach(function (entry, i) {
+ var li = document.createElement('li');
+ if (entry.name.search('.htm') !== -1) {
+ li.innerHTML = ['<span data-filename="', entry.name, '">', entry.name,
+ '<a class="launch" href="', entry.toURL() ,'" target="_blank">Launch</a></span>'].join('');
+ }
+ else {
+ li.innerHTML = ['<span data-filename="', entry.name, '">', entry.name, '</span>'].join('');
+ }
+ fragment.appendChild(li);
+ fileList[i] = entry;
+ });
+
+ currentFile = fileList[0];
+ $('#files').append(fragment);
+
+ // Unfortunately these have to be binded here and not in app.js since
+ // the li's were inserted dynamically.
+ $('#files li').click(function () {
+ var filename = $(this).find('span').data('filename');
+ $('title').html(filename);
+ FileWriter.files.saveFile();
+ FileWriter.files.loadFile(filename);
+ $('#files>li>span').removeClass('active');
+ $(this).find('span').addClass('active');
+ });
+
+ $('#files li:first-child').click();
+ },
+
+ refreshList: function () {
+ var readEntries, dirReader, entries = [];
+
+ $('#files').html('');
+ dirReader = filesystem.root.createReader();
+ readEntries = function () {
+ dirReader.readEntries(function (results) {
+ if (!results.length) {
+ FileWriter.helpers.listResults(entries.sort());
+ } else {
+ entries = entries.concat(FileWriter.helpers.toArray(results));
+ readEntries();
+ }
+ });
+ };
+ readEntries();
+ },
+
+ toArray: function (list) {
+ return Array.prototype.slice.call(list || [], 0);
+ },
+
+ getMime: function (file) {
+ var name = file.name;
+
+ if (name.search('.js') !== -1) {
+ return 'text/javascript';
+ }
+ else if (name.search('.css') !== -1) {
+ return 'text/css';
+ }
+ else if (name.search('.htm') !== -1) {
+ return 'text/html';
+ }
+ else {
+ return 'text/plain';
+ }
+ },
+
+ errorHandler: function (e) {
+ var msg = '';
+
+ switch (e.code) {
+ case FileError.QUOTA_EXCEEDED_ERR:
+ msg = 'QUOTA_EXCEEDED_ERR';
+ break;
+ case FileError.NOT_FOUND_ERR:
+ msg = 'NOT_FOUND_ERR';
+ break;
+ case FileError.SECURITY_ERR:
+ msg = 'SECURITY_ERR';
+ break;
+ case FileError.INVALID_MODIFICATION_ERR:
+ msg = 'INVALID_MODIFICATION_ERR';
+ break;
+ case FileError.INVALID_STATE_ERR:
+ msg = 'INVALID_STATE_ERR';
+ break;
+ default:
+ msg = 'Unknown Error';
+ break;
+ }
+
+ console.log('Error: ' + msg);
+ }
+ }
+ };
+
+ window.FileWriter = window.FileWriter || FileWriter;
+})();
Oops, something went wrong.

0 comments on commit bdb0552

Please sign in to comment.