1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 01:17:59 +01:00

use the singleton construction idiom to create vimperator.tabs

This commit is contained in:
Doug Kearns
2007-11-12 12:29:54 +00:00
parent 68f1597c38
commit 695fd63e91
7 changed files with 178 additions and 179 deletions

View File

@@ -1934,7 +1934,7 @@ vimperator.Commands = function () //{{{
else if (/^\d+$/.test(args)) else if (/^\d+$/.test(args))
{ {
var index = parseInt(args, 10) - 1; var index = parseInt(args, 10) - 1;
if (index < vimperator.tabs.count()) if (index < vimperator.tabs.count)
vimperator.tabs.select(index, true); vimperator.tabs.select(index, true);
else else
vimperator.beep(); vimperator.beep();

View File

@@ -552,7 +552,7 @@ vimperator.Mappings = function () //{{{
addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["<C-^>", "<C-6>"], addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["<C-^>", "<C-6>"],
function () function ()
{ {
if (vimperator.tabs.getTab() == vimperator.tabs.alternate) if (vimperator.tabs.alternate == null || vimperator.tabs.getTab() == vimperator.tabs.alternate)
{ {
vimperator.echoerr("E23: No alternate page"); vimperator.echoerr("E23: No alternate page");
return; return;

View File

@@ -38,13 +38,12 @@ vimperator.Tabs = function () //{{{
////////////////////// PRIVATE SECTION ///////////////////////////////////////// ////////////////////// PRIVATE SECTION /////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
/** @param spec can either be: // @param spec can either be:
* - an absolute integer // - an absolute integer
* - "" for the current tab // - "" for the current tab
* - "+1" for the next tab // - "+1" for the next tab
* - "-3" for the tab, which is 3 positions left of the current // - "-3" for the tab, which is 3 positions left of the current
* - "$" for the last tab // - "$" for the last tab
*/
function indexFromSpec(spec, wrap) function indexFromSpec(spec, wrap)
{ {
var position = getBrowser().tabContainer.selectedIndex; var position = getBrowser().tabContainer.selectedIndex;
@@ -80,14 +79,20 @@ vimperator.Tabs = function () //{{{
return position; return position;
} }
var alternates = [null, null]; var alternates = [getBrowser().mCurrentTab, null];
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}
////////////////////// PUBLIC SECTION ////////////////////////////////////////// ////////////////////// PUBLIC SECTION //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
return {
get alternate() { return alternates[1]; },
get count() { return getBrowser().mTabs.length; },
// @returns the index of the currently selected tab starting with 0 // @returns the index of the currently selected tab starting with 0
this.index = function (tab) index: function (tab)
{ {
if (tab) if (tab)
{ {
@@ -101,16 +106,11 @@ vimperator.Tabs = function () //{{{
} }
return getBrowser().tabContainer.selectedIndex; return getBrowser().tabContainer.selectedIndex;
}; },
this.count = function ()
{
return getBrowser().mTabs.length;
};
// TODO: implement filter // TODO: implement filter
// @returns an array of tabs which match filter // @returns an array of tabs which match filter
this.get = function (filter) get: function (filter)
{ {
var buffers = []; var buffers = [];
var browsers = getBrowser().browsers; var browsers = getBrowser().browsers;
@@ -122,34 +122,32 @@ vimperator.Tabs = function () //{{{
buffers.push([number, title, uri]); buffers.push([number, title, uri]);
} }
return buffers; return buffers;
}; },
this.getTab = function (index) getTab: function (index)
{ {
if (index) if (index)
return getBrowser().mTabs[index]; return getBrowser().mTabs[index];
return getBrowser().tabContainer.selectedItem; return getBrowser().tabContainer.selectedItem;
}; },
/* spec == "" moves the tab to the last position as per Vim // spec == "" moves the tab to the last position as per Vim
* wrap causes the movement to wrap around the start and end of the tab list // wrap causes the movement to wrap around the start and end of the tab list
* NOTE: position is a 0 based index // NOTE: position is a 0 based index
* FIXME: tabmove! N should probably produce an error // FIXME: tabmove! N should probably produce an error
*/ move: function (tab, spec, wrap)
this.move = function (tab, spec, wrap)
{ {
if (spec === "") if (spec === "")
spec = "$"; // if not specified, move to the last tab -> XXX: move to ex handling? spec = "$"; // if not specified, move to the last tab -> XXX: move to ex handling?
var index = indexFromSpec(spec, wrap); var index = indexFromSpec(spec, wrap);
getBrowser().moveTabTo(tab, index); getBrowser().moveTabTo(tab, index);
}; },
/* quit_on_last_tab = 1: quit without saving session // quit_on_last_tab = 1: quit without saving session
* quit_on_last_tab = 2: quit and save session // quit_on_last_tab = 2: quit and save session
*/ remove: function (tab, count, focus_left_tab, quit_on_last_tab)
this.remove = function (tab, count, focus_left_tab, quit_on_last_tab)
{ {
function removeOrBlankTab (tab) function removeOrBlankTab (tab)
{ {
@@ -195,20 +193,20 @@ vimperator.Tabs = function () //{{{
else else
{ {
var i = index + count - 1; var i = index + count - 1;
if (i >= this.count()) if (i >= this.count)
i = this.count() - 1; i = this.count - 1;
for (; i >= index; i--) for (; i >= index; i--)
removeOrBlankTab(this.getTab(i)); removeOrBlankTab(this.getTab(i));
} }
}; },
this.keepOnly = function (tab) keepOnly: function (tab)
{ {
getBrowser().removeAllTabsBut(tab); getBrowser().removeAllTabsBut(tab);
}; },
this.select = function (spec, wrap) select: function (spec, wrap)
{ {
var index = indexFromSpec(spec, wrap); var index = indexFromSpec(spec, wrap);
if (index === false) if (index === false)
@@ -217,22 +215,18 @@ vimperator.Tabs = function () //{{{
return false; return false;
} }
getBrowser().mTabContainer.selectedIndex = index; getBrowser().mTabContainer.selectedIndex = index;
}; },
// TODO: when restarting a session FF selects the first tab and then the // TODO: when restarting a session FF selects the first tab and then the
// tab that was selected when the session was created. As a result the // tab that was selected when the session was created. As a result the
// alternate after a restart is often incorrectly tab 1 when there // alternate after a restart is often incorrectly tab 1 when there
// shouldn't be one yet. // shouldn't be one yet.
this.updateSelectionHistory = function () updateSelectionHistory: function ()
{ {
alternates = [this.getTab(), alternates[0]]; alternates = [this.getTab(), alternates[0]];
this.alternate = alternates[1]; },
};
// TODO: move to v.buffers reload: function (tab, bypass_cache)
this.alternate = this.getTab();
this.reload = function (tab, bypass_cache)
{ {
if (bypass_cache) if (bypass_cache)
{ {
@@ -244,9 +238,9 @@ vimperator.Tabs = function () //{{{
{ {
getBrowser().reloadTab(tab); getBrowser().reloadTab(tab);
} }
}; },
this.reloadAll = function (bypass_cache) reloadAll: function (bypass_cache)
{ {
if (bypass_cache) if (bypass_cache)
{ {
@@ -267,6 +261,8 @@ vimperator.Tabs = function () //{{{
{ {
getBrowser().reloadAllTabs(); getBrowser().reloadAllTabs();
} }
}
}; };
//}}} //}}}
}; //}}} }; //}}}

View File

@@ -1184,7 +1184,7 @@ vimperator.StatusLine = function () //{{{
if (!cur_index || typeof cur_index != "number") if (!cur_index || typeof cur_index != "number")
cur_index = vimperator.tabs.index() + 1; cur_index = vimperator.tabs.index() + 1;
if (!total_tabs || typeof cur_index != "number") if (!total_tabs || typeof cur_index != "number")
total_tabs = vimperator.tabs.count(); total_tabs = vimperator.tabs.count;
tabcount_widget.value = "[" + cur_index + "/" + total_tabs + "]"; tabcount_widget.value = "[" + cur_index + "/" + total_tabs + "]";
}, },

View File

@@ -245,9 +245,12 @@ const vimperator = (function () //{{{
var string = ""; var string = "";
var obj = ""; var obj = "";
try { // for window.JSON try
{ // for window.JSON
obj = object.toString(); obj = object.toString();
} catch (e) { }
catch (e)
{
obj = "&lt;Object&gt;"; obj = "&lt;Object&gt;";
} }
@@ -604,7 +607,7 @@ const vimperator = (function () //{{{
vimperator.log("Loading module editor...", 3); vimperator.log("Loading module editor...", 3);
vimperator.editor = vimperator.Editor(); vimperator.editor = vimperator.Editor();
vimperator.log("Loading module tabs...", 3); vimperator.log("Loading module tabs...", 3);
vimperator.tabs = new vimperator.Tabs(); vimperator.tabs = vimperator.Tabs();
vimperator.log("Loading module marks...", 3); vimperator.log("Loading module marks...", 3);
vimperator.marks = vimperator.Marks(); vimperator.marks = vimperator.Marks();
vimperator.log("Loading module quickmarks...", 3); vimperator.log("Loading module quickmarks...", 3);