зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1457027 - Part 5 - Move _describeType to HandlerInfoWrapper. r=jaws
MozReview-Commit-ID: NjmxPwLngc --HG-- extra : rebase_source : 597e6eb0aa0c03626e5ca3b30735143ddcecb527
This commit is contained in:
Родитель
b9c14b465a
Коммит
0076ed20af
|
@ -15,18 +15,17 @@ var gAppManagerDialog = {
|
||||||
this.handlerInfo = window.arguments[0];
|
this.handlerInfo = window.arguments[0];
|
||||||
Services.scriptloader.loadSubScript("chrome://browser/content/preferences/in-content/main.js",
|
Services.scriptloader.loadSubScript("chrome://browser/content/preferences/in-content/main.js",
|
||||||
window);
|
window);
|
||||||
var pane = gMainPane;
|
|
||||||
|
|
||||||
const appDescElem = document.getElementById("appDescription");
|
const appDescElem = document.getElementById("appDescription");
|
||||||
if (this.handlerInfo.type == TYPE_MAYBE_FEED) {
|
if (this.handlerInfo.type == TYPE_MAYBE_FEED) {
|
||||||
document.l10n.setAttributes(appDescElem, "app-manager-handle-webfeeds");
|
document.l10n.setAttributes(appDescElem, "app-manager-handle-webfeeds");
|
||||||
} else if (this.handlerInfo.wrappedHandlerInfo instanceof Ci.nsIMIMEInfo) {
|
} else if (this.handlerInfo.wrappedHandlerInfo instanceof Ci.nsIMIMEInfo) {
|
||||||
document.l10n.setAttributes(appDescElem, "app-manager-handle-file", {
|
document.l10n.setAttributes(appDescElem, "app-manager-handle-file", {
|
||||||
type: pane._describeType(this.handlerInfo)
|
type: this.handlerInfo.typeDescription,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
document.l10n.setAttributes(appDescElem, "app-manager-handle-protocol", {
|
document.l10n.setAttributes(appDescElem, "app-manager-handle-protocol", {
|
||||||
type: pane._describeType(this.handlerInfo)
|
type: this.handlerInfo.typeDescription,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,12 +33,12 @@ var gAppManagerDialog = {
|
||||||
var apps = this.handlerInfo.possibleApplicationHandlers.enumerate();
|
var apps = this.handlerInfo.possibleApplicationHandlers.enumerate();
|
||||||
while (apps.hasMoreElements()) {
|
while (apps.hasMoreElements()) {
|
||||||
let app = apps.getNext();
|
let app = apps.getNext();
|
||||||
if (!pane.isValidHandlerApp(app))
|
if (!gMainPane.isValidHandlerApp(app))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
app.QueryInterface(Ci.nsIHandlerApp);
|
app.QueryInterface(Ci.nsIHandlerApp);
|
||||||
var item = list.appendItem(app.name);
|
var item = list.appendItem(app.name);
|
||||||
item.setAttribute("image", pane._getIconURLForHandlerApp(app));
|
item.setAttribute("image", gMainPane._getIconURLForHandlerApp(app));
|
||||||
item.className = "listitem-iconic";
|
item.className = "listitem-iconic";
|
||||||
item.app = app;
|
item.app = app;
|
||||||
}
|
}
|
||||||
|
|
|
@ -258,12 +258,6 @@ var gMainPane = {
|
||||||
// that match that string.
|
// that match that string.
|
||||||
_visibleTypes: [],
|
_visibleTypes: [],
|
||||||
|
|
||||||
// A count of the number of times each visible type description appears.
|
|
||||||
// We use these counts to determine whether or not to annotate descriptions
|
|
||||||
// with their types to distinguish duplicate descriptions from each other.
|
|
||||||
// A hash of integer counts, indexed by string description.
|
|
||||||
_visibleTypeDescriptionCount: {},
|
|
||||||
|
|
||||||
// browser.startup.page values
|
// browser.startup.page values
|
||||||
STARTUP_PREF_BLANK: 0,
|
STARTUP_PREF_BLANK: 0,
|
||||||
STARTUP_PREF_HOMEPAGE: 1,
|
STARTUP_PREF_HOMEPAGE: 1,
|
||||||
|
@ -1453,9 +1447,13 @@ var gMainPane = {
|
||||||
// View Construction
|
// View Construction
|
||||||
|
|
||||||
async _rebuildVisibleTypes() {
|
async _rebuildVisibleTypes() {
|
||||||
// Reset the list of visible types and the visible type description counts.
|
|
||||||
this._visibleTypes = [];
|
this._visibleTypes = [];
|
||||||
this._visibleTypeDescriptionCount = {};
|
|
||||||
|
// Map whose keys are string descriptions and values are references to the
|
||||||
|
// first visible HandlerInfoWrapper that has this description. We use this
|
||||||
|
// to determine whether or not to annotate descriptions with their types to
|
||||||
|
// distinguish duplicate descriptions from each other.
|
||||||
|
let visibleDescriptions = new Map();
|
||||||
|
|
||||||
// Get the preferences that help determine what types to show.
|
// Get the preferences that help determine what types to show.
|
||||||
var showPlugins = Services.prefs.getBoolPref(PREF_SHOW_PLUGINS_IN_LIST);
|
var showPlugins = Services.prefs.getBoolPref(PREF_SHOW_PLUGINS_IN_LIST);
|
||||||
|
@ -1489,10 +1487,19 @@ var gMainPane = {
|
||||||
// We couldn't find any reason to exclude the type, so include it.
|
// We couldn't find any reason to exclude the type, so include it.
|
||||||
this._visibleTypes.push(handlerInfo);
|
this._visibleTypes.push(handlerInfo);
|
||||||
|
|
||||||
if (handlerInfo.description in this._visibleTypeDescriptionCount)
|
let otherHandlerInfo = visibleDescriptions.get(handlerInfo.description);
|
||||||
this._visibleTypeDescriptionCount[handlerInfo.description]++;
|
if (!otherHandlerInfo) {
|
||||||
else
|
// This is the first type with this description that we encountered
|
||||||
this._visibleTypeDescriptionCount[handlerInfo.description] = 1;
|
// while rebuilding the _visibleTypes array this time. Make sure the
|
||||||
|
// flag is reset so we won't add the type to the description.
|
||||||
|
handlerInfo.disambiguateDescription = false;
|
||||||
|
visibleDescriptions.set(handlerInfo.description, handlerInfo);
|
||||||
|
} else {
|
||||||
|
// There is at least another type with this description. Make sure we
|
||||||
|
// add the type to the description on both HandlerInfoWrapper objects.
|
||||||
|
handlerInfo.disambiguateDescription = true;
|
||||||
|
otherHandlerInfo.disambiguateDescription = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1513,7 +1520,7 @@ var gMainPane = {
|
||||||
for (let visibleType of visibleTypes) {
|
for (let visibleType of visibleTypes) {
|
||||||
let item = document.createElement("richlistitem");
|
let item = document.createElement("richlistitem");
|
||||||
item.setAttribute("type", visibleType.type);
|
item.setAttribute("type", visibleType.type);
|
||||||
item.setAttribute("typeDescription", this._describeType(visibleType));
|
item.setAttribute("typeDescription", visibleType.typeDescription);
|
||||||
if (visibleType.smallIcon)
|
if (visibleType.smallIcon)
|
||||||
item.setAttribute("typeIcon", visibleType.smallIcon);
|
item.setAttribute("typeIcon", visibleType.smallIcon);
|
||||||
item.setAttribute("actionDescription",
|
item.setAttribute("actionDescription",
|
||||||
|
@ -1534,29 +1541,10 @@ var gMainPane = {
|
||||||
|
|
||||||
_matchesFilter(aType) {
|
_matchesFilter(aType) {
|
||||||
var filterValue = this._filter.value.toLowerCase();
|
var filterValue = this._filter.value.toLowerCase();
|
||||||
return this._describeType(aType).toLowerCase().includes(filterValue) ||
|
return aType.typeDescription.toLowerCase().includes(filterValue) ||
|
||||||
this._describePreferredAction(aType).toLowerCase().includes(filterValue);
|
this._describePreferredAction(aType).toLowerCase().includes(filterValue);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Describe, in a human-readable fashion, the type represented by the given
|
|
||||||
* handler info object. Normally this is just the description provided by
|
|
||||||
* the info object, but if more than one object presents the same description,
|
|
||||||
* then we annotate the duplicate descriptions with the type itself to help
|
|
||||||
* users distinguish between those types.
|
|
||||||
*
|
|
||||||
* @param aHandlerInfo {nsIHandlerInfo} the type being described
|
|
||||||
* @returns {string} a description of the type
|
|
||||||
*/
|
|
||||||
_describeType(aHandlerInfo) {
|
|
||||||
if (this._visibleTypeDescriptionCount[aHandlerInfo.description] > 1)
|
|
||||||
return gMainPane._prefsBundle.getFormattedString("typeDescriptionWithType",
|
|
||||||
[aHandlerInfo.description,
|
|
||||||
aHandlerInfo.type]);
|
|
||||||
|
|
||||||
return aHandlerInfo.description;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describe, in a human-readable fashion, the preferred action to take on
|
* Describe, in a human-readable fashion, the preferred action to take on
|
||||||
* the type represented by the given handler info object.
|
* the type represented by the given handler info object.
|
||||||
|
@ -1948,8 +1936,8 @@ var gMainPane = {
|
||||||
var t = this;
|
var t = this;
|
||||||
|
|
||||||
function sortByType(a, b) {
|
function sortByType(a, b) {
|
||||||
return t._describeType(a).toLowerCase().
|
return a.typeDescription.toLowerCase().
|
||||||
localeCompare(t._describeType(b).toLowerCase());
|
localeCompare(b.typeDescription.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
function sortByAction(a, b) {
|
function sortByAction(a, b) {
|
||||||
|
@ -2628,6 +2616,7 @@ class HandlerInfoWrapper {
|
||||||
constructor(type, handlerInfo) {
|
constructor(type, handlerInfo) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.wrappedHandlerInfo = handlerInfo;
|
this.wrappedHandlerInfo = handlerInfo;
|
||||||
|
this.disambiguateDescription = false;
|
||||||
|
|
||||||
// A plugin that can handle this type, if any.
|
// A plugin that can handle this type, if any.
|
||||||
//
|
//
|
||||||
|
@ -2664,6 +2653,22 @@ class HandlerInfoWrapper {
|
||||||
return this.type;
|
return this.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describe, in a human-readable fashion, the type represented by the given
|
||||||
|
* handler info object. Normally this is just the description, but if more
|
||||||
|
* than one object presents the same description, "disambiguateDescription"
|
||||||
|
* is set and we annotate the duplicate descriptions with the type itself
|
||||||
|
* to help users distinguish between those types.
|
||||||
|
*/
|
||||||
|
get typeDescription() {
|
||||||
|
if (this.disambiguateDescription) {
|
||||||
|
return gMainPane._prefsBundle.getFormattedString(
|
||||||
|
"typeDescriptionWithType", [this.description, this.type]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.description;
|
||||||
|
}
|
||||||
|
|
||||||
get preferredApplicationHandler() {
|
get preferredApplicationHandler() {
|
||||||
return this.wrappedHandlerInfo.preferredApplicationHandler;
|
return this.wrappedHandlerInfo.preferredApplicationHandler;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче