Skip to content

Instantly share code, notes, and snippets.

@mikechambers
Created May 9, 2012 17:03
Show Gist options
  • Save mikechambers/2646740 to your computer and use it in GitHub Desktop.
Save mikechambers/2646740 to your computer and use it in GitHub Desktop.
/*
* 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, browser: true, nomen: true, indent: 4, maxerr: 50 */
/*global define: false, FileError: false */
//TODO: rename to EditorThemeManager?
/**
* Manages global application commands that can be called from menu items, key bindings, or subparts
* of the application.
*/
define(function (require, exports, module) {
'use strict';
var NativeFileSystem = require("file/NativeFileSystem").NativeFileSystem;
var FileUtils = require("file/FileUtils");
//TODO: where is the right place for this?
var THEME_DIRECTORY = "/Users/mesh/tmp/themes/";
var THEME_STYLE_NAME = "editor.css";
var THEME_PACKAGE_NAME = "package.json";
var _getErrorMessage = function (fileError) {
var msg = '';
switch (fileError.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;
}
return msg;
};
var _loadTheme = function (themeName) {
var directory = new NativeFileSystem.DirectoryEntry(themeName);
//TODO : need util API for combining paths
var themePath = THEME_DIRECTORY + themeName;
NativeFileSystem.requestNativeFileSystem(
themePath,
function (directoryEntry) {
directoryEntry.getFile(
themePath + "/" + THEME_PACKAGE_NAME,
{},
function (fileEntry) {
fileEntry.file(
function (file) {
var reader = new NativeFileSystem.FileReader();
reader.onloadend = function (e) {
console.log("data loaded");
console.log(this.result);
};
reader.onerror = function (e) {
console.log("onerror");
console.log(_getErrorMessage(e.target.error));
};
reader.readAsText(file);
},
function (e) {
console.log("error");
console.log(e);
}
);
},
function (error) {
console.log(_getErrorMessage(error));
}
);
},
//todo: need constants for file errors
function (error) {
console.log("failure");
console.log(error);
}
);
};
/*
var _addTheme = function(themePath){
}
var _removeTheme = function(themeName){
}
*/
exports.loadTheme = _loadTheme;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment