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

Commit

Permalink
Merge pull request #2501 from adobe/jasonsanjose/issue-1951
Browse files Browse the repository at this point in the history
Load extensions before loading project, then fire APP_READY.
  • Loading branch information
dangoor committed Jan 11, 2013
2 parents c3de0d8 + a5ffffb commit 3018b11
Show file tree
Hide file tree
Showing 13 changed files with 283 additions and 251 deletions.
15 changes: 6 additions & 9 deletions src/LiveDevelopment/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ define(function main(require, exports, module) {
}

/** Initialize LiveDevelopment */
function init() {
AppInit.appReady(function () {
params.parse();

Inspector.init(config);
Expand All @@ -204,12 +204,10 @@ define(function main(require, exports, module) {
}

// trigger autoconnect
if (config.autoconnect && window.sessionStorage.getItem("live.enabled") === "true") {
AppInit.appReady(function () {
if (DocumentManager.getCurrentDocument()) {
_handleGoLiveCommand();
}
});
if (config.autoconnect &&
window.sessionStorage.getItem("live.enabled") === "true" &&
DocumentManager.getCurrentDocument()) {
_handleGoLiveCommand();
}

// Redraw highlights when window gets focus. This ensures that the highlights
Expand All @@ -219,7 +217,7 @@ define(function main(require, exports, module) {
LiveDevelopment.redrawHighlight();
}
});
}
});

// init prefs
prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_KEY, {highlight: true});
Expand All @@ -231,5 +229,4 @@ define(function main(require, exports, module) {
CommandManager.get(Commands.FILE_LIVE_HIGHLIGHT).setEnabled(false);

// Export public functions
exports.init = init;
});
270 changes: 116 additions & 154 deletions src/brackets.js

Large diffs are not rendered by default.

13 changes: 5 additions & 8 deletions src/command/KeyBindingManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ define(function (require, exports, module) {

require("utils/Global");

var CommandManager = require("command/CommandManager"),
var AppInit = require("utils/AppInit"),
CommandManager = require("command/CommandManager"),
KeyEvent = require("utils/KeyEvent"),
Strings = require("strings");

Expand Down Expand Up @@ -573,11 +574,8 @@ define(function (require, exports, module) {
}
}

/**
* Install keydown event listener.
*/
function init() {
// init
AppInit.htmlReady(function () {
// Install keydown event listener.
window.document.body.addEventListener(
"keydown",
function (event) {
Expand All @@ -591,15 +589,14 @@ define(function (require, exports, module) {

exports.useWindowsCompatibleBindings = (brackets.platform !== "mac")
&& (brackets.platform !== "win");
}
});

$(CommandManager).on("commandRegistered", _handleCommandRegistered);

// unit test only
exports._reset = _reset;

// Define public API
exports.init = init;
exports.getKeymap = getKeymap;
exports.handleKey = handleKey;
exports.setEnabled = setEnabled;
Expand Down
26 changes: 12 additions & 14 deletions src/command/Menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ define(function (require, exports, module) {
"use strict";

// Load dependent modules
var Global = require("utils/Global"),
Commands = require("command/Commands"),
KeyBindingManager = require("command/KeyBindingManager"),
EditorManager = require("editor/EditorManager"),
Strings = require("strings"),
StringUtils = require("utils/StringUtils"),
CommandManager = require("command/CommandManager"),
PopUpManager = require("widgets/PopUpManager");
var AppInit = require("utils/AppInit"),
Global = require("utils/Global"),
Commands = require("command/Commands"),
KeyBindingManager = require("command/KeyBindingManager"),
EditorManager = require("editor/EditorManager"),
Strings = require("strings"),
StringUtils = require("utils/StringUtils"),
CommandManager = require("command/CommandManager"),
PopUpManager = require("widgets/PopUpManager");

/**
* Brackets Application Menu Constants
Expand Down Expand Up @@ -866,10 +867,8 @@ define(function (require, exports, module) {
// function removeMenu(id) {
// NOT IMPLEMENTED
// }


function init() {


AppInit.htmlReady(function () {
/*
* File menu
*/
Expand Down Expand Up @@ -1102,10 +1101,9 @@ define(function (require, exports, module) {
$(this).addClass("open");
}
});
}
});

// Define public API
exports.init = init;
exports.AppMenuBar = AppMenuBar;
exports.ContextMenuIds = ContextMenuIds;
exports.MenuSection = MenuSection;
Expand Down
65 changes: 32 additions & 33 deletions src/document/DocumentCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ define(function (require, exports, module) {
require("thirdparty/path-utils/path-utils.min");

// Load dependent modules
var CommandManager = require("command/CommandManager"),
var AppInit = require("utils/AppInit"),
CommandManager = require("command/CommandManager"),
Commands = require("command/Commands"),
KeyBindingManager = require("command/KeyBindingManager"),
NativeFileSystem = require("file/NativeFileSystem").NativeFileSystem,
Expand Down Expand Up @@ -823,42 +824,40 @@ define(function (require, exports, module) {
ProjectManager.showInTree(DocumentManager.getCurrentDocument().file);
}


function init($titleContainerToolbar) {
// Init DOM elements
AppInit.htmlReady(function () {
var $titleContainerToolbar = $("#main-toolbar");
_$titleContainerToolbar = $titleContainerToolbar;
_$titleWrapper = $(".title-wrapper", _$titleContainerToolbar);
_$title = $(".title", _$titleWrapper);
_$dirtydot = $(".dirty-dot", _$titleWrapper);
});

// Register global commands
CommandManager.register(Strings.CMD_FILE_OPEN, Commands.FILE_OPEN, handleFileOpen);
CommandManager.register(Strings.CMD_ADD_TO_WORKING_SET, Commands.FILE_ADD_TO_WORKING_SET, handleFileAddToWorkingSet);
// TODO: (issue #274) For now, hook up File > New to the "new in project" handler. Eventually
// File > New should open a new blank tab, and handleFileNewInProject should
// be called from a "+" button in the project
CommandManager.register(Strings.CMD_FILE_NEW, Commands.FILE_NEW, handleFileNewInProject);
CommandManager.register(Strings.CMD_FILE_NEW_FOLDER, Commands.FILE_NEW_FOLDER, handleNewFolderInProject);
CommandManager.register(Strings.CMD_FILE_SAVE, Commands.FILE_SAVE, handleFileSave);
CommandManager.register(Strings.CMD_FILE_SAVE_ALL, Commands.FILE_SAVE_ALL, handleFileSaveAll);
CommandManager.register(Strings.CMD_FILE_RENAME, Commands.FILE_RENAME, handleFileRename);

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);
CommandManager.register(Strings.CMD_QUIT, Commands.FILE_QUIT, handleFileQuit);
CommandManager.register(Strings.CMD_REFRESH_WINDOW, Commands.DEBUG_REFRESH_WINDOW, handleFileReload);
CommandManager.register(Strings.CMD_ABORT_QUIT, Commands.APP_ABORT_QUIT, _handleAbortQuit);

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);

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

// Define public API
exports.init = init;
// Register global commands
CommandManager.register(Strings.CMD_FILE_OPEN, Commands.FILE_OPEN, handleFileOpen);
CommandManager.register(Strings.CMD_ADD_TO_WORKING_SET, Commands.FILE_ADD_TO_WORKING_SET, handleFileAddToWorkingSet);
// TODO: (issue #274) For now, hook up File > New to the "new in project" handler. Eventually
// File > New should open a new blank tab, and handleFileNewInProject should
// be called from a "+" button in the project
CommandManager.register(Strings.CMD_FILE_NEW, Commands.FILE_NEW, handleFileNewInProject);
CommandManager.register(Strings.CMD_FILE_NEW_FOLDER, Commands.FILE_NEW_FOLDER, handleNewFolderInProject);
CommandManager.register(Strings.CMD_FILE_SAVE, Commands.FILE_SAVE, handleFileSave);
CommandManager.register(Strings.CMD_FILE_SAVE_ALL, Commands.FILE_SAVE_ALL, handleFileSaveAll);
CommandManager.register(Strings.CMD_FILE_RENAME, Commands.FILE_RENAME, handleFileRename);

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);
CommandManager.register(Strings.CMD_QUIT, Commands.FILE_QUIT, handleFileQuit);
CommandManager.register(Strings.CMD_REFRESH_WINDOW, Commands.DEBUG_REFRESH_WINDOW, handleFileReload);
CommandManager.register(Strings.CMD_ABORT_QUIT, Commands.APP_ABORT_QUIT, _handleAbortQuit);

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);

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

6 changes: 4 additions & 2 deletions src/document/DocumentManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ define(function (require, exports, module) {
* @private
* Initializes the working set.
*/
function _projectOpen() {
function _projectOpen(e) {
_isProjectChanging = false;

// file root is appended for each project
Expand Down Expand Up @@ -1124,7 +1124,9 @@ define(function (require, exports, module) {
}

if (activeFile) {
CommandManager.execute(Commands.FILE_OPEN, { fullPath: activeFile });
var promise = CommandManager.execute(Commands.FILE_OPEN, { fullPath: activeFile });
// Add this promise to the event's promises to signal that this handler isn't done yet
e.promises.push(promise);
}
}

Expand Down
28 changes: 18 additions & 10 deletions src/extensions/default/HTMLCodeHints/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ define(function (require, exports, module) {
"use strict";

// Load dependent modules
var CodeHintManager = brackets.getModule("editor/CodeHintManager"),
var AppInit = brackets.getModule("utils/AppInit"),
CodeHintManager = brackets.getModule("editor/CodeHintManager"),
DocumentManager = brackets.getModule("document/DocumentManager"),
EditorManager = brackets.getModule("editor/EditorManager"),
HTMLUtils = brackets.getModule("language/HTMLUtils"),
Expand All @@ -38,8 +39,8 @@ define(function (require, exports, module) {
StringUtils = brackets.getModule("utils/StringUtils"),
HTMLTags = require("text!HtmlTags.json"),
HTMLAttributes = require("text!HtmlAttributes.json"),
tags = JSON.parse(HTMLTags),
attributes = JSON.parse(HTMLAttributes);
tags,
attributes;

/**
* @constructor
Expand Down Expand Up @@ -622,12 +623,19 @@ define(function (require, exports, module) {
return false;
};

var tagHints = new TagHints();
var attrHints = new AttrHints();
CodeHintManager.registerHintProvider(tagHints, ["html"], 0);
CodeHintManager.registerHintProvider(attrHints, ["html"], 0);
AppInit.appReady(function () {
// Parse JSON files
tags = JSON.parse(HTMLTags);
attributes = JSON.parse(HTMLAttributes);

// Register code hint providers
var tagHints = new TagHints();
var attrHints = new AttrHints();
CodeHintManager.registerHintProvider(tagHints, ["html"], 0);
CodeHintManager.registerHintProvider(attrHints, ["html"], 0);

// For unit testing
exports.tagHintProvider = tagHints;
exports.attrHintProvider = attrHints;
// For unit testing
exports.tagHintProvider = tagHints;
exports.attrHintProvider = attrHints;
});
});
10 changes: 6 additions & 4 deletions src/extensions/default/RecentProjects/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,12 @@ define(function (require, exports, module) {
}

// Initialize extension
ExtensionUtils.loadStyleSheet(module, "styles.css");

$(ProjectManager).on("projectOpen", add);
$(ProjectManager).on("beforeProjectClose", add);
AppInit.appReady(function () {
ExtensionUtils.loadStyleSheet(module, "styles.css");

$(ProjectManager).on("projectOpen", add);
$(ProjectManager).on("beforeProjectClose", add);
});

AppInit.htmlReady(function () {
$("#project-title")
Expand Down
19 changes: 11 additions & 8 deletions src/help/HelpCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
define(function (require, exports, module) {
"use strict";

var Global = require("utils/Global"),
var AppInit = require("utils/AppInit"),
Global = require("utils/Global"),
BuildInfoUtils = require("utils/BuildInfoUtils"),
Commands = require("command/Commands"),
CommandManager = require("command/CommandManager"),
Expand Down Expand Up @@ -73,14 +74,16 @@ define(function (require, exports, module) {
Dialogs.showModalDialogUsingTemplate(Mustache.render(AboutDialogTemplate, templateVars));
}

// Read "build number" SHAs off disk immediately at load time, instead
// Read "build number" SHAs off disk immediately at APP_READY, instead
// of later, when they may have been updated to a different version
BuildInfoUtils.getBracketsSHA().done(function (branch, sha, isRepo) {
// If we've successfully determined a "build number" via .git metadata, add it to dialog
sha = sha ? sha.substr(0, 9) : "";
if (branch || sha) {
buildInfo = StringUtils.format("({0} {1})", branch, sha).trim();
}
AppInit.appReady(function () {
BuildInfoUtils.getBracketsSHA().done(function (branch, sha, isRepo) {
// If we've successfully determined a "build number" via .git metadata, add it to dialog
sha = sha ? sha.substr(0, 9) : "";
if (branch || sha) {
buildInfo = StringUtils.format("({0} {1})", branch, sha).trim();
}
});
});

CommandManager.register(Strings.CMD_CHECK_FOR_UPDATE, Commands.HELP_CHECK_FOR_UPDATE, _handleCheckForUpdates);
Expand Down
10 changes: 6 additions & 4 deletions src/project/ProjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -782,10 +782,13 @@ define(function (require, exports, module) {

resultRenderTree.done(function () {
if (projectRootChanged) {
$(exports).triggerHandler("projectOpen", _projectRoot);
// Allow asynchronous event handlers to finish before resolving result by collecting promises from them
var promises = [];
$(exports).triggerHandler({ type: "projectOpen", promises: promises }, [_projectRoot, promises]);
$.when.apply($, promises).pipe(result.resolve, result.reject);
} else {
result.resolve();
}

result.resolve();
});
resultRenderTree.fail(function () {
PerfUtils.terminateMeasurement(perfTimerName);
Expand Down Expand Up @@ -1315,7 +1318,6 @@ define(function (require, exports, module) {
$(".jstree-rename-input").blur();
}


// Initialize variables and listeners that depend on the HTML DOM
AppInit.htmlReady(function () {
$projectTreeContainer = $("#project-files-container");
Expand Down
Loading

0 comments on commit 3018b11

Please sign in to comment.