2010-07-06 19:32:42 -07:00
|
|
|
# ***** BEGIN LICENSE BLOCK *****
|
|
|
|
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
#
|
|
|
|
# The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
# 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
# the License. You may obtain a copy of the License at
|
|
|
|
# http://www.mozilla.org/MPL/
|
|
|
|
#
|
|
|
|
# Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
# for the specific language governing rights and limitations under the
|
|
|
|
# License.
|
|
|
|
#
|
2010-07-29 12:37:25 -07:00
|
|
|
# The Original Code is the Tab View
|
2010-07-06 19:32:42 -07:00
|
|
|
#
|
2010-07-29 12:37:25 -07:00
|
|
|
# The Initial Developer of the Original Code is Mozilla Foundation.
|
|
|
|
# Portions created by the Initial Developer are Copyright (C) 2010
|
2010-07-06 19:32:42 -07:00
|
|
|
# the Initial Developer. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s):
|
|
|
|
# Raymond Lee <raymond@appcoast.com>
|
2010-08-11 14:48:02 -07:00
|
|
|
# Ian Gilman <ian@iangilman.com>
|
2011-02-02 17:43:32 -08:00
|
|
|
# Tim Taubert <tim.taubert@gmx.de>
|
2010-07-06 19:32:42 -07:00
|
|
|
#
|
|
|
|
# Alternatively, the contents of this file may be used under the terms of
|
|
|
|
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
# in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
# of those above. If you wish to allow use of your version of this file only
|
|
|
|
# under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
# use your version of this file under the terms of the MPL, indicate your
|
|
|
|
# decision by deleting the provisions above and replace them with the notice
|
|
|
|
# and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
# the provisions above, a recipient may use your version of this file under
|
|
|
|
# the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
#
|
|
|
|
# ***** END LICENSE BLOCK *****
|
|
|
|
|
2010-07-29 12:37:25 -07:00
|
|
|
let TabView = {
|
2010-08-10 14:23:53 -07:00
|
|
|
_deck: null,
|
2011-04-13 20:28:58 -07:00
|
|
|
_iframe: null,
|
2010-08-09 17:24:08 -07:00
|
|
|
_window: null,
|
2011-06-10 02:40:10 -07:00
|
|
|
_initialized: false,
|
2011-02-04 01:16:23 -08:00
|
|
|
_browserKeyHandlerInitialized: false,
|
2011-10-10 02:50:07 -07:00
|
|
|
_closedLastVisibleTabBeforeFrameInitialized: false,
|
2011-04-22 14:44:06 -07:00
|
|
|
_isFrameLoading: false,
|
|
|
|
_initFrameCallbacks: [],
|
2011-05-03 11:30:08 -07:00
|
|
|
_lastSessionGroupName: null,
|
2011-05-17 15:00:05 -07:00
|
|
|
PREF_BRANCH: "browser.panorama.",
|
|
|
|
PREF_FIRST_RUN: "browser.panorama.experienced_first_run",
|
|
|
|
PREF_STARTUP_PAGE: "browser.startup.page",
|
|
|
|
PREF_RESTORE_ENABLED_ONCE: "browser.panorama.session_restore_enabled_once",
|
2011-05-25 18:33:08 -07:00
|
|
|
GROUPS_IDENTIFIER: "tabview-groups",
|
2011-05-03 11:30:08 -07:00
|
|
|
VISIBILITY_IDENTIFIER: "tabview-visibility",
|
2010-11-12 10:37:34 -08:00
|
|
|
|
2010-08-11 12:17:57 -07:00
|
|
|
// ----------
|
|
|
|
get windowTitle() {
|
|
|
|
delete this.windowTitle;
|
|
|
|
let brandBundle = document.getElementById("bundle_brand");
|
|
|
|
let brandShortName = brandBundle.getString("brandShortName");
|
2010-08-13 18:51:32 -07:00
|
|
|
let title = gNavigatorBundle.getFormattedString("tabView2.title", [brandShortName]);
|
2010-08-11 12:17:57 -07:00
|
|
|
return this.windowTitle = title;
|
|
|
|
},
|
2011-02-16 08:06:54 -08:00
|
|
|
|
2011-02-04 01:16:23 -08:00
|
|
|
// ----------
|
2011-02-16 08:06:54 -08:00
|
|
|
get firstUseExperienced() {
|
2011-05-17 15:00:05 -07:00
|
|
|
let pref = this.PREF_FIRST_RUN;
|
|
|
|
if (Services.prefs.prefHasUserValue(pref))
|
|
|
|
return Services.prefs.getBoolPref(pref);
|
|
|
|
|
|
|
|
return false;
|
2011-02-16 08:06:54 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
set firstUseExperienced(val) {
|
2011-05-17 15:00:05 -07:00
|
|
|
Services.prefs.setBoolPref(this.PREF_FIRST_RUN, val);
|
2011-02-04 01:16:23 -08:00
|
|
|
},
|
2010-08-11 12:17:57 -07:00
|
|
|
|
2010-08-09 17:24:08 -07:00
|
|
|
// ----------
|
2011-05-17 15:00:05 -07:00
|
|
|
get sessionRestoreEnabledOnce() {
|
|
|
|
let pref = this.PREF_RESTORE_ENABLED_ONCE;
|
|
|
|
if (Services.prefs.prefHasUserValue(pref))
|
|
|
|
return Services.prefs.getBoolPref(pref);
|
2011-02-04 01:16:23 -08:00
|
|
|
|
2011-05-17 15:00:05 -07:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
set sessionRestoreEnabledOnce(val) {
|
|
|
|
Services.prefs.setBoolPref(this.PREF_RESTORE_ENABLED_ONCE, val);
|
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
init: function TabView_init() {
|
2011-10-04 09:53:56 -07:00
|
|
|
// disable the ToggleTabView command for popup windows
|
2011-10-14 22:21:49 -07:00
|
|
|
goSetCommandEnabled("Browser:ToggleTabView", window.toolbar.visible);
|
|
|
|
if (!window.toolbar.visible)
|
2011-10-04 09:53:56 -07:00
|
|
|
return;
|
|
|
|
|
2011-06-10 02:40:10 -07:00
|
|
|
if (this._initialized)
|
|
|
|
return;
|
|
|
|
|
2011-05-17 15:00:05 -07:00
|
|
|
if (this.firstUseExperienced) {
|
2011-02-04 01:16:23 -08:00
|
|
|
if ((gBrowser.tabs.length - gBrowser.visibleTabs.length) > 0)
|
|
|
|
this._setBrowserKeyHandlers();
|
|
|
|
|
|
|
|
// ___ visibility
|
|
|
|
let sessionstore =
|
|
|
|
Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
|
|
|
|
|
2011-05-25 18:33:08 -07:00
|
|
|
let data = sessionstore.getWindowValue(window, this.VISIBILITY_IDENTIFIER);
|
2011-02-04 01:16:23 -08:00
|
|
|
if (data && data == "true") {
|
|
|
|
this.show();
|
|
|
|
} else {
|
2011-05-25 18:33:08 -07:00
|
|
|
try {
|
|
|
|
data = sessionstore.getWindowValue(window, this.GROUPS_IDENTIFIER);
|
|
|
|
if (data) {
|
|
|
|
let parsedData = JSON.parse(data);
|
2011-06-06 20:52:30 -07:00
|
|
|
this.updateGroupNumberBroadcaster(parsedData.totalNumber || 1);
|
2011-05-25 18:33:08 -07:00
|
|
|
}
|
|
|
|
} catch (e) { }
|
2011-02-04 01:16:23 -08:00
|
|
|
|
2011-05-25 18:33:08 -07:00
|
|
|
let self = this;
|
|
|
|
// if a tab is changed from hidden to unhidden and the iframe is not
|
2011-02-04 01:16:23 -08:00
|
|
|
// initialized, load the iframe and setup the tab.
|
2011-10-10 02:50:07 -07:00
|
|
|
this._tabShowEventListener = function(event) {
|
2011-02-04 01:16:23 -08:00
|
|
|
if (!self._window)
|
|
|
|
self._initFrame(function() {
|
|
|
|
self._window.UI.onTabSelect(gBrowser.selectedTab);
|
2011-10-10 02:50:07 -07:00
|
|
|
if (self._closedLastVisibleTabBeforeFrameInitialized) {
|
|
|
|
self._closedLastVisibleTabBeforeFrameInitialized = false;
|
|
|
|
self._window.UI.showTabView(false);
|
|
|
|
}
|
2011-02-04 01:16:23 -08:00
|
|
|
});
|
|
|
|
};
|
2011-10-10 02:50:07 -07:00
|
|
|
this._tabCloseEventListener = function(event) {
|
|
|
|
if (!self._window && gBrowser.visibleTabs.length == 0)
|
|
|
|
self._closedLastVisibleTabBeforeFrameInitialized = true;
|
|
|
|
};
|
|
|
|
gBrowser.tabContainer.addEventListener(
|
|
|
|
"TabShow", this._tabShowEventListener, false);
|
2011-02-04 01:16:23 -08:00
|
|
|
gBrowser.tabContainer.addEventListener(
|
2011-10-10 02:50:07 -07:00
|
|
|
"TabClose", this._tabCloseEventListener, false);
|
2011-02-04 01:16:23 -08:00
|
|
|
}
|
|
|
|
}
|
2011-05-17 15:00:05 -07:00
|
|
|
|
|
|
|
Services.prefs.addObserver(this.PREF_BRANCH, this, false);
|
2011-06-10 02:40:10 -07:00
|
|
|
|
|
|
|
this._initialized = true;
|
2011-02-04 01:16:23 -08:00
|
|
|
},
|
2010-08-09 17:24:08 -07:00
|
|
|
|
2011-02-04 01:16:23 -08:00
|
|
|
// ----------
|
|
|
|
// Observes topic changes.
|
|
|
|
observe: function TabView_observe(subject, topic, data) {
|
2011-05-17 15:00:05 -07:00
|
|
|
if (data == this.PREF_FIRST_RUN && this.firstUseExperienced) {
|
2011-02-16 08:06:54 -08:00
|
|
|
this._addToolbarButton();
|
2011-05-17 15:00:05 -07:00
|
|
|
this.enableSessionRestore();
|
2011-02-04 01:16:23 -08:00
|
|
|
}
|
|
|
|
},
|
2011-01-17 18:44:50 -08:00
|
|
|
|
2011-02-04 01:16:23 -08:00
|
|
|
// ----------
|
|
|
|
// Uninitializes TabView.
|
|
|
|
uninit: function TabView_uninit() {
|
2011-06-10 02:40:10 -07:00
|
|
|
if (!this._initialized)
|
|
|
|
return;
|
|
|
|
|
2011-05-17 15:00:05 -07:00
|
|
|
Services.prefs.removeObserver(this.PREF_BRANCH, this);
|
|
|
|
|
2011-10-10 02:50:07 -07:00
|
|
|
if (this._tabShowEventListener)
|
2011-02-04 01:16:23 -08:00
|
|
|
gBrowser.tabContainer.removeEventListener(
|
2011-10-10 02:50:07 -07:00
|
|
|
"TabShow", this._tabShowEventListener, false);
|
|
|
|
|
|
|
|
if (this._tabCloseEventListener)
|
|
|
|
gBrowser.tabContainer.removeEventListener(
|
|
|
|
"TabClose", this._tabCloseEventListener, false);
|
2011-06-10 02:40:10 -07:00
|
|
|
|
|
|
|
this._initialized = false;
|
2010-08-09 17:24:08 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
2010-08-10 14:23:53 -07:00
|
|
|
// Creates the frame and calls the callback once it's loaded.
|
|
|
|
// If the frame already exists, calls the callback immediately.
|
|
|
|
_initFrame: function TabView__initFrame(callback) {
|
2011-04-22 14:44:06 -07:00
|
|
|
let hasCallback = typeof callback == "function";
|
|
|
|
|
2011-10-04 09:53:56 -07:00
|
|
|
// prevent frame to be initialized for popup windows
|
|
|
|
if (!window.toolbar.visible)
|
|
|
|
return;
|
|
|
|
|
2010-08-10 14:23:53 -07:00
|
|
|
if (this._window) {
|
2011-04-22 14:44:06 -07:00
|
|
|
if (hasCallback)
|
2010-08-10 14:23:53 -07:00
|
|
|
callback();
|
2011-04-22 14:44:06 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasCallback)
|
|
|
|
this._initFrameCallbacks.push(callback);
|
|
|
|
|
|
|
|
if (this._isFrameLoading)
|
|
|
|
return;
|
2010-11-12 10:37:34 -08:00
|
|
|
|
2011-04-22 14:44:06 -07:00
|
|
|
this._isFrameLoading = true;
|
2010-11-12 10:37:34 -08:00
|
|
|
|
2011-04-22 14:44:06 -07:00
|
|
|
// ___ find the deck
|
|
|
|
this._deck = document.getElementById("tab-view-deck");
|
2010-11-12 10:37:34 -08:00
|
|
|
|
2011-04-22 14:44:06 -07:00
|
|
|
// ___ create the frame
|
|
|
|
this._iframe = document.createElement("iframe");
|
|
|
|
this._iframe.id = "tab-view";
|
|
|
|
this._iframe.setAttribute("transparent", "true");
|
2011-11-30 21:53:44 -08:00
|
|
|
this._iframe.setAttribute("tooltip", "tab-view-tooltip");
|
2011-04-22 14:44:06 -07:00
|
|
|
this._iframe.flex = 1;
|
2010-08-10 14:23:53 -07:00
|
|
|
|
2011-04-22 14:44:06 -07:00
|
|
|
let self = this;
|
|
|
|
|
|
|
|
window.addEventListener("tabviewframeinitialized", function onInit() {
|
|
|
|
window.removeEventListener("tabviewframeinitialized", onInit, false);
|
|
|
|
|
|
|
|
self._isFrameLoading = false;
|
|
|
|
self._window = self._iframe.contentWindow;
|
|
|
|
self._setBrowserKeyHandlers();
|
|
|
|
|
|
|
|
if (self._tabShowEventListener) {
|
2010-11-12 10:37:34 -08:00
|
|
|
gBrowser.tabContainer.removeEventListener(
|
2011-10-10 02:50:07 -07:00
|
|
|
"TabShow", self._tabShowEventListener, false);
|
2011-04-22 14:44:06 -07:00
|
|
|
self._tabShowEventListener = null;
|
2010-11-12 10:37:34 -08:00
|
|
|
}
|
2011-10-10 02:50:07 -07:00
|
|
|
if (self._tabCloseEventListener) {
|
|
|
|
gBrowser.tabContainer.removeEventListener(
|
|
|
|
"TabClose", self._tabCloseEventListener, false);
|
|
|
|
self._tabCloseEventListener = null;
|
|
|
|
}
|
2011-04-22 14:44:06 -07:00
|
|
|
self._initFrameCallbacks.forEach(function (cb) cb());
|
|
|
|
self._initFrameCallbacks = [];
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
this._iframe.setAttribute("src", "chrome://browser/content/tabview.html");
|
|
|
|
this._deck.appendChild(this._iframe);
|
2011-11-30 21:53:44 -08:00
|
|
|
|
|
|
|
// ___ create tooltip
|
|
|
|
let tooltip = document.createElement("tooltip");
|
|
|
|
tooltip.id = "tab-view-tooltip";
|
|
|
|
tooltip.setAttribute("onpopupshowing", "return TabView.fillInTooltip(document.tooltipNode);");
|
|
|
|
document.getElementById("mainPopupSet").appendChild(tooltip);
|
2010-08-07 15:32:17 -07:00
|
|
|
},
|
2010-11-12 10:37:34 -08:00
|
|
|
|
2010-09-21 14:56:52 -07:00
|
|
|
// ----------
|
|
|
|
getContentWindow: function TabView_getContentWindow() {
|
|
|
|
return this._window;
|
|
|
|
},
|
2010-08-07 15:32:17 -07:00
|
|
|
|
2010-08-09 17:24:08 -07:00
|
|
|
// ----------
|
2011-04-13 20:28:58 -07:00
|
|
|
isVisible: function TabView_isVisible() {
|
|
|
|
return (this._deck ? this._deck.selectedPanel == this._iframe : false);
|
2010-08-06 07:17:01 -07:00
|
|
|
},
|
|
|
|
|
2010-08-09 17:24:08 -07:00
|
|
|
// ----------
|
2011-10-10 00:04:27 -07:00
|
|
|
show: function TabView_show() {
|
2010-08-10 14:23:53 -07:00
|
|
|
if (this.isVisible())
|
|
|
|
return;
|
2011-04-11 01:15:38 -07:00
|
|
|
|
|
|
|
let self = this;
|
2010-08-10 14:23:53 -07:00
|
|
|
this._initFrame(function() {
|
2011-04-11 01:15:38 -07:00
|
|
|
self._window.UI.showTabView(true);
|
2010-08-10 14:23:53 -07:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
2011-10-10 00:04:27 -07:00
|
|
|
hide: function TabView_hide() {
|
2010-08-10 14:23:53 -07:00
|
|
|
if (!this.isVisible())
|
|
|
|
return;
|
|
|
|
|
2011-04-11 01:15:38 -07:00
|
|
|
this._window.UI.exit();
|
2010-08-10 14:23:53 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
2011-10-10 00:04:27 -07:00
|
|
|
toggle: function TabView_toggle() {
|
2010-08-10 14:23:53 -07:00
|
|
|
if (this.isVisible())
|
|
|
|
this.hide();
|
|
|
|
else
|
|
|
|
this.show();
|
2010-07-06 19:32:42 -07:00
|
|
|
},
|
|
|
|
|
2010-08-09 17:24:08 -07:00
|
|
|
// ----------
|
2011-10-10 00:04:27 -07:00
|
|
|
updateContextMenu: function TabView_updateContextMenu(tab, popup) {
|
2010-08-19 13:23:18 -07:00
|
|
|
let separator = document.getElementById("context_tabViewNamedGroups");
|
2010-08-08 10:28:24 -07:00
|
|
|
let isEmpty = true;
|
|
|
|
|
2010-08-19 13:23:18 -07:00
|
|
|
while (popup.firstChild && popup.firstChild != separator)
|
|
|
|
popup.removeChild(popup.firstChild);
|
2010-08-06 07:17:01 -07:00
|
|
|
|
2010-08-08 10:28:24 -07:00
|
|
|
let self = this;
|
2010-08-10 14:23:53 -07:00
|
|
|
this._initFrame(function() {
|
2011-01-11 00:20:08 -08:00
|
|
|
let activeGroup = tab._tabViewTabItem.parent;
|
2010-08-10 14:23:53 -07:00
|
|
|
let groupItems = self._window.GroupItems.groupItems;
|
2010-08-19 13:23:18 -07:00
|
|
|
|
2010-09-10 07:40:27 -07:00
|
|
|
groupItems.forEach(function(groupItem) {
|
|
|
|
// if group has title, it's not hidden and there is no active group or
|
|
|
|
// the active group id doesn't match the group id, a group menu item
|
|
|
|
// would be added.
|
|
|
|
if (groupItem.getTitle().length > 0 && !groupItem.hidden &&
|
2010-08-10 14:23:53 -07:00
|
|
|
(!activeGroup || activeGroup.id != groupItem.id)) {
|
|
|
|
let menuItem = self._createGroupMenuItem(groupItem);
|
2010-08-19 13:23:18 -07:00
|
|
|
popup.insertBefore(menuItem, separator);
|
2010-08-10 14:23:53 -07:00
|
|
|
isEmpty = false;
|
|
|
|
}
|
|
|
|
});
|
2010-08-19 13:23:18 -07:00
|
|
|
separator.hidden = isEmpty;
|
2010-08-08 10:28:24 -07:00
|
|
|
});
|
2010-08-06 07:17:01 -07:00
|
|
|
},
|
|
|
|
|
2010-08-09 17:24:08 -07:00
|
|
|
// ----------
|
2011-02-04 01:16:23 -08:00
|
|
|
_createGroupMenuItem: function TabView__createGroupMenuItem(groupItem) {
|
2010-08-06 07:17:01 -07:00
|
|
|
let menuItem = document.createElement("menuitem")
|
2010-08-08 10:03:11 -07:00
|
|
|
menuItem.setAttribute("label", groupItem.getTitle());
|
2010-08-06 12:52:14 -07:00
|
|
|
menuItem.setAttribute(
|
|
|
|
"oncommand",
|
2010-08-08 10:03:11 -07:00
|
|
|
"TabView.moveTabTo(TabContextMenu.contextTab,'" + groupItem.id + "')");
|
2010-08-06 07:17:01 -07:00
|
|
|
|
|
|
|
return menuItem;
|
|
|
|
},
|
|
|
|
|
2010-08-09 17:24:08 -07:00
|
|
|
// ----------
|
2011-02-04 01:16:23 -08:00
|
|
|
moveTabTo: function TabView_moveTabTo(tab, groupItemId) {
|
|
|
|
if (this._window) {
|
2010-08-09 17:24:08 -07:00
|
|
|
this._window.GroupItems.moveTabToGroupItem(tab, groupItemId);
|
2011-02-04 01:16:23 -08:00
|
|
|
} else {
|
|
|
|
let self = this;
|
|
|
|
this._initFrame(function() {
|
|
|
|
self._window.GroupItems.moveTabToGroupItem(tab, groupItemId);
|
|
|
|
});
|
|
|
|
}
|
2010-08-09 17:24:08 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
2010-08-11 12:17:57 -07:00
|
|
|
// Adds new key commands to the browser, for invoking the Tab Candy UI
|
|
|
|
// and for switching between groups of tabs when outside of the Tab Candy UI.
|
2011-02-04 01:16:23 -08:00
|
|
|
_setBrowserKeyHandlers: function TabView__setBrowserKeyHandlers() {
|
|
|
|
if (this._browserKeyHandlerInitialized)
|
|
|
|
return;
|
2010-08-09 17:24:08 -07:00
|
|
|
|
2011-02-04 01:16:23 -08:00
|
|
|
this._browserKeyHandlerInitialized = true;
|
|
|
|
|
|
|
|
let self = this;
|
2010-08-09 17:24:08 -07:00
|
|
|
window.addEventListener("keypress", function(event) {
|
2011-02-04 01:16:23 -08:00
|
|
|
if (self.isVisible() ||
|
|
|
|
(gBrowser.tabs.length - gBrowser.visibleTabs.length) == 0)
|
2010-08-09 17:24:08 -07:00
|
|
|
return;
|
|
|
|
|
2010-08-11 12:17:57 -07:00
|
|
|
let charCode = event.charCode;
|
2010-08-09 17:24:08 -07:00
|
|
|
// Control (+ Shift) + `
|
|
|
|
if (event.ctrlKey && !event.metaKey && !event.altKey &&
|
|
|
|
(charCode == 96 || charCode == 126)) {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
|
2010-08-10 14:23:53 -07:00
|
|
|
self._initFrame(function() {
|
2011-01-27 10:15:18 -08:00
|
|
|
let groupItems = self._window.GroupItems;
|
|
|
|
let tabItem = groupItems.getNextGroupItemTab(event.shiftKey);
|
|
|
|
if (!tabItem)
|
|
|
|
return;
|
|
|
|
|
2011-06-17 05:07:59 -07:00
|
|
|
// Switch to the new tab
|
2011-01-27 10:15:18 -08:00
|
|
|
window.gBrowser.selectedTab = tabItem.tab;
|
2010-08-10 14:23:53 -07:00
|
|
|
});
|
2010-08-09 17:24:08 -07:00
|
|
|
}
|
|
|
|
}, true);
|
2010-11-29 21:03:51 -08:00
|
|
|
},
|
2011-02-02 17:43:32 -08:00
|
|
|
|
2010-11-29 21:03:51 -08:00
|
|
|
// ----------
|
|
|
|
// Prepares the tab view for undo close tab.
|
2011-10-10 00:04:27 -07:00
|
|
|
prepareUndoCloseTab: function TabView_prepareUndoCloseTab(blankTabToRemove) {
|
2011-02-02 17:43:32 -08:00
|
|
|
if (this._window) {
|
2010-11-29 21:03:51 -08:00
|
|
|
this._window.UI.restoredClosedTab = true;
|
2011-02-02 17:43:32 -08:00
|
|
|
|
2011-06-17 09:47:43 -07:00
|
|
|
if (blankTabToRemove && blankTabToRemove._tabViewTabItem)
|
|
|
|
blankTabToRemove._tabViewTabItem.isRemovedAfterRestore = true;
|
2011-02-02 17:43:32 -08:00
|
|
|
}
|
2011-01-27 10:15:18 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Cleans up the tab view after undo close tab.
|
2011-10-10 00:04:27 -07:00
|
|
|
afterUndoCloseTab: function TabView_afterUndoCloseTab() {
|
2011-01-27 10:15:18 -08:00
|
|
|
if (this._window)
|
|
|
|
this._window.UI.restoredClosedTab = false;
|
2011-02-04 01:16:23 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// On move to group pop showing.
|
|
|
|
moveToGroupPopupShowing: function TabView_moveToGroupPopupShowing(event) {
|
2011-04-06 14:03:41 -07:00
|
|
|
// Update the context menu only if Panorama was already initialized or if
|
|
|
|
// there are hidden tabs.
|
|
|
|
let numHiddenTabs = gBrowser.tabs.length - gBrowser.visibleTabs.length;
|
|
|
|
if (this._window || numHiddenTabs > 0)
|
2011-02-04 01:16:23 -08:00
|
|
|
this.updateContextMenu(TabContextMenu.contextTab, event.target);
|
2011-02-16 08:06:54 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: _addToolbarButton
|
|
|
|
// Adds the TabView button to the TabsToolbar.
|
|
|
|
_addToolbarButton: function TabView__addToolbarButton() {
|
|
|
|
let buttonId = "tabview-button";
|
|
|
|
|
|
|
|
if (document.getElementById(buttonId))
|
|
|
|
return;
|
|
|
|
|
|
|
|
let toolbar = document.getElementById("TabsToolbar");
|
|
|
|
let currentSet = toolbar.currentSet.split(",");
|
|
|
|
|
|
|
|
let alltabsPos = currentSet.indexOf("alltabs-button");
|
|
|
|
if (-1 == alltabsPos)
|
|
|
|
return;
|
|
|
|
|
|
|
|
currentSet[alltabsPos] += "," + buttonId;
|
|
|
|
currentSet = currentSet.join(",");
|
|
|
|
toolbar.currentSet = currentSet;
|
|
|
|
toolbar.setAttribute("currentset", currentSet);
|
|
|
|
document.persist(toolbar.id, "currentset");
|
2011-05-17 15:00:05 -07:00
|
|
|
},
|
|
|
|
|
2011-05-25 18:33:08 -07:00
|
|
|
// ----------
|
|
|
|
// Function: updateGroupNumberBroadcaster
|
|
|
|
// Updates the group number broadcaster.
|
|
|
|
updateGroupNumberBroadcaster: function TabView_updateGroupNumberBroadcaster(number) {
|
|
|
|
let groupsNumber = document.getElementById("tabviewGroupsNumber");
|
|
|
|
groupsNumber.setAttribute("groups", number);
|
|
|
|
},
|
|
|
|
|
2011-05-17 15:00:05 -07:00
|
|
|
// ----------
|
|
|
|
// Function: enableSessionRestore
|
|
|
|
// Enables automatic session restore when the browser is started. Does
|
|
|
|
// nothing if we already did that once in the past.
|
2011-10-10 00:04:27 -07:00
|
|
|
enableSessionRestore: function TabView_enableSessionRestore() {
|
2011-05-17 15:00:05 -07:00
|
|
|
if (!this._window || !this.firstUseExperienced)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// do nothing if we already enabled session restore once
|
|
|
|
if (this.sessionRestoreEnabledOnce)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.sessionRestoreEnabledOnce = true;
|
|
|
|
|
2011-07-13 10:36:13 -07:00
|
|
|
// enable session restore if necessary
|
|
|
|
if (Services.prefs.getIntPref(this.PREF_STARTUP_PAGE) != 3) {
|
|
|
|
Services.prefs.setIntPref(this.PREF_STARTUP_PAGE, 3);
|
|
|
|
|
|
|
|
// show banner
|
|
|
|
this._window.UI.notifySessionRestoreEnabled();
|
|
|
|
}
|
2011-11-30 21:53:44 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: fillInTooltip
|
|
|
|
// Fills in the tooltip text.
|
|
|
|
fillInTooltip: function fillInTooltip(tipElement) {
|
|
|
|
let retVal = false;
|
|
|
|
let titleText = null;
|
|
|
|
let direction = tipElement.ownerDocument.dir;
|
|
|
|
|
|
|
|
while (!titleText && tipElement) {
|
|
|
|
if (tipElement.nodeType == Node.ELEMENT_NODE)
|
|
|
|
titleText = tipElement.getAttribute("title");
|
|
|
|
tipElement = tipElement.parentNode;
|
|
|
|
}
|
|
|
|
let tipNode = document.getElementById("tab-view-tooltip");
|
|
|
|
tipNode.style.direction = direction;
|
|
|
|
|
|
|
|
if (titleText) {
|
|
|
|
tipNode.setAttribute("label", titleText);
|
|
|
|
retVal = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retVal;
|
2010-07-06 19:32:42 -07:00
|
|
|
}
|
|
|
|
};
|