| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @fileoverview WebInspector panel representing command line debugger. | |
| 7 */ | |
| 8 | |
| 9 /** | |
| 10 * Command line debugger panel. | |
| 11 * @constructor | |
| 12 * @extends {WebInspector.Panel} | |
| 13 */ | |
| 14 WebInspector.DebuggerPanel = function() | |
| 15 { | |
| 16 WebInspector.Panel.call(this); | |
| 17 | |
| 18 this.contentElement = document.createElement("div"); | |
| 19 this.contentElement.id = "debugger-content"; | |
| 20 | |
| 21 var table = document.createElement("table"); | |
| 22 table.id = 'outer'; | |
| 23 var tr = document.createElement("tr"); | |
| 24 this._output = document.createElement("td"); | |
| 25 this._output.id = "output"; | |
| 26 this._output.valign = "bottom"; | |
| 27 this.appendText("Chrome JavaScript Debugger"); | |
| 28 this.appendText("Type 'help' for a list of commands."); | |
| 29 | |
| 30 tr.appendChild(this._output); | |
| 31 table.appendChild(tr); | |
| 32 this.contentElement.appendChild(table); | |
| 33 | |
| 34 | |
| 35 var commandLine = document.createElement("div"); | |
| 36 commandLine.id = "command-line"; | |
| 37 var input = document.createElement("input"); | |
| 38 input.id = "command-line-text"; | |
| 39 input.addEventListener('keydown', this._onInputKeyDown.bind(this), true); | |
| 40 input.addEventListener('keypress', this._onInputKeyPress.bind(this), true); | |
| 41 input.type = "text"; | |
| 42 this.commandLineInput_ = input; | |
| 43 | |
| 44 commandLine.appendChild(input); | |
| 45 this.contentElement.appendChild(commandLine); | |
| 46 | |
| 47 // command object stores command-line history state. | |
| 48 this._command = { | |
| 49 history: [], | |
| 50 history_index: 0, | |
| 51 pending: null | |
| 52 }; | |
| 53 | |
| 54 this.element.appendChild(this.contentElement); | |
| 55 p('DebuggerPanel created'); | |
| 56 }; | |
| 57 | |
| 58 WebInspector.DebuggerPanel.prototype = { | |
| 59 toolbarItemClass: "debugger", | |
| 60 | |
| 61 get toolbarItemLabel() | |
| 62 { | |
| 63 return "Debugger"; //WebInspector.UIString("Debugger"); | |
| 64 }, | |
| 65 | |
| 66 show: function() | |
| 67 { | |
| 68 WebInspector.Panel.prototype.show.call(this); | |
| 69 this.focusOnCommandLine(); | |
| 70 }, | |
| 71 | |
| 72 /** | |
| 73 * Sets focus to command-line-text element. | |
| 74 */ | |
| 75 focusOnCommandLine: function() | |
| 76 { | |
| 77 if (this.visible) { | |
| 78 this.commandLineInput_.focus(); | |
| 79 } | |
| 80 }, | |
| 81 | |
| 82 /** | |
| 83 * Called by chrome code when there's output to display. | |
| 84 * @param {string} txt | |
| 85 */ | |
| 86 appendText: function(txt) | |
| 87 { | |
| 88 this._output.appendChild(document.createTextNode(txt)); | |
| 89 this._output.appendChild(document.createElement('br')); | |
| 90 }, | |
| 91 | |
| 92 /** | |
| 93 * Called by chrome code to set the current state as to whether the debugger | |
| 94 * is stopped at a breakpoint or is running. | |
| 95 * @param {boolean} isBroken | |
| 96 */ | |
| 97 setDebuggerBreak: function(isBroken) | |
| 98 { | |
| 99 var out = this._output; | |
| 100 if (isBroken) { | |
| 101 out.style.color = "black"; | |
| 102 this.focusOnCommandLine(); | |
| 103 } else { | |
| 104 out.style.color = "gray"; | |
| 105 } | |
| 106 }, | |
| 107 | |
| 108 /** | |
| 109 * Execute a debugger command, add it to the command history and display | |
| 110 * it in the output window. | |
| 111 * @param {string} str | |
| 112 */ | |
| 113 executeCommand: function(str) | |
| 114 { | |
| 115 this.appendText("$ " + str); | |
| 116 // Sends message to DebuggerContents.HandleCommand. | |
| 117 if (DebugShell.singleton) { | |
| 118 DebugShell.singleton.command(str); | |
| 119 } else { | |
| 120 this.appendText("FAILED to send the command as DebugShell is null"); | |
| 121 } | |
| 122 | |
| 123 this._command.history.push(str); | |
| 124 this._command.history_index = this._command.history.length; | |
| 125 this._command.pending = null; | |
| 126 }, | |
| 127 | |
| 128 /** | |
| 129 * Display the previous history item in the given text field. | |
| 130 * @param {HTMLInputElement} field | |
| 131 */ | |
| 132 _selectPreviousCommand: function(field) | |
| 133 { | |
| 134 var command = this._command; | |
| 135 if (command.history_index > 0) { | |
| 136 // Remember the current field value as a pending command if we're at
the | |
| 137 // end (it's something the user typed in). | |
| 138 if (command.history_index == command.history.length) | |
| 139 command.pending = field.value; | |
| 140 command.history_index--; | |
| 141 field.value = command.history[command.history_index]; | |
| 142 field.select(); | |
| 143 } | |
| 144 }, | |
| 145 | |
| 146 /** | |
| 147 * Display the next history item in the given text field. | |
| 148 * @param {HTMLInputElement} field | |
| 149 */ | |
| 150 _selectNextCommand: function(field) | |
| 151 { | |
| 152 var command = this._command; | |
| 153 if (command.history_index < command.history.length) { | |
| 154 command.history_index++; | |
| 155 if (command.history_index == command.history.length) { | |
| 156 field.value = command.pending || ""; | |
| 157 } else { | |
| 158 field.value = command.history[command.history_index]; | |
| 159 } | |
| 160 field.select(); | |
| 161 } | |
| 162 }, | |
| 163 | |
| 164 /** | |
| 165 * command-line-text's onkeydown handler. | |
| 166 * @param {KeyboardEvent} e | |
| 167 * @return {boolean} | |
| 168 */ | |
| 169 _onInputKeyDown: function (e) | |
| 170 { | |
| 171 var field = e.target; | |
| 172 var key = e.keyCode; | |
| 173 if (key == 38) { // up arrow | |
| 174 this._selectPreviousCommand(field); | |
| 175 return false; | |
| 176 } else if (key == 40) { // down arrow | |
| 177 this._selectNextCommand(field); | |
| 178 return false; | |
| 179 } | |
| 180 return true; | |
| 181 }, | |
| 182 | |
| 183 /** | |
| 184 * command-line-text's onkeypress handler. | |
| 185 * @param {KeyboardEvent} e | |
| 186 * @return {boolean} | |
| 187 */ | |
| 188 _onInputKeyPress: function (e) | |
| 189 { | |
| 190 var field = e.target; | |
| 191 var key = e.keyCode; | |
| 192 if (key == 13) { // enter | |
| 193 this.executeCommand(field.value); | |
| 194 field.value = ""; | |
| 195 return false; | |
| 196 } | |
| 197 return true; | |
| 198 } | |
| 199 }; | |
| 200 | |
| 201 WebInspector.DebuggerPanel.prototype.__proto__ = WebInspector.Panel.prototype; | |
| OLD | NEW |