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

Commit e47dc5b

Browse files
committed
move to DebugCommands
1 parent 003890e commit e47dc5b

5 files changed

Lines changed: 77 additions & 48 deletions

File tree

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
2+
* Copyright (c) 2014 Adobe Systems Incorporated. All rights reserved.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),
@@ -27,14 +27,13 @@
2727
define(function (require, exports, module) {
2828
"use strict";
2929

30-
var ExtensionUtils = brackets.getModule("utils/ExtensionUtils");
30+
var Strings = brackets.getModule("strings");
3131

32-
var $span = null,
33-
errorCount = 0,
34-
_windowOnError = window.onerror,
35-
_consoleError = window.console.error;
36-
37-
ExtensionUtils.loadStyleSheet(module, "style.css");
32+
var $span = null,
33+
errorCount = 0,
34+
_attached = false,
35+
_windowOnError,
36+
_consoleError;
3837

3938
function showDeveloperTools() {
4039
try {
@@ -44,37 +43,71 @@ define(function (require, exports, module) {
4443
}
4544
}
4645

47-
function showIcon() {
46+
function refreshIcon() {
47+
// never show 0 errors
48+
if (errorCount === 0) {
49+
return;
50+
}
51+
52+
// update span if it was created before
4853
if ($span) {
54+
$span.parent().toggle(_attached);
4955
$span.text(errorCount);
5056
return;
5157
}
58+
59+
// create the span
5260
$span = $("<span>").text(errorCount);
53-
$("<a>")
54-
.addClass("consoleErrorIcon")
61+
$("<div>")
62+
.addClass("error")
63+
.text(Strings.ERRORS + ":")
5564
.append($span)
5665
.on("click", showDeveloperTools)
57-
.appendTo("#main-toolbar .buttons");
66+
.prependTo("#status-bar .indicators");
5867
}
5968

6069
function incErrorCount() {
6170
errorCount++;
62-
showIcon();
71+
refreshIcon();
6372
}
6473

65-
// https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers.onerror
66-
window.onerror = function (errorMsg, url, lineNumber) {
67-
incErrorCount();
68-
if (_windowOnError) {
69-
return _windowOnError(errorMsg, url, lineNumber);
70-
}
71-
// return false means that we didn't handle this error and it should run the default handler
72-
return false;
73-
};
74-
75-
window.console.error = function () {
76-
incErrorCount();
77-
return _consoleError.apply(window.console, arguments);
78-
};
74+
function attachFunctions() {
75+
if (_attached) { return; }
76+
77+
_attached = true;
78+
_windowOnError = window.onerror;
79+
_consoleError = window.console.error;
80+
81+
// https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers.onerror
82+
window.onerror = function (errorMsg, url, lineNumber) {
83+
incErrorCount();
84+
if (_windowOnError) {
85+
return _windowOnError(errorMsg, url, lineNumber);
86+
}
87+
// return false means that we didn't handle this error and it should run the default handler
88+
return false;
89+
};
90+
91+
window.console.error = function () {
92+
incErrorCount();
93+
return _consoleError.apply(window.console, arguments);
94+
};
95+
}
96+
97+
function detachFunctions() {
98+
if (!_attached) { return; }
99+
100+
_attached = false;
101+
window.onerror = _windowOnError;
102+
window.console.error = _consoleError;
103+
}
104+
105+
function toggle(bool) {
106+
if (bool) { attachFunctions(); } else { detachFunctions(); }
107+
refreshIcon();
108+
}
109+
110+
// Public API
111+
exports.toggle = toggle;
79112

80113
});

src/extensions/default/DebugCommands/main.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ define(function (require, exports, module) {
4040
Dialogs = brackets.getModule("widgets/Dialogs"),
4141
Strings = brackets.getModule("strings"),
4242
PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
43+
ErrorNotification = require("ErrorNotification"),
4344
NodeDebugUtils = require("NodeDebugUtils"),
4445
PerfDialogTemplate = require("text!htmlContent/perf-dialog.html"),
4546
LanguageDialogTemplate = require("text!htmlContent/language-dialog.html");
@@ -233,12 +234,16 @@ define(function (require, exports, module) {
233234
});
234235
}
235236

236-
function toggleErrorsInStatusBar() {
237-
// get the current value
238-
var val = PreferencesManager.get(DEBUG_SHOW_ERRORS_IN_STATUS_BAR);
237+
function toggleErrorNotification(bool) {
238+
var val;
239239

240-
// toggle the value
241-
val = !val;
240+
if (typeof bool === "undefined") {
241+
val = !PreferencesManager.get(DEBUG_SHOW_ERRORS_IN_STATUS_BAR);
242+
} else {
243+
val = !!bool;
244+
}
245+
246+
ErrorNotification.toggle(val);
242247

243248
// update menu
244249
CommandManager.get(DEBUG_SHOW_ERRORS_IN_STATUS_BAR).setChecked(val);
@@ -260,14 +265,15 @@ define(function (require, exports, module) {
260265

261266
CommandManager.register(Strings.CMD_SHOW_PERF_DATA, DEBUG_SHOW_PERF_DATA, handleShowPerfData);
262267
CommandManager.register(Strings.CMD_SWITCH_LANGUAGE, DEBUG_SWITCH_LANGUAGE, handleSwitchLanguage);
263-
CommandManager.register(Strings.CMD_SHOW_ERRORS_IN_STATUS_BAR, DEBUG_SHOW_ERRORS_IN_STATUS_BAR, toggleErrorsInStatusBar);
268+
CommandManager.register(Strings.CMD_SHOW_ERRORS_IN_STATUS_BAR, DEBUG_SHOW_ERRORS_IN_STATUS_BAR, toggleErrorNotification);
264269

265270
// Node-related Commands
266271
CommandManager.register(Strings.CMD_ENABLE_NODE_DEBUGGER, DEBUG_ENABLE_NODE_DEBUGGER, NodeDebugUtils.enableDebugger);
267272
CommandManager.register(Strings.CMD_LOG_NODE_STATE, DEBUG_LOG_NODE_STATE, NodeDebugUtils.logNodeState);
268273
CommandManager.register(Strings.CMD_RESTART_NODE, DEBUG_RESTART_NODE, NodeDebugUtils.restartNode);
269274

270275
enableRunTestsMenuItem();
276+
toggleErrorNotification(PreferencesManager.get(DEBUG_SHOW_ERRORS_IN_STATUS_BAR));
271277

272278
/*
273279
* Debug menu

src/extensions/default/ErrorIcon/style.css

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/nls/root/strings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ define({
493493

494494
// extensions/default/DebugCommands
495495
"DEBUG_MENU" : "Debug",
496+
"ERRORS" : "Errors",
496497
"CMD_SHOW_DEV_TOOLS" : "Show Developer Tools",
497498
"CMD_REFRESH_WINDOW" : "Reload With Extensions",
498499
"CMD_RELOAD_WITHOUT_USER_EXTS" : "Reload Without Extensions",

src/styles/brackets.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ a, img {
132132
line-height: 25px;
133133
height: 26px;
134134
overflow: hidden;
135+
.error {
136+
font-weight: @font-weight-semibold;
137+
color: @tc-error-text;
138+
}
135139
}
136140

137141
#status-info {

0 commit comments

Comments
 (0)