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

Commit b7c06ac

Browse files
committed
Merge branch 'master' into jasonsanjose/cc-license
Conflicts: src/strings.js
2 parents 3ee5786 + 589dcb0 commit b7c06ac

File tree

97 files changed

+3037
-739
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+3037
-739
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Brackets",
3-
"version": "0.24.0-0",
4-
"apiVersion": "0.24.0",
3+
"version": "0.25.0-0",
4+
"apiVersion": "0.25.0",
55
"homepage": "http://brackets.io",
66
"issues": {
77
"url": "http://github.com/adobe/brackets/issues"
@@ -33,4 +33,4 @@
3333
"url": "https://github.com/adobe/brackets/blob/master/LICENSE"
3434
}
3535
]
36-
}
36+
}

src/LiveDevelopment/LiveDevelopment.js

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,23 @@
4242
* # STATUS
4343
*
4444
* Status updates are dispatched as `statusChange` jQuery events. The status
45-
* codes are:
45+
* is passed as the first parameter and the reason for the change as the second
46+
* parameter. Currently only the "Inactive" status supports the reason parameter.
47+
* The status codes are:
4648
*
4749
* -1: Error
4850
* 0: Inactive
4951
* 1: Connecting to the remote debugger
5052
* 2: Loading agents
5153
* 3: Active
5254
* 4: Out of sync
55+
*
56+
* The reason codes are:
57+
* - null (Unknown reason)
58+
* - "explicit_close" (LiveDevelopment.close() was called)
59+
* - "navigated_away" (The browser changed to a location outside of the project)
60+
* - "detached_target_closed" (The tab or window was closed)
61+
* - "detached_replaced_with_devtools" (The developer tools were opened in the browser)
5362
*/
5463
define(function LiveDevelopment(require, exports, module) {
5564
"use strict";
@@ -69,7 +78,6 @@ define(function LiveDevelopment(require, exports, module) {
6978
DocumentManager = require("document/DocumentManager"),
7079
EditorManager = require("editor/EditorManager"),
7180
FileUtils = require("file/FileUtils"),
72-
HTMLInstrumentation = require("language/HTMLInstrumentation"),
7381
LiveDevServerManager = require("LiveDevelopment/LiveDevServerManager"),
7482
NativeFileError = require("file/NativeFileError"),
7583
NativeApp = require("utils/NativeApp"),
@@ -134,7 +142,8 @@ define(function LiveDevelopment(require, exports, module) {
134142
var _liveDocument; // the document open for live editing.
135143
var _relatedDocuments; // CSS and JS documents that are used by the live HTML document
136144
var _serverProvider; // current LiveDevServerProvider
137-
145+
var _closeReason; // reason why live preview was closed
146+
138147
function _isHtmlFileExt(ext) {
139148
return (FileUtils.isStaticHtmlFileExt(ext) ||
140149
(ProjectManager.getBaseUrl() && FileUtils.isServerHtmlFileExt(ext)));
@@ -452,8 +461,14 @@ define(function LiveDevelopment(require, exports, module) {
452461
* @param {integer} new status
453462
*/
454463
function _setStatus(status) {
464+
// Don't send a notification when the status didn't actually change
465+
if (status === exports.status) {
466+
return;
467+
}
468+
455469
exports.status = status;
456-
$(exports).triggerHandler("statusChange", status);
470+
var reason = status === STATUS_INACTIVE ? _closeReason : null;
471+
$(exports).triggerHandler("statusChange", [status, reason]);
457472
}
458473

459474
/** Triggered by Inspector.error */
@@ -505,13 +520,6 @@ define(function LiveDevelopment(require, exports, module) {
505520
});
506521
}
507522

508-
/** Triggered by Inspector.detached */
509-
function _onDetached(event, res) {
510-
// res.reason, e.g. "replaced_with_devtools", "target_closed", "canceled_by_user"
511-
// Sample list taken from https://chromiumcodereview.appspot.com/10947037/patch/12001/13004
512-
// However, the link refers to the Chrome Extension API, it may not apply 100% to the Inspector API
513-
}
514-
515523
// WebInspector Event: Page.frameNavigated
516524
function _onFrameNavigated(event, res) {
517525
// res = {frame}
@@ -540,6 +548,7 @@ define(function LiveDevelopment(require, exports, module) {
540548
if (!url.match(baseUrlRegExp)) {
541549
// No longer in site, so terminate live dev, but don't close browser window
542550
Inspector.disconnect();
551+
_closeReason = "navigated_away";
543552
_setStatus(STATUS_INACTIVE);
544553
_serverProvider = null;
545554
}
@@ -555,10 +564,22 @@ define(function LiveDevelopment(require, exports, module) {
555564
_setStatus(STATUS_INACTIVE);
556565
}
557566

567+
function _onDetached(event, res) {
568+
// If there already is a reason for closing the session, do not overwrite it
569+
if (!_closeReason) {
570+
// Get the explanation from res.reason, e.g. "replaced_with_devtools", "target_closed", "canceled_by_user"
571+
// Examples taken from https://chromiumcodereview.appspot.com/10947037/patch/12001/13004
572+
// However, the link refers to the Chrome Extension API, it may not apply 100% to the Inspector API
573+
// Prefix with "detached_" to create a quasi-namespace for Chrome's reasons
574+
_closeReason = "detached_" + res.reason;
575+
}
576+
}
577+
558578
function reconnect() {
559579
unloadAgents();
560-
var promises = loadAgents();
580+
561581
_setStatus(STATUS_LOADING_AGENTS);
582+
var promises = loadAgents();
562583
$.when.apply(undefined, promises).done(_onLoad).fail(_onError);
563584
}
564585

@@ -570,6 +591,8 @@ define(function LiveDevelopment(require, exports, module) {
570591
var browserStarted = false;
571592
var retryCount = 0;
572593

594+
_closeReason = null;
595+
573596
function showWrongDocError() {
574597
Dialogs.showModalDialog(
575598
Dialogs.DIALOG_ID_ERROR,
@@ -723,6 +746,8 @@ define(function LiveDevelopment(require, exports, module) {
723746
* @return {jQuery.Promise} Resolves once the connection is closed
724747
*/
725748
function close() {
749+
_closeReason = "explicit_close";
750+
726751
var deferred = $.Deferred();
727752

728753
/*
@@ -836,7 +861,6 @@ define(function LiveDevelopment(require, exports, module) {
836861
$.when.apply(undefined, promises).done(_onLoad).fail(_onError);
837862
}
838863

839-
$(Inspector.Inspector).on("detached.livedev", _onDetached);
840864
$(Inspector.Page).on("frameNavigated.livedev", _onFrameNavigated);
841865

842866
waitForInterstitialPageLoad()
@@ -961,6 +985,7 @@ define(function LiveDevelopment(require, exports, module) {
961985
$(Inspector).on("connect", _onConnect)
962986
.on("disconnect", _onDisconnect)
963987
.on("error", _onError);
988+
$(Inspector.Inspector).on("detached", _onDetached);
964989
$(DocumentManager).on("currentDocumentChange", _onDocumentChange)
965990
.on("documentSaved", _onDocumentSaved)
966991
.on("dirtyFlagChange", _onDirtyFlagChange);

src/LiveDevelopment/main.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ define(function main(require, exports, module) {
4848
Dialogs = require("widgets/Dialogs"),
4949
UrlParams = require("utils/UrlParams").UrlParams,
5050
Strings = require("strings"),
51-
ExtensionUtils = require("utils/ExtensionUtils");
51+
ExtensionUtils = require("utils/ExtensionUtils"),
52+
StringUtils = require("utils/StringUtils");
5253

5354
var prefs;
5455
var params = new UrlParams();
@@ -131,17 +132,48 @@ define(function main(require, exports, module) {
131132
}
132133
}
133134

135+
/** Called on status change */
136+
function _showStatusChangeReason(reason) {
137+
// Destroy the previous twipsy (options are not updated otherwise)
138+
_$btnGoLive.twipsy("hide").removeData("twipsy");
139+
140+
// If there was no reason or the action was an explicit request by the user, don't show a twipsy
141+
if (!reason || reason === "explicit_close") {
142+
return;
143+
}
144+
145+
// Translate the reason
146+
var translatedReason = Strings["LIVE_DEV_" + reason.toUpperCase()];
147+
if (!translatedReason) {
148+
translatedReason = StringUtils.format(Strings.LIVE_DEV_CLOSED_UNKNOWN_REASON, reason);
149+
}
150+
151+
// Configure the twipsy
152+
var options = {
153+
placement: "left",
154+
trigger: "manual",
155+
autoHideDelay: 5000,
156+
title: function () {
157+
return translatedReason;
158+
}
159+
};
160+
161+
// Show the twipsy with the explanation
162+
_$btnGoLive.twipsy(options).twipsy("show");
163+
}
164+
134165
/** Create the menu item "Go Live" */
135166
function _setupGoLiveButton() {
136167
_$btnGoLive = $("#toolbar-go-live");
137168
_$btnGoLive.click(function onGoLive() {
138169
_handleGoLiveCommand();
139170
});
140-
$(LiveDevelopment).on("statusChange", function statusChange(event, status) {
171+
$(LiveDevelopment).on("statusChange", function statusChange(event, status, reason) {
141172
// status starts at -1 (error), so add one when looking up name and style
142173
// See the comments at the top of LiveDevelopment.js for details on the
143174
// various status codes.
144175
_setLabel(_$btnGoLive, null, _statusStyle[status + 1], _statusTooltip[status + 1]);
176+
_showStatusChangeReason(reason);
145177
if (config.autoconnect) {
146178
window.sessionStorage.setItem("live.enabled", status === 3);
147179
}

src/brackets.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ define(function (require, exports, module) {
5353
// Load dependent non-module scripts
5454
require("widgets/bootstrap-dropdown");
5555
require("widgets/bootstrap-modal");
56+
require("widgets/bootstrap-twipsy-mod");
5657
require("thirdparty/path-utils/path-utils.min");
5758
require("thirdparty/smart-auto-complete/jquery.smart_autocomplete");
5859

src/command/Menus.js

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,32 @@ define(function (require, exports, module) {
9191

9292

9393
/**
94-
* Insertion position constants
95-
* Used by addMenu(), addMenuItem(), and addSubMenu() to
96-
* specify the relative position of a newly created menu object
97-
* @enum {string}
98-
*/
99-
var BEFORE = "before";
100-
var AFTER = "after";
101-
var FIRST = "first";
102-
var LAST = "last";
103-
var FIRST_IN_SECTION = "firstInSection";
104-
var LAST_IN_SECTION = "lastInSection";
105-
106-
/**
107-
* Other constants
108-
*/
109-
var DIVIDER = "---";
94+
* Insertion position constants
95+
* Used by addMenu(), addMenuItem(), and addSubMenu() to
96+
* specify the relative position of a newly created menu object
97+
* @enum {string}
98+
*/
99+
var BEFORE = "before",
100+
AFTER = "after",
101+
FIRST = "first",
102+
LAST = "last",
103+
FIRST_IN_SECTION = "firstInSection",
104+
LAST_IN_SECTION = "lastInSection";
110105

106+
/**
107+
* Other constants
108+
*/
109+
var DIVIDER = "---";
110+
111+
/**
112+
* Error Codes from Brackets Shell
113+
* @enum {number}
114+
*/
115+
var NO_ERROR = 0,
116+
ERR_UNKNOWN = 1,
117+
ERR_INVALID_PARAMS = 2,
118+
ERR_NOT_FOUND = 3;
119+
111120
/**
112121
* Maps menuID's to Menu objects
113122
* @type {Object.<string, Menu>}
@@ -462,7 +471,8 @@ define(function (require, exports, module) {
462471
* @return {MenuItem} the newly created MenuItem
463472
*/
464473
Menu.prototype.addMenuItem = function (command, keyBindings, position, relativeID) {
465-
var id,
474+
var menuID = this.id,
475+
id,
466476
$menuItem,
467477
$link,
468478
menuItem,
@@ -547,8 +557,17 @@ define(function (require, exports, module) {
547557
}
548558

549559
brackets.app.addMenuItem(this.id, name, commandID, bindingStr, displayStr, position, relativeID, function (err) {
550-
if (err) {
551-
console.error("addMenuItem() -- error: " + err + " when adding command: " + commandID);
560+
switch (err) {
561+
case NO_ERROR:
562+
break;
563+
case ERR_INVALID_PARAMS:
564+
console.error("addMenuItem(): Invalid Parameters when adding the command " + commandID);
565+
break;
566+
case ERR_NOT_FOUND:
567+
console.error("_getRelativeMenuItem(): MenuItem with Command id " + relativeID + " not found in the Menu " + menuID);
568+
break;
569+
default:
570+
console.error("addMenuItem(); Unknown Error (" + err + ") when adding the command " + commandID);
552571
}
553572
});
554573
menuItem.isNative = true;
@@ -800,15 +819,26 @@ define(function (require, exports, module) {
800819

801820
if (!_isHTMLMenu(id)) {
802821
brackets.app.addMenu(name, id, position, relativeID, function (err) {
803-
if (err) {
804-
console.error("addMenu() -- error: " + err + " when adding menu with ID: " + id);
805-
} else {
822+
switch (err) {
823+
case NO_ERROR:
806824
// Make sure name is up to date
807825
brackets.app.setMenuTitle(id, name, function (err) {
808826
if (err) {
809827
console.error("setMenuTitle() -- error: " + err);
810828
}
811829
});
830+
break;
831+
case ERR_UNKNOWN:
832+
console.error("addMenu(): Unknown Error when adding the menu " + id);
833+
break;
834+
case ERR_INVALID_PARAMS:
835+
console.error("addMenu(): Invalid Parameters when adding the menu " + id);
836+
break;
837+
case ERR_NOT_FOUND:
838+
console.error("addMenu(): Menu with command " + relativeID + " could not be found when adding the menu " + id);
839+
break;
840+
default:
841+
console.error("addMenu(): Unknown Error (" + err + ") when adding the menu " + id);
812842
}
813843
});
814844
return menu;

src/config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"extension_wiki_url": "https://github.com/adobe/brackets/wiki/Brackets-Extensions"
1616
},
1717
"name": "Brackets",
18-
"version": "0.24.0-0",
19-
"apiVersion": "0.24.0",
18+
"version": "0.25.0-0",
19+
"apiVersion": "0.25.0",
2020
"homepage": "http://brackets.io",
2121
"issues": {
2222
"url": "http://github.com/adobe/brackets/issues"

src/document/DocumentManager.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,14 @@ define(function (require, exports, module) {
814814
* given new text; if text == "", then the entire range is effectively deleted. If 'end' is omitted,
815815
* then the new text is inserted at that point and all existing text is preserved. Line endings will
816816
* be rewritten to match the document's current line-ending style.
817+
*
818+
* IMPORTANT NOTE: Because of #1688, do not use this in cases where you might be
819+
* operating on a linked document (like the main document for an inline editor)
820+
* during an outer CodeMirror operation (like a key event that's handled by the
821+
* editor itself). A common case of this is code hints in inline editors. In
822+
* such cases, use `editor._codeMirror.replaceRange()` instead. This should be
823+
* fixed when we migrate to use CodeMirror's native document-linking functionality.
824+
*
817825
* @param {!string} text Text to insert or replace the range with
818826
* @param {!{line:number, ch:number}} start Start of range, inclusive (if 'to' specified) or insertion point (if not)
819827
* @param {?{line:number, ch:number}} end End of range, exclusive; optional

0 commit comments

Comments
 (0)