2 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * 2. 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
16 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC.
20 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * @extends {WebInspector.SourceFrame}
32 * @param {!WebInspector.UISourceCode} uiSourceCode
34 WebInspector.UISourceCodeFrame = function(uiSourceCode)
36 this._uiSourceCode = uiSourceCode;
37 WebInspector.SourceFrame.call(this, this._uiSourceCode);
38 this.textEditor.setAutocompleteDelegate(new WebInspector.SimpleAutocompleteDelegate());
40 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyChanged, this);
41 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyCommitted, this);
42 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.SavedStateUpdated, this._onSavedStateUpdated, this);
46 WebInspector.UISourceCodeFrame.prototype = {
48 * @return {!WebInspector.UISourceCode}
50 uiSourceCode: function()
52 return this._uiSourceCode;
57 WebInspector.SourceFrame.prototype.wasShown.call(this);
58 this._boundWindowFocused = this._windowFocused.bind(this);
59 this.element.ownerDocument.defaultView.addEventListener("focus", this._boundWindowFocused, false);
60 this._checkContentUpdated();
65 WebInspector.SourceFrame.prototype.willHide.call(this);
66 this.element.ownerDocument.defaultView.removeEventListener("focus", this._boundWindowFocused, false);
67 delete this._boundWindowFocused;
68 this._uiSourceCode.removeWorkingCopyGetter();
75 canEditSource: function()
77 var projectType = this._uiSourceCode.project().type();
78 if (projectType === WebInspector.projectTypes.Service || projectType === WebInspector.projectTypes.Debugger || projectType === WebInspector.projectTypes.Formatter)
80 if (projectType === WebInspector.projectTypes.Network && this._uiSourceCode.contentType() === WebInspector.resourceTypes.Document)
85 _windowFocused: function(event)
87 this._checkContentUpdated();
90 _checkContentUpdated: function()
92 if (!this.loaded || !this.isShowing())
94 this._uiSourceCode.checkContentUpdated();
97 commitEditing: function()
99 if (!this._uiSourceCode.isDirty())
102 this._muteSourceCodeEvents = true;
103 this._uiSourceCode.commitWorkingCopy();
104 delete this._muteSourceCodeEvents;
107 onTextChanged: function(oldRange, newRange)
109 WebInspector.SourceFrame.prototype.onTextChanged.call(this, oldRange, newRange);
110 if (this._isSettingContent)
112 this._muteSourceCodeEvents = true;
113 if (this._textEditor.isClean())
114 this._uiSourceCode.resetWorkingCopy();
116 this._uiSourceCode.setWorkingCopyGetter(this._textEditor.text.bind(this._textEditor));
117 delete this._muteSourceCodeEvents;
121 * @param {!WebInspector.Event} event
123 _onWorkingCopyChanged: function(event)
125 if (this._muteSourceCodeEvents)
127 this._innerSetContent(this._uiSourceCode.workingCopy());
128 this.onUISourceCodeContentChanged();
132 * @param {!WebInspector.Event} event
134 _onWorkingCopyCommitted: function(event)
136 if (!this._muteSourceCodeEvents) {
137 this._innerSetContent(this._uiSourceCode.workingCopy());
138 this.onUISourceCodeContentChanged();
140 this._textEditor.markClean();
145 * @param {!WebInspector.Event} event
147 _onSavedStateUpdated: function(event)
152 _updateStyle: function()
154 this.element.classList.toggle("source-frame-unsaved-committed-changes", this._uiSourceCode.hasUnsavedCommittedChanges());
157 onUISourceCodeContentChanged: function()
162 * @param {string} content
164 _innerSetContent: function(content)
166 this._isSettingContent = true;
167 this.setContent(content);
168 delete this._isSettingContent;
171 populateTextAreaContextMenu: function(contextMenu, lineNumber, columnNumber)
173 WebInspector.SourceFrame.prototype.populateTextAreaContextMenu.call(this, contextMenu, lineNumber, columnNumber);
174 contextMenu.appendApplicableItems(this._uiSourceCode);
175 contextMenu.appendApplicableItems(new WebInspector.UILocation(this._uiSourceCode, lineNumber, columnNumber));
176 contextMenu.appendSeparator();
180 * @param {!Array.<!WebInspector.UISourceCodeFrame.Infobar|undefined>} infobars
182 attachInfobars: function(infobars)
184 for (var i = infobars.length - 1; i >= 0; --i) {
185 var infobar = infobars[i];
188 this.element.insertBefore(infobar.element, this.element.children[0]);
189 infobar._attached(this);
196 this._textEditor.dispose();
200 __proto__: WebInspector.SourceFrame.prototype
205 * @extends {WebInspector.Infobar}
206 * @param {!WebInspector.Infobar.Type} type
207 * @param {string} message
208 * @param {!WebInspector.Setting=} disableSetting
210 WebInspector.UISourceCodeFrame.Infobar = function(type, message, disableSetting)
212 WebInspector.Infobar.call(this, type, disableSetting);
213 this.setCloseCallback(this.dispose.bind(this));
214 this.element.classList.add("source-frame-infobar");
215 this._rows = this.element.createChild("div", "source-frame-infobar-rows");
217 this._mainRow = this._rows.createChild("div", "source-frame-infobar-main-row");
218 this._mainRow.createChild("span", "source-frame-infobar-row-message").textContent = message;
220 this._toggleElement = this._mainRow.createChild("div", "source-frame-infobar-toggle link");
221 this._toggleElement.addEventListener("click", this._onToggleDetails.bind(this), false);
222 this._detailsContainer = this._rows.createChild("div", "source-frame-infobar-details-container");
223 this._updateToggleElement();
226 WebInspector.UISourceCodeFrame.Infobar.prototype = {
227 _onResize: function()
229 if (this._uiSourceCodeFrame)
230 this._uiSourceCodeFrame.doResize();
233 _onToggleDetails: function()
235 this._toggled = !this._toggled;
236 this._updateToggleElement();
240 _updateToggleElement: function()
242 this._toggleElement.textContent = this._toggled ? WebInspector.UIString("less") : WebInspector.UIString("more");
243 this._detailsContainer.classList.toggle("hidden", !this._toggled);
247 * @param {!WebInspector.UISourceCodeFrame} uiSourceCodeFrame
249 _attached: function(uiSourceCodeFrame)
251 this._uiSourceCodeFrame = uiSourceCodeFrame;
252 this.setVisible(true);
256 * @param {string=} message
259 createDetailsRowMessage: function(message)
261 var infobarDetailsRow = this._detailsContainer.createChild("div", "source-frame-infobar-details-row");
262 var detailsRowMessage = infobarDetailsRow.createChild("span", "source-frame-infobar-row-message");
263 detailsRowMessage.textContent = message || "";
264 return detailsRowMessage;
269 this.element.remove();
271 delete this._uiSourceCodeFrame;
274 __proto__: WebInspector.Infobar.prototype