home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2011 November
/
CHIP_2011_11.iso
/
Programy
/
Narzedzia
/
AIMP2
/
aimp_2.61.583.exe
/
$TEMP
/
YandexPackSetup.msi
/
filD41E50A3CAB5C3956B107CFACBF41AF3
< prev
next >
Wrap
Text File
|
2010-07-12
|
8KB
|
229 lines
XB.WindowEngine = function XBWndEngine_constructor(overlayController) {
this._eid = "WndEngine" + XB._base.genWindowEngineID();
this._logger = overlayController.application.core.Log4Moz.repository.getLogger(XB._base.loggersRoot + "." + this._eid);
this._widgetsMap = {__proto__: null};
this._overlayController = overlayController;
};
XB.WindowEngine.prototype = {
constructor: XB.WindowEngine,
navigate: function XBWndEngine_navigate(url, target, windowWidth, windowHeight, yandexAction, widgetProto) {
this._overlayController.navigate(url, target, windowWidth, windowHeight, yandexAction, widgetProto);
},
setupWidget: function XBWndEngine_setupWidget(widgetInstance) {
this._overlayController.setupWidget(widgetInstance.id);
},
addWidget: function XBWndEngine_addWidget(protoID, settingsMap, relativeTo, placeAfter) {
let widgetItem = this._overlayController.addWidgetItem(protoID, settingsMap, relativeTo, placeAfter);
if (widgetItem && "instanceID" in widgetItem)
this.setupWidget(widgetItem);
},
removeWidget: function XBWndEngine_removeWidget(WIID) {
this._overlayController.removeItem(WIID);
},
clear: function XBWndEngine_clear() {
for each (let widgetPair in this._widgetsMap) {
try {
widgetPair.widget.finalize();
}
catch (e) {}
}
this._widgetsMap = {__proto__: null};
this._overlayController = null;
},
hasWidget: function XBWndEngine_hasWidget(widgetIID) {
return (widgetIID in this._widgetsMap);
},
createWidget: function XBWndEngine_createWidget(protoID, instID, settings, boundToolbarElement) {
if (!instID)
throw new Error(this._consts.ERR_INSTID_REQUIRED);
var widget;
if (this.hasWidget(instID)) {
this._logger.warn("Widget with this ID (" + instID + ") already exists. Will return the old one.");
widget = this.getWidget(instID);
if (settings) {
for (let settingName in settings) {
widget.applySetting(settingName, settings[settingName]);
}
}
} else {
widget = this._overlayController.application.widgetLibrary.getWidgetProto(protoID)
.createInstance(instID, this, settings);
this._widgetsMap[instID] = {widget: widget, toolbarElement: boundToolbarElement};
}
try {
this._overlayController.guiBuilder.build(widget.prototype.srcElement, boundToolbarElement, instID);
}
catch (e) {
this._logger.error("Could not build toolbar element content. " +
this._overlayController.application.core.Lib.misc.formatError(e));
this._logger.debug(e.stack);
}
return widget;
},
destroyWidget: function XBWndEngine_destroyWidget(instID, eraseSettingsIfNeeded) {
this._logger.debug("Widget " + instID + " destruction requested");
var widgetPair = this._getWidgetPair(instID);
try {
let toolbarElement = widgetPair.toolbarElement;
toolbarElement.constructed = false;
this._overlayController.guiBuilder.cleanNode(toolbarElement);
}
catch (e) {
this._logger.error("Could not clean widget toolbar element. " +
this._overlayController.application.core.Lib.misc.formatError(e));
}
try {
let widget = widgetPair.widget;
if (eraseSettingsIfNeeded) {
let widgetProto = widget.prototype;
if (widgetProto.isUnique && widgetProto.spawnedWidgets.length == 1) {
for each (let setting in widget.settings) {
try {
setting.node.erase();
}
catch (e) {
this._logger.error("Could not erase widget setting. " +
this._overlayController.application.core.Lib.misc.formatError(e));
}
}
}
}
widget.finalize();
}
finally {
delete this._widgetsMap[instID];
}
},
getWidget: function XBWndEngine_getWidget(widgetIID) {
return this._getWidgetPair(widgetIID).widget;
},
getToolbarElement: function XBWndEngine_getToolbarElement(widgetIID) {
return this._getWidgetPair(widgetIID).toolbarElement;
},
getValueAsString: function XBWndEngine_getValueAsString(widgetIID, valUID) {
return this._safeGetStrNodeValue(this._getCalcNode(widgetIID, valUID));
},
getValue: function XBWndEngine_getValue(widgetIID, valUID) {
return this._getCalcNode(widgetIID, valUID).getValue(this);
},
perform: function XBWndEngine_perform(widgetIID, valUID, eventInfo) {
try {
var procNode = this._getCalcNode(widgetIID, valUID);
}
catch (e) {
throw new XB.WindowEngine.ENoActionHandler(e.message);
}
if ( !(procNode instanceof XB._calcNodes.ProcNode) )
throw new TypeError(XB._base.consts.ERR_PROC_NODE_EXPECTED);
procNode.perform(eventInfo);
},
valueNotNeeded: function XBWndEngine_valueNotNeeded(widgetIID, valUID) {
this._getCalcNode(widgetIID, valUID).unsubscribe(this);
},
freeze: function XBWndEngine_freeze() {
},
melt: function XBWndEngine_melt(changedNode) {
if (!changedNode) return;
try {
this._notifyUIBuilder(changedNode);
}
catch (e) {
this._logger.error("Failed notifying UI builder. " + misc.formatError(e));
if (e.stack)
this._logger.debug(e.stack);
}
},
get effectiveID() {
return this.id;
},
get id() {
return this._eid;
},
get logger() {
return this._logger;
},
_consts: {
ERR_INSTID_REQUIRED: "Instance ID required",
ERR_XF_NOT_FOUND: "Requested value not found",
ERR_WIDGET_NOT_FOUND: "Couldn't find widget with this ID",
ERR_WI_EXPECTED: "Widgets info array expected",
ERR_CANT_CONSTRUCT_WIDGET: "Failed creating widget"
},
_logger: null,
_eid: undefined,
_overlayController: null,
_widgetsMap: null,
_getHumanReadableID: function XBWndEngine_getHumanReadableID() {
return this._eid;
},
_getWidgetPair: function XBWndEngine_getWidgetPair(widgetIID) {
let widgetPair = this._widgetsMap[widgetIID];
if (!widgetPair)
throw new Error(this._consts.ERR_WIDGET_NOT_FOUND + " (" + widgetIID + ")");
return widgetPair;
},
_getCalcNode: function XBWndEngine__getCalcNode(widgetIID, valUID) {
var calcNode = this.getWidget(widgetIID).findReference(valUID);
if (!calcNode)
throw new Error(this._consts.ERR_XF_NOT_FOUND + " (" + [widgetIID, valUID] + ")");
return calcNode;
},
_safeGetStrNodeValue: function XBWndEngine__safeGetStrNodeValue(node) {
var strVal = "";
try {
strVal = XB._base.runtime.xToString(node.getValue(this));
}
catch (e) {
this._logger.error("Converting value to string failed. " + misc.formatError(e) + ". Will return empty string.");
}
return strVal;
},
_notifyUIBuilder: function XBWndEngine__notifyUIBuilder(changedNode) {
this._logger.trace("Notifying UI builder");
this._overlayController.guiBuilder.handleDataChange(changedNode.parentWidget.id,
changedNode.baseID,
changedNode.getValue(this));
}
};
XB.WindowEngine.ENoActionHandler = function XBWE_ENoActionHandler(msg) {
this.name = "No action handler error";
this.message = msg;
};
XB.WindowEngine.ENoActionHandler.prototype = new Error();