Bug 1217129: Part 4a - Allow creating CustomizableUI widgets without tooltips. r?gijs
--- a/browser/components/customizableui/CustomizableUI.jsm
+++ b/browser/components/customizableui/CustomizableUI.jsm
@@ -1337,17 +1337,19 @@ var CustomizableUIInternal = {
additionalTooltipArguments.push(ShortcutUtils.prettifyShortcut(keyEl));
} else {
ERROR("Key element with id '" + aWidget.shortcutId + "' for widget '" + aWidget.id +
"' not found!");
}
}
let tooltip = this.getLocalizedProperty(aWidget, "tooltiptext", additionalTooltipArguments);
- node.setAttribute("tooltiptext", tooltip);
+ if (tooltip) {
+ node.setAttribute("tooltiptext", tooltip);
+ }
node.setAttribute("class", "toolbarbutton-1 chromeclass-toolbar-additional");
let commandHandler = this.handleWidgetCommand.bind(this, aWidget, node);
node.addEventListener("command", commandHandler, false);
let clickHandler = this.handleWidgetClick.bind(this, aWidget, node);
node.addEventListener("click", clickHandler, false);
// If the widget has a view, and has view showing / hiding listeners,
@@ -1390,34 +1392,36 @@ var CustomizableUIInternal = {
}
if (!aWidget) {
throw new Error("getLocalizedProperty was passed a non-widget to work with.");
}
let def, name;
// Let widgets pass their own string identifiers or strings, so that
// we can use strings which aren't the default (in case string ids change)
// and so that non-builtin-widgets can also provide labels, tooltips, etc.
- if (aWidget[aProp]) {
+ if (aWidget[aProp] != null) {
name = aWidget[aProp];
// By using this as the default, if a widget provides a full string rather
// than a string ID for localization, we will fall back to that string
// and return that.
def = aDef || name;
} else {
name = aWidget.id + "." + aProp;
def = aDef || "";
}
try {
if (Array.isArray(aFormatArgs) && aFormatArgs.length) {
return gWidgetsBundle.formatStringFromName(name, aFormatArgs,
aFormatArgs.length) || def;
}
return gWidgetsBundle.GetStringFromName(name) || def;
} catch(ex) {
- if (!def) {
+ // If an empty string was explicitly passed, treat it as an actual
+ // value rather than a missing property.
+ if (!def && name != "") {
ERROR("Could not localize property '" + name + "'.");
}
}
return def;
},
addShortcut: function(aShortcutNode, aTargetNode) {
if (!aTargetNode)