More error checking, more XBL cleanup, change some prefs

This commit is contained in:
mkaply%us.ibm.com 2006-04-04 19:59:25 +00:00
parent 8aafd2f1c4
commit 078406eedf
6 changed files with 130 additions and 117 deletions

View File

@ -23,7 +23,7 @@
<!ENTITY configLocation.label "Location of configuration">
<!ENTITY saveOnExit.label "Save configuration automatically on exit">
<!ENTITY zipLocation.label "In order to create the XPI, we need to use ZIP. If ZIP is not in your path, you can specify it here">
<!ENTITY zipLocation.label "In order to create the XPI, we need to use ZIP. If ZIP is not in your path, you can specify it here:">
@ -51,8 +51,8 @@
<!ENTITY customizePartOne.label "Customize the Browser - Part One">
<!ENTITY orgName.error "Company Identifier is required">
<!ENTITY orgName.description "The Company Identifier is included as part of the browser's user agent string which appears when you open the Help menu and select About Mozilla Firefox.">
<!ENTITY orgName.error "Company Identifier is required and cannot contain any spaces.">
<!ENTITY orgName.description "The Company Identifier is included as part of the browser's user agent string which appears when you open the Help menu and select About Mozilla Firefox. It is required.">
<!ENTITY orgName.label "Enter Your Company Identifier (up to 10 characters; no spaces):">
<!ENTITY orgName.caption "Company Identifier">

View File

@ -21,10 +21,7 @@
</content>
<implementation>
<constructor>
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[1].setAttribute("disabled","true");
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[2].setAttribute("disabled","true");
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[3].setAttribute("disabled","true");
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[4].setAttribute("disabled","true");
this._enableDisableButtons();
</constructor>
<method name="clear">
<body>
@ -61,34 +58,38 @@
var listbox=document.getAnonymousNodes(this)[0].childNodes[0].childNodes[0];
listboxitem = listbox.appendItem(label, value);
listboxitem.cck = new Array();
if ((listbox.selectedIndex != 0) && (listbox.selectedIndex != -1))
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[3].setAttribute("disabled","false");
else
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[3].setAttribute("disabled","true");
if ((listbox.selectedIndex != listbox.getRowCount()-1) && (listbox.selectedIndex != -1))
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[4].setAttribute("disabled","false");
else
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[4].setAttribute("disabled","true");
this._enableDisableButtons();
return listboxitem;
]]>
</body>
</method>
<method name="_enableDisableButtons">
<body>
var listbox=document.getAnonymousNodes(this)[0].childNodes[0].childNodes[0];
if (listbox.selectedIndex == -1) {
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[1].setAttribute("disabled","true");
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[2].setAttribute("disabled","true");
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[3].setAttribute("disabled","true");
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[4].setAttribute("disabled","true");
} else {
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[1].setAttribute("disabled","false");
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[2].setAttribute("disabled","false");
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[3].setAttribute("disabled","false");
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[4].setAttribute("disabled","false");
if (listbox.selectedIndex == 0)
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[3].setAttribute("disabled","true");
if (listbox.selectedIndex == listbox.getRowCount()-1)
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[4].setAttribute("disabled","true");
}
</body>
</method>
<property name="selectedItem"
onget="return document.getAnonymousNodes(this)[0].childNodes[0].childNodes[0].selectedItem;"
onset="document.getAnonymousNodes(this)[0].childNodes[0].childNodes[0].selectedItem = val;"/>
</implementation>
<handlers>
<handler event="select">
var listbox=document.getAnonymousNodes(this)[0].childNodes[0].childNodes[0];
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[1].setAttribute("disabled","false");
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[2].setAttribute("disabled","false");
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[3].setAttribute("disabled","false");
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[4].setAttribute("disabled","false");
if (listbox.selectedIndex == 0)
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[3].setAttribute("disabled","true");
if (listbox.selectedIndex == listbox.getRowCount()-1)
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[4].setAttribute("disabled","true");
this._enableDisableButtons();
</handler>
<handler event="dblclick">
if (event.originalTarget.tagName == "listitem")
@ -97,8 +98,8 @@
<handler event="command">
if (event.originalTarget.type == "delete") {
var listbox=document.getAnonymousNodes(this)[0].childNodes[0].childNodes[0];
listbox.removeItemAt(listbox.selectedIndex);
} else if ((event.originalTarget.type == "moveup") || (event.originalTarget.type == "movedown")) {
listbox.removeItemAt(listbox.selectedIndex);
} else if ((event.originalTarget.type == "moveup") || (event.originalTarget.type == "movedown")) {
var listbox=document.getAnonymousNodes(this)[0].childNodes[0].childNodes[0];
var listitem=listbox.selectedItem;
var index;
@ -122,23 +123,16 @@
} else {
eval(this.getAttribute(event.originalTarget.type));
}
if (listbox.selectedIndex == -1) {
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[1].setAttribute("disabled","true");
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[2].setAttribute("disabled","true");
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[3].setAttribute("disabled","true");
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[4].setAttribute("disabled","true");
} else {
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[1].setAttribute("disabled","false");
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[2].setAttribute("disabled","false");
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[3].setAttribute("disabled","false");
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[4].setAttribute("disabled","false");
if (listbox.selectedIndex == 0)
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[3].setAttribute("disabled","true");
if (listbox.selectedIndex == listbox.getRowCount()-1)
document.getAnonymousNodes(this)[0].childNodes[1].childNodes[4].setAttribute("disabled","true");
}
this._enableDisableButtons();
</handler>
<handler event="keypress" keycode="VK_DELETE">
if (event.originalTarget.tagName == "xul:listbox") {
var listbox=document.getAnonymousNodes(this)[0].childNodes[0].childNodes[0];
listbox.removeItemAt(listbox.selectedIndex);
this._enableDisableButtons();
}
</handler>
</handlers>
</binding>
</bindings>

View File

@ -49,8 +49,7 @@ function choosefile(labelname)
var nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
fp.init(window, "Choose File...", nsIFilePicker.modeOpen);
fp.appendFilters(nsIFilePicker.filterHTML | nsIFilePicker.filterText |
nsIFilePicker.filterAll | nsIFilePicker.filterImages | nsIFilePicker.filterXML);
fp.appendFilters(nsIFilePicker.filterAll);
if (fp.show() == nsIFilePicker.returnOK && fp.fileURL.spec && fp.fileURL.spec.length > 0) {
var label = document.getElementById(labelname);
@ -89,7 +88,7 @@ function chooseimage(labelname, imagename)
var nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
fp.init(window, "Choose File...", nsIFilePicker.modeOpen);
fp.appendFilters(nsIFilePicker.filterImages | nsIFilePicker.filterA);
fp.appendFilters(nsIFilePicker.filterImages);
if (fp.show() == nsIFilePicker.returnOK && fp.fileURL.spec && fp.fileURL.spec.length > 0) {
var label = document.getElementById(labelname);
@ -224,6 +223,7 @@ function setcurrentconfig(newconfig)
currentconfigname = newconfig;
currentconfigpath = gPrefBranch.getCharPref("cck.config." + currentconfigname);
destdir.initWithPath(currentconfigpath);
ClearAll();
CCKReadConfigFile(destdir);
}
@ -259,8 +259,8 @@ function CloseCCKWizard()
var bundle = document.getElementById("bundle_cckwizard");
var button = gPromptService.confirmEx(window, bundle.getString("windowTitle"), bundle.getString("cancelConfirm"),
gPromptService.BUTTON_TITLE_YES * gPromptService.BUTTON_POS_0 +
gPromptService.BUTTON_TITLE_NO * gPromptService.BUTTON_POS_1,
(gPromptService.BUTTON_TITLE_YES * gPromptService.BUTTON_POS_0) +
(gPromptService.BUTTON_TITLE_NO * gPromptService.BUTTON_POS_1),
null, null, null, null, {});
} else {
button = 0;
@ -282,7 +282,7 @@ function OnConfigLoad()
function ClearAll()
{
/* clear out all data */
var elements = this.opener.document.getElementsByAttribute("id", "*");
var elements = document.getElementsByAttribute("id", "*");
for (var i=0; i < elements.length; i++) {
if ((elements[i].nodeName == "textbox") ||
(elements[i].nodeName == "radiogroup") ||
@ -294,27 +294,17 @@ function ClearAll()
} else if (elements[i].nodeName == "checkbox") {
if (elements[i].id != "saveOnExit")
elements[i].checked = false;
} else if (elements[i].id == "prefList") {
listbox = this.opener.document.getElementById('prefList');
listbox.clear();
} else if (elements[i].id == "browserPluginList") {
listbox = this.opener.document.getElementById('browserPluginList');
listbox.clear();
} else if (elements[i].id == "tbFolder.bookmarkList") {
listbox = this.opener.document.getElementById('tbFolder.bookmarkList');
listbox.clear();
} else if (elements[i].id == "regList") {
listbox = this.opener.document.getElementById('regList');
listbox.clear();
} else if (elements[i].id == "searchEngineList") {
listbox = this.opener.document.getElementById('searchEngineList');
listbox.clear();
} else if (elements[i].className == "ccklist") {
document.getElementById(elements[i].id).clear;
}
}
}
function OnConfigOK()
{
if (!(ValidateDir('cnc-location'))) {
return false;
}
var configname = document.getElementById('cnc-name').value;
var configlocation = document.getElementById('cnc-location').value;
if (window.name == 'copyconfig') {
@ -322,8 +312,6 @@ function OnConfigOK()
.createInstance(Components.interfaces.nsILocalFile);
destdir.initWithPath(configlocation);
this.opener.CCKWriteConfigFile(destdir);
} else {
ClearAll();
}
gPrefBranch.setCharPref("cck.config." + configname, configlocation);
this.opener.setcurrentconfig(configname);
@ -734,7 +722,7 @@ function CreateCCK()
destdir.initWithPath(currentconfigpath);
destdir.append("xpi");
destdir.append("plugins");
destdir.append("platform");
try {
destdir.remove(true);
destdir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0775);
@ -745,8 +733,13 @@ function CreateCCK()
for (var i=0; i < listbox.getRowCount(); i++) {
listitem = listbox.getItemAtIndex(i);
var pluginsubdir = destdir.clone();
if (listitem.value)
/* If there is no value, assume windows - this should only happen for migration */
if (listitem.value) {
pluginsubdir.append(listitem.value);
} else {
pluginsubdir.append("WINNT_x86-msvc");
}
pluginsubdir.append("plugins");
try {
pluginsubdir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0775);
} catch(ex) {}
@ -774,35 +767,15 @@ function CreateCCK()
CCKCopyChromeToFile("chrome.manifest", destdir)
CCKWriteInstallRDF(destdir);
// For now, do to a Firefox 1.5 bug, we have to put install.rdf in a subdir and install
// it from there. So the installer needs a different XPI.
var installrdfdir = destdir.clone();
installrdfdir.append("installrdf");
try {
installrdfdir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0775);
} catch(ex) {}
CCKWriteInstallRDF(installrdfdir);
// For now, do to a Firefox 1.5 bug, we have to put install.rdf in a subdir and install
// it from there. So the installer needs a different XPI.
// We do this first so the install.js that is in the dir is the "good" one.
var installerfilename = document.getElementById("filename").value;
if (installerfilename.length == 0)
installerfilename = "cck";
installerfilename += "-installer.xpi";
CCKWriteInstallJS(destdir, true);
CCKZip(installerfilename, destdir,
"chrome", "components", "defaults", "plugins", "searchplugins", "chrome.manifest", "installrdf", "install.js");
CCKWriteInstallJS(destdir, false);
CCKWriteInstallJS(destdir);
var filename = document.getElementById("filename").value;
if (filename.length == 0)
filename = "cck";
filename += ".xpi";
CCKZip(filename, destdir,
"chrome", "components", "defaults", "plugins", "searchplugins", "chrome.manifest", "install.rdf", "install.js");
"chrome", "components", "defaults", "platform", "searchplugins", "chrome.manifest", "install.rdf", "install.js");
var bundle = document.getElementById("bundle_cckwizard");
@ -1487,7 +1460,7 @@ function CCKWriteInstallRDF(destdir)
fos.close();
}
function CCKWriteInstallJS(destdir, useinstallrdfdir)
function CCKWriteInstallJS(destdir)
{
var file = destdir.clone();
file.append("install.js");
@ -1525,13 +1498,7 @@ function CCKWriteInstallJS(destdir, useinstallrdfdir)
else
str = str.replace(/%searchplugins%/g, '');
var brokeway = "addDirectory(\"\", \"%version%\", \"installrdf\", cckextensiondir, \"\", true);";
var goodway = "addFile(\"\", \"%version%\", \"install.rdf\", cckextensiondir, \"\", true);";
if (useinstallrdfdir)
str = str.replace(/%installrdf%/g, brokeway);
else
str = str.replace(/%installrdf%/g, goodway);
str = str.replace(/%installrdf%/g, 'addFile("", "%version%", "install.rdf", cckextensiondir, "", true);');
str = str.replace(/%version%/g, document.getElementById("version").value);
@ -1624,17 +1591,25 @@ function CCKWriteConfigFile(destdir)
var elements = document.getElementsByAttribute("id", "*")
for (var i=0; i < elements.length; i++) {
if ((elements[i].nodeName == "textbox") ||
(elements[i].nodeName == "radiogroup") ||
(elements[i].id == "RootKey1") ||
(elements[i].id == "Type1")) {
if ((elements[i].id != "saveOnExit") && (elements[i].id != "zipLocation")) {
var line = elements[i].getAttribute("id") + "=" + elements[i].value + "\n";
fos.write(line, line.length);
if (elements[i].value.length > 0) {
var line = elements[i].getAttribute("id") + "=" + elements[i].value + "\n";
fos.write(line, line.length);
}
}
} else if (elements[i].nodeName == "radiogroup") {
if ((elements[i].value.length > 0) && (elements[i].value != "0")) {
var line = elements[i].getAttribute("id") + "=" + elements[i].value + "\n";
fos.write(line, line.length);
}
} else if (elements[i].nodeName == "checkbox") {
if (elements[i].id != "saveOnExit") {
var line = elements[i].getAttribute("id") + "=" + elements[i].checked + "\n";
fos.write(line, line.length);
if (elements[i].checked) {
var line = elements[i].getAttribute("id") + "=" + elements[i].checked + "\n";
fos.write(line, line.length);
}
}
} else if (elements[i].id == "prefList") {
listbox = document.getElementById('prefList');
@ -1767,7 +1742,7 @@ function CCKReadConfigFile(srcdir)
toggleProxySettings();
return;
}
var stream = Components.classes["@mozilla.org/network/file-input-stream;1"]
.createInstance(Components.interfaces.nsIFileInputStream);
@ -1963,6 +1938,20 @@ function Validate(field, message)
return true;
}
function ValidateNoSpace(field, message)
{
for (var i=0; i < arguments.length; i+=2) {
var str = document.getElementById(arguments[i]).value;
if ((str == '') || (str.match(" "))) {
var bundle = document.getElementById("bundle_cckwizard");
gPromptService.alert(window, bundle.getString("windowTitle"), arguments[i+1]);
return false;
}
}
return true;
}
function ValidateFile()
{
for (var i=0; i < arguments.length; i++) {
@ -1985,6 +1974,27 @@ function ValidateFile()
return true;
}
function ValidateDir()
{
for (var i=0; i < arguments.length; i++) {
var filename = document.getElementById(arguments[i]).value;
if (filename.length > 0) {
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
try {
file.initWithPath(filename);
} catch (e) {
gPromptService.alert(window, "", "Directory " + filename + " not found");
return false;
}
if (!file.exists() || !file.isDirectory()) {
gPromptService.alert(window, "", "Directory " + filename + " not found");
return false;
}
}
}
return true;
}
function toggleProxySettings()
{

View File

@ -46,7 +46,7 @@
<wizard id="example-window" title="&cckWizard.title;"
height="480"
width="640"
onwizardcancel="CloseCCKWizard();"
onwizardcancel="return CloseCCKWizard();"
onwizardfinish="CreateCCK();"
onload="OpenCCKWizard();"
xmlns:html="http://www.w3.org/1999/xhtml"
@ -164,7 +164,7 @@
<label control="filename">&filename.label;</label>
</vbox>
<hbox align="center">
<textbox flex="1" id="filename"/>
<textbox id="filename"/>
<label>.xpi</label>
</hbox>
</row>
@ -172,7 +172,7 @@
</grid>
</wizardpage>
<wizardpage label="&customizePartOne.label;" onpageadvanced="return Validate('OrganizationName','&orgName.error;')">
<wizardpage label="&customizePartOne.label;" onpageadvanced="return ValidateNoSpace('OrganizationName','&orgName.error;')">
<groupbox>
<caption label="&orgName.caption;"/>
<description>&orgName.description;</description>

View File

@ -53,10 +53,10 @@
<label>&configName.label;</label>
<vbox flex="1">
<textbox flex="1" id="cnc-name" onchange="configCheckOKButton();" onkeyup="configCheckOKButton();"/>/>
<textbox flex="1" id="cnc-name" onchange="configCheckOKButton();" onkeyup="configCheckOKButton();"/>
&configLocation.label;
<hbox>
<textbox readonly="true" flex="1" id="cnc-location"/>
<textbox flex="1" id="cnc-location" onchange="configCheckOKButton();" onkeyup="configCheckOKButton();"/>
<button label="&chooseDir.label;" oncommand="choosedir('cnc-location');configCheckOKButton();"/>
</hbox>
</vbox>

View File

@ -90,13 +90,6 @@ CCKService.prototype={
} catch (ex) {
return;
}
var cckinited;
try {
cckinited = prefbranch.getBoolPref("cck.initialized");
} catch (ex) {
cckinited = false;
}
var sbs;
var bundle;
var pm;
@ -111,6 +104,21 @@ CCKService.prototype={
return;
}
var cckinited;
try {
OrgName = bundle.GetStringFromName("OrganizationName");
cckinited = prefbranch.getBoolPref("cck." + OrgName + ".initialized");
} catch (ex) {
try {
cckinited = prefbranch.getBoolPref("cck.initialized");
OrgName = bundle.GetStringFromName("OrganizationName");
prefbranch.setBoolPref("cck." + OrgName + ".initialized", cckinited);
prefbranch.deleteBranch("cck.initialized");
} catch (ex) {
cckinited = false;
}
}
if ("@mozilla.org/windows-registry-key;1" in Components.classes) {
const nsIWindowsRegKey = Components.interfaces.nsIWindowsRegKey;
@ -268,7 +276,8 @@ CCKService.prototype={
addBookmarks(bundle, BMSVC, "", bmRoot, bmIndex);
}
prefbranch.setBoolPref("cck.initialized", true);
OrgName = bundle.GetStringFromName("OrganizationName");
prefbranch.setBoolPref("cck." + OrgName + ".initialized", true);
}
}
}