1 /* See license.txt for terms of usage */ 2 3 define([ 4 "firebug/lib/object", 5 "firebug/firebug", 6 "firebug/chrome/firefox", 7 "firebug/lib/locale", 8 "firebug/lib/events", 9 "firebug/lib/dom", 10 "firebug/lib/options", 11 "firebug/firefox/browserOverlayLib", 12 ], 13 function(Obj, Firebug, Firefox, Locale, Events, Dom, Options, BrowserOverlayLib) { 14 15 // ********************************************************************************************* // 16 // Constants 17 18 const Cc = Components.classes; 19 const Ci = Components.interfaces; 20 21 // ********************************************************************************************* // 22 // Module Implementation 23 24 /** 25 * @module StartButton module represents the UI entry point to Firebug. This "start buttton" 26 * formerly known as "the status bar icon" is automatically appended into Firefox toolbar 27 * (since Firefox 4). 28 * 29 * Start button is associated with a menu (fbStatusContextMenu) that contains basic actions 30 * such as panel activation and also indicates whether Firebug is activated/deactivated for 31 * the current page (by changing its color). 32 */ 33 Firebug.StartButton = Obj.extend(Firebug.Module, 34 /** @lends Firebug.StartButton */ 35 { 36 dispatchName: "startButton", 37 38 initializeUI: function() 39 { 40 Firebug.Module.initializeUI.apply(this, arguments); 41 42 if (FBTrace.DBG_INITIALIZE) 43 FBTrace.sysout("StartButton.initializeUI;"); 44 45 // When Firebug is full loaded content of the start button tooltip 46 // will be generated by this StartButton object. 47 var firebugButton = Firefox.getElementById("firebug-buttonTooltip"); 48 firebugButton.setAttribute("onpopupshowing", 49 "Firebug.StartButton.onTooltipShowing(event)"); 50 }, 51 52 shutdown: function() 53 { 54 }, 55 56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 57 // Tooltip 58 59 onTooltipShowing: function(event) 60 { 61 var tooltip = event.target; 62 var doc = tooltip.ownerDocument; 63 64 Dom.eraseNode(tooltip); 65 66 with (BrowserOverlayLib) 67 { 68 tooltip.appendChild($label(doc, { 69 "class": "version", 70 value: "Firebug " + Firebug.getVersion() 71 })); 72 73 var status = $el(doc, "hbox"); 74 tooltip.appendChild(status); 75 76 var suspended = Firebug.getSuspended(); 77 status.appendChild($label(doc, { 78 "class": "status", 79 value: suspended ? Locale.$STR("startbutton.tip.deactivated") : 80 Locale.$STRP("plural.Total_Firebugs2", [Firebug.TabWatcher.contexts.length]) 81 })); 82 83 if (suspended) 84 return; 85 86 status.appendChild($label(doc, { 87 "class": "placement", 88 value: "(" + Locale.$STR(Firebug.getPlacement()) + ")" 89 })); 90 91 if (Firebug.allPagesActivation == "on") 92 { 93 tooltip.appendChild($label(doc, { 94 "class": "alwaysOn", 95 value: Locale.$STR("enablement.on") + " " + 96 Locale.$STR("enablement.for_all_pages") 97 })); 98 } 99 100 // Panel enablement status info 101 tooltip.appendChild($label(doc, { 102 "class": "enablement", 103 value: Locale.$STR("enablement.Panel_activation_status") 104 })); 105 106 var statuses = this.getEnablementStatus(); 107 for (var i=0; i<statuses.length; i++) 108 { 109 var status = statuses[i]; 110 var parent = $el(doc, "hbox"); 111 tooltip.appendChild(parent); 112 113 parent.appendChild($label(doc, { 114 "class": "panelName " + status.status, 115 value: status.name + ":" 116 })); 117 118 parent.appendChild($label(doc, { 119 "class": "panelStatus " + status.status, 120 value: status.statusLabel 121 })); 122 } 123 } 124 }, 125 126 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 127 // Error count 128 129 showCount: function(errorCount) 130 { 131 var firebugButton = Firefox.getElementById("firebug-button"); 132 if (errorCount && Firebug.showErrorCount) 133 { 134 if (firebugButton) 135 { 136 firebugButton.setAttribute("showErrors", "true"); 137 firebugButton.setAttribute("errorCount", errorCount); 138 } 139 } 140 else 141 { 142 if (firebugButton) 143 { 144 firebugButton.removeAttribute("showErrors"); 145 146 // Use '0', so the horizontal space for the number is still allocated. 147 // The button will cause re-layout if there are more than 9 errors. 148 firebugButton.setAttribute("errorCount", "0"); 149 } 150 } 151 }, 152 153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 154 // Tooltip 155 156 resetTooltip: function() 157 { 158 var firebugStatus = Firefox.getElementById("firebugStatus"); 159 if (!firebugStatus) 160 return; 161 162 // The start button is colorful only if there is a context 163 var active = Firebug.currentContext ? "true" : "false"; 164 firebugStatus.setAttribute("firebugActive", active); 165 166 if (FBTrace.DBG_TOOLTIP) 167 FBTrace.sysout("StartButton.resetTooltip; called: firebug active: " + active); 168 }, 169 170 getEnablementStatus: function() 171 { 172 var firebugStatus = Firefox.getElementById("firebugStatus"); 173 if (!firebugStatus) 174 return; 175 176 var panels = Firebug.getActivablePanelTypes(); 177 var statuses = []; 178 179 var strOn = Locale.$STR("enablement.on"); 180 var strOff = Locale.$STR("enablement.off"); 181 182 for (var i=0; i<panels.length; ++i) 183 { 184 var panelName = panels[i].prototype.name; 185 var status = firebugStatus.getAttribute(panelName); 186 var statusLabel = (status == "on") ? strOn : strOff; 187 188 statuses.push({ 189 name: Firebug.getPanelTitle(panels[i]), 190 status: status, 191 statusLabel: statusLabel 192 }); 193 } 194 195 return statuses; 196 }, 197 198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 199 // Activation 200 201 getSuspended: function() 202 { 203 var suspendMarker = Firefox.getElementById("firebugStatus"); 204 if (suspendMarker && suspendMarker.hasAttribute("suspended")) 205 return suspendMarker.getAttribute("suspended"); 206 207 return null; 208 }, 209 210 setSuspended: function(value) 211 { 212 var suspendMarker = Firefox.getElementById("firebugStatus"); 213 214 if (FBTrace.DBG_ACTIVATION) 215 FBTrace.sysout("StartButton.setSuspended; to " + value + ". Browser: " + 216 Firebug.chrome.window.document.title); 217 218 if (value == "suspended") 219 suspendMarker.setAttribute("suspended", value); 220 else 221 suspendMarker.removeAttribute("suspended"); 222 223 this.resetTooltip(); 224 } 225 }); 226 227 // ********************************************************************************************* // 228 // Registration 229 230 Firebug.registerModule(Firebug.StartButton); 231 232 // ********************************************************************************************* // 233 234 return Firebug.StartButton; 235 }); 236