mirror of
https://github.com/adobe/brackets.git
synced 2024-11-20 09:53:00 +01:00
Merge remote-tracking branch 'origin/master' into tvoliter/issue-924-take2
* origin/master: now that the working set view handles mousedown instead of click in order to capture left and right clicks, it's necessary to call preventDefault() so the focus is not removed from the editor. remove high ascii file fix typo git munged high ascii in file name, so use only low ascii Fix typo Update ExtensionLoader require paths to include text plugin. Update InlineImageViewer to use text plugin to load an HTML template. Correct showInlineEditor to toggleQuickEdit. Updated all references and ran unit tests. Fix SHOW_INLINE_EDITOR command handler to return a promise. Clean up Debug menu (issues #977, #1056): - Move JSLint to View menu; Use Tabs to Edit menu - Remove "Experimental" heading - Remove "Close Browsers" command (after discussion w/ Glenn) - underlying NativeApp API not removed since it's still used by unit tests - Reorder remaining Debug menu items - Rename "Reload Window"->"Reload Brackets" for clarity - Rename "New Window"->"New Brackets Window" for clarity - Move JSLint command impl to JSLintUtils - (Left Use Tabs impl in DebugCommandHandlers for now until it has a more natural home) Add unit tests for filtering out token types in JavaScript Quick Edit. initial set of tests complete intermediate checkin for first unit test RequireJS text plugin 1.0.8 Conflicts: src/extensions/default/JavaScriptQuickEdit/unittests.js
This commit is contained in:
commit
cfd66159c5
@ -23,7 +23,13 @@
|
||||
|
||||
|
||||
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
|
||||
/*global define, brackets: true, $, PathUtils, window, navigator */
|
||||
/*global require, define, brackets: true, $, PathUtils, window, navigator */
|
||||
|
||||
require.config({
|
||||
paths: {
|
||||
"text" : "thirdparty/text"
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* brackets is the root of the Brackets codebase. This file pulls in all other modules as
|
||||
@ -205,6 +211,7 @@ define(function (require, exports, module) {
|
||||
LiveDevelopment : require("LiveDevelopment/LiveDevelopment"),
|
||||
Inspector : require("LiveDevelopment/Inspector/Inspector"),
|
||||
NativeApp : require("utils/NativeApp"),
|
||||
ExtensionUtils : require("utils/ExtensionUtils"),
|
||||
doneLoading : false
|
||||
};
|
||||
|
||||
|
@ -60,12 +60,14 @@ define(function (require, exports, module) {
|
||||
exports.EDIT_UNINDENT = "edit.unindent";
|
||||
exports.EDIT_DUPLICATE = "edit.duplicate";
|
||||
exports.EDIT_LINE_COMMENT = "edit.lineComment";
|
||||
exports.TOGGLE_USE_TAB_CHARS = "debug.useTabChars";
|
||||
|
||||
// VIEW
|
||||
exports.VIEW_HIDE_SIDEBAR = "view.hideSidebar";
|
||||
exports.VIEW_INCREASE_FONT_SIZE = "view.increaseFontSize";
|
||||
exports.VIEW_DECREASE_FONT_SIZE = "view.decreaseFontSize";
|
||||
exports.VIEW_RESTORE_FONT_SIZE = "view.restoreFontSize";
|
||||
exports.TOGGLE_JSLINT = "debug.jslint";
|
||||
|
||||
// Navigate
|
||||
exports.NAVIGATE_NEXT_DOC = "navigate.nextDoc";
|
||||
@ -73,20 +75,16 @@ define(function (require, exports, module) {
|
||||
exports.NAVIGATE_QUICK_OPEN = "navigate.quickOpen";
|
||||
exports.NAVIGATE_GOTO_DEFINITION = "navigate.gotoDefinition";
|
||||
exports.NAVIGATE_GOTO_LINE = "navigate.gotoLine";
|
||||
exports.SHOW_INLINE_EDITOR = "navigate.showInlineEditor";
|
||||
exports.TOGGLE_QUICK_EDIT = "navigate.toggleQuickEdit";
|
||||
exports.QUICK_EDIT_NEXT_MATCH = "navigate.nextMatch";
|
||||
exports.QUICK_EDIT_PREV_MATCH = "navigate.previousMatch";
|
||||
|
||||
// Debug
|
||||
exports.DEBUG_EXPERIMENTAL = "debug.experimental";
|
||||
exports.DEBUG_REFRESH_WINDOW = "debug.refreshWindow"; // string must MATCH string in native code (brackets_extensions)
|
||||
exports.DEBUG_SHOW_DEVELOPER_TOOLS = "debug.showDeveloperTools";
|
||||
exports.DEBUG_RUN_UNIT_TESTS = "debug.runUnitTests";
|
||||
exports.DEBUG_JSLINT = "debug.jslint";
|
||||
exports.DEBUG_SHOW_PERF_DATA = "debug.showPerfData";
|
||||
exports.DEBUG_NEW_BRACKETS_WINDOW = "debug.newBracketsWindow";
|
||||
exports.DEBUG_CLOSE_ALL_LIVE_BROWSERS = "debug.closeAllLiveBrowsers";
|
||||
exports.DEBUG_USE_TAB_CHARS = "debug.useTabChars";
|
||||
|
||||
// Command that does nothing. Can be used for place holder menuItems
|
||||
|
||||
|
@ -354,7 +354,7 @@ define(function (require, exports, module) {
|
||||
/**
|
||||
* Add one or more key bindings to a particular Command.
|
||||
*
|
||||
* @param {string} commandID
|
||||
* @param {!string} commandID
|
||||
* @param {?({key: string, displayKey: string} | Array.<{key: string, displayKey: string, platform: string)}>} keyBindings - a single key binding
|
||||
* or an array of keybindings. Example: "Shift-Cmd-F". Mac and Win key equivalents are automatically
|
||||
* mapped to each other. Use displayKey property to display a different string (e.g. "CMD+" instead of "CMD=").
|
||||
@ -394,8 +394,8 @@ define(function (require, exports, module) {
|
||||
/**
|
||||
* Remove a key binding from _keymap
|
||||
*
|
||||
* @param {string} key - a key-description string that may or may not be normalized.
|
||||
* @param {string} platform - the intended OS of the key.
|
||||
* @param {!string} key - a key-description string that may or may not be normalized.
|
||||
* @param {?string} platform - OS from which to remove the binding (all platforms if unspecified)
|
||||
*/
|
||||
function removeBinding(key, platform) {
|
||||
if (!key || ((platform !== null) && (platform !== undefined) && (platform !== brackets.platform))) {
|
||||
|
@ -781,6 +781,8 @@ define(function (require, exports, module) {
|
||||
menu.addMenuDivider();
|
||||
menu.addMenuItem(Commands.EDIT_DUPLICATE, "Ctrl-D");
|
||||
menu.addMenuItem(Commands.EDIT_LINE_COMMENT, "Ctrl-/");
|
||||
menu.addMenuDivider();
|
||||
menu.addMenuItem(Commands.TOGGLE_USE_TAB_CHARS);
|
||||
|
||||
/*
|
||||
* View menu
|
||||
@ -791,6 +793,8 @@ define(function (require, exports, module) {
|
||||
menu.addMenuItem(Commands.VIEW_INCREASE_FONT_SIZE, [{key: "Ctrl-=", displayKey: "Ctrl-+"}]);
|
||||
menu.addMenuItem(Commands.VIEW_DECREASE_FONT_SIZE, [{key: "Ctrl--", displayKey: "Ctrl-\u2212"}]);
|
||||
menu.addMenuItem(Commands.VIEW_RESTORE_FONT_SIZE, "Ctrl-0");
|
||||
menu.addMenuDivider();
|
||||
menu.addMenuItem(Commands.TOGGLE_JSLINT);
|
||||
|
||||
/*
|
||||
* Navigate menu
|
||||
@ -802,7 +806,7 @@ define(function (require, exports, module) {
|
||||
|
||||
menu.addMenuItem(Commands.NAVIGATE_GOTO_DEFINITION, "Ctrl-T");
|
||||
menu.addMenuDivider();
|
||||
menu.addMenuItem(Commands.SHOW_INLINE_EDITOR, "Ctrl-E");
|
||||
menu.addMenuItem(Commands.TOGGLE_QUICK_EDIT, "Ctrl-E");
|
||||
menu.addMenuItem(Commands.QUICK_EDIT_PREV_MATCH, {key: "Alt-Up", displayKey: "Alt-\u2191"});
|
||||
menu.addMenuItem(Commands.QUICK_EDIT_NEXT_MATCH, {key: "Alt-Down", displayKey: "Alt-\u2193"});
|
||||
|
||||
@ -810,20 +814,14 @@ define(function (require, exports, module) {
|
||||
* Debug menu
|
||||
*/
|
||||
menu = addMenu(Strings.DEBUG_MENU, AppMenuBar.DEBUG_MENU);
|
||||
menu.addMenuItem(Commands.DEBUG_REFRESH_WINDOW, [{key: "F5", platform: "win"},
|
||||
{key: "Ctrl-R", platform: "mac"}]);
|
||||
|
||||
menu.addMenuItem(Commands.DEBUG_SHOW_DEVELOPER_TOOLS, [{key: "F12", platform: "win"},
|
||||
{key: "Ctrl-Opt-I", platform: "mac"}]);
|
||||
menu.addMenuItem(Commands.DEBUG_RUN_UNIT_TESTS);
|
||||
menu.addMenuItem(Commands.DEBUG_JSLINT);
|
||||
menu.addMenuItem(Commands.DEBUG_SHOW_PERF_DATA);
|
||||
|
||||
menu.addMenuDivider();
|
||||
menu.addMenuItem(Commands.DEBUG_EXPERIMENTAL);
|
||||
menu.addMenuItem(Commands.DEBUG_REFRESH_WINDOW, [{key: "F5", platform: "win"},
|
||||
{key: "Ctrl-R", platform: "mac"}]);
|
||||
menu.addMenuItem(Commands.DEBUG_NEW_BRACKETS_WINDOW);
|
||||
menu.addMenuItem(Commands.DEBUG_CLOSE_ALL_LIVE_BROWSERS);
|
||||
menu.addMenuItem(Commands.DEBUG_USE_TAB_CHARS);
|
||||
menu.addMenuDivider();
|
||||
menu.addMenuItem(Commands.DEBUG_RUN_UNIT_TESTS);
|
||||
menu.addMenuItem(Commands.DEBUG_SHOW_PERF_DATA);
|
||||
|
||||
|
||||
/*
|
||||
@ -832,7 +830,7 @@ define(function (require, exports, module) {
|
||||
var project_cmenu = registerContextMenu(ContextMenuIds.PROJECT_MENU);
|
||||
|
||||
var editor_cmenu = registerContextMenu(ContextMenuIds.EDITOR_MENU);
|
||||
editor_cmenu.addMenuItem(Commands.SHOW_INLINE_EDITOR);
|
||||
editor_cmenu.addMenuItem(Commands.TOGGLE_QUICK_EDIT);
|
||||
editor_cmenu.addMenuItem(Commands.EDIT_SELECT_ALL);
|
||||
|
||||
/**
|
||||
|
@ -32,7 +32,6 @@ define(function (require, exports, module) {
|
||||
CommandManager = require("command/CommandManager"),
|
||||
Editor = require("editor/Editor").Editor,
|
||||
Strings = require("strings"),
|
||||
JSLintUtils = require("language/JSLintUtils"),
|
||||
PerfUtils = require("utils/PerfUtils"),
|
||||
NativeApp = require("utils/NativeApp");
|
||||
|
||||
@ -40,16 +39,10 @@ define(function (require, exports, module) {
|
||||
brackets.app.showDeveloperTools();
|
||||
}
|
||||
|
||||
function _handleEnableJSLint() {
|
||||
var enabled = !JSLintUtils.getEnabled();
|
||||
JSLintUtils.setEnabled(enabled);
|
||||
CommandManager.get(Commands.DEBUG_JSLINT).setChecked(enabled);
|
||||
}
|
||||
|
||||
function _handleUseTabChars() {
|
||||
var useTabs = !Editor.getUseTabChar();
|
||||
Editor.setUseTabChar(useTabs);
|
||||
CommandManager.get(Commands.DEBUG_USE_TAB_CHARS).setChecked(useTabs);
|
||||
CommandManager.get(Commands.TOGGLE_USE_TAB_CHARS).setChecked(useTabs);
|
||||
}
|
||||
|
||||
|
||||
@ -138,24 +131,14 @@ define(function (require, exports, module) {
|
||||
window.open(window.location.href);
|
||||
}
|
||||
|
||||
function _handleCloseAllLiveBrowsers() {
|
||||
NativeApp.closeAllLiveBrowsers().always(function () {
|
||||
console.log("all live browsers closed");
|
||||
});
|
||||
}
|
||||
|
||||
// Register all the command handlers
|
||||
CommandManager.register(Strings.CMD_SHOW_DEV_TOOLS, Commands.DEBUG_SHOW_DEVELOPER_TOOLS, handleShowDeveloperTools);
|
||||
CommandManager.register(Strings.CMD_JSLINT, Commands.DEBUG_JSLINT, _handleEnableJSLint)
|
||||
.setChecked(JSLintUtils.getEnabled());
|
||||
CommandManager.register(Strings.CMD_RUN_UNIT_TESTS, Commands.DEBUG_RUN_UNIT_TESTS, _handleRunUnitTests);
|
||||
CommandManager.register(Strings.CMD_SHOW_PERF_DATA, Commands.DEBUG_SHOW_PERF_DATA, _handleShowPerfData);
|
||||
CommandManager.register(Strings.CMD_EXPERIMENTAL, Commands.DEBUG_EXPERIMENTAL, function () {})
|
||||
.setEnabled(false);
|
||||
CommandManager.register(Strings.CMD_NEW_BRACKETS_WINDOW,
|
||||
Commands.DEBUG_NEW_BRACKETS_WINDOW, _handleNewBracketsWindow);
|
||||
CommandManager.register(Strings.CMD_CLOSE_ALL_LIVE_BROWSERS,
|
||||
Commands.DEBUG_CLOSE_ALL_LIVE_BROWSERS, _handleCloseAllLiveBrowsers);
|
||||
CommandManager.register(Strings.CMD_USE_TAB_CHARS, Commands.DEBUG_USE_TAB_CHARS, _handleUseTabChars)
|
||||
|
||||
CommandManager.register(Strings.CMD_USE_TAB_CHARS, Commands.TOGGLE_USE_TAB_CHARS, _handleUseTabChars)
|
||||
.setChecked(Editor.getUseTabChar());
|
||||
});
|
||||
|
@ -501,15 +501,20 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Show Inline Editor command handler
|
||||
* Toggle Quick Edit command handler
|
||||
* @return {!Promise} A promise resolved with true if an inline editor
|
||||
* is opened or false when closed. The promise is rejected if there
|
||||
* is no current editor or an inline editor is not created.
|
||||
*/
|
||||
function _showInlineEditor() {
|
||||
function _toggleQuickEdit() {
|
||||
var result = new $.Deferred();
|
||||
|
||||
if (_currentEditor) {
|
||||
var inlineWidget = null,
|
||||
result = getFocusedInlineWidget();
|
||||
focusedWidgetResult = getFocusedInlineWidget();
|
||||
|
||||
if (result) {
|
||||
inlineWidget = result.widget;
|
||||
if (focusedWidgetResult) {
|
||||
inlineWidget = focusedWidgetResult.widget;
|
||||
}
|
||||
|
||||
if (inlineWidget) {
|
||||
@ -517,14 +522,26 @@ define(function (require, exports, module) {
|
||||
PerfUtils.markStart(PerfUtils.INLINE_EDITOR_CLOSE);
|
||||
inlineWidget.close();
|
||||
PerfUtils.addMeasurement(PerfUtils.INLINE_EDITOR_CLOSE);
|
||||
|
||||
// return a resolved promise to CommandManager
|
||||
result.resolve(false);
|
||||
} else {
|
||||
// main editor has focus, so create an inline editor
|
||||
_openInlineWidget(_currentEditor);
|
||||
_openInlineWidget(_currentEditor).done(function () {
|
||||
result.resolve(true);
|
||||
}).fail(function () {
|
||||
result.reject();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Can not open an inline editor without a host editor
|
||||
result.reject();
|
||||
}
|
||||
|
||||
return result.promise();
|
||||
}
|
||||
|
||||
CommandManager.register(Strings.CMD_SHOW_INLINE_EDITOR, Commands.SHOW_INLINE_EDITOR, _showInlineEditor);
|
||||
CommandManager.register(Strings.CMD_TOGGLE_QUICK_EDIT, Commands.TOGGLE_QUICK_EDIT, _toggleQuickEdit);
|
||||
|
||||
// Initialize: register listeners
|
||||
$(DocumentManager).on("currentDocumentChange", _onCurrentDocumentChange);
|
||||
|
@ -164,6 +164,7 @@ define(function (require, exports, module) {
|
||||
PerfUtils.createPerfMeasurement("JAVASCRIPT_FIND_FUNCTION", "JavaScript Find Function");
|
||||
|
||||
// for unit tests only
|
||||
exports._createInlineEditor = _createInlineEditor;
|
||||
exports._findInProject = _findInProject;
|
||||
exports.javaScriptFunctionProvider = javaScriptFunctionProvider;
|
||||
exports._createInlineEditor = _createInlineEditor;
|
||||
exports._findInProject = _findInProject;
|
||||
});
|
||||
|
@ -0,0 +1,9 @@
|
||||
function foo () {
|
||||
}
|
||||
|
||||
var regExp = /{{0}}foo()/;
|
||||
/*
|
||||
{{1}}foo()
|
||||
*/
|
||||
// {{2}}foo()
|
||||
var str1 = "{{3}}foo()", str2 = '{{4}}foo()';
|
@ -0,0 +1,4 @@
|
||||
<div>
|
||||
<div class="filename"><span/></div>
|
||||
<img style="display: block; margin: 20px auto; opacity: 0;"/>
|
||||
</div>
|
@ -31,6 +31,9 @@ define(function (require, exports, module) {
|
||||
// Load Brackets modules
|
||||
var InlineWidget = brackets.getModule("editor/InlineWidget").InlineWidget;
|
||||
|
||||
// Load tempalte
|
||||
var inlineEditorTemplate = require("text!InlineImageViewer.html");
|
||||
|
||||
function InlineImageViewer(fileName, fullPath) {
|
||||
this.fileName = fileName;
|
||||
this.fullPath = fullPath;
|
||||
@ -47,23 +50,16 @@ define(function (require, exports, module) {
|
||||
|
||||
InlineImageViewer.prototype.load = function (hostEditor) {
|
||||
this.parentClass.load.call(this, hostEditor);
|
||||
|
||||
|
||||
this.$wrapperDiv = $(inlineEditorTemplate);
|
||||
|
||||
// TODO (jason-sanjose): Use handlebars.js and update template to
|
||||
// use expressions instead e.g. {{filename}}
|
||||
// Header
|
||||
var $filenameDiv = $("<div/>")
|
||||
.addClass("filename")
|
||||
.append($("<span></span>").text(this.fileName));
|
||||
$(this.$wrapperDiv.find("span")).text(this.fileName);
|
||||
|
||||
// Image
|
||||
this.$image = $("<img/>")
|
||||
.css("display", "block")
|
||||
.css("margin", "20px auto")
|
||||
.css("opacity", 0)
|
||||
.attr("src", this.fullPath);
|
||||
|
||||
// Wrapper
|
||||
this.$wrapperDiv = $("<div/>")
|
||||
.append($filenameDiv)
|
||||
.append(this.$image);
|
||||
this.$image = $(this.$wrapperDiv.find("img")).attr("src", this.fullPath);
|
||||
|
||||
this.$htmlContent.append(this.$wrapperDiv);
|
||||
this.$htmlContent.click(this.close.bind(this));
|
||||
|
@ -37,9 +37,12 @@ define(function (require, exports, module) {
|
||||
require("thirdparty/jslint/jslint");
|
||||
|
||||
// Load dependent modules
|
||||
var DocumentManager = require("document/DocumentManager"),
|
||||
var Commands = require("command/Commands"),
|
||||
CommandManager = require("command/CommandManager"),
|
||||
DocumentManager = require("document/DocumentManager"),
|
||||
PreferencesManager = require("preferences/PreferencesManager"),
|
||||
PerfUtils = require("utils/PerfUtils"),
|
||||
Strings = require("strings"),
|
||||
EditorManager = require("editor/EditorManager");
|
||||
|
||||
/**
|
||||
@ -172,6 +175,8 @@ define(function (require, exports, module) {
|
||||
|
||||
function _setEnabled(enabled) {
|
||||
_enabled = enabled;
|
||||
|
||||
CommandManager.get(Commands.TOGGLE_JSLINT).setChecked(_enabled);
|
||||
_updateListeners();
|
||||
_prefs.setValue("enabled", _enabled);
|
||||
|
||||
@ -189,6 +194,15 @@ define(function (require, exports, module) {
|
||||
}
|
||||
}
|
||||
|
||||
/** Command to toggle enablement */
|
||||
function _handleToggleJSLint() {
|
||||
setEnabled(!getEnabled());
|
||||
}
|
||||
|
||||
|
||||
// Register command handlers
|
||||
CommandManager.register(Strings.CMD_JSLINT, Commands.TOGGLE_JSLINT, _handleToggleJSLint);
|
||||
|
||||
// Init PreferenceStorage
|
||||
_prefs = PreferencesManager.getPreferenceStorage(module.id, { enabled: true });
|
||||
_setEnabled(_prefs.getValue("enabled"));
|
||||
|
@ -167,8 +167,9 @@ define(function (require, exports, module) {
|
||||
_updateFileStatusIcon($newItem, isOpenAndDirty(file), false);
|
||||
_updateListItemSelection($newItem, curDoc);
|
||||
|
||||
$newItem.mousedown(function () {
|
||||
$newItem.mousedown(function (e) {
|
||||
FileViewController.openAndSelectDocument(file.fullPath, FileViewController.WORKING_SET_VIEW);
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$newItem.hover(
|
||||
|
@ -98,8 +98,7 @@ define(function (require, exports, module) {
|
||||
|
||||
/**
|
||||
* Command Name Constants
|
||||
*
|
||||
*/
|
||||
*/
|
||||
|
||||
// File menu commands
|
||||
exports.FILE_MENU = "File";
|
||||
@ -137,7 +136,7 @@ define(function (require, exports, module) {
|
||||
exports.CMD_QUICK_OPEN = "Quick Open";
|
||||
exports.CMD_GOTO_LINE = "Go to Line";
|
||||
exports.CMD_GOTO_DEFINITION = "Go to Definition";
|
||||
exports.CMD_SHOW_INLINE_EDITOR = "Quick Edit";
|
||||
exports.CMD_TOGGLE_QUICK_EDIT = "Quick Edit";
|
||||
exports.CMD_QUICK_EDIT_PREV_MATCH = "Previous Match";
|
||||
exports.CMD_QUICK_EDIT_NEXT_MATCH = "Next Match";
|
||||
exports.CMD_NEXT_DOC = "Next Document";
|
||||
@ -145,18 +144,17 @@ define(function (require, exports, module) {
|
||||
|
||||
// Debug menu commands
|
||||
exports.DEBUG_MENU = "Debug";
|
||||
exports.CMD_REFRESH_WINDOW = "Reload Window";
|
||||
exports.CMD_CLOSE_WINDOW = "Close Window";
|
||||
exports.CMD_REFRESH_WINDOW = "Reload Brackets";
|
||||
exports.CMD_SHOW_DEV_TOOLS = "Show Developer Tools";
|
||||
exports.CMD_RUN_UNIT_TESTS = "Run Tests";
|
||||
exports.CMD_JSLINT = "Enable JSLint";
|
||||
exports.CMD_SHOW_PERF_DATA = "Show Perf Data";
|
||||
exports.CMD_EXPERIMENTAL = "Experimental";
|
||||
exports.CMD_NEW_BRACKETS_WINDOW = "New Window";
|
||||
exports.CMD_CLOSE_ALL_LIVE_BROWSERS = "Close Browsers";
|
||||
exports.CMD_SHOW_PERF_DATA = "Show Performance Data";
|
||||
exports.CMD_NEW_BRACKETS_WINDOW = "New Brackets Window";
|
||||
exports.CMD_USE_TAB_CHARS = "Use Tab Characters";
|
||||
|
||||
// Help menu commands
|
||||
exports.CMD_ABOUT = "About";
|
||||
|
||||
// Special commands invoked by the native shell
|
||||
exports.CMD_CLOSE_WINDOW = "Close Window";
|
||||
});
|
||||
|
282
src/thirdparty/text.js
vendored
Executable file
282
src/thirdparty/text.js
vendored
Executable file
@ -0,0 +1,282 @@
|
||||
/**
|
||||
* @license RequireJS text 1.0.8 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
|
||||
* Available via the MIT or new BSD license.
|
||||
* see: http://github.com/jrburke/requirejs for details
|
||||
*/
|
||||
/*jslint regexp: true, plusplus: true, sloppy: true */
|
||||
/*global require: false, XMLHttpRequest: false, ActiveXObject: false,
|
||||
define: false, window: false, process: false, Packages: false,
|
||||
java: false, location: false */
|
||||
|
||||
(function () {
|
||||
var progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'],
|
||||
xmlRegExp = /^\s*<\?xml(\s)+version=[\'\"](\d)*.(\d)*[\'\"](\s)*\?>/im,
|
||||
bodyRegExp = /<body[^>]*>\s*([\s\S]+)\s*<\/body>/im,
|
||||
hasLocation = typeof location !== 'undefined' && location.href,
|
||||
defaultProtocol = hasLocation && location.protocol && location.protocol.replace(/\:/, ''),
|
||||
defaultHostName = hasLocation && location.hostname,
|
||||
defaultPort = hasLocation && (location.port || undefined),
|
||||
buildMap = [];
|
||||
|
||||
define(function () {
|
||||
var text, fs;
|
||||
|
||||
text = {
|
||||
version: '1.0.8',
|
||||
|
||||
strip: function (content) {
|
||||
//Strips <?xml ...?> declarations so that external SVG and XML
|
||||
//documents can be added to a document without worry. Also, if the string
|
||||
//is an HTML document, only the part inside the body tag is returned.
|
||||
if (content) {
|
||||
content = content.replace(xmlRegExp, "");
|
||||
var matches = content.match(bodyRegExp);
|
||||
if (matches) {
|
||||
content = matches[1];
|
||||
}
|
||||
} else {
|
||||
content = "";
|
||||
}
|
||||
return content;
|
||||
},
|
||||
|
||||
jsEscape: function (content) {
|
||||
return content.replace(/(['\\])/g, '\\$1')
|
||||
.replace(/[\f]/g, "\\f")
|
||||
.replace(/[\b]/g, "\\b")
|
||||
.replace(/[\n]/g, "\\n")
|
||||
.replace(/[\t]/g, "\\t")
|
||||
.replace(/[\r]/g, "\\r");
|
||||
},
|
||||
|
||||
createXhr: function () {
|
||||
//Would love to dump the ActiveX crap in here. Need IE 6 to die first.
|
||||
var xhr, i, progId;
|
||||
if (typeof XMLHttpRequest !== "undefined") {
|
||||
return new XMLHttpRequest();
|
||||
} else if (typeof ActiveXObject !== "undefined") {
|
||||
for (i = 0; i < 3; i++) {
|
||||
progId = progIds[i];
|
||||
try {
|
||||
xhr = new ActiveXObject(progId);
|
||||
} catch (e) {}
|
||||
|
||||
if (xhr) {
|
||||
progIds = [progId]; // so faster next time
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return xhr;
|
||||
},
|
||||
|
||||
/**
|
||||
* Parses a resource name into its component parts. Resource names
|
||||
* look like: module/name.ext!strip, where the !strip part is
|
||||
* optional.
|
||||
* @param {String} name the resource name
|
||||
* @returns {Object} with properties "moduleName", "ext" and "strip"
|
||||
* where strip is a boolean.
|
||||
*/
|
||||
parseName: function (name) {
|
||||
var strip = false, index = name.indexOf("."),
|
||||
modName = name.substring(0, index),
|
||||
ext = name.substring(index + 1, name.length);
|
||||
|
||||
index = ext.indexOf("!");
|
||||
if (index !== -1) {
|
||||
//Pull off the strip arg.
|
||||
strip = ext.substring(index + 1, ext.length);
|
||||
strip = strip === "strip";
|
||||
ext = ext.substring(0, index);
|
||||
}
|
||||
|
||||
return {
|
||||
moduleName: modName,
|
||||
ext: ext,
|
||||
strip: strip
|
||||
};
|
||||
},
|
||||
|
||||
xdRegExp: /^((\w+)\:)?\/\/([^\/\\]+)/,
|
||||
|
||||
/**
|
||||
* Is an URL on another domain. Only works for browser use, returns
|
||||
* false in non-browser environments. Only used to know if an
|
||||
* optimized .js version of a text resource should be loaded
|
||||
* instead.
|
||||
* @param {String} url
|
||||
* @returns Boolean
|
||||
*/
|
||||
useXhr: function (url, protocol, hostname, port) {
|
||||
var match = text.xdRegExp.exec(url),
|
||||
uProtocol, uHostName, uPort;
|
||||
if (!match) {
|
||||
return true;
|
||||
}
|
||||
uProtocol = match[2];
|
||||
uHostName = match[3];
|
||||
|
||||
uHostName = uHostName.split(':');
|
||||
uPort = uHostName[1];
|
||||
uHostName = uHostName[0];
|
||||
|
||||
return (!uProtocol || uProtocol === protocol) &&
|
||||
(!uHostName || uHostName === hostname) &&
|
||||
((!uPort && !uHostName) || uPort === port);
|
||||
},
|
||||
|
||||
finishLoad: function (name, strip, content, onLoad, config) {
|
||||
content = strip ? text.strip(content) : content;
|
||||
if (config.isBuild) {
|
||||
buildMap[name] = content;
|
||||
}
|
||||
onLoad(content);
|
||||
},
|
||||
|
||||
load: function (name, req, onLoad, config) {
|
||||
//Name has format: some.module.filext!strip
|
||||
//The strip part is optional.
|
||||
//if strip is present, then that means only get the string contents
|
||||
//inside a body tag in an HTML string. For XML/SVG content it means
|
||||
//removing the <?xml ...?> declarations so the content can be inserted
|
||||
//into the current doc without problems.
|
||||
|
||||
// Do not bother with the work if a build and text will
|
||||
// not be inlined.
|
||||
if (config.isBuild && !config.inlineText) {
|
||||
onLoad();
|
||||
return;
|
||||
}
|
||||
|
||||
var parsed = text.parseName(name),
|
||||
nonStripName = parsed.moduleName + '.' + parsed.ext,
|
||||
url = req.toUrl(nonStripName),
|
||||
useXhr = (config && config.text && config.text.useXhr) ||
|
||||
text.useXhr;
|
||||
|
||||
//Load the text. Use XHR if possible and in a browser.
|
||||
if (!hasLocation || useXhr(url, defaultProtocol, defaultHostName, defaultPort)) {
|
||||
text.get(url, function (content) {
|
||||
text.finishLoad(name, parsed.strip, content, onLoad, config);
|
||||
});
|
||||
} else {
|
||||
//Need to fetch the resource across domains. Assume
|
||||
//the resource has been optimized into a JS module. Fetch
|
||||
//by the module name + extension, but do not include the
|
||||
//!strip part to avoid file system issues.
|
||||
req([nonStripName], function (content) {
|
||||
text.finishLoad(parsed.moduleName + '.' + parsed.ext,
|
||||
parsed.strip, content, onLoad, config);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
write: function (pluginName, moduleName, write, config) {
|
||||
if (buildMap.hasOwnProperty(moduleName)) {
|
||||
var content = text.jsEscape(buildMap[moduleName]);
|
||||
write.asModule(pluginName + "!" + moduleName,
|
||||
"define(function () { return '" +
|
||||
content +
|
||||
"';});\n");
|
||||
}
|
||||
},
|
||||
|
||||
writeFile: function (pluginName, moduleName, req, write, config) {
|
||||
var parsed = text.parseName(moduleName),
|
||||
nonStripName = parsed.moduleName + '.' + parsed.ext,
|
||||
//Use a '.js' file name so that it indicates it is a
|
||||
//script that can be loaded across domains.
|
||||
fileName = req.toUrl(parsed.moduleName + '.' +
|
||||
parsed.ext) + '.js';
|
||||
|
||||
//Leverage own load() method to load plugin value, but only
|
||||
//write out values that do not have the strip argument,
|
||||
//to avoid any potential issues with ! in file names.
|
||||
text.load(nonStripName, req, function (value) {
|
||||
//Use own write() method to construct full module value.
|
||||
//But need to create shell that translates writeFile's
|
||||
//write() to the right interface.
|
||||
var textWrite = function (contents) {
|
||||
return write(fileName, contents);
|
||||
};
|
||||
textWrite.asModule = function (moduleName, contents) {
|
||||
return write.asModule(moduleName, fileName, contents);
|
||||
};
|
||||
|
||||
text.write(pluginName, nonStripName, textWrite, config);
|
||||
}, config);
|
||||
}
|
||||
};
|
||||
|
||||
if (text.createXhr()) {
|
||||
text.get = function (url, callback) {
|
||||
var xhr = text.createXhr();
|
||||
xhr.open('GET', url, true);
|
||||
xhr.onreadystatechange = function (evt) {
|
||||
//Do not explicitly handle errors, those should be
|
||||
//visible via console output in the browser.
|
||||
if (xhr.readyState === 4) {
|
||||
callback(xhr.responseText);
|
||||
}
|
||||
};
|
||||
xhr.send(null);
|
||||
};
|
||||
} else if (typeof process !== "undefined" &&
|
||||
process.versions &&
|
||||
!!process.versions.node) {
|
||||
//Using special require.nodeRequire, something added by r.js.
|
||||
fs = require.nodeRequire('fs');
|
||||
|
||||
text.get = function (url, callback) {
|
||||
var file = fs.readFileSync(url, 'utf8');
|
||||
//Remove BOM (Byte Mark Order) from utf8 files if it is there.
|
||||
if (file.indexOf('\uFEFF') === 0) {
|
||||
file = file.substring(1);
|
||||
}
|
||||
callback(file);
|
||||
};
|
||||
} else if (typeof Packages !== 'undefined') {
|
||||
//Why Java, why is this so awkward?
|
||||
text.get = function (url, callback) {
|
||||
var encoding = "utf-8",
|
||||
file = new java.io.File(url),
|
||||
lineSeparator = java.lang.System.getProperty("line.separator"),
|
||||
input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(file), encoding)),
|
||||
stringBuffer, line,
|
||||
content = '';
|
||||
try {
|
||||
stringBuffer = new java.lang.StringBuffer();
|
||||
line = input.readLine();
|
||||
|
||||
// Byte Order Mark (BOM) - The Unicode Standard, version 3.0, page 324
|
||||
// http://www.unicode.org/faq/utf_bom.html
|
||||
|
||||
// Note that when we use utf-8, the BOM should appear as "EF BB BF", but it doesn't due to this bug in the JDK:
|
||||
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4508058
|
||||
if (line && line.length() && line.charAt(0) === 0xfeff) {
|
||||
// Eat the BOM, since we've already found the encoding on this file,
|
||||
// and we plan to concatenating this buffer with others; the BOM should
|
||||
// only appear at the top of a file.
|
||||
line = line.substring(1);
|
||||
}
|
||||
|
||||
stringBuffer.append(line);
|
||||
|
||||
while ((line = input.readLine()) !== null) {
|
||||
stringBuffer.append(lineSeparator);
|
||||
stringBuffer.append(line);
|
||||
}
|
||||
//Make sure we return a JavaScript string and not a Java string.
|
||||
content = String(stringBuffer.toString()); //String
|
||||
} finally {
|
||||
input.close();
|
||||
}
|
||||
callback(content);
|
||||
};
|
||||
}
|
||||
|
||||
return text;
|
||||
});
|
||||
}());
|
@ -60,7 +60,11 @@ define(function (require, exports, module) {
|
||||
var result = new $.Deferred(),
|
||||
extensionRequire = brackets.libRequire.config({
|
||||
context: name,
|
||||
baseUrl: config.baseUrl
|
||||
baseUrl: config.baseUrl,
|
||||
/* FIXME (issue #1087): can we pass this from the global require context instead of hardcoding twice? */
|
||||
paths: {
|
||||
"text" : "../../../thirdparty/text"
|
||||
}
|
||||
});
|
||||
contexts[name] = extensionRequire;
|
||||
|
||||
|
@ -39,9 +39,10 @@ define(function (require, exports, module) {
|
||||
* @return {!$.Promise} A promise object that is resolved if the CSS file can be loaded.
|
||||
*/
|
||||
function loadStyleSheet(module, path) {
|
||||
var url = encodeURI(module.uri.replace("main.js", "") + path),
|
||||
var modulePath = module.uri.substr(0, module.uri.lastIndexOf("/") + 1),
|
||||
url = encodeURI(modulePath + path),
|
||||
result = new $.Deferred();
|
||||
|
||||
|
||||
// Make a request for the same file in order to record success or failure.
|
||||
// The link element's onload and onerror events are not consistently supported.
|
||||
$.get(url).done(function () {
|
||||
|
@ -94,6 +94,7 @@ define(function (require, exports, module) {
|
||||
|
||||
/** closeAllLiveBrowsers
|
||||
* Closes all the browsers that were tracked on open
|
||||
* TODO: does not seem to work on Windows
|
||||
* @return {$.Promise}
|
||||
*/
|
||||
function closeAllLiveBrowsers() {
|
||||
|
@ -34,6 +34,7 @@ define(function (require, exports, module) {
|
||||
require("spec/DocumentCommandHandlers-test");
|
||||
require("spec/Editor-test");
|
||||
require("spec/EditorCommandHandlers-test");
|
||||
require("spec/ExtensionUtils-test");
|
||||
require("spec/FileIndexManager-test");
|
||||
require("spec/InlineEditorProviders-test");
|
||||
require("spec/KeyBindingManager-test");
|
||||
|
@ -80,7 +80,7 @@ define(function (require, exports, module) {
|
||||
});
|
||||
runs(function () {
|
||||
// Open inline editor onto test.css's ".testClass" rule
|
||||
promise = SpecRunnerUtils.openInlineEditorAtOffset(EditorManager.getCurrentFullEditor(), {line: 8, ch: 4});
|
||||
promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 8, ch: 4});
|
||||
waitsForDone(promise, "Open inline editor");
|
||||
});
|
||||
runs(function () {
|
||||
|
6
test/spec/ExtensionUtils-test-files/basic.css
Normal file
6
test/spec/ExtensionUtils-test-files/basic.css
Normal file
@ -0,0 +1,6 @@
|
||||
/* basic.css */
|
||||
@import url("sub dir/second.css");
|
||||
|
||||
#project-title {
|
||||
font-size: 25px;
|
||||
}
|
5
test/spec/ExtensionUtils-test-files/sub dir/second.css
Normal file
5
test/spec/ExtensionUtils-test-files/sub dir/second.css
Normal file
@ -0,0 +1,5 @@
|
||||
/* second.css */
|
||||
|
||||
#project-title {
|
||||
font-weight: 500;
|
||||
}
|
5
test/spec/ExtensionUtils-test-files/sub dir/third.css
Normal file
5
test/spec/ExtensionUtils-test-files/sub dir/third.css
Normal file
@ -0,0 +1,5 @@
|
||||
/* HighASCII_été.css */
|
||||
|
||||
#project-title {
|
||||
font-variant: small-caps;
|
||||
}
|
90
test/spec/ExtensionUtils-test.js
Normal file
90
test/spec/ExtensionUtils-test.js
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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, nomen: true, indent: 4, maxerr: 50 */
|
||||
/*global define, describe, it, expect, beforeEach, afterEach, waitsFor, runs, waitsForDone, $ */
|
||||
|
||||
define(function (require, exports, module) {
|
||||
'use strict';
|
||||
|
||||
var ExtensionUtils,
|
||||
SpecRunnerUtils = require("./SpecRunnerUtils.js");
|
||||
|
||||
|
||||
describe("Extension Utils", function () {
|
||||
|
||||
var testWindow;
|
||||
|
||||
beforeEach(function () {
|
||||
SpecRunnerUtils.createTestWindowAndRun(this, function (w) {
|
||||
testWindow = w;
|
||||
|
||||
// Load module instances from brackets.test
|
||||
ExtensionUtils = testWindow.brackets.test.ExtensionUtils;
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
SpecRunnerUtils.closeTestWindow();
|
||||
});
|
||||
|
||||
describe("loadStyleSheet", function () {
|
||||
|
||||
// putting everything in 1 test so it runs faster
|
||||
it("should attach style sheets", function () {
|
||||
|
||||
// attach style sheet
|
||||
runs(function () {
|
||||
var promise = ExtensionUtils.loadStyleSheet(module, "ExtensionUtils-test-files/basic.css");
|
||||
waitsForDone(promise, "loadStyleSheet: basic.css");
|
||||
});
|
||||
|
||||
// placing this code in a separate closure forces styles to update
|
||||
runs(function () {
|
||||
// basic.css
|
||||
var $projectTitle = testWindow.$("#project-title");
|
||||
var fontSize = $projectTitle.css("font-size");
|
||||
expect(fontSize).toEqual("25px");
|
||||
|
||||
// second.css is imported in basic.css
|
||||
var fontWeight = $projectTitle.css("font-weight");
|
||||
expect(fontWeight).toEqual("500");
|
||||
});
|
||||
|
||||
// attach another style sheet in a sub-directory with space and high-ascii chars in name.
|
||||
// note that git choked on double-byte chars, so those were removed.
|
||||
runs(function () {
|
||||
var promise = ExtensionUtils.loadStyleSheet(module, "ExtensionUtils-test-files/sub dir/third.css");
|
||||
waitsForDone(promise, "loadStyleSheet: third.css");
|
||||
});
|
||||
|
||||
runs(function () {
|
||||
// HighASCII_été.css
|
||||
var $projectTitle = testWindow.$("#project-title");
|
||||
var fontVariant = $projectTitle.css("font-variant");
|
||||
expect(fontVariant).toEqual("small-caps");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -134,13 +134,13 @@ define(function (require, exports, module) {
|
||||
var editor = EditorManager.getCurrentFullEditor();
|
||||
|
||||
// open inline editor at specified offset index
|
||||
var inlineEditorResult = SpecRunnerUtils.openInlineEditorAtOffset(
|
||||
var inlineEditorResult = SpecRunnerUtils.toggleQuickEditAtOffset(
|
||||
editor,
|
||||
spec.infos[openFile].offsets[openOffset]
|
||||
);
|
||||
|
||||
inlineEditorResult.done(function () {
|
||||
inlineOpened = true;
|
||||
inlineEditorResult.done(function (isOpened) {
|
||||
inlineOpened = isOpened;
|
||||
}).fail(function () {
|
||||
inlineOpened = false;
|
||||
});
|
||||
|
@ -436,11 +436,10 @@ define(function (require, exports, module) {
|
||||
* @return {$.Promise} a promise that will be resolved when an inline
|
||||
* editor is created or rejected when no inline editors are available.
|
||||
*/
|
||||
function openInlineEditorAtOffset(editor, offset) {
|
||||
function toggleQuickEditAtOffset(editor, offset) {
|
||||
editor.setCursorPos(offset.line, offset.ch);
|
||||
|
||||
// TODO (jasonsj): refactor CMD+E as a Command instead of a CodeMirror key binding?
|
||||
return testWindow.brackets.test.EditorManager._openInlineWidget(editor);
|
||||
return testWindow.executeCommand(Commands.TOGGLE_QUICK_EDIT);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -475,7 +474,7 @@ define(function (require, exports, module) {
|
||||
exports.clickDialogButton = clickDialogButton;
|
||||
exports.loadProjectInTestWindow = loadProjectInTestWindow;
|
||||
exports.openProjectFiles = openProjectFiles;
|
||||
exports.openInlineEditorAtOffset = openInlineEditorAtOffset;
|
||||
exports.toggleQuickEditAtOffset = toggleQuickEditAtOffset;
|
||||
exports.saveFilesWithOffsets = saveFilesWithOffsets;
|
||||
exports.saveFilesWithoutOffsets = saveFilesWithoutOffsets;
|
||||
exports.saveFileWithoutOffsets = saveFileWithoutOffsets;
|
||||
|
Loading…
Reference in New Issue
Block a user