2012-06-25 16:11:16 -07:00
|
|
|
// -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-21 16:52:24 -07:00
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsIPrefLocalizedString = Components.interfaces.nsIPrefLocalizedString;
|
|
|
|
const nsISupportsString = Components.interfaces.nsISupportsString;
|
|
|
|
const nsIPrefBranch = Components.interfaces.nsIPrefBranch;
|
|
|
|
const nsIClipboardHelper = Components.interfaces.nsIClipboardHelper;
|
|
|
|
const nsIAtomService = Components.interfaces.nsIAtomService;
|
|
|
|
|
|
|
|
const nsSupportsString_CONTRACTID = "@mozilla.org/supports-string;1";
|
|
|
|
const nsPrompt_CONTRACTID = "@mozilla.org/embedcomp/prompt-service;1";
|
|
|
|
const nsPrefService_CONTRACTID = "@mozilla.org/preferences-service;1";
|
|
|
|
const nsClipboardHelper_CONTRACTID = "@mozilla.org/widget/clipboardhelper;1";
|
|
|
|
const nsAtomService_CONTRACTID = "@mozilla.org/atom-service;1";
|
|
|
|
|
2012-03-29 02:48:40 -07:00
|
|
|
const gPrefBranch = Services.prefs;
|
2007-03-22 10:30:00 -07:00
|
|
|
const gClipboardHelper = Components.classes[nsClipboardHelper_CONTRACTID].getService(nsIClipboardHelper);
|
|
|
|
const gAtomService = Components.classes[nsAtomService_CONTRACTID].getService(nsIAtomService);
|
|
|
|
|
|
|
|
var gLockAtoms = [gAtomService.getAtom("default"), gAtomService.getAtom("user"), gAtomService.getAtom("locked")];
|
|
|
|
// we get these from a string bundle
|
|
|
|
var gLockStrs = [];
|
|
|
|
var gTypeStrs = [];
|
|
|
|
|
|
|
|
const PREF_IS_DEFAULT_VALUE = 0;
|
|
|
|
const PREF_IS_USER_SET = 1;
|
|
|
|
const PREF_IS_LOCKED = 2;
|
|
|
|
|
|
|
|
var gPrefHash = {};
|
|
|
|
var gPrefArray = [];
|
|
|
|
var gPrefView = gPrefArray; // share the JS array
|
|
|
|
var gSortedColumn = "prefCol";
|
|
|
|
var gSortFunction = null;
|
|
|
|
var gSortDirection = 1; // 1 is ascending; -1 is descending
|
|
|
|
var gConfigBundle = null;
|
2011-06-06 14:53:05 -07:00
|
|
|
var gFilter = null;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
var view = {
|
|
|
|
get rowCount() { return gPrefView.length; },
|
|
|
|
getCellText : function(index, col) {
|
|
|
|
if (!(index in gPrefView))
|
|
|
|
return "";
|
|
|
|
|
|
|
|
var value = gPrefView[index][col.id];
|
|
|
|
|
|
|
|
switch (col.id) {
|
|
|
|
case "lockCol":
|
|
|
|
return gLockStrs[value];
|
|
|
|
case "typeCol":
|
|
|
|
return gTypeStrs[value];
|
|
|
|
default:
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
getRowProperties : function(index, prop) {},
|
|
|
|
getCellProperties : function(index, col, prop) {
|
|
|
|
if (index in gPrefView)
|
|
|
|
prop.AppendElement(gLockAtoms[gPrefView[index].lockCol]);
|
|
|
|
},
|
|
|
|
getColumnProperties : function(col, prop) {},
|
|
|
|
treebox : null,
|
|
|
|
selection : null,
|
|
|
|
isContainer : function(index) { return false; },
|
|
|
|
isContainerOpen : function(index) { return false; },
|
|
|
|
isContainerEmpty : function(index) { return false; },
|
|
|
|
isSorted : function() { return true; },
|
|
|
|
canDrop : function(index, orientation) { return false; },
|
|
|
|
drop : function(row, orientation) {},
|
|
|
|
setTree : function(out) { this.treebox = out; },
|
|
|
|
getParentIndex: function(rowIndex) { return -1; },
|
|
|
|
hasNextSibling: function(rowIndex, afterIndex) { return false; },
|
|
|
|
getLevel: function(index) { return 1; },
|
|
|
|
getImageSrc: function(row, col) { return ""; },
|
|
|
|
toggleOpenState : function(index) {},
|
|
|
|
cycleHeader: function(col) {
|
|
|
|
var index = this.selection.currentIndex;
|
2011-06-06 14:53:05 -07:00
|
|
|
if (col.id == gSortedColumn) {
|
2007-03-22 10:30:00 -07:00
|
|
|
gSortDirection = -gSortDirection;
|
|
|
|
gPrefArray.reverse();
|
|
|
|
if (gPrefView != gPrefArray)
|
|
|
|
gPrefView.reverse();
|
|
|
|
if (index >= 0)
|
|
|
|
index = gPrefView.length - index - 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var pref = null;
|
2011-06-06 14:53:05 -07:00
|
|
|
if (index >= 0)
|
|
|
|
pref = gPrefView[index];
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var old = document.getElementById(gSortedColumn);
|
|
|
|
old.setAttribute("sortDirection", "");
|
|
|
|
gPrefArray.sort(gSortFunction = gSortFunctions[col.id]);
|
2011-06-06 14:53:05 -07:00
|
|
|
if (gPrefView != gPrefArray)
|
|
|
|
gPrefView.sort(gSortFunction);
|
2007-03-22 10:30:00 -07:00
|
|
|
gSortedColumn = col.id;
|
|
|
|
if (pref)
|
2011-06-06 14:53:05 -07:00
|
|
|
index = getViewIndexOfPref(pref);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
col.element.setAttribute("sortDirection", gSortDirection > 0 ? "ascending" : "descending");
|
|
|
|
this.treebox.invalidate();
|
|
|
|
if (index >= 0) {
|
|
|
|
this.selection.select(index);
|
|
|
|
this.treebox.ensureRowIsVisible(index);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
selectionChanged : function() {},
|
|
|
|
cycleCell: function(row, col) {},
|
|
|
|
isEditable: function(row, col) {return false; },
|
|
|
|
isSelectable: function(row, col) {return false; },
|
|
|
|
setCellValue: function(row, col, value) {},
|
|
|
|
setCellText: function(row, col, value) {},
|
|
|
|
performAction: function(action) {},
|
|
|
|
performActionOnRow: function(action, row) {},
|
|
|
|
performActionOnCell: function(action, row, col) {},
|
|
|
|
isSeparator: function(index) {return false; }
|
|
|
|
};
|
|
|
|
|
|
|
|
// find the index in gPrefView of a pref object
|
|
|
|
// or -1 if it does not exist in the filtered view
|
|
|
|
function getViewIndexOfPref(pref)
|
|
|
|
{
|
|
|
|
var low = -1, high = gPrefView.length;
|
|
|
|
var index = (low + high) >> 1;
|
|
|
|
while (index > low) {
|
|
|
|
var mid = gPrefView[index];
|
|
|
|
if (mid == pref)
|
|
|
|
return index;
|
|
|
|
if (gSortFunction(mid, pref) < 0)
|
|
|
|
low = index;
|
|
|
|
else
|
|
|
|
high = index;
|
|
|
|
index = (low + high) >> 1;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-06-06 14:53:05 -07:00
|
|
|
// find the index in gPrefView where a pref object belongs
|
|
|
|
function getNearestViewIndexOfPref(pref)
|
|
|
|
{
|
|
|
|
var low = -1, high = gPrefView.length;
|
|
|
|
var index = (low + high) >> 1;
|
|
|
|
while (index > low) {
|
|
|
|
if (gSortFunction(gPrefView[index], pref) < 0)
|
|
|
|
low = index;
|
|
|
|
else
|
|
|
|
high = index;
|
|
|
|
index = (low + high) >> 1;
|
|
|
|
}
|
|
|
|
return high;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// find the index in gPrefArray of a pref object
|
|
|
|
function getIndexOfPref(pref)
|
|
|
|
{
|
2011-06-06 14:53:05 -07:00
|
|
|
var low = -1, high = gPrefArray.length;
|
2007-03-22 10:30:00 -07:00
|
|
|
var index = (low + high) >> 1;
|
|
|
|
while (index > low) {
|
|
|
|
var mid = gPrefArray[index];
|
|
|
|
if (mid == pref)
|
|
|
|
return index;
|
|
|
|
if (gSortFunction(mid, pref) < 0)
|
|
|
|
low = index;
|
|
|
|
else
|
|
|
|
high = index;
|
|
|
|
index = (low + high) >> 1;
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getNearestIndexOfPref(pref)
|
|
|
|
{
|
2011-06-06 14:53:05 -07:00
|
|
|
var low = -1, high = gPrefArray.length;
|
2007-03-22 10:30:00 -07:00
|
|
|
var index = (low + high) >> 1;
|
|
|
|
while (index > low) {
|
|
|
|
if (gSortFunction(gPrefArray[index], pref) < 0)
|
|
|
|
low = index;
|
|
|
|
else
|
|
|
|
high = index;
|
|
|
|
index = (low + high) >> 1;
|
|
|
|
}
|
|
|
|
return high;
|
|
|
|
}
|
|
|
|
|
|
|
|
var gPrefListener =
|
|
|
|
{
|
|
|
|
observe: function(subject, topic, prefName)
|
|
|
|
{
|
|
|
|
if (topic != "nsPref:changed")
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (/^capability\./.test(prefName)) // avoid displaying "private" preferences
|
|
|
|
return;
|
|
|
|
|
2011-06-16 03:50:56 -07:00
|
|
|
var arrayIndex = gPrefArray.length;
|
|
|
|
var viewIndex = arrayIndex;
|
2011-06-06 14:53:05 -07:00
|
|
|
var selectedIndex = view.selection.currentIndex;
|
|
|
|
var pref;
|
|
|
|
var updateView = false;
|
|
|
|
var updateArray = false;
|
|
|
|
var addedRow = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (prefName in gPrefHash) {
|
2011-06-06 14:53:05 -07:00
|
|
|
pref = gPrefHash[prefName];
|
|
|
|
viewIndex = getViewIndexOfPref(pref);
|
|
|
|
arrayIndex = getIndexOfPref(pref);
|
|
|
|
fetchPref(prefName, arrayIndex);
|
|
|
|
// fetchPref replaces the existing pref object
|
|
|
|
pref = gPrefHash[prefName];
|
|
|
|
if (viewIndex >= 0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Might need to update the filtered view
|
2011-06-06 14:53:05 -07:00
|
|
|
gPrefView[viewIndex] = gPrefHash[prefName];
|
|
|
|
view.treebox.invalidateRow(viewIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-06-06 14:53:05 -07:00
|
|
|
if (gSortedColumn == "lockCol" || gSortedColumn == "valueCol") {
|
|
|
|
updateArray = true;
|
|
|
|
gPrefArray.splice(arrayIndex, 1);
|
|
|
|
if (gFilter && gFilter.test(pref.prefCol + ";" + pref.valueCol)) {
|
|
|
|
updateView = true;
|
|
|
|
gPrefView.splice(viewIndex, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fetchPref(prefName, arrayIndex);
|
|
|
|
pref = gPrefArray.pop();
|
|
|
|
updateArray = true;
|
|
|
|
addedRow = true;
|
|
|
|
if (gFilter && gFilter.test(pref.prefCol + ";" + pref.valueCol)) {
|
|
|
|
updateView = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (updateArray) {
|
|
|
|
// Reinsert in the data array
|
|
|
|
var newIndex = getNearestIndexOfPref(pref);
|
|
|
|
gPrefArray.splice(newIndex, 0, pref);
|
|
|
|
|
|
|
|
if (updateView) {
|
|
|
|
// View is filtered, reinsert in the view separately
|
|
|
|
newIndex = getNearestViewIndexOfPref(pref);
|
|
|
|
gPrefView.splice(newIndex, 0, pref);
|
|
|
|
}
|
|
|
|
else if (gFilter) {
|
|
|
|
// View is filtered, but nothing to update
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addedRow)
|
|
|
|
view.treebox.rowCountChanged(newIndex, 1);
|
|
|
|
|
|
|
|
// Invalidate the changed range in the view
|
|
|
|
var low = Math.min(viewIndex, newIndex);
|
|
|
|
var high = Math.max(viewIndex, newIndex);
|
|
|
|
view.treebox.invalidateRange(low, high);
|
|
|
|
|
|
|
|
if (selectedIndex == viewIndex) {
|
|
|
|
selectedIndex = newIndex;
|
|
|
|
}
|
|
|
|
else if (selectedIndex >= low && selectedIndex <= high) {
|
|
|
|
selectedIndex += (newIndex > viewIndex) ? -1 : 1;
|
|
|
|
}
|
|
|
|
if (selectedIndex >= 0) {
|
|
|
|
view.selection.select(selectedIndex);
|
|
|
|
if (selectedIndex == newIndex)
|
|
|
|
view.treebox.ensureRowIsVisible(selectedIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function prefObject(prefName, prefIndex)
|
|
|
|
{
|
|
|
|
this.prefCol = prefName;
|
|
|
|
}
|
|
|
|
|
|
|
|
prefObject.prototype =
|
|
|
|
{
|
|
|
|
lockCol: PREF_IS_DEFAULT_VALUE,
|
|
|
|
typeCol: nsIPrefBranch.PREF_STRING,
|
|
|
|
valueCol: ""
|
|
|
|
};
|
|
|
|
|
|
|
|
function fetchPref(prefName, prefIndex)
|
|
|
|
{
|
|
|
|
var pref = new prefObject(prefName);
|
|
|
|
|
|
|
|
gPrefHash[prefName] = pref;
|
|
|
|
gPrefArray[prefIndex] = pref;
|
|
|
|
|
|
|
|
if (gPrefBranch.prefIsLocked(prefName))
|
|
|
|
pref.lockCol = PREF_IS_LOCKED;
|
|
|
|
else if (gPrefBranch.prefHasUserValue(prefName))
|
|
|
|
pref.lockCol = PREF_IS_USER_SET;
|
|
|
|
|
|
|
|
try {
|
|
|
|
switch (gPrefBranch.getPrefType(prefName)) {
|
|
|
|
case gPrefBranch.PREF_BOOL:
|
|
|
|
pref.typeCol = gPrefBranch.PREF_BOOL;
|
|
|
|
// convert to a string
|
|
|
|
pref.valueCol = gPrefBranch.getBoolPref(prefName).toString();
|
|
|
|
break;
|
|
|
|
case gPrefBranch.PREF_INT:
|
|
|
|
pref.typeCol = gPrefBranch.PREF_INT;
|
|
|
|
// convert to a string
|
|
|
|
pref.valueCol = gPrefBranch.getIntPref(prefName).toString();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case gPrefBranch.PREF_STRING:
|
|
|
|
pref.valueCol = gPrefBranch.getComplexValue(prefName, nsISupportsString).data;
|
|
|
|
// Try in case it's a localized string (will throw an exception if not)
|
|
|
|
if (pref.lockCol == PREF_IS_DEFAULT_VALUE &&
|
|
|
|
/^chrome:\/\/.+\/locale\/.+\.properties/.test(pref.valueCol))
|
|
|
|
pref.valueCol = gPrefBranch.getComplexValue(prefName, nsIPrefLocalizedString).data;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
// Also catch obscure cases in which you can't tell in advance
|
|
|
|
// that the pref exists but has no user or default value...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onConfigLoad()
|
|
|
|
{
|
|
|
|
// Load strings
|
|
|
|
gConfigBundle = document.getElementById("configBundle");
|
|
|
|
|
|
|
|
gLockStrs[PREF_IS_DEFAULT_VALUE] = gConfigBundle.getString("default");
|
|
|
|
gLockStrs[PREF_IS_USER_SET] = gConfigBundle.getString("user");
|
|
|
|
gLockStrs[PREF_IS_LOCKED] = gConfigBundle.getString("locked");
|
|
|
|
|
|
|
|
gTypeStrs[nsIPrefBranch.PREF_STRING] = gConfigBundle.getString("string");
|
|
|
|
gTypeStrs[nsIPrefBranch.PREF_INT] = gConfigBundle.getString("int");
|
|
|
|
gTypeStrs[nsIPrefBranch.PREF_BOOL] = gConfigBundle.getString("bool");
|
|
|
|
|
|
|
|
var showWarning = gPrefBranch.getBoolPref("general.warnOnAboutConfig");
|
|
|
|
|
|
|
|
if (showWarning)
|
|
|
|
document.getElementById("warningButton").focus();
|
|
|
|
else
|
|
|
|
ShowPrefs();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unhide the warning message
|
|
|
|
function ShowPrefs()
|
|
|
|
{
|
2009-10-26 13:02:06 -07:00
|
|
|
var prefArray = gPrefBranch.getChildList("");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-10-26 13:02:06 -07:00
|
|
|
prefArray.forEach(function (prefName) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (/^capability\./.test(prefName)) // avoid displaying "private" preferences
|
2009-10-26 13:02:06 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
fetchPref(prefName, gPrefArray.length);
|
2009-10-26 13:02:06 -07:00
|
|
|
});
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
var descending = document.getElementsByAttribute("sortDirection", "descending");
|
|
|
|
if (descending.item(0)) {
|
|
|
|
gSortedColumn = descending[0].id;
|
|
|
|
gSortDirection = -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var ascending = document.getElementsByAttribute("sortDirection", "ascending");
|
|
|
|
if (ascending.item(0))
|
|
|
|
gSortedColumn = ascending[0].id;
|
|
|
|
else
|
|
|
|
document.getElementById(gSortedColumn).setAttribute("sortDirection", "ascending");
|
|
|
|
}
|
|
|
|
gSortFunction = gSortFunctions[gSortedColumn];
|
|
|
|
gPrefArray.sort(gSortFunction);
|
|
|
|
|
|
|
|
gPrefBranch.addObserver("", gPrefListener, false);
|
|
|
|
|
|
|
|
var configTree = document.getElementById("configTree");
|
|
|
|
configTree.view = view;
|
|
|
|
configTree.controllers.insertControllerAt(0, configController);
|
|
|
|
|
|
|
|
document.getElementById("configDeck").setAttribute("selectedIndex", 1);
|
2008-10-10 18:10:48 -07:00
|
|
|
document.getElementById("configTreeKeyset").removeAttribute("disabled");
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!document.getElementById("showWarningNextTime").checked)
|
|
|
|
gPrefBranch.setBoolPref("general.warnOnAboutConfig", false);
|
|
|
|
|
2011-08-04 00:05:29 -07:00
|
|
|
// Process about:config?filter=<string>
|
2008-07-12 02:03:30 -07:00
|
|
|
var textbox = document.getElementById("textbox");
|
2011-09-22 22:03:50 -07:00
|
|
|
// About URIs don't support query params, so do this manually
|
|
|
|
var loc = document.location.href;
|
|
|
|
var matches = /[?&]filter\=([^&]+)/i.exec(loc);
|
2011-08-04 00:05:29 -07:00
|
|
|
if (matches)
|
|
|
|
textbox.value = decodeURIComponent(matches[1]);
|
|
|
|
|
|
|
|
// Even if we did not set the filter string via the URL query,
|
|
|
|
// textbox might have been set via some other mechanism
|
2008-07-12 02:03:30 -07:00
|
|
|
if (textbox.value)
|
|
|
|
FilterPrefs();
|
|
|
|
textbox.focus();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function onConfigUnload()
|
|
|
|
{
|
|
|
|
if (document.getElementById("configDeck").getAttribute("selectedIndex") == 1) {
|
|
|
|
gPrefBranch.removeObserver("", gPrefListener);
|
|
|
|
var configTree = document.getElementById("configTree");
|
|
|
|
configTree.view = null;
|
|
|
|
configTree.controllers.removeController(configController);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function FilterPrefs()
|
|
|
|
{
|
2012-05-04 19:46:35 -07:00
|
|
|
if (document.getElementById("configDeck").getAttribute("selectedIndex") != 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var substring = document.getElementById("textbox").value;
|
|
|
|
// Check for "/regex/[i]"
|
|
|
|
if (substring.charAt(0) == '/') {
|
|
|
|
var r = substring.match(/^\/(.*)\/(i?)$/);
|
|
|
|
try {
|
2011-06-06 14:53:05 -07:00
|
|
|
gFilter = RegExp(r[1], r[2]);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
return; // Do nothing on incomplete or bad RegExp
|
|
|
|
}
|
|
|
|
}
|
2011-06-06 14:53:05 -07:00
|
|
|
else if (substring) {
|
|
|
|
gFilter = RegExp(substring.replace(/([^* \w])/g, "\\$1")
|
|
|
|
.replace(/^\*+/, "").replace(/\*+/g, ".*"), "i");
|
|
|
|
} else {
|
|
|
|
gFilter = null;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-12-21 10:37:20 -08:00
|
|
|
var prefCol = (view.selection && view.selection.currentIndex < 0) ?
|
|
|
|
null : gPrefView[view.selection.currentIndex].prefCol;
|
2007-03-22 10:30:00 -07:00
|
|
|
var oldlen = gPrefView.length;
|
|
|
|
gPrefView = gPrefArray;
|
2011-06-06 14:53:05 -07:00
|
|
|
if (gFilter) {
|
2007-03-22 10:30:00 -07:00
|
|
|
gPrefView = [];
|
|
|
|
for (var i = 0; i < gPrefArray.length; ++i)
|
2011-06-06 14:53:05 -07:00
|
|
|
if (gFilter.test(gPrefArray[i].prefCol + ";" + gPrefArray[i].valueCol))
|
2007-03-22 10:30:00 -07:00
|
|
|
gPrefView.push(gPrefArray[i]);
|
|
|
|
}
|
|
|
|
view.treebox.invalidate();
|
|
|
|
view.treebox.rowCountChanged(oldlen, gPrefView.length - oldlen);
|
|
|
|
gotoPref(prefCol);
|
|
|
|
}
|
|
|
|
|
|
|
|
function prefColSortFunction(x, y)
|
|
|
|
{
|
|
|
|
if (x.prefCol > y.prefCol)
|
|
|
|
return gSortDirection;
|
|
|
|
if (x.prefCol < y.prefCol)
|
|
|
|
return -gSortDirection;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function lockColSortFunction(x, y)
|
|
|
|
{
|
|
|
|
if (x.lockCol != y.lockCol)
|
|
|
|
return gSortDirection * (y.lockCol - x.lockCol);
|
|
|
|
return prefColSortFunction(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
function typeColSortFunction(x, y)
|
|
|
|
{
|
|
|
|
if (x.typeCol != y.typeCol)
|
|
|
|
return gSortDirection * (y.typeCol - x.typeCol);
|
|
|
|
return prefColSortFunction(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
function valueColSortFunction(x, y)
|
|
|
|
{
|
|
|
|
if (x.valueCol > y.valueCol)
|
|
|
|
return gSortDirection;
|
|
|
|
if (x.valueCol < y.valueCol)
|
|
|
|
return -gSortDirection;
|
|
|
|
return prefColSortFunction(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
const gSortFunctions =
|
|
|
|
{
|
|
|
|
prefCol: prefColSortFunction,
|
|
|
|
lockCol: lockColSortFunction,
|
|
|
|
typeCol: typeColSortFunction,
|
|
|
|
valueCol: valueColSortFunction
|
|
|
|
};
|
|
|
|
|
|
|
|
const configController = {
|
|
|
|
supportsCommand: function supportsCommand(command) {
|
|
|
|
return command == "cmd_copy";
|
|
|
|
},
|
|
|
|
isCommandEnabled: function isCommandEnabled(command) {
|
|
|
|
return view.selection && view.selection.currentIndex >= 0;
|
|
|
|
},
|
|
|
|
doCommand: function doCommand(command) {
|
|
|
|
copyPref();
|
|
|
|
},
|
|
|
|
onEvent: function onEvent(event) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateContextMenu()
|
|
|
|
{
|
|
|
|
var lockCol = PREF_IS_LOCKED;
|
|
|
|
var typeCol = nsIPrefBranch.PREF_STRING;
|
|
|
|
var valueCol = "";
|
|
|
|
var copyDisabled = true;
|
|
|
|
var prefSelected = view.selection.currentIndex >= 0;
|
|
|
|
|
|
|
|
if (prefSelected) {
|
|
|
|
var prefRow = gPrefView[view.selection.currentIndex];
|
|
|
|
lockCol = prefRow.lockCol;
|
|
|
|
typeCol = prefRow.typeCol;
|
|
|
|
valueCol = prefRow.valueCol;
|
|
|
|
copyDisabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var copyPref = document.getElementById("copyPref");
|
|
|
|
copyPref.setAttribute("disabled", copyDisabled);
|
|
|
|
|
|
|
|
var copyName = document.getElementById("copyName");
|
|
|
|
copyName.setAttribute("disabled", copyDisabled);
|
|
|
|
|
|
|
|
var copyValue = document.getElementById("copyValue");
|
|
|
|
copyValue.setAttribute("disabled", copyDisabled);
|
|
|
|
|
|
|
|
var resetSelected = document.getElementById("resetSelected");
|
|
|
|
resetSelected.setAttribute("disabled", lockCol != PREF_IS_USER_SET);
|
|
|
|
|
|
|
|
var canToggle = typeCol == nsIPrefBranch.PREF_BOOL && valueCol != "";
|
|
|
|
// indicates that a pref is locked or no pref is selected at all
|
|
|
|
var isLocked = lockCol == PREF_IS_LOCKED;
|
|
|
|
|
|
|
|
var modifySelected = document.getElementById("modifySelected");
|
|
|
|
modifySelected.setAttribute("disabled", isLocked);
|
|
|
|
modifySelected.hidden = canToggle;
|
|
|
|
|
|
|
|
var toggleSelected = document.getElementById("toggleSelected");
|
|
|
|
toggleSelected.setAttribute("disabled", isLocked);
|
|
|
|
toggleSelected.hidden = !canToggle;
|
|
|
|
}
|
|
|
|
|
|
|
|
function copyPref()
|
|
|
|
{
|
|
|
|
var pref = gPrefView[view.selection.currentIndex];
|
2012-04-16 19:14:01 -07:00
|
|
|
gClipboardHelper.copyString(pref.prefCol + ';' + pref.valueCol, document);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function copyName()
|
|
|
|
{
|
2012-04-16 19:14:01 -07:00
|
|
|
gClipboardHelper.copyString(gPrefView[view.selection.currentIndex].prefCol, document);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function copyValue()
|
|
|
|
{
|
2012-04-16 19:14:01 -07:00
|
|
|
gClipboardHelper.copyString(gPrefView[view.selection.currentIndex].valueCol, document);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function ModifySelected()
|
|
|
|
{
|
|
|
|
if (view.selection.currentIndex >= 0)
|
|
|
|
ModifyPref(gPrefView[view.selection.currentIndex]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function ResetSelected()
|
|
|
|
{
|
|
|
|
var entry = gPrefView[view.selection.currentIndex];
|
|
|
|
gPrefBranch.clearUserPref(entry.prefCol);
|
|
|
|
}
|
|
|
|
|
|
|
|
function NewPref(type)
|
|
|
|
{
|
|
|
|
var result = { value: "" };
|
|
|
|
var dummy = { value: 0 };
|
2012-03-21 16:52:24 -07:00
|
|
|
if (Services.prompt.prompt(window,
|
|
|
|
gConfigBundle.getFormattedString("new_title",
|
|
|
|
[gTypeStrs[type]]),
|
|
|
|
gConfigBundle.getString("new_prompt"),
|
|
|
|
result,
|
|
|
|
null,
|
|
|
|
dummy)) {
|
2011-09-20 09:20:51 -07:00
|
|
|
result.value = result.value.trim();
|
|
|
|
if (!result.value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var pref;
|
|
|
|
if (result.value in gPrefHash)
|
|
|
|
pref = gPrefHash[result.value];
|
|
|
|
else
|
|
|
|
pref = { prefCol: result.value, lockCol: PREF_IS_DEFAULT_VALUE, typeCol: type, valueCol: "" };
|
|
|
|
if (ModifyPref(pref))
|
|
|
|
setTimeout(gotoPref, 0, result.value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function gotoPref(pref)
|
|
|
|
{
|
|
|
|
// make sure the pref exists and is displayed in the current view
|
|
|
|
var index = pref in gPrefHash ? getViewIndexOfPref(gPrefHash[pref]) : -1;
|
|
|
|
if (index >= 0) {
|
|
|
|
view.selection.select(index);
|
|
|
|
view.treebox.ensureRowIsVisible(index);
|
|
|
|
} else {
|
|
|
|
view.selection.clearSelection();
|
|
|
|
view.selection.currentIndex = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function ModifyPref(entry)
|
|
|
|
{
|
|
|
|
if (entry.lockCol == PREF_IS_LOCKED)
|
|
|
|
return false;
|
|
|
|
var title = gConfigBundle.getFormattedString("modify_title", [gTypeStrs[entry.typeCol]]);
|
|
|
|
if (entry.typeCol == nsIPrefBranch.PREF_BOOL) {
|
|
|
|
var check = { value: entry.valueCol == "false" };
|
2012-03-21 16:52:24 -07:00
|
|
|
if (!entry.valueCol && !Services.prompt.select(window, title, entry.prefCol, 2, [false, true], check))
|
2007-03-22 10:30:00 -07:00
|
|
|
return false;
|
|
|
|
gPrefBranch.setBoolPref(entry.prefCol, check.value);
|
2010-06-15 19:31:33 -07:00
|
|
|
} else {
|
2007-03-22 10:30:00 -07:00
|
|
|
var result = { value: entry.valueCol };
|
|
|
|
var dummy = { value: 0 };
|
2012-03-21 16:52:24 -07:00
|
|
|
if (!Services.prompt.prompt(window, title, entry.prefCol, result, null, dummy))
|
2007-03-22 10:30:00 -07:00
|
|
|
return false;
|
2010-06-15 19:31:33 -07:00
|
|
|
if (entry.typeCol == nsIPrefBranch.PREF_INT) {
|
|
|
|
// | 0 converts to integer or 0; - 0 to float or NaN.
|
|
|
|
// Thus, this check should catch all cases.
|
|
|
|
var val = result.value | 0;
|
|
|
|
if (val != result.value - 0) {
|
|
|
|
var err_title = gConfigBundle.getString("nan_title");
|
|
|
|
var err_text = gConfigBundle.getString("nan_text");
|
2012-03-21 16:52:24 -07:00
|
|
|
Services.prompt.alert(window, err_title, err_text);
|
2010-06-15 19:31:33 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
gPrefBranch.setIntPref(entry.prefCol, val);
|
|
|
|
} else {
|
|
|
|
var supportsString = Components.classes[nsSupportsString_CONTRACTID].createInstance(nsISupportsString);
|
|
|
|
supportsString.data = result.value;
|
|
|
|
gPrefBranch.setComplexValue(entry.prefCol, nsISupportsString, supportsString);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-21 16:52:24 -07:00
|
|
|
Services.prefs.savePrefFile(null);
|
2007-03-22 10:30:00 -07:00
|
|
|
return true;
|
|
|
|
}
|