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
/
filA12A566DFAB875FFAD5B9F3849A4A1C0
< prev
next >
Wrap
Text File
|
2010-07-12
|
14KB
|
366 lines
(function() {
var APP_NAME = "yasearch";
function OverlayControllerF() {
this._barCore = Components.classes["@yandex.ru/custombarcore;" + this._appName].getService().wrappedJSObject;
this._application = this._barCore.application;
this._id = this._application.getNewControllerID();
this._logger = this._barCore.Log4Moz.repository.getLogger(this._appName + ".OverlayController");
window.addEventListener("load", this, false);
this._init();
}
OverlayControllerF.prototype = {
get id() {
return this._id;
},
get application() {
return this._application;
},
get guiBuilder() {
return this._guiBuilder;
},
get windowEngine() {
return this._wndEngine;
},
navigate: function wndCtrl_navigate(url, target, windowWidth, windowHeight, yandexAction, widgetProto) {
this._application.navigate(window, url, target, windowWidth, windowHeight, yandexAction, widgetProto);
},
addWidgetItem: function wndCtrl_addWidgetItem(protoID, settingsMap, relativeTo, placeAfter, dontPersist) {
var widgetProto = this._application.widgetLibrary.getWidgetProto(protoID);
var paletteItemID;
var spawnedWidgets = widgetProto.spawnedWidgets;
var WIID = (widgetProto.isUnique && spawnedWidgets.length > 0) ? spawnedWidgets[0].id : 0;
if (this._wndEngine.hasWidget(WIID)) {
paletteItemID = this._wndEngine.getToolbarElement(WIID).getAttribute("id");
}
else {
let palette = this._toolbox.palette;
paletteItemID = this._application.overlayProvider.compileWidgetItemId(widgetProto.id, 0);
if (!palette.getElementsByAttribute("id", paletteItemID).length) {
this._logger.debug("Adding new item to palette " + paletteItemID);
let paletteItem = this._application.overlayProvider.makePaletteItem(document, widgetProto, 0);
palette.appendChild(paletteItem);
}
}
var beforeElement;
if (relativeTo) {
let relativeToElement;
if (relativeTo instanceof Components.interfaces.nsIDOMNode)
relativeToElement = relativeTo;
else
if (relativeTo instanceof this._barCore.Lib.XB._Parser.Unit.WidgetInstance)
relativeToElement = this._wndEngine.getToolbarElement(relativeTo.id);
else
throw new TypeError("relativeTo must be either a WidgetInstance or nsIDOMNode");
beforeElement = placeAfter? relativeToElement.nextSibling: relativeToElement;
}
var destToolbar = beforeElement? beforeElement.parentNode: this._appToolbar;
let toolbarItem = document.getElementById(paletteItemID);
if (toolbarItem) {
let sourceToolbar = toolbarItem.parentNode;
if (beforeElement)
destToolbar.insertBefore(toolbarItem, beforeElement);
else
destToolbar.appendChild(toolbarItem);
if (!dontPersist && sourceToolbar !== destToolbar)
this._persistToolbarSet(sourceToolbar);
} else {
toolbarItem = destToolbar.insertItem(paletteItemID, beforeElement);
if (settingsMap) {
let widget = this._wndEngine.getWidget(toolbarItem.instanceID);
for (let settingName in settingsMap)
try {
widget.applySetting(settingName, settingsMap[settingName]);
}
catch (e) {
this._logger.warn("Could not apply widget setting '" + settingName + "'");
}
}
}
if (!dontPersist)
this._persistToolbarSet(destToolbar);
return toolbarItem;
},
removeItem: function wndCtrl_removeWidgetItem(DOMElementOrWidgetInstanceID, dontPersist) {
var widgetElement;
if (DOMElementOrWidgetInstanceID instanceof Components.interfaces.nsIDOMElement)
widgetElement = DOMElementOrWidgetInstanceID;
else if (typeof DOMElementOrWidgetInstanceID == "string")
widgetElement = this._wndEngine.getToolbarElement(DOMElementOrWidgetInstanceID);
else
throw new TypeError("Widget DOM element or instance ID string required");
var toolbar = widgetElement.parentNode;
var palette = this._toolbox.palette;
if (widgetElement.isXBWidget) {
if (widgetElement.isUnique) {
let paletteItem = this._application.overlayProvider
.makePaletteItem(document, widgetElement.prototype, 0);
if (!palette.getElementsByAttribute("id", paletteItem.id).length)
palette.appendChild(paletteItem);
}
widgetElement.kill();
toolbar.removeChild(widgetElement);
} else {
widgetElement = toolbar.removeChild(widgetElement);
if (["toolbarseparator", "toolbarspacer", "toolbarspring"].indexOf(widgetElement.localName) == -1) {
if (!palette.getElementsByAttribute("id", widgetElement.id).length)
palette.appendChild(widgetElement);
}
}
if (!dontPersist)
this._persistToolbarSet(toolbar);
},
removeWidgetsOfPackage: function wndCtrl_removeWidgetsOfPackage(packageID) {
for each (let toolbarItem in this.getAppWidgetItems(packageID, undefined))
this.removeItem(toolbarItem);
},
removeWidgetsOfProto: function wndCtrl_removeWidgetsOfProto(protoID) {
for each (let toolbarItem in this.getAppWidgetItems(undefined, protoID))
this.removeItem(toolbarItem);
},
removeItemById: function wndCtrl_removeItemById(aDOMElementId, aDontPersist) {
this.removeItem(document.getElementById(aDOMElementId), aDontPersist);
},
setupWidget: function wndCtrl_setupWidget(widgetInstanceID) {
const winType = this._appName + ":Preferences";
let prefWindow = this._barCore.Lib.misc.getTopWindowOfType(winType);
if (prefWindow) {
prefWindow.focus();
prefWindow.Preferences.selectWidget(widgetInstanceID);
} else {
let instantApply = this._barCore.Preferences.get("browser.preferences.instantApply", false);
let features = "chrome,titlebar,toolbar,centerscreen,resizable," + (instantApply ? "dialog=no" : "modal");
prefWindow = window.openDialog("chrome://" + this._appName + "/content/custombar/preferences/preferences.xul",
winType, features, "prefpane-customize", widgetInstanceID);
}
},
clearToolbar: function wndCtrl_clearToolbar() {
Array.slice(this._appToolbar.childNodes)
.forEach(function(item) {
if (!this.isPermanetToolbarItem(item))
this.removeItem(item, true);
}, this);
},
updatePalette: function wndCtrl_updatePalette(newPackagesIDs) {
var palette = this._toolbox.palette;
let items = palette.getElementsByTagName("toolbaritem");
for (let i = items.length; i--;) {
let item = items.item(i);
if (item.getAttribute("xb-app") == this._application.name) {
let protoID = item.getAttribute("xb-proto-id");
let [packageID, ] = this._application.widgetLibrary.parseWidgetProtoID(protoID);
let isNewPackage = newPackagesIDs.indexOf(packageID) >= 0;
if (!this._application.widgetLibrary.isKnownWidget(protoID) || isNewPackage)
item.parentNode.removeChild(item);
}
}
for each (let packageId in newPackagesIDs) {
for each (let widgetProto in this._application.widgetLibrary.getWidgetProtos(packageId)) {
if (document.getElementsByAttribute("xb-proto-id", widgetProto.id).length)
continue;
let widgetItem = this._application.overlayProvider.makePaletteItem(document, widgetProto, 0);
palette.appendChild(widgetItem);
}
}
},
deleteObsoleteWidgetItems: function wndCtrl_deleteObsoleteWidgetItems() {
var toolbars = {__proto__: null};
for each (let widgetItem in this.getAppWidgetItems()) {
if (this._application.widgetLibrary.isKnownWidget(widgetItem.prototypeID)) continue;
let toolbar = widgetItem.parentNode;
toolbars[toolbar.id] = toolbar;
widgetItem.kill();
widgetItem.parentNode.removeChild(widgetItem);
}
for each (let toolbar in toolbars)
this._persistToolbarSet(toolbar);
},
isPermanetToolbarItem: function(node) {
let ids = [
"yasearch-search",
"yasearch-container",
"yasearch-bloggers",
"yasearch-translate"
];
let protoIds = [
"http://bar.yandex.ru/packages/yandexbar#town"
];
if (node.id && ids.indexOf(node.id) != -1)
return true;
if (node.isXBWidget && (node.application == this._application) && protoIds.indexOf(node.prototypeID) != -1)
return true;
let nodeLocalName = node.localName;
if (["toolbarseparator", "toolbarspacer", "toolbarspring"].indexOf(nodeLocalName) != -1) {
let previousSiblingLocalName = node.previousSibling ? node.previousSibling.localName : null;
if (nodeLocalName != previousSiblingLocalName)
return true;
}
return false;
},
getToolbarSpring: function() {
var item = this._appToolbar.firstChild;
while (item) {
if (item.localName == "toolbarspring")
return item;
item = item.nextSibling;
}
return this._appToolbar.insertItem("spring");
},
setWidgets: function wndCtrl_setWidgets(widgetsInfo, placement) {
if (placement == "replace")
this.clearToolbar();
var relativeElement,
placeAfter = (placement == "after");
if (placeAfter) {
widgetsInfo.reverse();
relativeElement = this._appToolbar.lastChild;
} else {
relativeElement = this.getToolbarSpring();
}
for each (let info in widgetsInfo)
this.addWidgetItem(info.protoID, info.settings, relativeElement, placeAfter);
this._persistToolbarSet(this._appToolbar);
},
handleXBAction: function wndCtrl_handleXBAction(WIID, command) {
this._logger.debug("handleXBAction " + [WIID, command]);
switch(command) {
case "reload-package":
this._application.restartWidgets(this._wndEngine.getWidget(WIID).prototype.unit.unitPackage.id);
break;
}
},
handleEvent: function wndCtrl_handleEvent(event) {
switch (event.type) {
case "load":
this._onOverlayLoaded(event);
break;
case "unload":
this._onOverlayUnload(event);
break;
}
},
switchWidgets: function wndCtrl_switchWidgets(packageID, on) {
for each (let widgetItem in this.getAppWidgetItems(packageID, undefined))
try {
widgetItem.switchOn(on);
}
catch (e) {
this._logger.error("Could not switch widget. " + this._application.core.Lib.misc.formatError(e));
}
},
getAppWidgetItems: function wndCtrl_getAppWidgetItems(packageID, protoID, knownIDs) {
var items = this._toolbox.getElementsByTagName("toolbaritem");
var result = [];
for (let i = 0, len = items.length; i < len; i++) {
let item = items[i];
if (item.isXBWidget && (item.application == this._application)
&& (!protoID || item.prototypeID == protoID)
&& (!packageID || item.prototypeID.indexOf(packageID) == 0)
|| (knownIDs && knownIDs.indexOf(item.id) != -1) )
result.push(item);
}
return result;
},
_id: 0,
_appName: APP_NAME,
_barCore: null,
_application: null,
_logger: null,
_wndEngine: null,
_guiBuilder: null,
_init: function() {
this._wndEngine = new this._barCore.Lib.XB.WindowEngine(this);
this._guiBuilder = new this._barCore.Lib.XB.UI.Builder(this._wndEngine, this);
this._guiBuilder.registerExtActionsHelper(this);
},
_onOverlayLoaded: function wndCtrl_onOverlayLoaded(loadEvent) {
this._logger.info("Overlay loaded");
loadEvent.currentTarget.removeEventListener("load", this, false);
loadEvent.currentTarget.addEventListener("unload", this, false);
this._application.onNewNavigatorReady(this);
},
_onOverlayUnload: function wndCtrl_onOverlayUnload(unloadEvent) {
this._logger.info("Overlay unloads");
try {
unloadEvent.currentTarget.removeEventListener("unload", this, false);
}
finally {
}
},
_persistToolbarSet: function wndCtrl_persistToolbarSet(toolbar) {
toolbar.setAttribute("currentset", toolbar.currentSet);
document.persist(toolbar.id, "currentset");
},
get _toolbox() {
return document.getElementById("navigator-toolbox");
},
get _appToolbar() {
return document.getElementById(this._application.name + "-bar");
}
};
window[APP_NAME + "OverlayController"] = new OverlayControllerF();
})();