2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * Copyright (C) 2010 Apple Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 importScript("ace/ace.js");
37 * @extends {WebInspector.View}
38 * @implements {WebInspector.TextEditor}
39 * @param {?string} url
40 * @param {WebInspector.TextEditorDelegate} delegate
43 WebInspector.AceTextEditor = function(url, delegate)
45 WebInspector.View.call(this);
46 this._delegate = delegate;
48 this.element.className = "ace-editor-container";
50 var prefix = window.flattenImports ? "" : "ace/";
51 ace.config.setModuleUrl("ace/mode/javascript", prefix + "mode_javascript.js");
52 ace.config.setModuleUrl("ace/mode/javascript", prefix + "mode_css.js");
53 ace.config.setModuleUrl("ace/mode/javascript", prefix + "mode_html.js");
54 ace.config.setModuleUrl("ace/theme/textmate", prefix + "theme_textmate.js");
55 this._aceEditor = window.ace.edit(this.element);
57 this._aceEditor.setShowFoldWidgets(false);
58 this._aceEditor.on("gutterclick", this._gutterClick.bind(this));
59 this._aceEditor.on("change", this._onTextChange.bind(this));
60 this._aceEditor.setHighlightActiveLine(false);
61 this._aceEditor.session.setUseWorker(false);
62 this.registerRequiredCSS("ace/acedevtools.css");
65 WebInspector.AceTextEditor.prototype = {
67 _onTextChange: function(event)
69 this._delegate.onTextChanged(null, null);
72 _gutterClick: function(event)
74 var lineNumber = parseInt(event.domEvent.target.textContent) - 1;
75 this.dispatchEventToListeners(WebInspector.TextEditor.Events.GutterClick, { lineNumber: lineNumber, event: event.domEvent });
79 * @param {string} mimeType
81 set mimeType(mimeType)
85 this._aceEditor.getSession().setMode("ace/mode/html");
88 this._aceEditor.getSession().setMode("ace/mode/css");
90 case "text/javascript":
91 this._aceEditor.getSession().setMode("ace/mode/javascript");
97 * @param {boolean} readOnly
99 setReadOnly: function(readOnly)
101 this._aceEditor.setReadOnly(readOnly);
109 return this._aceEditor.getReadOnly();
114 this._aceEditor.focus();
120 defaultFocusedElement: function()
122 return this.element.firstChild;
126 * @param {string} regex
127 * @param {string} cssClass
128 * @return {WebInspector.TextEditorMainPanel.HighlightDescriptor}
130 highlightRegex: function(regex, cssClass)
132 console.log("aceEditor.highlightRegex not implemented");
136 * @param {WebInspector.TextRange} range
137 * @param {string} cssClass
139 highlightRange: function(range, cssClass)
141 console.log("aceEditor.highlightRange not implemented");
145 * @param {WebInspector.TextEditorMainPanel.HighlightDescriptor} highlightDescriptor
147 removeHighlight: function(highlightDescriptor)
149 console.log("aceEditor.removeHighlight not implemented");
153 * @param {number} lineNumber
155 revealLine: function(lineNumber) {
156 this._aceEditor.scrollToLine(lineNumber, false, true);
160 * @param {number} lineNumber
161 * @param {boolean} disabled
162 * @param {boolean} conditional
164 addBreakpoint: function(lineNumber, disabled, conditional)
166 this._aceEditor.getSession().setBreakpoint(lineNumber, "webkit-breakpoint");
170 * @param {number} lineNumber
172 removeBreakpoint: function(lineNumber)
174 this._aceEditor.getSession().clearBreakpoint(lineNumber);
178 * @param {number} lineNumber
180 setExecutionLine: function(lineNumber)
182 console.log("aceEditor.setExecutionLine not implemented");
186 * @param {WebInspector.TextRange} range
189 copyRange: function(range)
191 console.log("aceEditor.copyRange not implemented");
195 clearExecutionLine: function()
197 console.log("aceEditor.clearExecutionLine not implemented");
201 * @param {number} lineNumber
202 * @param {Element} element
204 addDecoration: function(lineNumber, element)
206 console.log("aceEditor.addDecoration not implemented");
210 * @param {number} lineNumber
211 * @param {Element} element
213 removeDecoration: function(lineNumber, element)
215 console.log("aceEditor.removeDecoration not implemented");
219 * @param {WebInspector.TextRange} range
221 markAndRevealRange: function(range)
223 console.log("aceEditor.markAndRevealRange not implemented");
227 * @param {number} lineNumber
229 highlightLine: function(lineNumber)
231 console.log("aceEditor.highlightLine not implemented");
234 clearLineHighlight: function() {
235 console.log("aceEditor.clearLineHighlight not implemented");
239 * @return {Array.<Element>}
241 elementsToRestoreScrollPositionsFor: function()
247 * @param {WebInspector.TextEditor} textEditor
249 inheritScrollPositions: function(textEditor)
251 console.log("aceEditor.inheritScrollPositions not implemented");
254 beginUpdates: function() { },
256 endUpdates: function() { },
258 onResize: function() { },
261 * @param {WebInspector.TextRange} range
262 * @param {string} text
263 * @return {WebInspector.TextRange}
265 editRange: function(range, text)
267 console.log("aceEditor.editRange not implemented");
271 * @param {number} lineNumber
273 scrollToLine: function(lineNumber)
275 this._aceEditor.scrollToLine(lineNumber, false, true);
279 * @return {WebInspector.TextRange}
281 selection: function()
283 console.log("aceEditor.selection not implemented");
287 * @return {WebInspector.TextRange?}
289 lastSelection: function()
291 console.log("aceEditor.lastSelection not implemented");
295 * @param {WebInspector.TextRange} textRange
297 setSelection: function(textRange)
299 console.log("aceEditor.setSelection not implemented");
303 * @param {string} text
305 setText: function(text)
307 this._aceEditor.getSession().setValue(text);
315 return this._aceEditor.getSession().getValue();
319 * @return {WebInspector.TextRange}
323 console.log("aceEditor.range not implemented");
327 * @param {number} lineNumber
330 line: function(lineNumber)
332 return this._aceEditor.getSession().getLine(lineNumber);
339 return this._aceEditor.getSession().getLength();
343 * @param {number} line
344 * @param {string} name
345 * @param {Object?} value
347 setAttribute: function(line, name, value)
349 console.log("aceEditor.setAttribute not implemented");
353 * @param {number} line
354 * @param {string} name
355 * @return {Object|null} value
357 getAttribute: function(line, name)
359 console.log("aceEditor.getAttribute not implemented");
363 * @param {number} line
364 * @param {string} name
366 removeAttribute: function(line, name)
368 console.log("aceEditor.removeAttribute not implemented");
371 wasShown: function() { },
373 __proto__: WebInspector.View.prototype