fix for #98559. implement sorting on about:config results, add color to about:config results,

clean up about:config xul and js.  r=chipc,sr=ben

wasting time on about:config is not a total waste, since it's an
implementation of nsIOutlinerView in js, and it's useful for QA (when debugging.)
This commit is contained in:
sspitzer%netscape.com 2001-10-30 01:00:12 +00:00
parent cd0a6755c1
commit 3cd4563bd8
3 changed files with 198 additions and 45 deletions

View File

@ -43,3 +43,19 @@ outlinerbody:-moz-outliner-cell-text(prefCol)
{
font-weight: bold;
}
outlinerbody:-moz-outliner-cell-text(user)
{
color: blue;
}
outlinerbody:-moz-outliner-cell-text(default)
{
color: green;
}
outlinerbody:-moz-outliner-cell-text(locked)
{
color: red;
}

View File

@ -16,20 +16,61 @@
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributors:
* Chip Clark <chipc@netscape.com>
* Seth Spitzer <sspitzer@netscape.com>
*/
var arr = new Array();
var baseArray = new Array();
const kDefault = 0;
const kUserSet = 1;
const kLocked = 2;
const nsIAtomService = Components.interfaces.nsIAtomService;
const nsAtomService_CONTRACTID = "@mozilla.org/atom-service;1";
var atomService = Components.classes[nsAtomService_CONTRACTID].getService(nsIAtomService);
var gLockAtoms = [atomService.getAtom("default"), atomService.getAtom("user"), atomService.getAtom("locked")];
// XXX get these from a string bundle
var gLockStrs = ["default", "user set","locked"];
const kStrType = 0;
const kIntType = 1;
const kBoolType = 2;
var gTypeStrs = ["string","int","bool"];
var gOutliner;
var view = ({
rowCount : 0,
getCellText : function(k, col)
{
if ( !arr[k] )
return;
return arr[k][col];
getCellText : function(k, col) {
if (!baseArray[k])
return "";
var value = baseArray[k][col];
var strvalue;
switch (col) {
case "lockCol":
strvalue = gLockStrs[value];
break;
case "typeCol":
strvalue = gTypeStrs[value];
break;
default:
// already a str.
strvalue = value;
break;
}
return strvalue;
},
getRowProperties : function(index, prop) {},
getCellProperties : function(index, col, prop) {},
getCellProperties : function(index, col, prop) {
prop.AppendElement(gLockAtoms[baseArray[index]["lockCol"]]);
},
getColumnProperties : function(col, elt, prop) {},
outlinerbox : null,
selection : null,
@ -54,17 +95,18 @@ var view = ({
performAction: function(action) {},
performActionOnRow: function(action, row) {},
performActionOnCell: function(action, row, colID) {},
isSeparator: function(index) {return false}
});
function onConfigLoad()
{
document.title = "about:config";
var prefCount = {value:0};
var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
var prefBranch = prefService.getBranch(null);
var prefArray = prefBranch.getChildList("" , prefCount);
const nsIPrefBranch = Components.interfaces.nsIPrefBranch;
var prefName, prefType, prefTypeName, prefValue, prefIndex, prefLockState;
var prefName, prefType, prefValue, prefIndex, prefLockState;
var i = 0;
var j = 0; // This is used to avoid counting the "capability" preferences
@ -82,42 +124,44 @@ function onConfigLoad()
k = (i - j); // avoid numbering "capability" prefs
prefIndex = k + 1;
prefLockState = "default";
if(prefBranch.prefIsLocked(prefArray[i])) // 0 = false
prefLockState = "locked";
else if(prefBranch.prefHasUserValue(prefArray[i])) // 0 = false
prefLockState = "user set";
if (prefBranch.prefIsLocked(prefArray[i]))
prefLockState = kLocked;
else if(prefBranch.prefHasUserValue(prefArray[i]))
prefLockState = kUserSet;
else
prefLockState = kDefault;
prefType = prefBranch.getPrefType(prefArray[i]);
switch(prefType)
{
case nsIPrefBranch.PREF_STRING:
prefTypeName = "string";
prefValue = prefBranch.getCharPref(prefArray[i]);
prefValue = htmlEscape(prefValue);
break;
const nsIPrefBranch = Components.interfaces.nsIPrefBranch;
switch (prefBranch.getPrefType(prefArray[i])) {
case nsIPrefBranch.PREF_INT:
prefTypeName = "int";
prefValue = prefBranch.getIntPref(prefArray[i]);
prefType = kIntType;
// convert to a string
prefValue = "" + prefBranch.getIntPref(prefArray[i]);
break;
case nsIPrefBranch.PREF_BOOL:
prefTypeName = "bool";
prefValue = prefBranch.getBoolPref(prefArray[i]);
prefType = kBoolType;
// convert to a string
if (prefBranch.getBoolPref(prefArray[i]))
prefValue = "true";
else
prefValue = "false";
break;
case nsIPrefBranch.PREF_STRING:
default:
prefTypeName = "unknown";
prefType = kStrType;
prefValue = htmlEscape(prefBranch.getCharPref(prefArray[i]));
break;
}
arr[k] = {indexCol:prefIndex, prefCol:prefArray[i], lockCol:prefLockState, typeCol:prefTypeName, valueCol:prefValue};
baseArray[k] = {indexCol:prefIndex, prefCol:prefArray[i], lockCol:prefLockState, typeCol:prefType, valueCol:prefValue};
}
view.rowCount = k + 1;
var outliner = document.getElementById("out");
outliner.outlinerBoxObject.view = view;
gOutliner = document.getElementById("configOutliner");
gOutliner.outlinerBoxObject.view = view;
}
function htmlEscape(s)
@ -129,3 +173,90 @@ function htmlEscape(s)
}
function ConfigOnClick(event)
{
// we only care about button 0 (left click) events
if (event.button != 0) return;
var t = event.originalTarget;
if (t.localName == "outlinercol") {
HandleColumnClick(t.id);
}
}
var gSortedColumn = "indexCol";
var gSortAscending = true;
function stringSortFunction(a,b)
{
var value;
if (a<b)
value = 1;
else if (a>b)
value = -1;
else
value = 0;
if (gSortAscending)
return value;
else
return (value * -1);
}
function intSortFunction(a,b)
{
if (gSortAscending)
return (a - b);
else
return (b - a);
}
function indexColSortFunction(x,y)
{
return intSortFunction(x.indexCol, y.indexCol);
}
function prefColSortFunction(x,y)
{
return stringSortFunction(x.prefCol, y.prefCol);
}
function lockColSortFunction(x,y)
{
return stringSortFunction(x.lockCol, y.lockCol);
}
function typeColSortFunction(x,y)
{
return intSortFunction(x.typeCol, y.typeCol);
}
function valueColSortFunction(x,y)
{
return stringSortFunction(x.valueCol, y.valueCol);
}
var gSortFunctions = {indexCol:indexColSortFunction,
prefCol:prefColSortFunction,
lockCol:lockColSortFunction,
typeCol:typeColSortFunction,
valueCol:valueColSortFunction};
function HandleColumnClick(id)
{
if (id == gSortedColumn) {
gSortAscending = !gSortAscending;
baseArray.reverse();
}
else {
baseArray.sort(gSortFunctions[id]);
gSortedColumn = id;
}
gOutliner.outlinerBoxObject.invalidate();
}

View File

@ -20,13 +20,15 @@ The Initial Developer of the Original Code is Netscape
Communications Corporation. Portions created by Netscape are
Copyright (C) 1998-1999 Netscape Communications Corporation. All
Rights Reserved.
Contributors:
Chip Clark <chipc@netscape.com>
Seth Spitzer <sspitzer@netscape.com>
-->
<!DOCTYPE window SYSTEM "chrome://global/locale/config.dtd">
<window id="config"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:web="http://home.netscape.com/WEB-rdf#"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
orient="vertical"
width="750"
@ -35,24 +37,28 @@ Rights Reserved.
<script src="chrome://global/content/config.js"/>
<outliner id="out" flex="1" >
<outlinercol id="indexCol" label="&idxColumn.label;" flex="1"/>
<outliner id="configOutliner" flex="1" onclick="ConfigOnClick(event);">
<outlinercol id="indexCol" label="&idxColumn.label;" flex="1"
class="sortDirectionIndicator"
persist="hidden width sortActive sortDirection"/>
<splitter class="tree-splitter" />
<outlinercol id="prefCol" label="&prefColumn.label;" flex="7"/>
<outlinercol id="prefCol" label="&prefColumn.label;" flex="7"
class="sortDirectionIndicator"
persist="hidden width sortActive sortDirection"/>
<splitter class="tree-splitter" />
<outlinercol id="lockCol" label="&lockColumn.label;" flex="1"/>
<outlinercol id="lockCol" label="&lockColumn.label;" flex="1"
class="sortDirectionIndicator"
persist="hidden width sortActive sortDirection"/>
<splitter class="tree-splitter" />
<outlinercol id="typeCol" label="&typeColumn.label;" flex="1"/>
<outlinercol id="typeCol" label="&typeColumn.label;" flex="1"
class="sortDirectionIndicator"
persist="hidden width sortActive sortDirection"/>
<splitter class="tree-splitter" />
<outlinercol id="valueCol" label="&valueColumn.label;" flex="10"/>
<outlinercol id="valueCol" label="&valueColumn.label;" flex="10"
class="sortDirectionIndicator"
persist="hidden width sortActive sortDirection"/>
<outlinerbody id="configOutlinerBody" flex="1" />
</outliner>
</window>