UISourceCodeFrame.js [plain text]
WebInspector.UISourceCodeFrame = function(uiSourceCode)
{
this._uiSourceCode = uiSourceCode;
WebInspector.SourceFrame.call(this, this._uiSourceCode);
this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.FormattedChanged, this._onFormattedChanged, this);
this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyChanged, this);
this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyCommitted, this);
}
WebInspector.UISourceCodeFrame.prototype = {
wasShown: function()
{
WebInspector.SourceFrame.prototype.wasShown.call(this);
this._boundWindowFocused = this._windowFocused.bind(this);
window.addEventListener("focus", this._boundWindowFocused, false);
this._checkContentUpdated();
},
willHide: function()
{
WebInspector.SourceFrame.prototype.willHide.call(this);
window.removeEventListener("focus", this._boundWindowFocused, false);
delete this._boundWindowFocused;
},
canEditSource: function()
{
return this._uiSourceCode.isEditable();
},
_windowFocused: function(event)
{
this._checkContentUpdated();
},
_checkContentUpdated: function()
{
if (!this.loaded || !this.isShowing())
return;
this._uiSourceCode.checkContentUpdated();
},
commitEditing: function(text)
{
if (!this._uiSourceCode.isDirty())
return;
this._isCommittingEditing = true;
this._uiSourceCode.commitWorkingCopy(this._didEditContent.bind(this));
delete this._isCommittingEditing;
},
onTextChanged: function(oldRange, newRange)
{
WebInspector.SourceFrame.prototype.onTextChanged.call(this, oldRange, newRange);
this._isSettingWorkingCopy = true;
this._uiSourceCode.setWorkingCopy(this._textEditor.text());
delete this._isSettingWorkingCopy;
},
_didEditContent: function(error)
{
if (error) {
WebInspector.log(error, WebInspector.ConsoleMessage.MessageLevel.Error, true);
return;
}
},
_onFormattedChanged: function(event)
{
var content = (event.data.content);
this._textEditor.setReadOnly(this._uiSourceCode.formatted());
this.setContent(content, false, this._uiSourceCode.mimeType());
},
_onWorkingCopyChanged: function(event)
{
this._innerSetContent(this._uiSourceCode.workingCopy());
},
_onWorkingCopyCommitted: function(event)
{
this._innerSetContent(this._uiSourceCode.workingCopy());
},
onUISourceCodeContentChanged: function(content)
{
this.setContent(content, false, this._uiSourceCode.mimeType());
},
_innerSetContent: function(content)
{
if (this._isSettingWorkingCopy || this._isCommittingEditing)
return;
this.onUISourceCodeContentChanged(content);
},
populateTextAreaContextMenu: function(contextMenu, lineNumber)
{
WebInspector.SourceFrame.prototype.populateTextAreaContextMenu.call(this, contextMenu, lineNumber);
contextMenu.appendApplicableItems(this._uiSourceCode);
contextMenu.appendSeparator();
},
dispose: function()
{
this.detach();
},
__proto__: WebInspector.SourceFrame.prototype
}