Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
75 changes: 75 additions & 0 deletions src/extensions/default/ErrorIcon/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2013 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, $, brackets, window, document */

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

var CommandManager = brackets.getModule("command/CommandManager"),
ExtensionUtils = brackets.getModule("utils/ExtensionUtils");

var $span = null,
errorCount = 0,
_windowOnError = window.onerror,
_consoleError = window.console.error;

ExtensionUtils.loadStyleSheet(module, "style.css");

function showDeveloperTools() {
CommandManager.execute("debug.showDeveloperTools");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A default extension shouldn't rely on another default extension.
I don't know how to work around this, but maybe at least a try {} catch {}.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried and no exception or console error is raised when you execute a command string that isn't registered. So no need to try-catch.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break if the other extension is not installed or disabled (eventually we'd like to add ability to disable extensions including default extensions). You should be able to call brackets.app.showDeveloperTools() directly.

}

function showIcon() {
if ($span) {
$span.text(errorCount);
return;
}
$span = $("<span>").text(errorCount);
$("<a>")
.addClass("consoleErrorIcon")
.append($span)
.on("click", showDeveloperTools)
.appendTo("#main-toolbar .buttons");
}

function incErrorCount() {
errorCount++;
showIcon();
}

window.onerror = function (errorMsg, url, lineNumber) {
incErrorCount();
if (_windowOnError) {
return _windowOnError(errorMsg, url, lineNumber);
}
return false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does return false signify anything for this event? We want to be careful not to prevent the dev tools 'break on uncaught errors' feature from working correctly...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return false means that we didn't handle this error and it should run the default handler

https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers.onerror

};

window.console.error = function () {
incErrorCount();
return _consoleError.apply(window.console, arguments);
};

});
15 changes: 15 additions & 0 deletions src/extensions/default/ErrorIcon/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#main-toolbar .buttons .consoleErrorIcon {
position: relative;
}
#main-toolbar .buttons .consoleErrorIcon span {
color: #454545;
background-color: #f74687;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: 2px;
line-height: 20px;
border-radius: 10px;
}