Bug 498619 - Pages list on History menu disappear when restore submenus are closed, r=dao

This commit is contained in:
Marco Bonardo 2009-06-23 01:00:44 +02:00
parent 7b4a63772f
commit 752037d42a
3 changed files with 168 additions and 160 deletions

View File

@ -451,8 +451,8 @@
accesskey="&historyMenu.accesskey;">
<menupopup id="goPopup"
type="places"
onpopupshowing="HistoryMenu.onPopupShowing(this);"
onpopuphidden="HistoryMenu.onPopupHidden(this);"
onpopupshowing="HistoryMenu.onPopupShowing(event);"
onpopuphidden="HistoryMenu.onPopupHidden(event);"
place="place:redirectsMode=2&amp;sort=4&amp;maxResults=10"
tooltip="btTooltip">
<menuitem id="historyMenuBack"

View File

@ -580,39 +580,192 @@ var PlacesCommandHook = {
}
};
// Functions for the history menu.
// Helper object for the history menu.
var HistoryMenu = {
get _ss() {
delete this._ss;
return this._ss = Components.classes["@mozilla.org/browser/sessionstore;1"].
getService(Components.interfaces.nsISessionStore);
return this._ss = Cc["@mozilla.org/browser/sessionstore;1"].
getService(Ci.nsISessionStore);
},
toggleRecentlyClosedTabs: function PHM_toggleRecentlyClosedTabs() {
// enable/disable the Recently Closed Tabs sub menu
var undoPopup = document.getElementById("historyUndoPopup");
// no restorable tabs, so disable menu
if (this._ss.getClosedTabCount(window) == 0)
undoPopup.parentNode.setAttribute("disabled", true);
else
undoPopup.parentNode.removeAttribute("disabled");
},
/**
* Re-open a closed tab and put it to the end of the tab strip.
* Used for a middle click.
* @param aEvent
* The event when the user clicks the menu item
*/
_undoCloseMiddleClick: function PHM__undoCloseMiddleClick(aEvent) {
if (aEvent.button != 1)
return;
undoCloseTab(aEvent.originalTarget.value);
gBrowser.moveTabToEnd();
},
/**
* Populate when the history menu is opened
*/
populateUndoSubmenu: function PHM_populateUndoSubmenu() {
var undoPopup = document.getElementById("historyUndoPopup");
// remove existing menu items
while (undoPopup.hasChildNodes())
undoPopup.removeChild(undoPopup.firstChild);
// no restorable tabs, so make sure menu is disabled, and return
if (this._ss.getClosedTabCount(window) == 0) {
undoPopup.parentNode.setAttribute("disabled", true);
return;
}
// enable menu
undoPopup.parentNode.removeAttribute("disabled");
// populate menu
var undoItems = eval("(" + this._ss.getClosedTabData(window) + ")");
for (var i = 0; i < undoItems.length; i++) {
var m = document.createElement("menuitem");
m.setAttribute("label", undoItems[i].title);
if (undoItems[i].image) {
let iconURL = undoItems[i].image;
// don't initiate a connection just to fetch a favicon (see bug 467828)
if (/^https?:/.test(iconURL))
iconURL = "moz-anno:favicon:" + iconURL;
m.setAttribute("image", iconURL);
}
m.setAttribute("class", "menuitem-iconic bookmark-item");
m.setAttribute("value", i);
m.setAttribute("oncommand", "undoCloseTab(" + i + ");");
m.addEventListener("click", this._undoCloseMiddleClick, false);
if (i == 0)
m.setAttribute("key", "key_undoCloseTab");
undoPopup.appendChild(m);
}
// "Open All in Tabs"
var strings = gNavigatorBundle;
undoPopup.appendChild(document.createElement("menuseparator"));
m = undoPopup.appendChild(document.createElement("menuitem"));
m.setAttribute("label", strings.getString("menuOpenAllInTabs.label"));
m.setAttribute("accesskey", strings.getString("menuOpenAllInTabs.accesskey"));
m.addEventListener("command", function() {
for (var i = 0; i < undoItems.length; i++)
undoCloseTab();
}, false);
},
toggleRecentlyClosedWindows: function PHM_toggleRecentlyClosedWindows() {
// enable/disable the Recently Closed Windows sub menu
let undoPopup = document.getElementById("historyUndoWindowPopup");
// no restorable windows, so disable menu
if (this._ss.getClosedWindowCount() == 0)
undoPopup.parentNode.setAttribute("disabled", true);
else
undoPopup.parentNode.removeAttribute("disabled");
},
/**
* Populate when the history menu is opened
*/
populateUndoWindowSubmenu: function PHM_populateUndoWindowSubmenu() {
let undoPopup = document.getElementById("historyUndoWindowPopup");
let menuLabelString = gNavigatorBundle.getString("menuUndoCloseWindowLabel");
let menuLabelStringSingleTab =
gNavigatorBundle.getString("menuUndoCloseWindowSingleTabLabel");
// remove existing menu items
while (undoPopup.hasChildNodes())
undoPopup.removeChild(undoPopup.firstChild);
// no restorable windows, so make sure menu is disabled, and return
if (this._ss.getClosedWindowCount() == 0) {
undoPopup.parentNode.setAttribute("disabled", true);
return;
}
// enable menu
undoPopup.parentNode.removeAttribute("disabled");
// populate menu
let undoItems = JSON.parse(this._ss.getClosedWindowData());
for (let i = 0; i < undoItems.length; i++) {
let undoItem = undoItems[i];
let otherTabsCount = undoItem.tabs.length - 1;
let label = (otherTabsCount == 0) ? menuLabelStringSingleTab
: PluralForm.get(otherTabsCount, menuLabelString);
let menuLabel = label.replace("#1", undoItem.title)
.replace("#2", otherTabsCount);
let m = document.createElement("menuitem");
m.setAttribute("label", menuLabel);
let selectedTab = undoItem.tabs[undoItem.selected - 1];
if (selectedTab.attributes.image) {
let iconURL = selectedTab.attributes.image;
// don't initiate a connection just to fetch a favicon (see bug 467828)
if (/^https?:/.test(iconURL))
iconURL = "moz-anno:favicon:" + iconURL;
m.setAttribute("image", iconURL);
}
m.setAttribute("class", "menuitem-iconic bookmark-item");
m.setAttribute("oncommand", "undoCloseWindow(" + i + ");");
if (i == 0)
m.setAttribute("key", "key_undoCloseWindow");
undoPopup.appendChild(m);
}
// "Open All in Windows"
undoPopup.appendChild(document.createElement("menuseparator"));
let m = undoPopup.appendChild(document.createElement("menuitem"));
m.setAttribute("label", gNavigatorBundle.getString("menuRestoreAllWindows.label"));
m.setAttribute("accesskey", gNavigatorBundle.getString("menuRestoreAllWindows.accesskey"));
m.setAttribute("oncommand",
"for (var i = 0; i < " + undoItems.length + "; i++) undoCloseWindow();");
},
/**
* popupshowing handler for the history menu.
* @param aMenuPopup
* XULNode for the history menupopup
* @param aEvent
* The popupshowing event.
*/
onPopupShowing: function PHM_onPopupShowing(aMenuPopup) {
var resultNode = aMenuPopup.getResultNode();
onPopupShowing: function PHM_onPopupShowing(aEvent) {
// Don't handle events for submenus.
if (aEvent.target != aEvent.currentTarget)
return;
var menuPopup = aEvent.target;
var resultNode = menuPopup.getResultNode();
var wasOpen = resultNode.containerOpen;
resultNode.containerOpen = true;
document.getElementById("endHistorySeparator").hidden =
resultNode.childCount == 0;
// HistoryMenu.toggleRecentlyClosedTabs, HistoryMenu.toggleRecentlyClosedWindows
// are defined in browser.js
this.toggleRecentlyClosedTabs();
this.toggleRecentlyClosedWindows();
},
/**
* popuphidden handler for the history menu.
* @param aMenuPopup
* XULNode for the history menupopup
* @param aEvent
* The popuphidden event.
*/
onPopupHidden: function PHM_onPopupHidden(aMenuPopup) {
var resultNode = aMenuPopup.getResultNode();
onPopupHidden: function PHM_onPopupHidden(aEvent) {
// Don't handle events for submenus.
if (aEvent.target != aEvent.currentTarget)
return;
var menuPopup = aEvent.target;
var resultNode = menuPopup.getResultNode();
if (resultNode.containerOpen)
resultNode.containerOpen = false;
}

View File

@ -6231,151 +6231,6 @@ var FeedHandler = {
#include browser-tabPreviews.js
HistoryMenu.toggleRecentlyClosedTabs = function PHM_toggleRecentlyClosedTabs() {
// enable/disable the Recently Closed Tabs sub menu
var undoPopup = document.getElementById("historyUndoPopup");
// no restorable tabs, so disable menu
if (this._ss.getClosedTabCount(window) == 0)
undoPopup.parentNode.setAttribute("disabled", true);
else
undoPopup.parentNode.removeAttribute("disabled");
}
/**
* Populate when the history menu is opened
*/
HistoryMenu.populateUndoSubmenu = function PHM_populateUndoSubmenu() {
var undoPopup = document.getElementById("historyUndoPopup");
// remove existing menu items
while (undoPopup.hasChildNodes())
undoPopup.removeChild(undoPopup.firstChild);
// no restorable tabs, so make sure menu is disabled, and return
if (this._ss.getClosedTabCount(window) == 0) {
undoPopup.parentNode.setAttribute("disabled", true);
return;
}
// enable menu
undoPopup.parentNode.removeAttribute("disabled");
// populate menu
var undoItems = eval("(" + this._ss.getClosedTabData(window) + ")");
for (var i = 0; i < undoItems.length; i++) {
var m = document.createElement("menuitem");
m.setAttribute("label", undoItems[i].title);
if (undoItems[i].image) {
let iconURL = undoItems[i].image;
// don't initiate a connection just to fetch a favicon (see bug 467828)
if (/^https?:/.test(iconURL))
iconURL = "moz-anno:favicon:" + iconURL;
m.setAttribute("image", iconURL);
}
m.setAttribute("class", "menuitem-iconic bookmark-item");
m.setAttribute("value", i);
m.setAttribute("oncommand", "undoCloseTab(" + i + ");");
m.addEventListener("click", undoCloseMiddleClick, false);
if (i == 0)
m.setAttribute("key", "key_undoCloseTab");
undoPopup.appendChild(m);
}
// "Open All in Tabs"
var strings = gNavigatorBundle;
undoPopup.appendChild(document.createElement("menuseparator"));
m = undoPopup.appendChild(document.createElement("menuitem"));
m.setAttribute("label", strings.getString("menuOpenAllInTabs.label"));
m.setAttribute("accesskey", strings.getString("menuOpenAllInTabs.accesskey"));
m.addEventListener("command", function() {
for (var i = 0; i < undoItems.length; i++)
undoCloseTab();
}, false);
}
HistoryMenu.toggleRecentlyClosedWindows = function PHM_toggleRecentlyClosedWindows() {
// enable/disable the Recently Closed Windows sub menu
let undoPopup = document.getElementById("historyUndoWindowPopup");
// no restorable windows, so disable menu
if (this._ss.getClosedWindowCount() == 0)
undoPopup.parentNode.setAttribute("disabled", true);
else
undoPopup.parentNode.removeAttribute("disabled");
}
/**
* Populate when the history menu is opened
*/
HistoryMenu.populateUndoWindowSubmenu = function PHM_populateUndoWindowSubmenu() {
let undoPopup = document.getElementById("historyUndoWindowPopup");
let menuLabelString = gNavigatorBundle.getString("menuUndoCloseWindowLabel");
let menuLabelStringSingleTab =
gNavigatorBundle.getString("menuUndoCloseWindowSingleTabLabel");
// remove existing menu items
while (undoPopup.hasChildNodes())
undoPopup.removeChild(undoPopup.firstChild);
// no restorable windows, so make sure menu is disabled, and return
if (this._ss.getClosedWindowCount() == 0) {
undoPopup.parentNode.setAttribute("disabled", true);
return;
}
// enable menu
undoPopup.parentNode.removeAttribute("disabled");
// populate menu
let undoItems = JSON.parse(this._ss.getClosedWindowData());
for (let i = 0; i < undoItems.length; i++) {
let undoItem = undoItems[i];
let otherTabsCount = undoItem.tabs.length - 1;
let label = (otherTabsCount == 0) ? menuLabelStringSingleTab
: PluralForm.get(otherTabsCount, menuLabelString);
let menuLabel = label.replace("#1", undoItem.title)
.replace("#2", otherTabsCount);
let m = document.createElement("menuitem");
m.setAttribute("label", menuLabel);
let selectedTab = undoItem.tabs[undoItem.selected - 1];
if (selectedTab.attributes.image) {
let iconURL = selectedTab.attributes.image;
// don't initiate a connection just to fetch a favicon (see bug 467828)
if (/^https?:/.test(iconURL))
iconURL = "moz-anno:favicon:" + iconURL;
m.setAttribute("image", iconURL);
}
m.setAttribute("class", "menuitem-iconic bookmark-item");
m.setAttribute("oncommand", "undoCloseWindow(" + i + ");");
if (i == 0)
m.setAttribute("key", "key_undoCloseWindow");
undoPopup.appendChild(m);
}
// "Open All in Windows"
undoPopup.appendChild(document.createElement("menuseparator"));
let m = undoPopup.appendChild(document.createElement("menuitem"));
m.setAttribute("label", gNavigatorBundle.getString("menuRestoreAllWindows.label"));
m.setAttribute("accesskey", gNavigatorBundle.getString("menuRestoreAllWindows.accesskey"));
m.setAttribute("oncommand",
"for (var i = 0; i < " + undoItems.length + "; i++) undoCloseWindow();");
}
/**
* Re-open a closed tab and put it to the end of the tab strip.
* Used for a middle click.
* @param aEvent
* The event when the user clicks the menu item
*/
function undoCloseMiddleClick(aEvent) {
if (aEvent.button != 1)
return;
undoCloseTab(aEvent.originalTarget.value);
gBrowser.moveTabToEnd();
}
/**
* Re-open a closed tab.
* @param aIndex