gecko-dev/xpfe/components/prefwindow/resources/content/pref-themes.js

178 строки
5.9 KiB
JavaScript
Исходник Обычный вид История

2000-05-10 07:11:32 +04:00
// Theme Selector
// ( 05/09/2000, Ben Goodger <ben@netscape.com> )
var gPrefutilitiesBundle;
2001-05-17 06:02:51 +04:00
var gBrandBundle;
var gShowDescription = true;
const DEBUG_USE_PROFILE = true;
2000-05-10 07:11:32 +04:00
try {
var chromeRegistry = Components.classes["@mozilla.org/chrome/chrome-registry;1"].getService();
if ( chromeRegistry )
chromeRegistry = chromeRegistry.QueryInterface( Components.interfaces.nsIChromeRegistry );
}
catch(e) {}
2000-05-10 07:11:32 +04:00
const kPrefSvcContractID = "@mozilla.org/preferences;1";
const kPrefSvcIID = Components.interfaces.nsIPref;
const kPrefSvc = Components.classes[kPrefSvcContractID].getService(kPrefSvcIID);
function Startup()
{
gPrefutilitiesBundle = document.getElementById("bundle_prefutilities");
2001-05-17 06:02:51 +04:00
gBrandBundle = document.getElementById("bundle_brand");
var tree = document.getElementById( "skinsTree" );
var theSkinKids = document.getElementById("theSkinKids");
if (theSkinKids.hasChildNodes() && theSkinKids.firstChild)
tree.selectItem(theSkinKids.firstChild);
try {
var strbundle = srGetStrBundle("chrome://navigator/locale/navigator.properties");
}
catch(e) {
}
var showSkinsDescription = strbundle.GetStringFromName("showskinsdescription");
if( showSkinsDescription == "false" )
{
gShowDescription = false;
var description = document.getElementById("description");
while (description.hasChildNodes())
description.removeChild(description.firstChild);
}
}
function applySkin()
{
var tree = document.getElementById("skinsTree");
var selectedSkinItem = tree.selectedItems[0];
var skinName = selectedSkinItem.getAttribute("name");
// XXX - this sucks and should only be temporary.
kPrefSvc.SetUnicharPref("general.skins.selectedSkin", skinName);
tree.selectItem(selectedSkinItem);
var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
observerService.Notify(null, "skin-selected", null);
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
try {
var strbundle = srGetStrBundle("chrome://navigator/locale/navigator.properties");
var brandbundle = srGetStrBundle("chrome://global/locale/brand.properties");
}
catch(e) {
return;
}
if (promptService) {
var dialogTitle = strbundle.GetStringFromName("switchskinstitle");
var brandName = brandbundle.GetStringFromName("brandShortName");
var msg = strbundle.formatStringFromName("switchskins",
[brandName],
1);
promptService.alert(window, dialogTitle, msg);
}
}
function uninstallSkin()
{
var tree = document.getElementById("skinsTree");
var selectedSkinItem = tree.selectedItems[0];
var skinName = selectedSkinItem.getAttribute("name");
var inUse = chromeRegistry.isSkinSelected(skinName, DEBUG_USE_PROFILE);
chromeRegistry.uninstallSkin(skinName, DEBUG_USE_PROFILE);
if (inUse)
chromeRegistry.refreshSkins();
tree.selectedIndex = 0;
}
2000-06-17 07:26:47 +04:00
function themeSelect()
{
var tree = document.getElementById("skinsTree");
2001-05-17 06:02:51 +04:00
if (!tree)
return;
var selectedItem = tree.selectedItems.length ? tree.selectedItems[0] : null;
var applyButton = document.getElementById("applySkin");
if (selectedItem && selectedItem.getAttribute("skin") == "true") {
var themeName = selectedItem.getAttribute("displayName");
2001-05-17 06:02:51 +04:00
var skinName = selectedItem.getAttribute("name");
var oldTheme;
try {
oldTheme = !chromeRegistry.checkThemeVersion(skinName);
}
catch(e) {
oldTheme = false;
}
var nameField = document.getElementById("displayName");
var author = document.getElementById("author");
var image = document.getElementById("previewImage");
var descText = document.createTextNode(selectedItem.getAttribute("description"));
var description = document.getElementById("description");
var uninstallButton = document.getElementById("uninstallSkin");
var applyLabel = gPrefutilitiesBundle.getString("applyThemePrefix");
var uninstallLabel = gPrefutilitiesBundle.getString("uninstallThemePrefix");
2001-05-17 06:02:51 +04:00
while (description.hasChildNodes())
description.removeChild(description.firstChild);
nameField.setAttribute("value", themeName);
author.setAttribute("value", selectedItem.getAttribute("author"));
image.setAttribute("src", selectedItem.getAttribute("image"));
// XXX - this sucks and should only be temporary.
var selectedSkin = "";
try {
selectedSkin = kPrefSvc.CopyCharPref("general.skins.selectedSkin");
}
catch (e) {
}
2001-05-17 06:02:51 +04:00
if (!oldTheme) {
if( gShowDescription )
description.appendChild(descText);
2001-05-17 06:02:51 +04:00
var locType = selectedItem.getAttribute("loctype");
uninstallButton.disabled = (selectedSkin == skinName) || (locType == "install");
applyButton.disabled = (selectedSkin == skinName);
2001-05-17 06:02:51 +04:00
applyLabel = applyLabel.replace(/%theme_name%/, themeName);
uninstallLabel = uninstallLabel.replace(/%theme_name%/, themeName);
applyButton.label = applyLabel;
uninstallButton.label = uninstallLabel;
}
else {
2001-05-17 06:02:51 +04:00
applyLabel = gPrefutilitiesBundle.getString("applyThemePrefix");
applyLabel = applyLabel.replace(/%theme_name%/, themeName);
applyButton.label = applyLabel;
applyButton.disabled = selectedSkin == skinName;
2001-05-17 06:02:51 +04:00
uninstallLabel = uninstallLabel.replace(/%theme_name%/, themeName);
uninstallButton.label = uninstallLabel;
applyButton.setAttribute("disabled", true);
uninstallButton.disabled = selectedSkin == skinName;
2001-05-17 06:02:51 +04:00
var newText = gPrefutilitiesBundle.getString("oldTheme");
newText = newText.replace(/%theme_name%/, themeName);
newText = newText.replace(/%brand%/g, gBrandBundle.getString("brandShortName"));
if( gShowDescription ) {
descText = document.createTextNode(newText);
description.appendChild(descText);
}
2001-05-17 06:02:51 +04:00
}
2000-06-17 07:26:47 +04:00
}
else {
applyButton.setAttribute("disabled", true);
}
}
2001-05-17 06:02:51 +04:00