2009-04-27 10:41:13 +00:00
|
|
|
const XULAppInfo = Components.classes['@mozilla.org/xre/app-info;1']
|
|
|
|
.getService(Components.interfaces.nsIXULAppInfo);
|
|
|
|
const comparator = Components.classes['@mozilla.org/xpcom/version-comparator;1']
|
|
|
|
.getService(Components.interfaces.nsIVersionComparator);
|
2009-07-27 07:22:56 +00:00
|
|
|
var Prefs = Components
|
|
|
|
.classes['@mozilla.org/preferences;1']
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
|
|
|
|
var gGroupBookmarkRadio,
|
|
|
|
gGroupBookmarkUnderParent,
|
|
|
|
gGroupBookmarkPref,
|
|
|
|
gGroupBookmarkReplace;
|
|
|
|
|
|
|
|
function ensureGroupBookmarkItems()
|
|
|
|
{
|
|
|
|
if (gGroupBookmarkPref) return;
|
|
|
|
|
|
|
|
gGroupBookmarkRadio = document.getElementById('openGroupBookmark-radiogroup');
|
|
|
|
gGroupBookmarkPref = document.getElementById('extensions.treestyletab.openGroupBookmark.behavior');
|
|
|
|
gGroupBookmarkUnderParent = document.getElementById('openGroupBookmark.underParent-check');
|
|
|
|
var bookmarkReplaceKey = 'browser.tabs.loadFolderAndReplace';
|
|
|
|
gGroupBookmarkReplace = document.getElementById(bookmarkReplaceKey);
|
|
|
|
try {
|
|
|
|
gGroupBookmarkReplace.value = Prefs.getBoolPref(bookmarkReplaceKey);
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
Prefs.setBoolPref(bookmarkReplaceKey, gGroupBookmarkReplace.value != 'false');
|
|
|
|
}
|
|
|
|
}
|
2009-04-27 10:41:13 +00:00
|
|
|
|
2009-04-28 02:10:49 +00:00
|
|
|
function init()
|
|
|
|
{
|
2009-07-27 07:22:56 +00:00
|
|
|
ensureGroupBookmarkItems();
|
2009-07-22 03:28:52 +00:00
|
|
|
// sizeToContent();
|
2009-04-28 02:10:49 +00:00
|
|
|
}
|
|
|
|
|
2009-04-27 10:41:13 +00:00
|
|
|
|
2009-07-24 11:00:53 +00:00
|
|
|
var gOpenLinkInTabScale,
|
|
|
|
gLoadLocationBarToNewTabScale,
|
|
|
|
gLoadLocationBarToChildTabScale,
|
2009-04-14 08:08:28 +00:00
|
|
|
gLastStateIsVertical;
|
2007-10-25 22:59:34 +00:00
|
|
|
var gTabbarPlacePositionInitialized = false;
|
2007-10-20 17:52:42 +00:00
|
|
|
|
2007-10-28 16:15:53 +00:00
|
|
|
function initTabPane()
|
2007-10-20 17:52:42 +00:00
|
|
|
{
|
2009-07-24 11:00:53 +00:00
|
|
|
gOpenLinkInTabScale = new ScaleSet(
|
|
|
|
['extensions.treestyletab.openOuterLinkInNewTab',
|
|
|
|
'extensions.treestyletab.openAnyLinkInNewTab'],
|
|
|
|
'openLinkInNewTab-scale',
|
|
|
|
'openLinkInNewTab-labels'
|
|
|
|
);
|
|
|
|
gLoadLocationBarToNewTabScale = new ScaleSet(
|
|
|
|
['extensions.treestyletab.urlbar.loadDifferentDomainToNewTab',
|
|
|
|
'extensions.treestyletab.urlbar.loadSameDomainToNewTab'],
|
|
|
|
'loadLocationBarToNewTab-scale',
|
|
|
|
'loadLocationBarToNewTab-labels'
|
|
|
|
);
|
|
|
|
gLoadLocationBarToChildTabScale = new ScaleSet(
|
|
|
|
['extensions.treestyletab.urlbar.loadSameDomainToNewTab.asChild',
|
|
|
|
'extensions.treestyletab.urlbar.loadDifferentDomainToNewTab.asChild'],
|
|
|
|
'loadLocationBarToChildTab-scale',
|
|
|
|
'loadLocationBarToChildTab-labels'
|
|
|
|
);
|
2007-10-28 16:15:53 +00:00
|
|
|
|
2008-03-03 08:26:51 +00:00
|
|
|
|
|
|
|
var restrictionKey = 'browser.link.open_newwindow.restriction';
|
|
|
|
var restriction = document.getElementById(restrictionKey);
|
|
|
|
try {
|
|
|
|
restriction.value = Prefs.getIntPref(restrictionKey);
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
Prefs.setIntPref(restrictionKey, parseInt(restriction.value));
|
|
|
|
}
|
|
|
|
|
2009-04-14 08:08:28 +00:00
|
|
|
gLastStateIsVertical = document.getElementById('extensions.treestyletab.tabbar.position-radiogroup').value;
|
|
|
|
gLastStateIsVertical = gLastStateIsVertical == 'left' || gLastStateIsVertical == 'right';
|
2007-10-20 17:52:42 +00:00
|
|
|
}
|
|
|
|
|
2009-07-27 07:22:56 +00:00
|
|
|
function onSyncGroupBookmarkRadioToPref()
|
2007-10-20 17:52:42 +00:00
|
|
|
{
|
2009-07-27 07:22:56 +00:00
|
|
|
ensureGroupBookmarkItems();
|
|
|
|
var behavior = parseInt(gGroupBookmarkRadio.value);
|
|
|
|
if (gGroupBookmarkUnderParent.checked) behavior += 256;
|
2009-06-18 08:57:54 +00:00
|
|
|
|
2009-07-27 07:22:56 +00:00
|
|
|
if (behavior & 1)
|
|
|
|
gGroupBookmarkUnderParent.removeAttribute('disabled');
|
2009-06-18 08:57:54 +00:00
|
|
|
else
|
2009-07-27 07:22:56 +00:00
|
|
|
gGroupBookmarkUnderParent.setAttribute('disabled', true);
|
|
|
|
|
|
|
|
return behavior;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onSyncPrefToGroupBookmarkRadio()
|
|
|
|
{
|
|
|
|
ensureGroupBookmarkItems();
|
|
|
|
var behavior = gGroupBookmarkPref.value & 1 ? 1 :
|
|
|
|
gGroupBookmarkPref.value & 2 ? 2 :
|
|
|
|
gGroupBookmarkPref.value & 4 ? 4 :
|
|
|
|
0;
|
|
|
|
gGroupBookmarkUnderParent.checked = gGroupBookmarkPref.value & 256 ? true : false ;
|
|
|
|
return behavior;
|
2007-10-20 17:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-25 22:59:34 +00:00
|
|
|
function onChangeTabbarPosition(aOnChange)
|
2007-10-22 03:08:14 +00:00
|
|
|
{
|
2007-10-23 06:05:44 +00:00
|
|
|
var pos = document.getElementById('extensions.treestyletab.tabbar.position-radiogroup').value;
|
2009-05-11 07:19:37 +00:00
|
|
|
var invertTab = document.getElementById('extensions.treestyletab.tabbar.invertTab-check');
|
|
|
|
var invertTabContents = document.getElementById('extensions.treestyletab.tabbar.invertTabContents-check');
|
|
|
|
var invertClosebox = document.getElementById('extensions.treestyletab.tabbar.invertClosebox-check');
|
|
|
|
|
|
|
|
invertTab.disabled = pos != 'right';
|
2009-05-11 23:19:11 +00:00
|
|
|
// invertTabContents.disabled = pos != 'right';
|
2009-05-11 07:19:37 +00:00
|
|
|
invertClosebox.setAttribute('label',
|
|
|
|
invertClosebox.getAttribute(
|
|
|
|
(pos == 'right' && invertTabContents.checked) ?
|
|
|
|
'label-right' :
|
|
|
|
'label-left'
|
|
|
|
)
|
|
|
|
);
|
2009-05-11 23:19:11 +00:00
|
|
|
if (invertClosebox.checked != document.getElementById('extensions.treestyletab.tabbar.invertClosebox').defaultValue)
|
|
|
|
invertClosebox.removeAttribute('collapsed');
|
|
|
|
else
|
|
|
|
invertClosebox.setAttribute('collapsed', true);
|
2007-10-25 22:59:34 +00:00
|
|
|
|
2009-07-08 00:17:36 +00:00
|
|
|
var indentCheckH = document.getElementById('extensions.treestyletab.enableSubtreeIndent.horizontal-check');
|
|
|
|
var indentCheckV = document.getElementById('extensions.treestyletab.enableSubtreeIndent.vertical-check');
|
|
|
|
var collapseCheckH = document.getElementById('extensions.treestyletab.allowSubtreeCollapseExpand.horizontal-check');
|
|
|
|
var collapseCheckV = document.getElementById('extensions.treestyletab.allowSubtreeCollapseExpand.vertical-check');
|
2009-07-22 02:22:00 +00:00
|
|
|
var hideNewTabCheckH = document.getElementById('extensions.treestyletab.tabbar.hideNewTabButton.horizontal-check');
|
|
|
|
var hideNewTabCheckV = document.getElementById('extensions.treestyletab.tabbar.hideNewTabButton.vertical-check');
|
|
|
|
var hideAllTabsCheckH = document.getElementById('extensions.treestyletab.tabbar.hideAlltabsButton.horizontal-check');
|
|
|
|
var hideAllTabsCheckV = document.getElementById('extensions.treestyletab.tabbar.hideAlltabsButton.vertical-check');
|
|
|
|
|
|
|
|
var newTabAvailable = comparator.compare(XULAppInfo.version, '3.1b3') >= 0;
|
|
|
|
if (!newTabAvailable) {
|
|
|
|
hideNewTabCheckH.setAttribute('collapsed', true);
|
|
|
|
hideNewTabCheckV.setAttribute('collapsed', true);
|
|
|
|
}
|
2007-11-09 05:48:39 +00:00
|
|
|
|
2007-11-09 04:17:41 +00:00
|
|
|
if (pos == 'left' || pos == 'right') {
|
2009-07-08 00:17:36 +00:00
|
|
|
indentCheckH.setAttribute('collapsed', true);
|
|
|
|
indentCheckV.removeAttribute('collapsed');
|
|
|
|
collapseCheckH.setAttribute('collapsed', true);
|
|
|
|
collapseCheckV.removeAttribute('collapsed');
|
2009-07-22 02:22:00 +00:00
|
|
|
if (newTabAvailable) {
|
|
|
|
hideNewTabCheckH.setAttribute('collapsed', true);
|
|
|
|
hideNewTabCheckV.removeAttribute('collapsed');
|
|
|
|
}
|
|
|
|
hideAllTabsCheckH.setAttribute('collapsed', true);
|
|
|
|
hideAllTabsCheckV.removeAttribute('collapsed');
|
|
|
|
}
|
2007-11-09 04:17:41 +00:00
|
|
|
else {
|
2009-07-08 00:17:36 +00:00
|
|
|
indentCheckH.removeAttribute('collapsed');
|
|
|
|
indentCheckV.setAttribute('collapsed', true);
|
|
|
|
collapseCheckH.removeAttribute('collapsed');
|
|
|
|
collapseCheckV.setAttribute('collapsed', true);
|
2009-07-22 02:22:00 +00:00
|
|
|
if (newTabAvailable) {
|
|
|
|
hideNewTabCheckH.removeAttribute('collapsed');
|
|
|
|
hideNewTabCheckV.setAttribute('collapsed', true);
|
|
|
|
}
|
|
|
|
hideAllTabsCheckH.removeAttribute('collapsed');
|
|
|
|
hideAllTabsCheckV.setAttribute('collapsed', true);
|
2007-11-09 04:17:41 +00:00
|
|
|
}
|
2007-10-25 22:59:34 +00:00
|
|
|
|
|
|
|
gTabbarPlacePositionInitialized = true;
|
2007-10-22 03:08:14 +00:00
|
|
|
}
|
2007-11-09 05:25:22 +00:00
|
|
|
|
2008-06-17 07:43:21 +00:00
|
|
|
|
2009-07-24 10:09:13 +00:00
|
|
|
var gAutoHideModeRadio,
|
|
|
|
gAutoHideModeToggle,
|
|
|
|
gTabbarTransparencyScale,
|
|
|
|
gTabbarTransparencyLabels;
|
2008-06-17 07:43:21 +00:00
|
|
|
function initAutoHidePane()
|
|
|
|
{
|
|
|
|
gAutoHideModeRadio = document.getElementById('extensions.treestyletab.tabbar.autoHide.mode-radio');
|
|
|
|
gAutoHideModeToggle = document.getElementById('extensions.treestyletab.tabbar.autoHide.mode.toggle');
|
2009-07-24 10:09:13 +00:00
|
|
|
gTabbarTransparencyScale = document.getElementById('tabbarTransparency-scale');
|
|
|
|
gTabbarTransparencyLabels = document.getElementById('tabbarTransparency-labels');
|
2008-06-17 07:43:21 +00:00
|
|
|
updateAutoHideModeLabel();
|
2009-07-24 10:09:13 +00:00
|
|
|
onTabbarTransparencyScaleChange();
|
2008-06-17 07:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function onChangeAutoHideMode()
|
|
|
|
{
|
|
|
|
if (!gAutoHideModeRadio) return;
|
|
|
|
var mode = gAutoHideModeRadio.value;
|
|
|
|
if (!mode) return;
|
|
|
|
if (gAutoHideModeRadio.value != 0) {
|
|
|
|
gAutoHideModeToggle.value = mode;
|
|
|
|
updateAutoHideModeLabel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateAutoHideModeLabel()
|
|
|
|
{
|
|
|
|
if (!gAutoHideModeRadio) return;
|
|
|
|
var mode = gAutoHideModeRadio.value;
|
|
|
|
var nodes = document.getElementsByAttribute('label-mode'+mode, '*');
|
|
|
|
if (nodes && nodes.length)
|
2008-07-18 00:19:24 +00:00
|
|
|
Array.slice(nodes).forEach(function(aNode) {
|
2008-06-17 07:43:21 +00:00
|
|
|
var label = aNode.getAttribute('label-mode'+mode);
|
|
|
|
var node = document.getElementById(aNode.getAttribute('target'));
|
|
|
|
var attr = node.localName == 'label' ? 'value' : 'label' ;
|
|
|
|
node.setAttribute(attr, label);
|
|
|
|
});
|
|
|
|
}
|
2009-06-10 03:34:47 +00:00
|
|
|
|
2009-07-24 10:09:13 +00:00
|
|
|
function onTabbarTransparencyScaleChange()
|
|
|
|
{
|
|
|
|
gTabbarTransparencyLabels.selectedIndex = gTabbarTransparencyScale.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-10 03:34:47 +00:00
|
|
|
function updateCloseRootBehaviorCheck()
|
|
|
|
{
|
|
|
|
var closeParentBehavior = document.getElementById('extensions.treestyletab.closeParentBehavior-radiogroup').value;
|
|
|
|
var closeRootBehavior = document.getElementById('extensions.treestyletab.closeRootBehavior-check');
|
|
|
|
if (closeParentBehavior == 0)
|
|
|
|
closeRootBehavior.removeAttribute('disabled');
|
|
|
|
else
|
|
|
|
closeRootBehavior.setAttribute('disabled', true);
|
|
|
|
}
|
2009-07-24 11:00:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function ScaleSet(aPrefs, aScale, aLabelsDeck)
|
|
|
|
{
|
|
|
|
this.prefs = aPrefs.map(document.getElementById, document);
|
|
|
|
this.scale = document.getElementById(aScale);
|
|
|
|
this.labels = document.getElementById(aLabelsDeck);
|
|
|
|
|
|
|
|
this.scale.value = this.prefs[1].value ? 2 :
|
|
|
|
this.prefs[0].value ? 1 :
|
|
|
|
0 ;
|
|
|
|
this.labels.selectedIndex = this.scale.value;
|
|
|
|
}
|
|
|
|
ScaleSet.prototype = {
|
|
|
|
onChange : function()
|
|
|
|
{
|
|
|
|
var value = this.value;
|
|
|
|
this.prefs[0].value = value > 0;
|
|
|
|
this.prefs[1].value = value > 1;
|
|
|
|
this.labels.selectedIndex = value;
|
|
|
|
},
|
|
|
|
|
|
|
|
set value(aValue)
|
|
|
|
{
|
|
|
|
this.scale.value = aValue;
|
|
|
|
this.onChange();
|
|
|
|
return aValue;
|
|
|
|
},
|
|
|
|
get value()
|
|
|
|
{
|
|
|
|
return parseInt(this.scale.value);
|
|
|
|
},
|
|
|
|
|
|
|
|
set disabled(aDisabled)
|
|
|
|
{
|
|
|
|
if (aDisabled) {
|
|
|
|
this.scale.setAttribute('disabled', true);
|
|
|
|
Array.slice(this.labels.childNodes).forEach(function(aNode) {
|
|
|
|
aNode.setAttribute('disabled', true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.scale.removeAttribute('disabled');
|
|
|
|
Array.slice(this.labels.childNodes).forEach(function(aNode) {
|
|
|
|
aNode.removeAttribute('disabled');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
get disabled()
|
|
|
|
{
|
|
|
|
return this.scale.getAttribute('disabled') == 'true';
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy : function()
|
|
|
|
{
|
|
|
|
this.prefs = null;
|
|
|
|
this.scale = null;
|
|
|
|
this.labels = null;
|
|
|
|
}
|
|
|
|
};
|