Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Support the core light/dark themes. Use cleaner, distinguishable path…
Browse files Browse the repository at this point in the history
…s for

the three cases where FS is used to read internal data files: core extensions,
user extensions, user preferences. This way, filesystem impls can easily
detect those cases and treat them specially (as the DemoFileSystem does for
themes i.e. core extensions).
  • Loading branch information
peterflynn committed Dec 8, 2014
1 parent 9ef6a0e commit c202b03
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/command/KeyBindingManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ define(function (require, exports, module) {

var KEYMAP_FILENAME = "keymap.json",
// _userKeyMapFilePath = brackets.app.getApplicationSupportDirectory() + "/" + KEYMAP_FILENAME;
_userKeyMapFilePath = "/&&&doesnt_exist&&&/" + KEYMAP_FILENAME;
_userKeyMapFilePath = "/$.brackets.config$/" + KEYMAP_FILENAME;

/**
* @private
Expand Down
86 changes: 86 additions & 0 deletions src/filesystem/impls/demo/AjaxFileSystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright (c) 2014 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, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global define, $ */

/**
* Limited subset of a file system impl used for reading from core extensions folder (part of the src code
* served up from the server)
*/
define(function (require, exports, module) {
"use strict";

var FileSystemError = require("filesystem/FileSystemError"),
FileSystemStats = require("filesystem/FileSystemStats");


/**
* To avoid spamming console with 404s, we hardcode a few known non-existent files
*/
function _exists(path) {
if (path.match(/Theme\/main.js$/) || path.match(/\/requirejs-config.json$/) || (path.match(/\/package.json$/) && !path.match(/Theme\/package.json$/))) {
// console.log("Assuming " + path + " does not exist");
return false;
}

return true; // TODO: use $.get(HEAD) to check if it really exists?
}


function stat(path, callback) {
if (!_exists(path)) {
callback(FileSystemError.NOT_FOUND);
} else {
// console.log("Assuming " + path + " exists");
var stats = new FileSystemStats({
isFile: true,
mtime: new Date(0),
hash: 0
});
callback(null, stats);
}
}

function readFile(path, callback) {
if (!_exists(path)) {
callback(FileSystemError.NOT_FOUND);
} else {
$.ajax(path, { dataType: "text" }).done(function (text) {
var stats = new FileSystemStats({
isFile: true,
mtime: new Date(0),
hash: 0
});
callback(null, text, stats);
}).fail(function (jqXHR, errorCode, httpError) {
callback(errorCode + ": " + httpError);
});
}
}

// Export public API
exports.stat = stat;
exports.readFile = readFile;
});
54 changes: 44 additions & 10 deletions src/filesystem/impls/demo/DemoFileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,37 @@


/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global define, appshell, $, window */
/*global define, window, PathUtils */

define(function (require, exports, module) {
"use strict";

var FileSystemError = require("filesystem/FileSystemError"),
FileSystemStats = require("filesystem/FileSystemStats");
FileSystemStats = require("filesystem/FileSystemStats"),
AjaxFileSystem = require("filesystem/impls/demo/AjaxFileSystem");


function showOpenDialog(allowMultipleSelection, chooseDirectories, title, initialPath, fileTypes, callback) {
// FIXME
throw new Error();
}
// Brackets uses FileSystem to read from various internal paths that are not in the user's project storage. We
// redirect core-extension access to a simple $.ajax() to read from the source code location we're running from,
// and for now we ignore we possibility of user-installable extensions or persistent user preferences.
var CORE_EXTENSIONS_PREFIX = PathUtils.directory(window.location.href) + "extensions/default/";
// var USER_EXTENSIONS_PREFIX = "/.brackets.user.extensions$/";
// var CONFIG_PREFIX = "/.$brackets.config$/";

function showSaveDialog(title, initialPath, proposedNewFilename, callback) {
// FIXME
throw new Error();
}

// Static, hardcoded file tree structure to serve up. Key is entry name, and value is either:
// - string = file
// - object = nested folder containing more entries
var demoContent = {
"index.html": "<html>\n<head>\n <title>Hello, world!</title>\n</head>\n<body>\n Welcome to Brackets!\n</body>\n</html>",
"main.css": ".hello {\n content: 'world!';\n}"
};


function _startsWith(path, prefix) {
return (path.substr(0, prefix.length) === prefix);
}

function _stripTrailingSlash(path) {
return path[path.length - 1] === "/" ? path.substr(0, path.length - 1) : path;
}
Expand Down Expand Up @@ -89,6 +96,11 @@ define(function (require, exports, module) {


function stat(path, callback) {
if (_startsWith(path, CORE_EXTENSIONS_PREFIX)) {
AjaxFileSystem.stat(path, callback);
return;
}

var result = _getDemoData(path);
if (result || result === "") {
callback(null, _makeStat(result));
Expand All @@ -108,6 +120,11 @@ define(function (require, exports, module) {
}

function readdir(path, callback) {
if (_startsWith(path, CORE_EXTENSIONS_PREFIX)) {
callback("Directory listing unavailable: " + path);
return;
}

var storeData = _getDemoData(path);
if (!storeData) {
callback(FileSystemError.NOT_FOUND);
Expand Down Expand Up @@ -137,6 +154,11 @@ define(function (require, exports, module) {
if (typeof options === "function") {
callback = options;
}

if (_startsWith(path, CORE_EXTENSIONS_PREFIX)) {
AjaxFileSystem.readFile(path, callback);
return;
}

var storeData = _getDemoData(path);
if (!storeData && storeData !== "") {
Expand All @@ -149,6 +171,7 @@ define(function (require, exports, module) {
}
}


function writeFile(path, data, options, callback) {
callback("Cannot save to HTTP demo server");
}
Expand Down Expand Up @@ -178,6 +201,17 @@ define(function (require, exports, module) {
callback();
}

function showOpenDialog(allowMultipleSelection, chooseDirectories, title, initialPath, fileTypes, callback) {
// FIXME
throw new Error();
}

function showSaveDialog(title, initialPath, proposedNewFilename, callback) {
// FIXME
throw new Error();
}


// Export public API
exports.showOpenDialog = showOpenDialog;
exports.showSaveDialog = showSaveDialog;
Expand Down
4 changes: 2 additions & 2 deletions src/preferences/PreferencesImpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ define(function (require, exports, module) {

// User-level preferences
// userPrefFile = brackets.app.getApplicationSupportDirectory() + "/" + SETTINGS_FILENAME;
userPrefFile = "/&&&doesnt_exist&&&/" + SETTINGS_FILENAME;
userPrefFile = "/$.brackets.config$/" + SETTINGS_FILENAME;

/**
* A deferred object which is used to indicate PreferenceManager readiness during the start-up.
Expand Down Expand Up @@ -118,7 +118,7 @@ define(function (require, exports, module) {
// It's for more internal, implicit things like window size, working set, etc.
var stateManager = new PreferencesBase.PreferencesSystem();
// var userStateFile = brackets.app.getApplicationSupportDirectory() + "/" + STATE_FILENAME;
var userStateFile = "/&&&doesnt_exist&&&/" + STATE_FILENAME;
var userStateFile = "/$.brackets.config$/" + STATE_FILENAME;
var smUserScope = new PreferencesBase.Scope(new PreferencesBase.FileStorage(userStateFile, true));
var stateProjectLayer = new PreferencesBase.ProjectLayer();
smUserScope.addLayer(stateProjectLayer);
Expand Down
6 changes: 3 additions & 3 deletions src/utils/ExtensionLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ define(function (require, exports, module) {
*/
function getUserExtensionPath() {
if (brackets.inBrowser) { // TODO: how will user-installed extensions work in-browser?
return "&&&does_not_exist&&&";
return "$.brackets.user.extensions$";
}

return brackets.app.getApplicationSupportDirectory() + "/extensions/user";
Expand Down Expand Up @@ -398,7 +398,7 @@ define(function (require, exports, module) {
// "test-server-file-system", // uncomment (and update the root main.js) to test your own FileSystem back-end
"CloseOthers",
"CSSCodeHints",
//"DarkTheme", - FIXME: does this work?
"DarkTheme", // Note: only themes ending in -Theme work with AjaxFileSystem
//"DebugCommands",
"HTMLCodeHints",
"HtmlEntityCodeHints",
Expand All @@ -408,7 +408,7 @@ define(function (require, exports, module) {
"JavaScriptQuickEdit",
"JSLint",
"LESSSupport",
//"LightTheme", - FIXME: does this work?
"LightTheme", // Note: only themes ending in -Theme work with AjaxFileSystem
"QuickOpenCSS",
"QuickOpenHTML",
"QuickOpenJavaScript",
Expand Down
4 changes: 0 additions & 4 deletions src/utils/ExtensionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,6 @@ define(function (require, exports, module) {
* or rejected if there is no package.json or the contents are not valid JSON.
*/
function loadPackageJson(folder) {
if (brackets.inBrowser) {
return new $.Deferred().reject().promise();
}

var file = FileSystem.getFileForPath(folder + "/package.json"),
result = new $.Deferred();
FileUtils.readAsText(file)
Expand Down

0 comments on commit c202b03

Please sign in to comment.