OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 WebInspector.BreakpointsSidebarPane = function() | 26 WebInspector.BreakpointsSidebarPane = function() |
27 { | 27 { |
28 WebInspector.SidebarPane.call(this, WebInspector.UIString("Breakpoints")); | 28 WebInspector.SidebarPane.call(this, WebInspector.UIString("Breakpoints")); |
29 | 29 |
30 this.breakpoints = []; | 30 this.breakpoints = {}; |
| 31 |
| 32 this.listElement = document.createElement("ol"); |
| 33 this.listElement.className = "breakpoint-list"; |
31 | 34 |
32 this.emptyElement = document.createElement("div"); | 35 this.emptyElement = document.createElement("div"); |
33 this.emptyElement.className = "info"; | 36 this.emptyElement.className = "info"; |
34 this.emptyElement.textContent = WebInspector.UIString("No Breakpoints"); | 37 this.emptyElement.textContent = WebInspector.UIString("No Breakpoints"); |
35 | 38 |
36 this.bodyElement.appendChild(this.emptyElement); | 39 this.bodyElement.appendChild(this.emptyElement); |
37 } | 40 } |
38 | 41 |
39 WebInspector.BreakpointsSidebarPane.prototype = { | 42 WebInspector.BreakpointsSidebarPane.prototype = { |
40 addBreakpoint: function(breakpoint) | 43 addBreakpoint: function(breakpoint) |
41 { | 44 { |
42 this.breakpoints.push(breakpoint); | 45 if (this.breakpoints[breakpoint.id]) |
| 46 return; |
| 47 |
| 48 this.breakpoints[breakpoint.id] = breakpoint; |
| 49 |
43 breakpoint.addEventListener("enabled", this._breakpointEnableChanged, th
is); | 50 breakpoint.addEventListener("enabled", this._breakpointEnableChanged, th
is); |
44 breakpoint.addEventListener("disabled", this._breakpointEnableChanged, t
his); | 51 breakpoint.addEventListener("disabled", this._breakpointEnableChanged, t
his); |
| 52 breakpoint.addEventListener("text-changed", this._breakpointTextChanged,
this); |
45 | 53 |
46 // FIXME: add to the breakpoints UI. | 54 this._appendBreakpointElement(breakpoint); |
| 55 |
| 56 if (this.emptyElement.parentElement) { |
| 57 this.bodyElement.removeChild(this.emptyElement); |
| 58 this.bodyElement.appendChild(this.listElement); |
| 59 } |
47 | 60 |
48 if (!InspectorController.debuggerEnabled() || !breakpoint.sourceID) | 61 if (!InspectorController.debuggerEnabled() || !breakpoint.sourceID) |
49 return; | 62 return; |
50 | 63 |
51 if (breakpoint.enabled) | 64 if (breakpoint.enabled) |
52 InspectorController.addBreakpoint(breakpoint.sourceID, breakpoint.li
ne); | 65 InspectorController.addBreakpoint(breakpoint.sourceID, breakpoint.li
ne); |
53 }, | 66 }, |
54 | 67 |
| 68 _appendBreakpointElement: function(breakpoint) |
| 69 { |
| 70 function checkboxClicked() |
| 71 { |
| 72 breakpoint.enabled = !breakpoint.enabled; |
| 73 } |
| 74 |
| 75 function labelClicked() |
| 76 { |
| 77 var script = WebInspector.panels.scripts.scriptOrResourceForID(break
point.sourceID); |
| 78 if (script) |
| 79 WebInspector.panels.scripts.showScript(script, breakpoint.line); |
| 80 } |
| 81 |
| 82 var breakpointElement = document.createElement("li"); |
| 83 breakpoint._breakpointListElement = breakpointElement; |
| 84 breakpointElement._breakpointObject = breakpoint; |
| 85 |
| 86 var checkboxElement = document.createElement("input"); |
| 87 checkboxElement.className = "checkbox-elem"; |
| 88 checkboxElement.type = "checkbox"; |
| 89 checkboxElement.checked = breakpoint.enabled; |
| 90 checkboxElement.addEventListener("click", checkboxClicked, false); |
| 91 breakpointElement.appendChild(checkboxElement); |
| 92 |
| 93 var labelElement = document.createElement("a"); |
| 94 labelElement.textContent = breakpoint.label; |
| 95 labelElement.addEventListener("click", labelClicked, false); |
| 96 breakpointElement.appendChild(labelElement); |
| 97 |
| 98 var sourceTextElement = document.createElement("div"); |
| 99 sourceTextElement.textContent = breakpoint.sourceText; |
| 100 sourceTextElement.className = "source-text"; |
| 101 breakpointElement.appendChild(sourceTextElement); |
| 102 |
| 103 var currentElement = this.listElement.firstChild; |
| 104 while (currentElement) { |
| 105 var currentBreak = currentElement._breakpointObject; |
| 106 if (currentBreak.url > breakpoint.url) { |
| 107 this.listElement.insertBefore(breakpointElement, currentElement)
; |
| 108 return; |
| 109 } else if (currentBreak.url == breakpoint.url && currentBreak.line >
breakpoint.line) { |
| 110 this.listElement.insertBefore(breakpointElement, currentElement)
; |
| 111 return; |
| 112 } |
| 113 currentElement = currentElement.nextSibling; |
| 114 } |
| 115 this.listElement.appendChild(breakpointElement); |
| 116 }, |
| 117 |
55 removeBreakpoint: function(breakpoint) | 118 removeBreakpoint: function(breakpoint) |
56 { | 119 { |
57 this.breakpoints.remove(breakpoint); | 120 if (!this.breakpoints[breakpoint.id]) |
| 121 return; |
| 122 delete this.breakpoints[breakpoint.id]; |
| 123 |
58 breakpoint.removeEventListener("enabled", null, this); | 124 breakpoint.removeEventListener("enabled", null, this); |
59 breakpoint.removeEventListener("disabled", null, this); | 125 breakpoint.removeEventListener("disabled", null, this); |
| 126 breakpoint.removeEventListener("text-changed", null, this); |
60 | 127 |
61 // FIXME: remove from the breakpoints UI. | 128 var element = breakpoint._breakpointListElement; |
| 129 element.parentElement.removeChild(element); |
| 130 |
| 131 if (!this.listElement.firstChild) { |
| 132 this.bodyElement.removeChild(this.listElement); |
| 133 this.bodyElement.appendChild(this.emptyElement); |
| 134 } |
62 | 135 |
63 if (!InspectorController.debuggerEnabled() || !breakpoint.sourceID) | 136 if (!InspectorController.debuggerEnabled() || !breakpoint.sourceID) |
64 return; | 137 return; |
65 | 138 |
66 InspectorController.removeBreakpoint(breakpoint.sourceID, breakpoint.lin
e); | 139 InspectorController.removeBreakpoint(breakpoint.sourceID, breakpoint.lin
e); |
67 }, | 140 }, |
68 | 141 |
69 _breakpointEnableChanged: function(event) | 142 _breakpointEnableChanged: function(event) |
70 { | 143 { |
71 var breakpoint = event.target; | 144 var breakpoint = event.target; |
72 | 145 |
73 // FIXME: change the breakpoint checkbox state in the UI. | 146 var checkbox = breakpoint._breakpointListElement.firstChild; |
| 147 checkbox.checked = breakpoint.enabled; |
74 | 148 |
75 if (!InspectorController.debuggerEnabled() || !breakpoint.sourceID) | 149 if (!InspectorController.debuggerEnabled() || !breakpoint.sourceID) |
76 return; | 150 return; |
77 | 151 |
78 if (breakpoint.enabled) | 152 if (breakpoint.enabled) |
79 InspectorController.addBreakpoint(breakpoint.sourceID, breakpoint.li
ne); | 153 InspectorController.addBreakpoint(breakpoint.sourceID, breakpoint.li
ne); |
80 else | 154 else |
81 InspectorController.removeBreakpoint(breakpoint.sourceID, breakpoint
.line); | 155 InspectorController.removeBreakpoint(breakpoint.sourceID, breakpoint
.line); |
| 156 }, |
| 157 |
| 158 _breakpointTextChanged: function(event) |
| 159 { |
| 160 var breakpoint = event.target; |
| 161 |
| 162 var sourceTextElement = breakpoint._breakpointListElement.firstChild.nex
tSibling.nextSibling; |
| 163 sourceTextElement.textContent = breakpoint.sourceText; |
82 } | 164 } |
83 } | 165 } |
84 | 166 |
85 WebInspector.BreakpointsSidebarPane.prototype.__proto__ = WebInspector.SidebarPa
ne.prototype; | 167 WebInspector.BreakpointsSidebarPane.prototype.__proto__ = WebInspector.SidebarPa
ne.prototype; |
OLD | NEW |