1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 20:47:58 +01:00

Add config.browser, config.tabbrowser. Fix mailbird. &c.

This commit is contained in:
Kris Maglione
2009-11-14 01:04:53 -05:00
parent a8f8ebaeb5
commit 86142105a1
10 changed files with 85 additions and 87 deletions

View File

@@ -36,14 +36,14 @@ const Browser = Module("browser", {
"string", "UTF-8",
{
scope: Option.SCOPE_LOCAL,
getter: function () getBrowser().docShell.QueryInterface(Ci.nsIDocCharset).charset,
getter: function () config.browser.docShell.QueryInterface(Ci.nsIDocCharset).charset,
setter: function (val) {
if (options["encoding"] == val)
return val;
// Stolen from browser.jar/content/browser/browser.js, more or less.
try {
getBrowser().docShell.QueryInterface(Ci.nsIDocCharset).charset = val;
config.browser.docShell.QueryInterface(Ci.nsIDocCharset).charset = val;
PlacesUtils.history.setCharsetForURI(getWebNavigation().currentURI, val);
getWebNavigation().reload(Ci.nsIWebNavigation.LOAD_FLAGS_CHARSET_CHANGE);
}

View File

@@ -146,7 +146,7 @@ const Buffer = Module("buffer", {
destroy: function () {
try {
getBrowser().removeProgressListener(this.progressListener);
config.browser.removeProgressListener(this.progressListener);
}
catch (e) {} // Why? --djk
},
@@ -200,7 +200,7 @@ const Buffer = Module("buffer", {
doc.pageIsFullyLoaded = 1;
// code which is only relevant if the page load is the current tab goes here:
if (doc == getBrowser().contentDocument) {
if (doc == config.browser.contentDocument) {
// we want to stay in command mode after a page has loaded
// TODO: move somewhere else, as focusing can already happen earlier than on "load"
if (options["focuscontent"]) {
@@ -387,7 +387,7 @@ const Buffer = Module("buffer", {
* @property {number} The current browser's text zoom level, as a
* percentage with 100 as 'normal'. Only affects text size.
*/
get textZoom() getBrowser().markupDocumentViewer.textZoom * 100,
get textZoom() config.browser.markupDocumentViewer.textZoom * 100,
set textZoom(value) { Buffer.setZoom(value, false); },
/**
@@ -395,7 +395,7 @@ const Buffer = Module("buffer", {
* percentage with 100 as 'normal'. Affects text size, as well as
* image size and block size.
*/
get fullZoom() getBrowser().markupDocumentViewer.fullZoom * 100,
get fullZoom() config.browser.markupDocumentViewer.fullZoom * 100,
set fullZoom(value) { Buffer.setZoom(value, true); },
/**
@@ -618,7 +618,7 @@ const Buffer = Module("buffer", {
* @property {nsISelectionController} The current document's selection
* controller.
*/
get selectionController() getBrowser().docShell
get selectionController() config.browser.docShell
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsISelectionDisplay)
.QueryInterface(Ci.nsISelectionController),
@@ -1132,7 +1132,7 @@ const Buffer = Module("buffer", {
options.setPref("print.always_print_silent", args.bang);
options.setPref("print.show_print_progress", !args.bang);
getBrowser().contentWindow.print();
config.browser.contentWindow.print();
});
if (arg)
@@ -1180,7 +1180,7 @@ const Buffer = Module("buffer", {
commands.add(["re[load]"],
"Reload the current web page",
function (args) { tabs.reload(getBrowser().mCurrentTab, args.bang); },
function (args) { tabs.reload(config.browser.mCurrentTab, args.bang); },
{
bang: true,
argCount: "0"
@@ -1228,7 +1228,7 @@ const Buffer = Module("buffer", {
commands.add(["st[op]"],
"Stop loading the current web page",
function () { tabs.stop(getBrowser().mCurrentTab); },
function () { tabs.stop(config.browser.mCurrentTab); },
{ argCount: "0" });
commands.add(["vie[wsource]"],
@@ -1333,14 +1333,16 @@ const Buffer = Module("buffer", {
.XULBrowserWindow = this.progressListener;
try {
getBrowser().addProgressListener(this.progressListener, Ci.nsIWebProgress.NOTIFY_ALL);
config.browser.addProgressListener(this.progressListener, Ci.nsIWebProgress.NOTIFY_ALL);
}
catch (e) {} // Why? --djk
let appContent = document.getElementById("appcontent");
if (appContent) {
events.addSessionListener(appContent, "DOMContentLoaded", this.closure.onDOMContentLoaded, true);
events.addSessionListener(appContent, "load", this.closure.onPageLoad, true);
events.addSessionListener(appContent, "scroll", this.closure._updateBufferPosition, false);
}
},
mappings: function () {
var myModes = config.browserModes;
@@ -1365,7 +1367,7 @@ const Buffer = Module("buffer", {
mappings.add(myModes, ["<C-c>"],
"Stop loading the current web page",
function () { tabs.stop(getBrowser().mCurrentTab); });
function () { tabs.stop(config.browser.mCurrentTab); });
// scrolling
mappings.add(myModes, ["j", "<Down>", "<C-e>"],
@@ -1520,11 +1522,11 @@ const Buffer = Module("buffer", {
// reloading
mappings.add(myModes, ["r"],
"Reload the current web page",
function () { tabs.reload(getBrowser().mCurrentTab, false); });
function () { tabs.reload(config.browser.mCurrentTab, false); });
mappings.add(myModes, ["R"],
"Reload while skipping the cache",
function () { tabs.reload(getBrowser().mCurrentTab, true); });
function () { tabs.reload(config.browser.mCurrentTab, true); });
// yanking
mappings.add(myModes, ["Y"],
@@ -1635,8 +1637,8 @@ const Buffer = Module("buffer", {
"Show current website with a minimal style sheet to make it easily accessible",
"boolean", false,
{
setter: function (value) getBrowser().markupDocumentViewer.authorStyleDisabled = value,
getter: function () getBrowser().markupDocumentViewer.authorStyleDisabled
setter: function (value) config.browser.markupDocumentViewer.authorStyleDisabled = value,
getter: function () config.browser.markupDocumentViewer.authorStyleDisabled
});
}
});

View File

@@ -11,6 +11,9 @@ const ConfigBase = Class(ModuleBase, {
*/
autocommands: [],
browser: window.gBrowser,
tabbrowser: window.gBrowser,
get browserModes() [modes.NORMAL],
/**
@@ -83,7 +86,7 @@ const ConfigBase = Class(ModuleBase, {
* @property {number} The height (px) that is available to the output
* window.
*/
get outputHeight() getBrowser().mPanelContainer.boxObject.height,
get outputHeight() config.browser.mPanelContainer.boxObject.height,
/**
* @property {[string]} A list of extra scripts in the liberator or

View File

@@ -231,7 +231,7 @@ const Finder = Module("finder", {
* @param {string} str The string to find.
*/
find: function (str) {
let fastFind = getBrowser().fastFind;
let fastFind = config.browser.fastFind;
this._processUserPattern(str);
fastFind.caseSensitive = this._caseSensitive;
@@ -252,11 +252,11 @@ const Finder = Module("finder", {
// This hack is needed to make n/N work with the correct string, if
// we typed /foo<esc> after the original search. Since searchString is
// readonly we have to call find() again to update it.
if (getBrowser().fastFind.searchString != this._lastSearchString)
if (config.browser.fastFind.searchString != this._lastSearchString)
this.find(this._lastSearchString);
let up = reverse ? !this._lastSearchBackwards : this._lastSearchBackwards;
let result = getBrowser().fastFind.findAgain(up, this._linksOnly);
let result = config.browser.fastFind.findAgain(up, this._linksOnly);
if (result == Ci.nsITypeAheadFind.FIND_NOTFOUND)
liberator.echoerr("E486: Pattern not found: " + this._lastSearchPattern, commandline.FORCE_SINGLELINE);
@@ -361,7 +361,7 @@ const Finder = Module("finder", {
// recreate selection since highlightDoc collapses the selection
if (window.content.getSelection().isCollapsed)
getBrowser().fastFind.findAgain(this._backwards, this._linksOnly);
config.browser.fastFind.findAgain(this._backwards, this._linksOnly);
// TODO: remove highlighting from non-link matches (HTML - A/AREA with href attribute; XML - Xlink [type="simple"])
},
@@ -980,7 +980,7 @@ const RangeFind = Class("RangeFind", {
get docShell() {
if (this._docShell)
return this._docShell;
for (let shell in iter(getBrowser().docShell.getDocShellEnumerator(Ci.nsIDocShellTreeItem.typeAll, Ci.nsIDocShell.ENUMERATE_FORWARDS)))
for (let shell in iter(config.browser.docShell.getDocShellEnumerator(Ci.nsIDocShellTreeItem.typeAll, Ci.nsIDocShell.ENUMERATE_FORWARDS)))
if (shell.QueryInterface(nsIWebNavigation).document == this.document)
return this._docShell = shell;
},

View File

@@ -400,7 +400,7 @@ const Hints = Module("hints", {
}
}
if (getBrowser().markupDocumentViewer.authorStyleDisabled) {
if (config.browser.markupDocumentViewer.authorStyleDisabled) {
let css = [];
// FIXME: Broken for imgspans.
for (let [, { doc: doc }] in Iterator(this._docs)) {

View File

@@ -779,8 +779,7 @@ const Liberator = Module("liberator", {
if (urls.length == 0)
return false;
let browser = window.getBrowser();
let browser = config.browser;
function open(urls, where) {
let url = Array.concat(urls)[0];
let postdata = Array.concat(urls)[1];
@@ -1514,7 +1513,7 @@ const Liberator = Module("liberator", {
liberator.has("tabs") ? "Quit current tab" : "Quit application",
function (args) {
if (liberator.has("tabs"))
tabs.remove(getBrowser().mCurrentTab, 1, false, 1);
tabs.remove(config.browser.mCurrentTab, 1, false, 1);
else
liberator.quit(false, args.bang);
}, {

View File

@@ -118,7 +118,7 @@ const Marks = Module("marks", {
if (Marks.isURLMark(mark)) {
let slice = this._urlMarks.get(mark);
if (slice && slice.tab && slice.tab.linkedBrowser) {
if (slice.tab.parentNode != getBrowser().tabContainer) {
if (slice.tab.parentNode != config.browser.tabContainer) {
this._pendingJumps.push(slice);
// NOTE: this obviously won't work on generated pages using
// non-unique URLs :(

View File

@@ -178,7 +178,7 @@ const StatusLine = Module("statusline", {
// update the ordinal which is used for numbered tabs
if (options.get("guioptions").has("n", "N"))
for (let [i, tab] in util.Array.iteritems(getBrowser().mTabs))
for (let [i, tab] in util.Array.iteritems(config.browser.mTabs))
tab.setAttribute("ordinal", i + 1);
this._tabCountWidget.value = "[" + (tabs.index() + 1) + "/" + tabs.count + "]";

View File

@@ -17,10 +17,7 @@ const Tabs = Module("tabs", {
requires: ["config"],
init: function () {
if (config.getBrowser)
this.getBrowser = config.getBrowser;
this._alternates = [this.getBrowser().mCurrentTab, null];
this._alternates = [config.tabbrowser.mCurrentTab, null];
// used for the "gb" and "gB" mappings to remember the last :buffer[!] command
this._lastBufferSwitchArgs = "";
@@ -29,7 +26,7 @@ const Tabs = Module("tabs", {
// hide tabs initially to prevent flickering when 'stal' would hide them
// on startup
if (config.hasTabbrowser)
this.getBrowser().mTabContainer.collapsed = true; // FIXME: see 'stal' comment
config.tabbrowser.mTabContainer.collapsed = true; // FIXME: see 'stal' comment
},
_updateTabCount: function () {
@@ -57,7 +54,7 @@ const Tabs = Module("tabs", {
* in the current window.
*/
get browsers() {
let browsers = this.getBrowser().browsers;
let browsers = config.tabbrowser.browsers;
for (let i = 0; i < browsers.length; i++)
yield [i, browsers[i]];
},
@@ -81,7 +78,7 @@ const Tabs = Module("tabs", {
/**
* @property {number} The number of tabs in the current window.
*/
get count() this.getBrowser().mTabs.length,
get count() config.tabbrowser.mTabs.length,
/**
* @property {Object} The local options store for the current tab.
@@ -93,8 +90,6 @@ const Tabs = Module("tabs", {
return store.options;
},
getBrowser: getBrowser,
/**
* Returns the local state store for the tab at the specified
* <b>tabIndex</b>. If <b>tabIndex</b> is not specified then the
@@ -137,9 +132,9 @@ const Tabs = Module("tabs", {
*/
index: function (tab) {
if (tab)
return Array.indexOf(this.getBrowser().mTabs, tab);
return Array.indexOf(config.tabbrowser.mTabs, tab);
else
return this.getBrowser().mTabContainer.selectedIndex;
return config.tabbrowser.mTabContainer.selectedIndex;
},
// TODO: implement filter
@@ -186,9 +181,9 @@ const Tabs = Module("tabs", {
*/
getTab: function (index) {
if (index != undefined)
return this.getBrowser().mTabs[index];
return config.tabbrowser.mTabs[index];
else
return this.getBrowser().mCurrentTab;
return config.tabbrowser.mCurrentTab;
},
/**
@@ -212,7 +207,7 @@ const Tabs = Module("tabs", {
*/
move: function (tab, spec, wrap) {
let index = Tabs.indexFromSpec(spec, wrap);
this.getBrowser().moveTabTo(tab, index);
config.tabbrowser.moveTabTo(tab, index);
},
/**
@@ -230,31 +225,31 @@ const Tabs = Module("tabs", {
remove: function (tab, count, focusLeftTab, quitOnLastTab) {
let removeOrBlankTab = {
Firefox: function (tab) {
if (tabs.getBrowser().mTabs.length > 1)
tabs.getBrowser().removeTab(tab);
if (config.tabbrowser.mTabs.length > 1)
config.tabbrowser.removeTab(tab);
else {
if (buffer.URL != "about:blank" ||
window.getWebNavigation().sessionHistory.count > 0) {
liberator.open("about:blank", liberator.NEW_BACKGROUND_TAB);
tabs.getBrowser().removeTab(tab);
config.tabbrowser.removeTab(tab);
}
else
liberator.beep();
}
},
Thunderbird: function (tab) {
if (tabs.getBrowser().mTabs.length > 1)
tabs.getBrowser().removeTab(tab);
if (config.tabbrowser.mTabs.length > 1)
config.tabbrowser.removeTab(tab);
else
liberator.beep();
},
Songbird: function (tab) {
if (tabs.getBrowser().mTabs.length > 1)
tabs.getBrowser().removeTab(tab);
if (config.tabbrowser.mTabs.length > 1)
config.tabbrowser.removeTab(tab);
else {
if (buffer.URL != "about:blank" || window.getWebNavigation().sessionHistory.count > 0) {
liberator.open("about:blank", liberator.NEW_BACKGROUND_TAB);
tabs.getBrowser().removeTab(tab);
config.tabbrowser.removeTab(tab);
}
else
liberator.beep();
@@ -265,7 +260,7 @@ const Tabs = Module("tabs", {
if (typeof count != "number" || count < 1)
count = 1;
if (quitOnLastTab >= 1 && this.getBrowser().mTabs.length <= count) {
if (quitOnLastTab >= 1 && config.tabbrowser.mTabs.length <= count) {
if (liberator.windows.length > 1)
window.close();
else
@@ -281,7 +276,7 @@ const Tabs = Module("tabs", {
removeOrBlankTab(this.getTab(i));
lastRemovedTab = i > 0 ? i : 1;
}
this.getBrowser().mTabContainer.selectedIndex = lastRemovedTab - 1;
config.tabbrowser.mTabContainer.selectedIndex = lastRemovedTab - 1;
}
else {
let i = index + count - 1;
@@ -290,7 +285,7 @@ const Tabs = Module("tabs", {
for (; i >= index; i--)
removeOrBlankTab(this.getTab(i));
this.getBrowser().mTabContainer.selectedIndex = index;
config.tabbrowser.mTabContainer.selectedIndex = index;
}
},
@@ -300,7 +295,7 @@ const Tabs = Module("tabs", {
* @param {Object} tab The tab to keep.
*/
keepOnly: function (tab) {
this.getBrowser().removeAllTabsBut(tab);
config.tabbrowser.removeAllTabsBut(tab);
},
/**
@@ -316,7 +311,7 @@ const Tabs = Module("tabs", {
// FIXME:
if (index == -1)
return void liberator.beep();
this.getBrowser().mTabContainer.selectedIndex = index;
config.tabbrowser.mTabContainer.selectedIndex = index;
},
/**
@@ -329,10 +324,10 @@ const Tabs = Module("tabs", {
reload: function (tab, bypassCache) {
if (bypassCache) {
const flags = Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_PROXY | Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE;
this.getBrowser().getBrowserForTab(tab).reloadWithFlags(flags);
config.tabbrowser.getBrowserForTab(tab).reloadWithFlags(flags);
}
else
this.getBrowser().reloadTab(tab);
config.tabbrowser.reloadTab(tab);
},
/**
@@ -343,9 +338,9 @@ const Tabs = Module("tabs", {
*/
reloadAll: function (bypassCache) {
if (bypassCache) {
for (let i = 0; i < this.getBrowser().mTabs.length; i++) {
for (let i = 0; i < config.tabbrowser.mTabs.length; i++) {
try {
this.reload(this.getBrowser().mTabs[i], bypassCache);
this.reload(config.tabbrowser.mTabs[i], bypassCache);
}
catch (e) {
// FIXME: can we do anything useful here without stopping the
@@ -354,7 +349,7 @@ const Tabs = Module("tabs", {
}
}
else
this.getBrowser().reloadAllTabs();
config.tabbrowser.reloadAllTabs();
},
/**
@@ -425,11 +420,11 @@ const Tabs = Module("tabs", {
matches = [];
let lowerBuffer = buffer.toLowerCase();
let first = tabs.index() + (reverse ? 0 : 1);
let nbrowsers = this.getBrowser().browsers.length;
let nbrowsers = config.tabbrowser.browsers.length;
for (let [i, ] in tabs.browsers) {
let index = (i + first) % nbrowsers;
let url = this.getBrowser().getBrowserAtIndex(index).contentDocument.location.href;
let title = this.getBrowser().getBrowserAtIndex(index).contentDocument.title.toLowerCase();
let url = config.tabbrowser.getBrowserAtIndex(index).contentDocument.location.href;
let title = config.tabbrowser.getBrowserAtIndex(index).contentDocument.title.toLowerCase();
if (url == buffer) {
tabs.select(index, false);
return;
@@ -462,11 +457,11 @@ const Tabs = Module("tabs", {
* @param {boolean} activate Whether to select the newly cloned tab.
*/
cloneTab: function (tab, activate) {
let newTab = this.getBrowser().addTab();
let newTab = config.tabbrowser.addTab();
Tabs.copyTab(newTab, tab);
if (activate)
this.getBrowser().mTabContainer.selectedItem = newTab;
config.tabbrowser.mTabContainer.selectedItem = newTab;
return newTab;
},
@@ -479,7 +474,7 @@ const Tabs = Module("tabs", {
*/
detachTab: function (tab) {
if (!tab)
tab = this.getBrowser().mTabContainer.selectedItem;
tab = config.tabbrowser.mTabContainer.selectedItem;
services.get("windowWatcher")
.openWindow(window, window.getBrowserURL(), null, "chrome,dialog=no,all", tab);
@@ -520,7 +515,7 @@ const Tabs = Module("tabs", {
}, {
copyTab: function (to, from) {
if (!from)
from = tabs.getBrowser().mTabContainer.selectedItem;
from = config.tabbrowser.mTabContainer.selectedItem;
let tabState = services.get("sessionStore").getTabState(from);
services.get("sessionStore").setTabState(to, tabState);
@@ -535,8 +530,8 @@ const Tabs = Module("tabs", {
* - "$" for the last tab
*/
indexFromSpec: function (spec, wrap) {
let position = tabs.getBrowser().mTabContainer.selectedIndex;
let length = tabs.getBrowser().mTabs.length;
let position = config.tabbrowser.mTabContainer.selectedIndex;
let length = config.tabbrowser.mTabs.length;
let last = length - 1;
if (spec === undefined || spec === "")
@@ -579,7 +574,7 @@ const Tabs = Module("tabs", {
}
else {
let str = arg.toLowerCase();
let browsers = tabs.getBrowser().browsers;
let browsers = config.tabbrowser.browsers;
for (let i = browsers.length - 1; i >= 0; i--) {
let host, title, uri = browsers[i].currentURI.spec;
@@ -787,7 +782,7 @@ const Tabs = Module("tabs", {
"E488: Trailing characters");
// if not specified, move to after the last tab
tabs.move(tabs.getBrowser().mCurrentTab, arg || "$", args.bang);
tabs.move(config.tabbrowser.mCurrentTab, arg || "$", args.bang);
}, {
argCount: "?",
bang: true
@@ -795,7 +790,7 @@ const Tabs = Module("tabs", {
commands.add(["tabo[nly]"],
"Close all other tabs",
function () { tabs.keepOnly(tabs.getBrowser().mCurrentTab); },
function () { tabs.keepOnly(config.tabbrowser.mCurrentTab); },
{ argCount: "0" });
commands.add(["tabopen", "t[open]", "tabnew"],
@@ -869,7 +864,7 @@ const Tabs = Module("tabs", {
browser.moveTabTo(dummy, util.Math.constrain(tabIndex || last, 0, last));
browser.selectedTab = dummy; // required
browser.swapBrowsersAndCloseOther(dummy, tabs.getBrowser().mCurrentTab);
browser.swapBrowsersAndCloseOther(dummy, config.tabbrowser.mCurrentTab);
}, {
argCount: "+",
completer: function (context, args) {
@@ -937,7 +932,7 @@ const Tabs = Module("tabs", {
completion.buffer);
},
events: function () {
let tabContainer = this.getBrowser().mTabContainer;
let tabContainer = config.tabbrowser.mTabContainer;
["TabMove", "TabOpen", "TabClose"].forEach(function (event) {
events.addSessionListener(tabContainer, event, this.closure._updateTabCount, false);
}, this);
@@ -1036,7 +1031,7 @@ const Tabs = Module("tabs", {
// don't have to fight against the host app's attempts to keep
// it open - hack! Adding a filter watch to mStrip is probably
// the cleanest solution.
let tabStrip = tabs.getBrowser().mTabContainer;
let tabStrip = config.tabbrowser.mTabContainer;
if (value == 0)
tabStrip.collapsed = true;

View File

@@ -102,15 +102,14 @@ const Config = Module("config", ConfigBase, {
}
},
getBrowser: function () {
var tabmail = { __proto__: document.getElementById("tabmail") };
tabmail.__defineGetter__("mTabContainer", function () this.tabContainer);
tabmail.__defineGetter__("mTabs", function () this.tabContainer.childNodes);
tabmail.__defineGetter__("mCurrentTab", function () this.tabContainer.selectedItem);
tabmail.__defineGetter__("mStrip", function () this.tabStrip);
tabmail.__defineGetter__("browsers", function () [browser for (browser in Iterator(this.mTabs))]);
config.getBrowser = function () tabmail;
return tabmail;
get browser() getBrowser(),
tabbrowser: {
__proto__: document.getElementById("tabmail"),
get mTabContainer() this.tabContainer,
get mTabs() this.tabContainer.childNodes,
get mCurrentTab() this.tabContainer.selectedItem,
get mStrip() this.tabStrip,
get browsers() [browser for (browser in Iterator(this.mTabs))]
},
// they are sorted by relevance, not alphabetically