Bug 964356 - Expose preferences for editor defaults in options panel. r=mratcliffe

This commit is contained in:
Brian Grinstead 2014-07-18 11:39:00 -04:00
Родитель f16a63df4e
Коммит 2acb35b234
5 изменённых файлов: 212 добавлений и 44 удалений

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

@ -21,11 +21,20 @@
.options-vertical-pane {
margin: 5px;
width: calc(50% - 30px);
min-width: 350px;
width: calc(100%/3 - 30px);
min-width: 260px;
-moz-padding-start: 5px;
}
/* Snap to 50% width once there is not room for 3 columns anymore.
This prevents having 2 columns showing in a row, but taking up
only ~66% of the available space. */
@media (max-width: 900px) {
.options-vertical-pane {
width: calc(100%/2 - 30px);
}
}
.options-vertical-pane > label {
padding: 2px 0;
font-size: 1.4rem;
@ -56,3 +65,11 @@
.hidden-labels-box.visible ~ .hidden-labels-box > label:last-child {
display: none;
}
#devtools-sourceeditor-keybinding-menulist {
min-width: 100px;
}
#devtools-sourceeditor-tabsize-menulist {
min-width: 50px;
}

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

@ -43,30 +43,64 @@ function testOptionsShortcut() {
return deferred.promise;
}
function testOptions() {
function* testOptions() {
let tool = toolbox.getPanel("options");
panelWin = tool.panelWin;
let prefNodes = tool.panelDoc.querySelectorAll("checkbox[data-pref]");
// Store modified pref names so that they can be cleared on error.
for (let node of prefNodes) {
for (let node of tool.panelDoc.querySelectorAll("[data-pref]")) {
let pref = node.getAttribute("data-pref");
modifiedPrefs.push(pref);
}
// Test each options pref
let p = promise.resolve();
for (let node of prefNodes) {
let prefValue = Services.prefs.getBoolPref(node.getAttribute("data-pref"));
p = p.then(testMouseClick.bind(null, node, prefValue));
}
// Do again with opposite values to reset prefs
for (let node of prefNodes) {
let prefValue = !Services.prefs.getBoolPref(node.getAttribute("data-pref"));
p = p.then(testMouseClick.bind(null, node, prefValue));
let prefValue = GetPref(node.getAttribute("data-pref"));
// Test clicking the checkbox for each options pref
yield testMouseClick(node, prefValue);
// Do again with opposite values to reset prefs
yield testMouseClick(node, !prefValue);
}
return p;
let prefDropdowns = tool.panelDoc.querySelectorAll("menulist[data-pref]");
for (let node of prefDropdowns) {
yield testMenuList(node);
}
}
function* testMenuList(menulist) {
let pref = menulist.getAttribute("data-pref");
let menuitems = menulist.querySelectorAll("menuitem");
info ("Checking menu list for: " + pref);
is (menulist.selectedItem.value, GetPref(pref), "Menu starts out selected");
for (let menuitem of menuitems) {
if (menuitem === menulist.selectedItem) {
continue;
}
let deferred = promise.defer();
gDevTools.once("pref-changed", (event, data) => {
if (data.pref == pref) {
ok(true, "Correct pref was changed");
is (GetPref(pref), menuitem.value, "Preference been switched for " + pref);
} else {
ok(false, "Pref " + pref + " was not changed correctly");
}
deferred.resolve();
});
menulist.selectedItem = menuitem;
let commandEvent = menulist.ownerDocument.createEvent("XULCommandEvent");
commandEvent.initCommandEvent("command", true, true, window, 0, false, false,
false, false, null);
menulist.dispatchEvent(commandEvent);
yield deferred.promise;
}
}
function testMouseClick(node, prefValue) {
@ -76,8 +110,8 @@ function testMouseClick(node, prefValue) {
gDevTools.once("pref-changed", (event, data) => {
if (data.pref == pref) {
ok(true, "Correct pref was changed");
is(data.oldValue, prefValue, "Previous value is correct");
is(data.newValue, !prefValue, "New value is correct");
is(data.oldValue, prefValue, "Previous value is correct for " + pref);
is(data.newValue, !prefValue, "New value is correct for " + pref);
} else {
ok(false, "Pref " + pref + " was not changed correctly");
}
@ -201,6 +235,34 @@ function checkRegistered(toolId, deferred, event, data) {
deferred.resolve();
}
function GetPref(name) {
let type = Services.prefs.getPrefType(name);
switch (type) {
case Services.prefs.PREF_STRING:
return Services.prefs.getCharPref(name);
case Services.prefs.PREF_INT:
return Services.prefs.getIntPref(name);
case Services.prefs.PREF_BOOL:
return Services.prefs.getBoolPref(name);
default:
throw new Error("Unknown type");
}
}
function SetPref(name, value) {
let type = Services.prefs.getPrefType(name);
switch (type) {
case Services.prefs.PREF_STRING:
return Services.prefs.setCharPref(name, value);
case Services.prefs.PREF_INT:
return Services.prefs.setIntPref(name, value);
case Services.prefs.PREF_BOOL:
return Services.prefs.setBoolPref(name, value);
default:
throw new Error("Unknown type");
}
}
function cleanup() {
toolbox.destroy().then(function() {
gBrowser.removeCurrentTab();

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

@ -28,6 +28,43 @@ XPCOMUtils.defineLazyGetter(this, "l10n", function() {
return l10n;
});
function GetPref(name) {
let type = Services.prefs.getPrefType(name);
switch (type) {
case Services.prefs.PREF_STRING:
return Services.prefs.getCharPref(name);
case Services.prefs.PREF_INT:
return Services.prefs.getIntPref(name);
case Services.prefs.PREF_BOOL:
return Services.prefs.getBoolPref(name);
default:
throw new Error("Unknown type");
}
}
function SetPref(name, value) {
let type = Services.prefs.getPrefType(name);
switch (type) {
case Services.prefs.PREF_STRING:
return Services.prefs.setCharPref(name, value);
case Services.prefs.PREF_INT:
return Services.prefs.setIntPref(name, value);
case Services.prefs.PREF_BOOL:
return Services.prefs.setBoolPref(name, value);
default:
throw new Error("Unknown type");
}
}
function InfallibleGetBoolPref(key) {
try {
return Services.prefs.getBoolPref(key);
} catch (ex) {
return true;
}
}
/**
* Represents the Options Panel in the Toolbox.
*/
@ -107,7 +144,7 @@ OptionsPanel.prototype = {
let onCheckboxClick = (checkbox) => {
let toolDefinition = toggleableButtons.filter(tool => tool.id === checkbox.id)[0];
Services.prefs.setBoolPref(toolDefinition.visibilityswitch, checkbox.checked);
SetPref(toolDefinition.visibilityswitch, checkbox.checked);
setToolboxButtonsVisibility();
};
@ -115,7 +152,7 @@ OptionsPanel.prototype = {
let checkbox = this.panelDoc.createElement("checkbox");
checkbox.setAttribute("id", tool.id);
checkbox.setAttribute("label", tool.label);
checkbox.setAttribute("checked", this.getBoolPref(tool.visibilityswitch));
checkbox.setAttribute("checked", InfallibleGetBoolPref(tool.visibilityswitch));
checkbox.addEventListener("command", onCheckboxClick.bind(this, checkbox));
return checkbox;
};
@ -125,15 +162,6 @@ OptionsPanel.prototype = {
}
},
getBoolPref: function(key) {
try {
return Services.prefs.getBoolPref(key);
}
catch (ex) {
return true;
}
},
setupToolsList: function() {
let defaultToolsBox = this.panelDoc.getElementById("default-tools-box");
let additionalToolsBox = this.panelDoc.getElementById("additional-tools-box");
@ -146,7 +174,7 @@ OptionsPanel.prototype = {
let onCheckboxClick = function(id) {
let toolDefinition = gDevTools._tools.get(id);
// Set the kill switch pref boolean to true
Services.prefs.setBoolPref(toolDefinition.visibilityswitch, this.checked);
SetPref(toolDefinition.visibilityswitch, this.checked);
if (this.checked) {
gDevTools.emit("tool-registered", id);
}
@ -168,7 +196,7 @@ OptionsPanel.prototype = {
l10n("options.toolNotSupportedMarker", tool.label));
checkbox.setAttribute("unsupported", "");
}
checkbox.setAttribute("checked", this.getBoolPref(tool.visibilityswitch));
checkbox.setAttribute("checked", InfallibleGetBoolPref(tool.visibilityswitch));
checkbox.addEventListener("command", onCheckboxClick.bind(checkbox, tool.id));
return checkbox;
};
@ -204,20 +232,20 @@ OptionsPanel.prototype = {
populatePreferences: function() {
let prefCheckboxes = this.panelDoc.querySelectorAll("checkbox[data-pref]");
for (let checkbox of prefCheckboxes) {
checkbox.checked = Services.prefs.getBoolPref(checkbox.getAttribute("data-pref"));
checkbox.checked = GetPref(checkbox.getAttribute("data-pref"));
checkbox.addEventListener("command", function() {
let data = {
pref: this.getAttribute("data-pref"),
newValue: this.checked
};
data.oldValue = Services.prefs.getBoolPref(data.pref);
Services.prefs.setBoolPref(data.pref, data.newValue);
data.oldValue = GetPref(data.pref);
SetPref(data.pref, data.newValue);
gDevTools.emit("pref-changed", data);
}.bind(checkbox));
}
let prefRadiogroups = this.panelDoc.querySelectorAll("radiogroup[data-pref]");
for (let radiogroup of prefRadiogroups) {
let selectedValue = Services.prefs.getCharPref(radiogroup.getAttribute("data-pref"));
let selectedValue = GetPref(radiogroup.getAttribute("data-pref"));
for (let radio of radiogroup.childNodes) {
radiogroup.selectedIndex = -1;
if (radio.getAttribute("value") == selectedValue) {
@ -230,18 +258,18 @@ OptionsPanel.prototype = {
pref: this.getAttribute("data-pref"),
newValue: this.selectedItem.getAttribute("value")
};
data.oldValue = Services.prefs.getCharPref(data.pref);
Services.prefs.setCharPref(data.pref, data.newValue);
data.oldValue = GetPref(data.pref);
SetPref(data.pref, data.newValue);
gDevTools.emit("pref-changed", data);
}.bind(radiogroup));
}
let prefMenulists = this.panelDoc.querySelectorAll("menulist[data-pref]");
for (let menulist of prefMenulists) {
let pref = Services.prefs.getCharPref(menulist.getAttribute("data-pref"));
let pref = GetPref(menulist.getAttribute("data-pref"));
let menuitems = menulist.querySelectorAll("menuitem");
for (let menuitem of menuitems) {
let value = menuitem.getAttribute("value");
if (value === pref) {
let value = menuitem.value;
if (value == pref) { // non strict check to allow int values.
menulist.selectedItem = menuitem;
break;
}
@ -251,8 +279,8 @@ OptionsPanel.prototype = {
pref: this.getAttribute("data-pref"),
newValue: this.value
};
data.oldValue = Services.prefs.getCharPref(data.pref);
Services.prefs.setCharPref(data.pref, data.newValue);
data.oldValue = GetPref(data.pref);
SetPref(data.pref, data.newValue);
gDevTools.emit("pref-changed", data);
}.bind(menulist));
}

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

@ -49,10 +49,9 @@
data-pref="devtools.inspector.showUserAgentStyles"/>
<hbox align="center">
<label value="&options.defaultColorUnit.label;"
control="defaultColorUnitMenuList"
accesskey="&options.defaultColorUnit.accesskey;"/>
control="defaultColorUnitMenuList"
accesskey="&options.defaultColorUnit.accesskey;"/>
<menulist id="defaultColorUnitMenuList"
label="&options.defaultColorUnit.label;"
data-pref="devtools.defaultColorUnit">
<menupopup>
<menuitem label="&options.defaultColorUnit.hex;" value="hex"/>
@ -85,6 +84,52 @@
tooltiptext="&options.showPlatformData.tooltip;"
data-pref="devtools.profiler.ui.show-platform-data"/>
</vbox>
</vbox>
<vbox id="sourceeditor-box" class="options-vertical-pane" flex="1">
<label value="&options.sourceeditor.label;"/>
<vbox id="sourceeditor-options" class="options-groupbox">
<checkbox id="devtools-sourceeditor-detectindentation"
label="&options.sourceeditor.detectindentation.label;"
tooltiptext="&options.sourceeditor.detectindentation.tooltip;"
data-pref="devtools.editor.detectindentation"/>
<checkbox id="devtools-sourceeditor-autoclosebrackets"
label="&options.sourceeditor.autoclosebrackets.label;"
tooltiptext="&options.sourceeditor.autoclosebrackets.tooltip;"
data-pref="devtools.editor.autoclosebrackets"/>
<checkbox id="devtools-sourceeditor-expandtab"
label="&options.sourceeditor.expandtab.label;"
tooltiptext="&options.sourceeditor.expandtab.tooltip;"
data-pref="devtools.editor.expandtab"/>
<hbox align="center">
<label value="&options.sourceeditor.tabsize.label;"
control="devtools-sourceeditor-tabsize-menulist"
accesskey="&options.sourceeditor.tabsize.accesskey;"/>
<menulist id="devtools-sourceeditor-tabsize-menulist"
data-pref="devtools.editor.tabsize">
<menupopup>
<menuitem label="2" value="2"/>
<menuitem label="4" value="4"/>
<menuitem label="8" value="8"/>
</menupopup>
</menulist>
</hbox>
<hbox align="center">
<label value="&options.sourceeditor.keybinding.label;"
control="devtools-sourceeditor-keybinding-menulist"
accesskey="&options.sourceeditor.keybinding.accesskey;"/>
<menulist id="devtools-sourceeditor-keybinding-menulist"
data-pref="devtools.editor.keymap">
<menupopup>
<menuitem value="default"
label="&options.sourceeditor.keybinding.default.label;"/>
<menuitem label="Vim" value="vim"/>
<menuitem label="Emacs" value="emacs"/>
<menuitem label="Sublime Text" value="sublime"/>
</menupopup>
</menulist>
</hbox>
</vbox>
<label value="&options.context.advancedSettings;"/>
<vbox id="context-options" class="options-groupbox">
<checkbox id="devtools-disable-cache"
@ -104,7 +149,7 @@
tooltiptext="&options.enableRemote.tooltip;"
data-pref="devtools.debugger.remote-enabled"/>
</hbox>
<label class="options-citation-label"
<label class="options-citation-label theme-comment"
value="&options.context.triggersPageRefresh;"/>
</vbox>
</vbox>

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

@ -165,3 +165,19 @@
<!ENTITY options.showPlatformData.label "Show Gecko platform data">
<!ENTITY options.showPlatformData.tooltip "If you enable this option the JavaScript Profiler reports will include
Gecko platform symbols">
<!-- LOCALIZATION NOTE (options.sourceeditor.*): Options under the editor
- section. -->
<!ENTITY options.sourceeditor.label "Editor Preferences">
<!ENTITY options.sourceeditor.detectindentation.label "Detect indentation">
<!ENTITY options.sourceeditor.detectindentation.tooltip "Guess indentation based on source content">
<!ENTITY options.sourceeditor.autoclosebrackets.label "Autoclose brackets">
<!ENTITY options.sourceeditor.autoclosebrackets.tooltip "Automatically insert closing brackets">
<!ENTITY options.sourceeditor.expandtab.label "Indent using spaces">
<!ENTITY options.sourceeditor.expandtab.tooltip "Use spaces intead of the tab character">
<!ENTITY options.sourceeditor.tabsize.label "Tab size">
<!ENTITY options.sourceeditor.tabsize.accesskey "T">
<!ENTITY options.sourceeditor.keybinding.label "Keybindings">
<!ENTITY options.sourceeditor.keybinding.accesskey "K">
<!ENTITY options.sourceeditor.keybinding.default.label "Default">