Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 54 additions & 23 deletions src/command/CommandManager.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/*
* 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
* 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,
* 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
* 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.
*
*
*/


Expand Down Expand Up @@ -102,7 +102,7 @@ define(function (require, exports, module) {
return this._enabled;
};

/**
/**
* Sets enabled state of Command and dispatches "enabledStateChange"
* when the enabled state changes.
* @param {boolean} enabled
Expand All @@ -116,7 +116,7 @@ define(function (require, exports, module) {
}
};

/**
/**
* Sets enabled state of Command and dispatches "checkedStateChange"
* when the enabled state changes.
* @param {boolean} checked
Expand All @@ -138,11 +138,11 @@ define(function (require, exports, module) {
/**
* Sets the name of the Command and dispatches "nameChange" so that
* UI that reflects the command name can update.
*
*
* Note, a Command name can appear in either HTML or native UI
* so HTML tags should not be used. To add a Unicode character,
* use \uXXXX instead of an HTML entity.
*
*
* @param {string} name
*/
Command.prototype.setName = function (name) {
Expand All @@ -166,7 +166,7 @@ define(function (require, exports, module) {
* @param {string} name - text that will be displayed in the UI to represent command
* @param {string} id - unique identifier for command.
* Core commands in Brackets use a simple command title as an id, for example "open.file".
* Extensions should use the following format: "author.myextension.mycommandname".
* Extensions should use the following format: "author.myextension.mycommandname".
* For example, "lschmitt.csswizard.format.css".
* @param {function(...)} commandFn - the function to call when the command is executed. Any arguments passed to
* execute() (after the id) are passed as arguments to the function. If the function is asynchronous,
Expand All @@ -192,6 +192,36 @@ define(function (require, exports, module) {
return command;
}

/**
* Registers a global internal only command.
* @param {string} id - unique identifier for command.
* Core commands in Brackets use a simple command title as an id, for example "app.abort_quit".
* Extensions should use the following format: "author.myextension.mycommandname".
* For example, "lschmitt.csswizard.format.css".
* @param {function(...)} commandFn - the function to call when the command is executed. Any arguments passed to
* execute() (after the id) are passed as arguments to the function. If the function is asynchronous,
* it must return a jQuery promise that is resolved when the command completes. Otherwise, the
* CommandManager will assume it is synchronous, and return a promise that is already resolved.
* @return {?Command}
*/
function registerInternal(id, commandFn) {
if (_commands[id]) {
console.log("Attempting to register an already-registered command: " + id);
return null;
}
if (!id || !commandFn) {
console.error("Attempting to register an internal command with a missing id, or command function: " + id);
return null;
}

var command = new Command(null, id, commandFn);
_commands[id] = command;

$(exports).triggerHandler("commandRegistered", [command]);

return command;
}

/**
* Clear all commands for unit testing, but first make copy of commands so that
* they can be restored afterward
Expand Down Expand Up @@ -249,10 +279,11 @@ define(function (require, exports, module) {
}

// Define public API
exports.register = register;
exports.execute = execute;
exports.get = get;
exports.getAll = getAll;
exports._testReset = _testReset;
exports._testRestore = _testRestore;
exports.register = register;
exports.registerInternal = registerInternal;
exports.execute = execute;
exports.get = get;
exports.getAll = getAll;
exports._testReset = _testReset;
exports._testRestore = _testRestore;
});
49 changes: 25 additions & 24 deletions src/document/DocumentCommandHandlers.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/*
* 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
* 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,
* 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
* 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.
*
*
*/


Expand Down Expand Up @@ -119,7 +119,7 @@ define(function (require, exports, module) {
/**
* Returns a short title for a given document.
*
* @param {Document} doc
* @param {Document} doc
* @return {string} - a short title for doc.
*/
function _shortTitleForDocument(doc) {
Expand Down Expand Up @@ -216,11 +216,11 @@ define(function (require, exports, module) {

/**
* @private
* Creates a document and displays an editor for the specified file path.
* Creates a document and displays an editor for the specified file path.
* If no path is specified, a file prompt is provided for input.
* @param {?string} fullPath - The path of the file to open; if it's null we'll prompt for it
* @param {boolean=} silent - If true, don't show error message
* @return {$.Promise} a jQuery promise that will be resolved with a new
* @return {$.Promise} a jQuery promise that will be resolved with a new
* document for the specified file path, or rejected if the file can not be read.
*/
function _doOpenWithOptionalPath(fullPath, silent) {
Expand Down Expand Up @@ -269,12 +269,12 @@ define(function (require, exports, module) {
* @private
* Splits a decorated file path into its parts.
* @param {?string} path - a string of the form "fullpath[:lineNumber[:columnNumber]]"
* @return {{path: string, line: ?number, column: ?number}}
* @return {{path: string, line: ?number, column: ?number}}
*/
function _parseDecoratedPath(path) {
var result = {path: path, line: null, column: null};
if (path) {
// If the path has a trailing :lineNumber and :columnNumber, strip
// If the path has a trailing :lineNumber and :columnNumber, strip
// these off and assign to result.line and result.column.
var matchResult = /(.+?):([0-9]+)(:([0-9]+))?$/.exec(path);
if (matchResult) {
Expand Down Expand Up @@ -322,7 +322,7 @@ define(function (require, exports, module) {
// from command line: ...../Brackets.app/Contents path - where 'path' is undecorated
// from command line: ...../Brackets.app path - where 'path' has the form "path:line"
// from command line: ...../Brackets.app path - where 'path' has the form "path:line:column"
// from command line: open -a ...../Brackets.app path - where 'path' is undecorated
// from command line: open -a ...../Brackets.app path - where 'path' is undecorated
// do "View Source" from Adobe Scout version 1.2 or newer (this will use decorated paths of the form "path:line:column")
}

Expand All @@ -345,7 +345,7 @@ define(function (require, exports, module) {
* @param {string} baseFileName The base to start with, "-n" will get appened to make unique
* @param {string} fileExt The file extension
* @param {boolean} isFolder True if the suggestion is for a folder name
* @return {$.Promise} a jQuery promise that will be resolved with a unique name starting with
* @return {$.Promise} a jQuery promise that will be resolved with a unique name starting with
* the given base name
*/
function _getUntitledFileSuggestion(dir, baseFileName, fileExt, isFolder) {
Expand Down Expand Up @@ -1200,26 +1200,27 @@ define(function (require, exports, module) {

CommandManager.register(Strings.CMD_FILE_CLOSE, Commands.FILE_CLOSE, handleFileClose);
CommandManager.register(Strings.CMD_FILE_CLOSE_ALL, Commands.FILE_CLOSE_ALL, handleFileCloseAll);
CommandManager.register(Strings.CMD_CLOSE_WINDOW, Commands.FILE_CLOSE_WINDOW, handleFileCloseWindow);

if (brackets.platform === "win") {
CommandManager.register(Strings.CMD_EXIT, Commands.FILE_QUIT, handleFileQuit);
} else {
CommandManager.register(Strings.CMD_QUIT, Commands.FILE_QUIT, handleFileQuit);
}

CommandManager.register(Strings.CMD_ABORT_QUIT, Commands.APP_ABORT_QUIT, _handleAbortQuit);
CommandManager.register(Strings.CMD_BEFORE_MENUPOPUP, Commands.APP_BEFORE_MENUPOPUP, _handleBeforeMenuPopup);

CommandManager.register(Strings.CMD_NEXT_DOC, Commands.NAVIGATE_NEXT_DOC, handleGoNextDoc);
CommandManager.register(Strings.CMD_PREV_DOC, Commands.NAVIGATE_PREV_DOC, handleGoPrevDoc);
CommandManager.register(Strings.CMD_SHOW_IN_TREE, Commands.NAVIGATE_SHOW_IN_FILE_TREE, handleShowInTree);
CommandManager.register(Strings.CMD_SHOW_IN_OS, Commands.NAVIGATE_SHOW_IN_OS, handleShowInOS);

// Those commands have no UI representation, and are only used internally
CommandManager.registerInternal(Commands.APP_ABORT_QUIT, _handleAbortQuit);
CommandManager.registerInternal(Commands.APP_BEFORE_MENUPOPUP, _handleBeforeMenuPopup);
CommandManager.registerInternal(Commands.FILE_CLOSE_WINDOW, handleFileCloseWindow);

// Listen for changes that require updating the editor titlebar
$(DocumentManager).on("dirtyFlagChange", handleDirtyChange);
$(DocumentManager).on("currentDocumentChange fileNameChange", updateDocumentTitle);

// Reset the untitled document counter before changing projects
// Reset the untitled document counter before changing projects
$(ProjectManager).on("beforeProjectClose", function () { _nextUntitledIndexToUse = 1; });
});
6 changes: 0 additions & 6 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,6 @@ define({
"CMD_TWITTER" : "{TWITTER_NAME} on Twitter",
"CMD_ABOUT" : "About {APP_TITLE}",


// Special commands invoked by the native shell
"CMD_CLOSE_WINDOW" : "Close Window",
"CMD_ABORT_QUIT" : "Abort Quit",
"CMD_BEFORE_MENUPOPUP" : "Before Menu Popup",

// Strings for main-view.html
"EXPERIMENTAL_BUILD" : "experimental build",
"DEVELOPMENT_BUILD" : "development build",
Expand Down