1 /* See license.txt for terms of usage */ 2 3 // ********************************************************************************************* // 4 // Constants 5 6 var Cc = Components.classes; 7 var Ci = Components.interfaces; 8 var Cu = Components.utils; 9 10 var EXPORTED_SYMBOLS = ["FirebugGCLICommands"]; 11 12 // ********************************************************************************************* // 13 // GCLI 14 15 var scope = {}; 16 17 try 18 { 19 Cu.import("resource:///modules/devtools/gcli.jsm", scope); 20 } 21 catch (err) 22 { 23 if (FBTrace.DBG_ERROR) 24 FBTrace.sysout("GCLI not available"); 25 } 26 27 // Load the Locale module and make sure Firebug string bundle is registered 28 // (GCLI commands needs to be localized) 29 var Locale = Cu.import("resource://firebug/locale.js").Locale; 30 Locale.registerStringBundle("chrome://firebug/locale/firebug.properties"); 31 32 if (scope.gcli) { 33 34 // ********************************************************************************************* // 35 // FirebugGCLICommands 36 37 var FirebugGCLICommands = 38 { 39 startup: function() 40 { 41 registerCommands(); 42 }, 43 44 shutdown: function() 45 { 46 unregisterCommands(); 47 } 48 } 49 50 // ********************************************************************************************* // 51 // Command Implementation 52 53 /** 54 * Read https://developer.mozilla.org/en/Tools/GCLI/Writing_GCLI_Commands 55 * about how to implement GCLI comands. 56 */ 57 var FirebugController = 58 { 59 openFirebug: function(args, context) 60 { 61 this.startFirebug(context, function(Firebug) { 62 Firebug.toggleBar(true); 63 }); 64 }, 65 66 hideFirebug: function(args, context) 67 { 68 this.startFirebug(context, function(Firebug) { 69 Firebug.minimizeBar(); 70 }); 71 }, 72 73 closeFirebug: function(args, context) 74 { 75 var Firebug = context.environment.chromeDocument.defaultView.Firebug; 76 if (!Firebug) 77 return; 78 79 if (!Firebug.isLoaded) 80 return; 81 82 this.startFirebug(context, function(Firebug) { 83 Firebug.closeFirebug(); 84 }); 85 }, 86 87 detachFirebug: function(args, context) 88 { 89 this.startFirebug(context, function(Firebug) { 90 Firebug.toggleDetachBar(true); 91 }); 92 }, 93 94 attachFirebug: function(args, context) 95 { 96 this.startFirebug(context, function(Firebug) { 97 if (Firebug.isDetached()) 98 Firebug.toggleDetachBar(); 99 Firebug.toggleBar(true); 100 }); 101 }, 102 103 startFirebug: function(context, callback) 104 { 105 var Firebug = context.environment.chromeDocument.defaultView.Firebug; 106 if (!Firebug) 107 return; 108 109 Firebug.browserOverlay.startFirebug(function(Firebug) { 110 callback(Firebug); 111 }); 112 }, 113 } 114 115 // ********************************************************************************************* // 116 // Registration 117 118 var commands = []; 119 120 function addCommand(command) 121 { 122 scope.gcli.addCommand(command); 123 commands.push(command); 124 } 125 126 function registerCommands() 127 { 128 addCommand({ 129 name: "firebug", 130 description: "Web Development Evolved" 131 }); 132 133 addCommand({ 134 name: "firebug open", 135 description: Locale.$STR("firebug.menu.tip.Open_Firebug"), 136 exec: FirebugController.openFirebug.bind(FirebugController) 137 }); 138 139 addCommand({ 140 name: "firebug hide", 141 description: Locale.$STR("firebug.menu.tip.Minimize_Firebug"), 142 exec: FirebugController.hideFirebug.bind(FirebugController) 143 }); 144 145 addCommand({ 146 name: "firebug close", 147 description: Locale.$STR("firebug.shortcut.tip.closeFirebug"), 148 exec: FirebugController.closeFirebug.bind(FirebugController) 149 }); 150 151 addCommand({ 152 name: "firebug detach", 153 description: Locale.$STR("firebug.DetachFirebug"), 154 exec: FirebugController.detachFirebug.bind(FirebugController) 155 }); 156 157 addCommand({ 158 name: "firebug attach", 159 description: Locale.$STR("firebug.AttachFirebug"), 160 exec: FirebugController.attachFirebug.bind(FirebugController) 161 }); 162 } 163 164 function unregisterCommands() 165 { 166 for (var i=0; i<commands.length; i++) 167 scope.gcli.removeCommand(commands[i]); 168 169 commands = []; 170 } 171 172 // ********************************************************************************************* // 173 } 174