2006-05-17 06:24:52 +04:00
|
|
|
/* -*- Mode: Java; tab-width: 4; c-basic-offset: 4; -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Ben "Count XULula" Goodger <ben@netscape.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
const _DEBUG = false;
|
|
|
|
|
|
|
|
/** PrefWindow IV
|
|
|
|
* =============
|
|
|
|
* This is a general page switcher and pref loader.
|
|
|
|
* =>> CHANGES MUST BE REVIEWED BY ben@netscape.com!! <<=
|
|
|
|
**/
|
Bookmarks Window Updates, includes fixes for
27495, 38004, 42080, 43146, 43753, 47494, 50835, 53403, 55447, 55448, 55787
r=blake, a=hyatt
2006-05-17 06:28:26 +04:00
|
|
|
|
|
|
|
var queuedTag;
|
2006-05-17 06:24:52 +04:00
|
|
|
function initPanel ( aPrefTag )
|
|
|
|
{
|
|
|
|
if( hPrefWindow )
|
Bookmarks Window Updates, includes fixes for
27495, 38004, 42080, 43146, 43753, 47494, 50835, 53403, 55447, 55448, 55787
r=blake, a=hyatt
2006-05-17 06:28:26 +04:00
|
|
|
hPrefWindow.onpageload( aPrefTag )
|
2006-05-17 06:27:43 +04:00
|
|
|
else
|
Bookmarks Window Updates, includes fixes for
27495, 38004, 42080, 43146, 43753, 47494, 50835, 53403, 55447, 55448, 55787
r=blake, a=hyatt
2006-05-17 06:28:26 +04:00
|
|
|
queuedTag = aPrefTag;
|
2006-05-17 06:24:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
window.doneLoading = false;
|
|
|
|
|
|
|
|
function nsPrefWindow( frame_id )
|
|
|
|
{
|
|
|
|
if ( !frame_id )
|
|
|
|
throw "Error: frame_id not supplied!";
|
|
|
|
|
|
|
|
this.contentFrame = frame_id
|
|
|
|
this.wsm = new nsWidgetStateManager( frame_id );
|
2006-05-17 06:31:51 +04:00
|
|
|
this.wsm.attributes = ["preftype", "prefstring", "prefattribute", "disabled"];
|
2006-05-17 06:24:52 +04:00
|
|
|
this.pref = null;
|
|
|
|
|
|
|
|
this.cancelHandlers = [];
|
|
|
|
this.okHandlers = [];
|
|
|
|
|
|
|
|
// set up window
|
|
|
|
this.onload();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPrefWindow.prototype =
|
|
|
|
{
|
|
|
|
onload:
|
|
|
|
function ()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
Bookmarks Window Updates, includes fixes for
27495, 38004, 42080, 43146, 43753, 47494, 50835, 53403, 55447, 55448, 55787
r=blake, a=hyatt
2006-05-17 06:28:26 +04:00
|
|
|
this.pref = Components.classes["@mozilla.org/preferences;1"].getService(Components.interfaces.nsIPref);
|
2006-05-17 06:24:52 +04:00
|
|
|
}
|
|
|
|
catch(e)
|
|
|
|
{
|
|
|
|
dump("*** Failed to create prefs object\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2006-05-17 06:25:12 +04:00
|
|
|
init:
|
|
|
|
function ()
|
|
|
|
{
|
|
|
|
if( window.queuedTag )
|
|
|
|
{
|
|
|
|
this.onpageload( window.queuedTag );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( window.arguments[1] )
|
Bookmarks Window Updates, includes fixes for
27495, 38004, 42080, 43146, 43753, 47494, 50835, 53403, 55447, 55448, 55787
r=blake, a=hyatt
2006-05-17 06:28:26 +04:00
|
|
|
this.closeBranches( window.arguments[1], window.arguments[2] );
|
2006-05-17 06:25:12 +04:00
|
|
|
},
|
|
|
|
|
2006-05-17 06:24:52 +04:00
|
|
|
onOK:
|
|
|
|
function ()
|
|
|
|
{
|
|
|
|
for( var i = 0; i < hPrefWindow.okHandlers.length; i++ )
|
|
|
|
{
|
|
|
|
hPrefWindow.okHandlers[i]();
|
|
|
|
}
|
|
|
|
|
|
|
|
var tag = document.getElementById( hPrefWindow.contentFrame ).getAttribute("tag");
|
|
|
|
if( tag == "" )
|
|
|
|
{
|
|
|
|
tag = document.getElementById( hPrefWindow.contentFrame ).getAttribute("src");
|
|
|
|
}
|
|
|
|
hPrefWindow.wsm.savePageData( tag );
|
|
|
|
hPrefWindow.savePrefs();
|
|
|
|
},
|
|
|
|
|
|
|
|
onCancel:
|
|
|
|
function ()
|
|
|
|
{
|
|
|
|
for( var i = 0; i < hPrefWindow.cancelHandlers.length; i++ )
|
|
|
|
{
|
|
|
|
hPrefWindow.cancelHandlers[i]();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
registerOKCallbackFunc:
|
|
|
|
function ( aFunctionReference )
|
|
|
|
{
|
|
|
|
this.okHandlers[this.okHandlers.length] = aFunctionReference;
|
|
|
|
},
|
|
|
|
|
|
|
|
registerCancelCallbackFunc:
|
|
|
|
function ( aFunctionReference )
|
|
|
|
{
|
|
|
|
this.cancelHandlers[this.cancelHandlers.length] = aFunctionReference;
|
|
|
|
},
|
2006-05-17 06:28:27 +04:00
|
|
|
getPrefIsLocked:
|
|
|
|
function ( aPrefString )
|
|
|
|
{
|
|
|
|
return hPrefWindow.pref.PrefIsLocked(aPrefString);
|
|
|
|
},
|
2006-05-17 06:24:52 +04:00
|
|
|
getPref:
|
|
|
|
function ( aPrefType, aPrefString, aDefaultFlag )
|
|
|
|
{
|
|
|
|
var pref = hPrefWindow.pref;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
switch ( aPrefType )
|
|
|
|
{
|
|
|
|
case "bool":
|
|
|
|
return !aDefaultFlag ? pref.GetBoolPref( aPrefString ) : pref.GetDefaultBoolPref( aPrefString );
|
|
|
|
case "int":
|
|
|
|
return !aDefaultFlag ? pref.GetIntPref( aPrefString ) : pref.GetDefaultIntPref( aPrefString );
|
2006-05-17 06:28:32 +04:00
|
|
|
case "localizedstring":
|
|
|
|
return pref.getLocalizedUnicharPref( aPrefString );
|
2006-05-17 06:24:52 +04:00
|
|
|
case "color":
|
|
|
|
case "string":
|
|
|
|
default:
|
2006-05-17 06:25:13 +04:00
|
|
|
return !aDefaultFlag ? pref.CopyUnicharPref( aPrefString ) : pref.CopyDefaultUnicharPref( aPrefString );
|
2006-05-17 06:24:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
|
|
|
if( _DEBUG )
|
|
|
|
{
|
|
|
|
dump("*** no default pref for " + aPrefType + " pref: " + aPrefString + "\n");
|
|
|
|
dump(e + "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "!/!ERROR_UNDEFINED_PREF!/!";
|
|
|
|
} ,
|
|
|
|
|
|
|
|
setPref:
|
|
|
|
function ( aPrefType, aPrefString, aValue )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
switch ( aPrefType )
|
|
|
|
{
|
|
|
|
case "bool":
|
|
|
|
hPrefWindow.pref.SetBoolPref( aPrefString, aValue );
|
|
|
|
break;
|
|
|
|
case "int":
|
|
|
|
hPrefWindow.pref.SetIntPref( aPrefString, aValue );
|
|
|
|
break;
|
|
|
|
case "color":
|
|
|
|
case "string":
|
2006-05-17 06:28:32 +04:00
|
|
|
case "localizedstring":
|
2006-05-17 06:24:52 +04:00
|
|
|
default:
|
|
|
|
hPrefWindow.pref.SetUnicharPref( aPrefString, aValue );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
|
|
|
dump(e + "\n");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
savePrefs:
|
|
|
|
function ()
|
|
|
|
{
|
|
|
|
for( var pageTag in this.wsm.dataManager.pageData )
|
|
|
|
{
|
|
|
|
var pageData = this.wsm.dataManager.getPageData( pageTag );
|
2006-05-17 06:28:31 +04:00
|
|
|
if (pageData.initialized)
|
|
|
|
{
|
2006-05-17 06:24:52 +04:00
|
|
|
for( var elementID in pageData )
|
|
|
|
{
|
2006-05-17 06:31:51 +04:00
|
|
|
if (elementID == "initialized") continue;
|
2006-05-17 06:24:52 +04:00
|
|
|
var itemObject = pageData[elementID];
|
2006-05-17 06:31:51 +04:00
|
|
|
if ( "prefstring" in itemObject && itemObject.prefstring )
|
2006-05-17 06:24:52 +04:00
|
|
|
{
|
107642 - XUL syntax/cleanup landing. Fixes 94470, 96008, 96019, 76800, 102637, 80399, 108303, and removes over a thousand unnecessary or nonsensical attributes. Also fixes 108302, 102366, 102367, 105815. r=sspitzer,cmanske on appropriate parts sr=ben
2006-05-17 06:31:28 +04:00
|
|
|
var elt = itemObject.localname;
|
|
|
|
var prefattribute = itemObject.prefattribute;
|
|
|
|
if (!prefattribute) {
|
|
|
|
if (elt == "radiogroup" || elt == "textbox" || elt == "menulist")
|
|
|
|
prefattribute = "value";
|
|
|
|
else if (elt == "checkbox")
|
|
|
|
prefattribute = "checked";
|
|
|
|
else if (elt == "button")
|
|
|
|
prefattribute = "disabled";
|
|
|
|
}
|
|
|
|
|
|
|
|
var value = itemObject[prefattribute];
|
|
|
|
var preftype = itemObject.preftype;
|
|
|
|
if (!preftype) {
|
|
|
|
if (elt == "textbox")
|
|
|
|
preftype = "string";
|
|
|
|
else if (elt == "checkbox" || elt == "button")
|
|
|
|
preftype = "bool";
|
2006-05-17 06:31:30 +04:00
|
|
|
else if (elt == "radiogroup" || elt == "menulist")
|
107642 - XUL syntax/cleanup landing. Fixes 94470, 96008, 96019, 76800, 102637, 80399, 108303, and removes over a thousand unnecessary or nonsensical attributes. Also fixes 108302, 102366, 102367, 105815. r=sspitzer,cmanske on appropriate parts sr=ben
2006-05-17 06:31:28 +04:00
|
|
|
preftype = "int";
|
|
|
|
}
|
|
|
|
switch( preftype )
|
2006-05-17 06:24:52 +04:00
|
|
|
{
|
|
|
|
case "bool":
|
|
|
|
if( value == "true" && typeof(value) == "string" )
|
|
|
|
value = true;
|
|
|
|
else if( value == "false" && typeof(value) == "string" )
|
|
|
|
value = false;
|
|
|
|
break;
|
|
|
|
case "int":
|
|
|
|
value = parseInt(value);
|
|
|
|
break;
|
|
|
|
case "color":
|
|
|
|
if( toString(value) == "" )
|
|
|
|
{
|
|
|
|
dump("*** ERROR CASE: illegal attempt to set an empty color pref. ignoring.\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "string":
|
2006-05-17 06:28:32 +04:00
|
|
|
case "localizedstring":
|
2006-05-17 06:24:52 +04:00
|
|
|
default:
|
|
|
|
if( typeof(value) != "string" )
|
|
|
|
{
|
|
|
|
value = toString(value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
107642 - XUL syntax/cleanup landing. Fixes 94470, 96008, 96019, 76800, 102637, 80399, 108303, and removes over a thousand unnecessary or nonsensical attributes. Also fixes 108302, 102366, 102367, 105815. r=sspitzer,cmanske on appropriate parts sr=ben
2006-05-17 06:31:28 +04:00
|
|
|
|
|
|
|
if( value != this.getPref( preftype, itemObject.prefstring ) )
|
2006-05-17 06:24:52 +04:00
|
|
|
{
|
107642 - XUL syntax/cleanup landing. Fixes 94470, 96008, 96019, 76800, 102637, 80399, 108303, and removes over a thousand unnecessary or nonsensical attributes. Also fixes 108302, 102366, 102367, 105815. r=sspitzer,cmanske on appropriate parts sr=ben
2006-05-17 06:31:28 +04:00
|
|
|
this.setPref( preftype, itemObject.prefstring, value );
|
2006-05-17 06:24:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-05-17 06:28:31 +04:00
|
|
|
}
|
2006-05-17 06:28:30 +04:00
|
|
|
this.pref.savePrefFile(null);
|
2006-05-17 06:24:52 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
switchPage:
|
|
|
|
function ()
|
|
|
|
{
|
|
|
|
var prefPanelTree = document.getElementById( "prefsTree" );
|
|
|
|
var selectedItem = prefPanelTree.selectedItems[0];
|
|
|
|
|
|
|
|
var oldURL = document.getElementById( this.contentFrame ).getAttribute("tag");
|
|
|
|
if( !oldURL )
|
|
|
|
{
|
|
|
|
oldURL = document.getElementById( this.contentFrame ).getAttribute("src");
|
|
|
|
}
|
|
|
|
this.wsm.savePageData( oldURL ); // save data from the current page.
|
|
|
|
var newURL = selectedItem.firstChild.firstChild.getAttribute("url");
|
|
|
|
var newTag = selectedItem.firstChild.firstChild.getAttribute("tag");
|
|
|
|
if( newURL != oldURL )
|
|
|
|
{
|
|
|
|
document.getElementById( this.contentFrame ).setAttribute( "src", newURL );
|
|
|
|
if( !newTag )
|
2006-05-17 06:25:16 +04:00
|
|
|
document.getElementById( this.contentFrame ).removeAttribute( "tag" );
|
|
|
|
else
|
|
|
|
document.getElementById( this.contentFrame ).setAttribute( "tag", newTag );
|
2006-05-17 06:24:52 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onpageload:
|
|
|
|
function ( aPageTag )
|
|
|
|
{
|
2006-05-17 06:31:51 +04:00
|
|
|
var header = document.getElementById("header");
|
|
|
|
header.setAttribute("title",
|
|
|
|
window.frames[this.contentFrame].document.documentElement.getAttribute("headertitle"));
|
2006-05-17 06:27:42 +04:00
|
|
|
if( !(aPageTag in this.wsm.dataManager.pageData) )
|
2006-05-17 06:24:52 +04:00
|
|
|
{
|
107642 - XUL syntax/cleanup landing. Fixes 94470, 96008, 96019, 76800, 102637, 80399, 108303, and removes over a thousand unnecessary or nonsensical attributes. Also fixes 108302, 102366, 102367, 105815. r=sspitzer,cmanske on appropriate parts sr=ben
2006-05-17 06:31:28 +04:00
|
|
|
var prefElements = window.frames[this.contentFrame].document.getElementsByAttribute( "prefstring", "*" );
|
2006-05-17 06:24:52 +04:00
|
|
|
this.wsm.dataManager.pageData[aPageTag] = [];
|
|
|
|
for( var i = 0; i < prefElements.length; i++ )
|
|
|
|
{
|
|
|
|
var prefstring = prefElements[i].getAttribute( "prefstring" );
|
|
|
|
var prefid = prefElements[i].getAttribute( "id" );
|
|
|
|
var preftype = prefElements[i].getAttribute( "preftype" );
|
107642 - XUL syntax/cleanup landing. Fixes 94470, 96008, 96019, 76800, 102637, 80399, 108303, and removes over a thousand unnecessary or nonsensical attributes. Also fixes 108302, 102366, 102367, 105815. r=sspitzer,cmanske on appropriate parts sr=ben
2006-05-17 06:31:28 +04:00
|
|
|
var elt = prefElements[i].localName;
|
|
|
|
if (!preftype) {
|
|
|
|
if (elt == "textbox")
|
|
|
|
preftype = "string";
|
|
|
|
else if (elt == "checkbox" || elt == "button")
|
|
|
|
preftype = "bool";
|
2006-05-17 06:31:29 +04:00
|
|
|
else if (elt == "radiogroup" || elt == "menulist")
|
107642 - XUL syntax/cleanup landing. Fixes 94470, 96008, 96019, 76800, 102637, 80399, 108303, and removes over a thousand unnecessary or nonsensical attributes. Also fixes 108302, 102366, 102367, 105815. r=sspitzer,cmanske on appropriate parts sr=ben
2006-05-17 06:31:28 +04:00
|
|
|
preftype = "int";
|
|
|
|
}
|
2006-05-17 06:24:52 +04:00
|
|
|
var prefdefval = prefElements[i].getAttribute( "prefdefval" );
|
|
|
|
var prefattribute = prefElements[i].getAttribute( "prefattribute" );
|
107642 - XUL syntax/cleanup landing. Fixes 94470, 96008, 96019, 76800, 102637, 80399, 108303, and removes over a thousand unnecessary or nonsensical attributes. Also fixes 108302, 102366, 102367, 105815. r=sspitzer,cmanske on appropriate parts sr=ben
2006-05-17 06:31:28 +04:00
|
|
|
if (!prefattribute) {
|
|
|
|
if (elt == "radiogroup" || elt == "textbox" || elt == "menulist")
|
|
|
|
prefattribute = "value";
|
|
|
|
else if (elt == "checkbox")
|
|
|
|
prefattribute = "checked";
|
|
|
|
else if (elt == "button")
|
|
|
|
prefattribute = "disabled";
|
|
|
|
}
|
2006-05-17 06:24:52 +04:00
|
|
|
var prefvalue;
|
|
|
|
switch( preftype )
|
|
|
|
{
|
|
|
|
case "bool":
|
|
|
|
prefvalue = this.getPref( preftype, prefstring );
|
|
|
|
break;
|
|
|
|
case "int":
|
|
|
|
prefvalue = this.getPref( preftype, prefstring );
|
|
|
|
break;
|
|
|
|
case "string":
|
2006-05-17 06:28:32 +04:00
|
|
|
case "localizedstring":
|
2006-05-17 06:24:52 +04:00
|
|
|
case "color":
|
|
|
|
default:
|
|
|
|
prefvalue = this.getPref( preftype, prefstring );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if( prefvalue == "!/!ERROR_UNDEFINED_PREF!/!" )
|
|
|
|
{
|
|
|
|
prefvalue = prefdefval;
|
|
|
|
}
|
|
|
|
var root = this.wsm.dataManager.getItemData( aPageTag, prefid );
|
|
|
|
root[prefattribute] = prefvalue;
|
2006-05-17 06:28:27 +04:00
|
|
|
var isPrefLocked = this.getPrefIsLocked(prefstring);
|
|
|
|
if (isPrefLocked)
|
2006-05-17 06:31:51 +04:00
|
|
|
root.disabled = "true";
|
107642 - XUL syntax/cleanup landing. Fixes 94470, 96008, 96019, 76800, 102637, 80399, 108303, and removes over a thousand unnecessary or nonsensical attributes. Also fixes 108302, 102366, 102367, 105815. r=sspitzer,cmanske on appropriate parts sr=ben
2006-05-17 06:31:28 +04:00
|
|
|
root.localname = prefElements[i].localName;
|
2006-05-17 06:24:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
this.wsm.setPageData( aPageTag ); // do not set extra elements, accept hard coded defaults
|
|
|
|
|
2006-05-17 06:27:42 +04:00
|
|
|
if( 'Startup' in window.frames[ this.contentFrame ])
|
2006-05-17 06:24:52 +04:00
|
|
|
{
|
|
|
|
window.frames[ this.contentFrame ].Startup();
|
|
|
|
}
|
2006-05-17 06:28:31 +04:00
|
|
|
this.wsm.dataManager.pageData[aPageTag].initialized=true;
|
2006-05-17 06:24:52 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
closeBranches:
|
Bookmarks Window Updates, includes fixes for
27495, 38004, 42080, 43146, 43753, 47494, 50835, 53403, 55447, 55448, 55787
r=blake, a=hyatt
2006-05-17 06:28:26 +04:00
|
|
|
function ( aComponentName, aSelectItem )
|
2006-05-17 06:24:52 +04:00
|
|
|
{
|
|
|
|
var panelChildren = document.getElementById( "panelChildren" );
|
|
|
|
var panelTree = document.getElementById( "prefsTree" );
|
|
|
|
for( var i = 0; i < panelChildren.childNodes.length; i++ )
|
|
|
|
{
|
|
|
|
var currentItem = panelChildren.childNodes[i];
|
2006-05-17 06:24:57 +04:00
|
|
|
if( currentItem.id != aComponentName && currentItem.id != "appearance" )
|
2006-05-17 06:24:52 +04:00
|
|
|
currentItem.removeAttribute( "open" );
|
|
|
|
}
|
Bookmarks Window Updates, includes fixes for
27495, 38004, 42080, 43146, 43753, 47494, 50835, 53403, 55447, 55448, 55787
r=blake, a=hyatt
2006-05-17 06:28:26 +04:00
|
|
|
var openItem = document.getElementById( aSelectItem );
|
2006-05-17 06:24:52 +04:00
|
|
|
panelTree.selectItem( openItem );
|
2006-05-17 06:27:44 +04:00
|
|
|
}
|
2006-05-17 06:24:52 +04:00
|
|
|
|
|
|
|
};
|
|
|
|
|