Skip to content

Commit

Permalink
Merge pull mozilla#19 - Tab groups
Browse files Browse the repository at this point in the history
  • Loading branch information
xabolcs committed Aug 6, 2013
2 parents b526e1f + e11907e commit b0b5072
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 0 deletions.
13 changes: 13 additions & 0 deletions extension/chrome/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ get tabTitle() {
return tabbrowser.mCurrentBrowser.contentTitle;
},

get tabGroupTitle() {
try
{
return nightlyApp.getTabGroupTitle(window);
}
catch (e) { }
},

init: function()
{
var brandbundle = document.getElementById("bundle_brand");
Expand All @@ -33,6 +41,11 @@ init: function()

tabbrowser.updateTitlebar = nightly.updateTitlebar;
tabbrowser.addEventListener("DOMTitleChanged", nightly.updateTitlebar, false);

try { // import tabGroupTitle functionality for titlebar customization
Components.utils.import("resource://nightly/tabGroupTitle.jsm", nightlyApp);
}
catch(e) { Components.utils.reportError(e); }
},

openURL: function(url)
Expand Down
1 change: 1 addition & 0 deletions extension/chrome/content/nightly.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ variables: {
get compiler() this.appInfo.XPCOMABI.split("-")[1],
get defaulttitle() { return nightlyApp.defaultTitle; },
get tabtitle() { return nightlyApp.tabTitle; },
get tabgroup() { return nightlyApp.tabGroupTitle; },
profile: null,
toolkit: "cairo",
flags: ""
Expand Down
1 change: 1 addition & 0 deletions extension/chrome/content/titlebar/customize.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ init: function(aEvent)

paneTitle.addVariable("DefaultTitle");
paneTitle.addVariable("TabTitle");
paneTitle.addVariable("TabGroup");
paneTitle.addVariable("AppID");
paneTitle.addVariable("Vendor");
paneTitle.addVariable("Name");
Expand Down
1 change: 1 addition & 0 deletions extension/chrome/locale/en-US/variables.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ variable.Processor.description=Compilation Processor
variable.Compiler.description=Compiler
variable.DefaultTitle.description=Default Application Title
variable.TabTitle.description=Current Tab's Title
variable.TabGroup.description=Current Tab Group
variable.Profile.description=Current Profile
variable.Toolkit.description=Graphics Toolkit
75 changes: 75 additions & 0 deletions extension/modules/tabGroupTitle.jsm
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
var EXPORTED_SYMBOLS = ["getTabGroupTitle"];

const Cc = Components.classes;
const Ci = Components.interfaces;

const GROUP_DATA_IDENTIFIER = "tabview-group";

let sstore = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);


/**
* Simply retrieves the active tabgroup's title from SessionStore
*/
function getActiveGroupName(win) {
let data = "", groupTitle = "";
try {
data = sstore.getWindowValue(win, win.TabView.GROUPS_IDENTIFIER);
if (data) {
let parsedData = {};
parsedData = JSON.parse(data);
let activeGroupId = parsedData.activeGroupId;
data = sstore.getWindowValue(win, GROUP_DATA_IDENTIFIER);
parsedData = JSON.parse(data);
groupTitle = parsedData[activeGroupId].title;
}
} catch (e) { }

return groupTitle;
}

/**
* Calculates Tab Group's title for nightlyApp
* @param {nsIDOMWindow} win A window which contains nightly.
*
* In Gecko 1.x title is set to "Undefined" as in other Apps
* Before FF10 title is managed by TabView
* After that we manages the title: using SessionStore and other borrowed code to generate
*/
function getTabGroupTitle(win) {
let nightlyApp = win.nightlyApp;
let TabView = win.TabView;

// TabView isn't implemented
if (!("TabView" in win))
return;

// If we are before Bug 682996,
// use TabView's own implementation except it is null
if (typeof(TabView.getActiveGroupName) === "function")
return TabView.getActiveGroupName() || "";

// TabView isn't initialized
if (!TabView._window) {
return getActiveGroupName(win);
}

// We get the active group this way, instead of querying
// GroupItems.getActiveGroupItem() because the tabSelect event
// will not have happened by the time the browser tries to
// update the title.
let groupItem = null;
let activeTab = win.gBrowser.selectedTab;
let activeTabItem = activeTab._tabViewTabItem;

if (activeTab.pinned) {
// It's an app tab, so it won't have a .tabItem. However, its .parent
// will already be set as the active group.
groupItem = TabView._window.GroupItems.getActiveGroupItem();
} else if (activeTabItem) {
groupItem = activeTabItem.parent;
}

// groupItem may still be null, if the active tab is an orphan.
return groupItem ? groupItem.getTitle() : "";
}

0 comments on commit b0b5072

Please sign in to comment.