Bug 1120110 - For the 'Bookmark All Tabs' feature, find a potentially more useful default folder name than '[Folder Name]'. r?mak
The name we can propose here would look something like 'Tabs from October 6 - 2',
where the - 2 suffix would indicate that a folder with the name 'Tabs from October 6'
and 'Tabs from October 6 - 1' already exist.
MozReview-Commit-ID: LPVA4A80xMt
--- a/browser/components/places/content/bookmarkProperties.js
+++ b/browser/components/places/content/bookmarkProperties.js
@@ -141,16 +141,44 @@ var BookmarkPropertiesPanel = {
}
if (this._action == ACTION_EDIT) {
return this._strings.getFormattedString("dialogTitleEdit", [this._title]);
}
return "";
},
/**
+ * Attempt to find a sensible default folder name that does not currently exist
+ * yet.
+ *
+ * @param {Array} titleParts Date segments that will be used to complete the
+ * default folder name strings.
+ * @param {Number} [count] Iteration counter.
+ * @return {String} A probably unique folder name that can be used to prefill
+ * a UI element.
+ */
+ async _getUniqueFolderName(titleParts, count = 0) {
+ let reachedMaxIterations = count >= 42;
+ let stringID = count > 0 ? "bookmarkAllTabsDefaultWithSuffix" : "bookmarkAllTabsDefault2";
+ let stringOptions = count > 0 ? titleParts.concat([reachedMaxIterations ? "\u221e" : count]) : titleParts;
+ let needle = this._strings.getFormattedString(stringID, stringOptions);
+ if (reachedMaxIterations) {
+ return needle;
+ }
+
+ for (let result of await PlacesUtils.bookmarks.search(needle)) {
+ if (result.type == PlacesUtils.bookmarks.TYPE_FOLDER &&
+ result.title == needle) {
+ return this._getUniqueFolderName(titleParts, count + 1);
+ }
+ }
+ return needle;
+ },
+
+ /**
* Determines the initial data for the item edited or added by this dialog
*/
async _determineItemInfo() {
let dialogInfo = window.arguments[0];
this._action = dialogInfo.action == "add" ? ACTION_ADD : ACTION_EDIT;
this._hiddenRows = dialogInfo.hiddenRows ? dialogInfo.hiddenRows : [];
if (this._action == ACTION_ADD) {
NS_ASSERT("type" in dialogInfo, "missing type property for add action");
@@ -197,17 +225,20 @@ var BookmarkPropertiesPanel = {
this._charSet = dialogInfo.charSet;
}
break;
case "folder":
this._itemType = BOOKMARK_FOLDER;
if (!this._title) {
if ("URIList" in dialogInfo) {
- this._title = this._strings.getString("bookmarkAllTabsDefault");
+ let now = new Date();
+ let month = now.toLocaleDateString(undefined, { month: "long" });
+ let date = now.getDate();
+ this._title = await this._getUniqueFolderName([month, date]);
this._URIs = dialogInfo.URIList;
} else
this._title = this._strings.getString("newFolderDefault");
this._dummyItem = true;
}
break;
case "livemark":
--- a/browser/locales/en-US/chrome/browser/browser.properties
+++ b/browser/locales/en-US/chrome/browser/browser.properties
@@ -11,20 +11,16 @@ droponhomemsgMultiple=Do you want these
# context menu strings
# LOCALIZATION NOTE (contextMenuSearch): %1$S is the search engine,
# %2$S is the selection string.
contextMenuSearch=Search %1$S for “%2$S”
contextMenuSearch.accesskey=S
-# bookmark dialog strings
-
-bookmarkAllTabsDefault=[Folder Name]
-
xpinstallPromptMessage=%S prevented this site from asking you to install software on your computer.
xpinstallPromptMessage.dontAllow=Don’t Allow
xpinstallPromptMessage.dontAllow.accesskey=D
xpinstallPromptAllowButton=Allow
# Accessibility Note:
# Be sure you do not choose an accesskey that is used elsewhere in the active context (e.g. main menu bar, submenu of the warning popup button)
# See http://www.mozilla.org/access/keyboard/accesskey for details
xpinstallPromptAllowButton.accesskey=A
--- a/browser/locales/en-US/chrome/browser/places/bookmarkProperties.properties
+++ b/browser/locales/en-US/chrome/browser/places/bookmarkProperties.properties
@@ -8,12 +8,20 @@ dialogAcceptLabelAddLivemark=Subscribe
dialogAcceptLabelAddMulti=Add Bookmarks
dialogAcceptLabelEdit=Save
dialogTitleAddBookmark=New Bookmark
dialogTitleAddLivemark=Subscribe with Live Bookmark
dialogTitleAddFolder=New Folder
dialogTitleAddMulti=New Bookmarks
dialogTitleEdit=Properties for “%S”
-bookmarkAllTabsDefault=[Folder Name]
+# LOCALIZATION NOTE (bookmarkAllTabsDefault2)
+# %1$S the full name of the month and %2$S is the day of month number.
+# Example: Tabs from January 22
+bookmarkAllTabsDefault2=Tabs from %1$S %2$S
+# LOCALIZATION NOTE (bookmarkAllTabsDefaultSuffix)
+# %1$S the full name of the month, %2$S is the day of month number and %3$S is a
+# counter value.
+# Example: Tabs from January 22 - 1
+bookmarkAllTabsDefaultWithSuffix=Tabs from %1$S %2$S - %3$S
newFolderDefault=New Folder
newBookmarkDefault=New Bookmark
newLivemarkDefault=New Live Bookmark