Bug 191410 Make it easier to change boolean preferences r=caillon sr=sspitzer

This commit is contained in:
neil%parkwaycc.co.uk 2004-07-14 21:48:02 +00:00
Родитель b59401c27a
Коммит c0bb9b1745
3 изменённых файлов: 59 добавлений и 36 удалений

Просмотреть файл

@ -432,15 +432,39 @@ const gSortFunctions =
valueCol: valueColSortFunction
};
function updateContextMenu(popup) {
if (view.selection.currentIndex < 0)
return false;
var pref = gPrefView[view.selection.currentIndex];
var reset = popup.lastChild;
reset.setAttribute("disabled", pref.lockCol != PREF_IS_USER_SET);
var modify = reset.previousSibling;
modify.setAttribute("disabled", pref.lockCol == PREF_IS_LOCKED);
return true;
function updateContextMenu()
{
var lockCol = PREF_IS_LOCKED;
var typeCol = nsIPrefBranch.PREF_STRING;
var valueCol = "";
var copyDisabled = true;
if (view.selection.currentIndex >= 0) {
var prefRow = gPrefView[view.selection.currentIndex];
lockCol = prefRow.lockCol;
typeCol = prefRow.typeCol;
valueCol = prefRow.valueCol;
copyDisabled = false;
}
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 != "";
var modifySelected = document.getElementById("modifySelected");
modifySelected.setAttribute("disabled", lockCol == PREF_IS_LOCKED);
modifySelected.hidden = canToggle;
var toggleSelected = document.getElementById("toggleSelected");
toggleSelected.setAttribute("disabled", lockCol == PREF_IS_LOCKED);
toggleSelected.hidden = !canToggle;
}
function copyName()
@ -455,7 +479,8 @@ function copyValue()
function ModifySelected()
{
ModifyPref(gPrefView[view.selection.currentIndex]);
if (view.selection.currentIndex >= 0)
ModifyPref(gPrefView[view.selection.currentIndex]);
}
function ResetSelected()
@ -468,7 +493,6 @@ function NewPref(type)
{
var result = { value: "" };
var dummy = { value: 0 };
// XXX get these from a string bundle
if (gPromptService.prompt(window,
gConfigBundle.getFormattedString("new_title", [gTypeStrs[type]]),
gConfigBundle.getString("new_prompt"),
@ -485,7 +509,8 @@ function NewPref(type)
}
}
function gotoPref(pref) {
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) {
@ -501,29 +526,24 @@ function ModifyPref(entry)
{
if (entry.lockCol == PREF_IS_LOCKED)
return false;
var result = { value: entry.valueCol };
var dummy = { value: 0 };
// XXX get this from a string bundle
if (!gPromptService.prompt(window,
gConfigBundle.getFormattedString("modify_title", [gTypeStrs[entry.typeCol]]),
entry.prefCol,
result,
null,
dummy))
return false;
switch (entry.typeCol) {
case nsIPrefBranch.PREF_BOOL:
gPrefBranch.setBoolPref(entry.prefCol, eval(result.value));
break;
case nsIPrefBranch.PREF_INT:
var title = gConfigBundle.getFormattedString("modify_title", [gTypeStrs[entry.typeCol]]);
if (entry.typeCol == nsIPrefBranch.PREF_BOOL) {
var check = { value: entry.valueCol == "false" };
if (!entry.valueCol && !gPromptService.select(window, title, entry.prefCol, 2, [false, true], check))
return false;
gPrefBranch.setBoolPref(entry.prefCol, check.value);
} else {
var result = { value: entry.valueCol };
var dummy = { value: 0 };
if (!gPromptService.prompt(window, title, entry.prefCol, result, null, dummy))
return false;
if (entry.typeCol == nsIPrefBranch.PREF_INT) {
gPrefBranch.setIntPref(entry.prefCol, eval(result.value));
break;
default:
case nsIPrefBranch.PREF_STRING:
} else {
var supportsString = Components.classes[nsSupportsString_CONTRACTID].createInstance(nsISupportsString);
supportsString.data = result.value;
gPrefBranch.setComplexValue(entry.prefCol, nsISupportsString, supportsString);
break;
}
}
return true;
}

Просмотреть файл

@ -55,9 +55,9 @@
<stringbundle id="configBundle" src="chrome://global/locale/config.properties"/>
<popup id="configContext" onpopupshowing="return updateContextMenu(this);">
<menuitem label="&copyName.label;" accesskey="&copyName.accesskey;" oncommand="copyName();"/>
<menuitem label="&copyValue.label;" accesskey="&copyValue.accesskey;" oncommand="copyValue();"/>
<popup id="configContext" onpopupshowing="if (event.target == this) updateContextMenu();">
<menuitem id="copyName" label="&copyName.label;" accesskey="&copyName.accesskey;" oncommand="copyName();"/>
<menuitem id="copyValue" label="&copyValue.label;" accesskey="&copyValue.accesskey;" oncommand="copyValue();"/>
<menu label="&new.label;" accesskey="&new.accesskey;">
<menupopup>
<menuitem label="&string.label;" accesskey="&string.accesskey;" oncommand="NewPref(nsIPrefBranch.PREF_STRING);"/>
@ -65,8 +65,9 @@
<menuitem label="&boolean.label;" accesskey="&boolean.accesskey;" oncommand="NewPref(nsIPrefBranch.PREF_BOOL);"/>
</menupopup>
</menu>
<menuitem label="&modify.label;" accesskey="&modify.accesskey;" oncommand="ModifySelected();"/>
<menuitem label="&reset.label;" accesskey="&reset.accesskey;" oncommand="ResetSelected();"/>
<menuitem id="toggleSelected" label="&toggle.label;" accesskey="&toggle.accesskey;" oncommand="ModifySelected();"/>
<menuitem id="modifySelected" label="&modify.label;" accesskey="&modify.accesskey;" oncommand="ModifySelected();"/>
<menuitem id="resetSelected" label="&reset.label;" accesskey="&reset.accesskey;" oncommand="ResetSelected();"/>
</popup>
<keyset>

Просмотреть файл

@ -57,6 +57,8 @@
<!ENTITY copyValue.accesskey "V">
<!ENTITY modify.label "Modify">
<!ENTITY modify.accesskey "M">
<!ENTITY toggle.label "Toggle">
<!ENTITY toggle.accesskey "T">
<!ENTITY reset.label "Reset">
<!ENTITY reset.accesskey "R">
<!ENTITY new.label "New">