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

now we have a Events() class

Please report all bugs which arised because of these changes
Still not sure, if we should put that into an event.js
This commit is contained in:
Martin Stubenschrott
2007-06-09 13:39:13 +00:00
parent 2e143ffe1a
commit 36a2ec59ec
5 changed files with 154 additions and 148 deletions

View File

@@ -1,6 +1,8 @@
<pre> <pre>
2007-05-02: 2007-05-02:
* version ??? * version ???
* The RSS feed button in the address bar works again
* reload/stop buttons update enabled state again
* added marks support (thanks Viktor Kojouharov) * added marks support (thanks Viktor Kojouharov)
* temporary shortcut Y to yank current selection (for non UNIX-users) * temporary shortcut Y to yank current selection (for non UNIX-users)
* Flashing frame with ]f now works as expected * Flashing frame with ]f now works as expected

14
TODO
View File

@@ -4,32 +4,26 @@ Priority list:
BUGS: BUGS:
- switching tabs while HINT_MODE_ALWAYS is on does not redisplay hints in new tabs, but exits hint mode - switching tabs while HINT_MODE_ALWAYS is on does not redisplay hints in new tabs, but exits hint mode
- The RSS feed button in the address bar no longer works.
- autoupdate does not work - autoupdate does not work
- multiple windows to not work at all, so :q will close the whole browser session, even when there are other windows which has tabs - multiple windows to not work at all, so :q will close the whole browser session, even when there are other windows which has tabs
- reload/stop buttons don't update enabled state
- http://en.wikipedia.org/wiki/Portal:Current_events - 'f' shows more hints than 'F' (on left side of nav bar) - http://en.wikipedia.org/wiki/Portal:Current_events - 'f' shows more hints than 'F' (on left side of nav bar)
- gu and gU don't work on local files properly - gu and gU don't work on local files properly
- dpb| 09:09:56 dpb :: when I save a page with vimperator, it adds <hints - dpb| 09:09:56 dpb :: when I save a page with vimperator, it adds <hints
id="hah_hints"></hints> near the end of it.. kinda annoying id="hah_hints"></hints> near the end of it.. kinda annoying
dpb| 09:11:50 dpb :: and this happens only when saving the complete dpb| 09:11:50 dpb :: and this happens only when saving the complete
webpage, saving only the html works just fine.. webpage, saving only the html works just fine..
- <ESC> key closes :addons window - <ESC> key closes :addons and other XUL windows
FEATURES: FEATURES:
9 marks of a Location, [m a-zA-Z] to set it, [` a-zA-Z] to go there 9 :map commands to keys
[m 0-9] marks a buffer instead [' 0-9] goes there 9 :command for new commands
also mark bookmarks (with M[a-zA-Z] maybe and use only lowercase marks for inbuffer marks?)
also support :mark and :marks
8 :map commands to keys
8 :command for new commands
8 middleclick in content == p, and if command line is open, paste there the clipboard buffer 8 middleclick in content == p, and if command line is open, paste there the clipboard buffer
8 Use our own find-as-you-type mechanism (like conkeror does) 8 Use our own find-as-you-type mechanism (like conkeror does)
8 make hints smarter, not only with characters from from hintchars, but use "NE" or "NP" for 'new posts' e.g. (might be too slow)
7 [ctrl-o/i] to Go back to a Previous Position (done partly, however currenty does not use a per tab jumplist) 7 [ctrl-o/i] to Go back to a Previous Position (done partly, however currenty does not use a per tab jumplist)
7 provide a buffer on the bottom where more than 1 line messages can be shown, preferrable 7 provide a buffer on the bottom where more than 1 line messages can be shown, preferrable
with color support (for things like :echo line1\nline2) with color support (for things like :echo line1\nline2)
7 make hints smarter, not only with characters from from hintchars, but use "NE" or "NP" for 'new posts' e.g. (might be too slow)
7 whereever possible: get rid of dialogs and ask console-like dialog questions or write error prompts directly on the webpage or with :echo() 7 whereever possible: get rid of dialogs and ask console-like dialog questions or write error prompts directly on the webpage or with :echo()
7 Ctrl-6/Ctrl-^ -> jump to the previously active tab 7 Ctrl-6/Ctrl-^ -> jump to the previously active tab
7 3d should delete 3 tabs 7 3d should delete 3 tabs

View File

@@ -653,7 +653,7 @@ function Mappings()//{{{
)); ));
// if you ever add/remove keys here, also check them in the vimperaotr.onEvent() // if you ever add/remove keys here, also check them in the vimperaotr.onEvent()
addDefaultMap(new Map(vimperator.modes.NORMAL, ["<Esc>", "<C-[>"], addDefaultMap(new Map(vimperator.modes.NORMAL, ["<Esc>", "<C-[>"],
onEscape, vimperator.events.onEscape,
{ {
short_help: "Cancel any operation", short_help: "Cancel any operation",
help: "Exits any command line or hint mode and returns to browser mode.<br/>" + help: "Exits any command line or hint mode and returns to browser mode.<br/>" +

View File

@@ -48,6 +48,10 @@ function init()
// these inner classes are created here, because outside the init() // these inner classes are created here, because outside the init()
// function, the chrome:// is not ready // function, the chrome:// is not ready
// TODO: can these classes be moved into a namesspace to now clobber
// the main namespace?
Vimperator.prototype.events = new Events;
Vimperator.prototype.commands = new Commands; Vimperator.prototype.commands = new Commands;
Vimperator.prototype.bookmarks = new Bookmarks; Vimperator.prototype.bookmarks = new Bookmarks;
Vimperator.prototype.history = new History; Vimperator.prototype.history = new History;
@@ -71,7 +75,8 @@ function init()
// this function adds all our required listeners to react on events // this function adds all our required listeners to react on events
// also stuff like window.onScroll is handled there. // also stuff like window.onScroll is handled there.
addEventListeners(); //addEventListeners();
//vimperator.events();
set_showtabline(get_pref("showtabline")); set_showtabline(get_pref("showtabline"));
set_guioptions(get_pref("guioptions")); set_guioptions(get_pref("guioptions"));
@@ -126,26 +131,11 @@ function unload()
} }
//////////////////////////////////////////////////////////////////////// function Events() //{{{1
// focus and mode handling //////////////////////////////////////// {{{1
////////////////////////////////////////////////////////////////////////
function onEscape()
{
if (!vimperator.hasMode(vimperator.modes.ESCAPE_ONE_KEY))
{
vimperator.setMode(vimperator.modes.NORMAL);
vimperator.echo("");
hah.disableHahMode();
vimperator.focusContent();
vimperator.statusline.updateUrl();
}
}
////////////////////////////////////////////////////////////////////////
// event listeners //////////////////////////////////////////////// {{{1
////////////////////////////////////////////////////////////////////////
function addEventListeners()
{ {
////////////////////////////////////////////////////////////////////////////////
////////////////////// CONSTRUCTOR /////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// any window related events // any window related events
window.addEventListener("unload", unload, false); window.addEventListener("unload", unload, false);
window.addEventListener("keypress", vimperator.onEvent, true); window.addEventListener("keypress", vimperator.onEvent, true);
@@ -173,6 +163,7 @@ function addEventListeners()
vimperator.statusline.updateTabCount(); vimperator.statusline.updateTabCount();
updateBufferList(); updateBufferList();
}, false); }, false);
// this adds an event which is is called on each page load, even if the // this adds an event which is is called on each page load, even if the
// page is loaded in a background tab // page is loaded in a background tab
getBrowser().addEventListener("load", onPageLoad, true); getBrowser().addEventListener("load", onPageLoad, true);
@@ -188,8 +179,100 @@ function addEventListeners()
//alert("titlechanged"); //alert("titlechanged");
}, null); }, null);
// for setOverLink() XXX: maybe there is an addEventListener way
window.XULBrowserWindow = buffer_changed_listener;
this.progressListener =
{
QueryInterface: function(aIID)
{
if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
aIID.equals(Components.interfaces.nsIXULBrowserWindow) || // for setOverLink();
aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
aIID.equals(Components.interfaces.nsISupports))
return this;
throw Components.results.NS_NOINTERFACE;
},
// XXX: function may later be needed to detect a canceled synchronous openURL()
onStateChange: function(webProgress, aRequest, flags, aStatus)
{
// STATE_IS_DOCUMENT | STATE_IS_WINDOW is important, because we also
// receive statechange events for loading images and other parts of the web page
if(flags & (Components.interfaces.nsIWebProgressListener.STATE_IS_DOCUMENT |
Components.interfaces.nsIWebProgressListener.STATE_IS_WINDOW))
{
// This fires when the load event is initiated
if(flags & Components.interfaces.nsIWebProgressListener.STATE_START)
{
vimperator.statusline.updateProgress(0);
}
else if (flags & Components.interfaces.nsIWebProgressListener.STATE_STOP)
;// vimperator.statusline.updateUrl();
}
},
// for notifying the user about secure web pages
onSecurityChange: function (webProgress, aRequest, aState)
{
const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener;
if(aState & nsIWebProgressListener.STATE_IS_INSECURE)
vimperator.statusline.setClass("insecure");
else if(aState & nsIWebProgressListener.STATE_IS_BROKEN)
vimperator.statusline.setClass("broken");
else if(aState & nsIWebProgressListener.STATE_IS_SECURE)
vimperator.statusline.setClass("secure");
},
onStatusChange: function(webProgress, request, status, message)
{
vimperator.statusline.updateUrl(message);
},
onProgressChange: function(webProgress, request, curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress)
{
vimperator.statusline.updateProgress(curTotalProgress/maxTotalProgress);
},
// happens when the users switches tabs
onLocationChange: function()
{
// if (vimperator.hasMode(vimperator.modes.HINTS) && !vimperator.hasMode(vimperator.modes.ALWAYS_HINT))
// hah.disableHahMode();
vimperator.statusline.updateUrl();
vimperator.statusline.updateProgress();
// if this is not delayed we get the wrong position of the old buffer
setTimeout(function() { vimperator.statusline.updateBufferPosition(); }, 100);
},
// called at the very end of a page load
asyncUpdateUI: function()
{
vimperator.statusline.updateUrl();
},
setOverLink : function(link, b)
{
var ssli = get_pref("showstatuslinks");
if (link && ssli)
{
if (ssli == 1)
vimperator.statusline.updateUrl("Link: " + link);
else if (ssli == 2)
vimperator.echo("Link: " + link);
}
if (link == "")
{
if (ssli == 1)
vimperator.statusline.updateUrl();
else if (ssli == 2)
vimperator.setMode(); // trick to reshow the mode in the command line
}
},
// stub functions for the interfaces
setJSStatus : function(status) { },
setJSDefaultStatus : function(status) { },
setDefaultStatus : function(status) { },
onLinkIconAvailable: function() { }
}
window.XULBrowserWindow = this.progressListener;
window.QueryInterface(Components.interfaces.nsIInterfaceRequestor) window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation) .getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShellTreeItem).treeOwner .QueryInterface(Components.interfaces.nsIDocShellTreeItem).treeOwner
@@ -198,130 +281,57 @@ function addEventListeners()
.XULBrowserWindow = window.XULBrowserWindow; .XULBrowserWindow = window.XULBrowserWindow;
// for onStateChange(), etc.: // for onStateChange(), etc.:
getBrowser().addProgressListener(buffer_changed_listener, Components.interfaces.nsIWebProgress.NOTIFY_ALL); getBrowser().addProgressListener(this.progressListener, Components.interfaces.nsIWebProgress.NOTIFY_ALL);
}
function onPageLoad(event)
{ ////////////////////////////////////////////////////////////////////////////////
if (event.originalTarget instanceof HTMLDocument) ////////////////////// PRIVATE SECTION /////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
function onPageLoad(event)
{ {
var doc = event.originalTarget; if (event.originalTarget instanceof HTMLDocument)
// document is part of a frameset
if (doc.defaultView.frameElement)
{ {
// hacky way to get rid of "Transfering data from ..." on sites with frames var doc = event.originalTarget;
// when you click on a link inside a frameset, because asyncUpdateUI // document is part of a frameset
// is not triggered there (firefox bug?) if (doc.defaultView.frameElement)
setTimeout(vimperator.statusline.updateUrl, 10); {
return; // hacky way to get rid of "Transfering data from ..." on sites with frames
} // when you click on a link inside a frameset, because asyncUpdateUI
// is not triggered there (firefox bug?)
setTimeout(vimperator.statusline.updateUrl, 10);
return;
}
// code which should happen for all (also background) newly loaded tabs goes here: // code which should happen for all (also background) newly loaded tabs goes here:
updateBufferList(); updateBufferList();
//update history //update history
var url = getCurrentLocation(); var url = getCurrentLocation();
var title = getCurrentTitle(); // not perfect "- Vimperator" in the title var title = getCurrentTitle(); // not perfect "- Vimperator" in the title
vimperator.history.add(url, title); vimperator.history.add(url, title);
// code which is only relevant if the page load is the current tab goes here: // code which is only relevant if the page load is the current tab goes here:
if(doc == getBrowser().selectedBrowser.contentDocument) if(doc == getBrowser().selectedBrowser.contentDocument)
{ {
/* none yet */ /* none yet */
}
} }
} }
}
var buffer_changed_listener = ////////////////////////////////////////////////////////////////////////////////
{ ////////////////////// PUBLIC SECTION //////////////////////////////////////////
QueryInterface: function(aIID) ////////////////////////////////////////////////////////////////////////////////
this.onEscape = function()
{ {
if (aIID.equals(Components.interfaces.nsIWebProgressListener) || if (!vimperator.hasMode(vimperator.modes.ESCAPE_ONE_KEY))
aIID.equals(Components.interfaces.nsIXULBrowserWindow) || // for setOverLink();
aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
aIID.equals(Components.interfaces.nsISupports))
return this;
throw Components.results.NS_NOINTERFACE;
},
// XXX: function may later be needed to detect a canceled synchronous openURL()
onStateChange: function(webProgress, aRequest, flags, aStatus)
{
// STATE_IS_DOCUMENT | STATE_IS_WINDOW is important, because we also
// receive statechange events for loading images and other parts of the web page
if(flags & (Components.interfaces.nsIWebProgressListener.STATE_IS_DOCUMENT |
Components.interfaces.nsIWebProgressListener.STATE_IS_WINDOW))
{ {
// This fires when the load event is initiated vimperator.setMode(vimperator.modes.NORMAL);
if(flags & Components.interfaces.nsIWebProgressListener.STATE_START) vimperator.echo("");
{ hah.disableHahMode();
vimperator.statusline.updateProgress(0); vimperator.focusContent();
} vimperator.statusline.updateUrl();
else if (flags & Components.interfaces.nsIWebProgressListener.STATE_STOP)
;// vimperator.statusline.updateUrl();
} }
}, }
// for notifying the user about secure web pages
onSecurityChange: function (webProgress, aRequest, aState)
{
const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener;
if(aState & nsIWebProgressListener.STATE_IS_INSECURE)
vimperator.statusline.setClass("insecure");
else if(aState & nsIWebProgressListener.STATE_IS_BROKEN)
vimperator.statusline.setClass("broken");
else if(aState & nsIWebProgressListener.STATE_IS_SECURE)
vimperator.statusline.setClass("secure");
},
onStatusChange: function(webProgress, request, status, message)
{
vimperator.statusline.updateUrl(message);
},
onProgressChange: function(webProgress, request, curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress)
{
vimperator.statusline.updateProgress(curTotalProgress/maxTotalProgress);
},
// happens when the users switches tabs
onLocationChange: function()
{
// if (vimperator.hasMode(vimperator.modes.HINTS) && !vimperator.hasMode(vimperator.modes.ALWAYS_HINT))
// hah.disableHahMode();
vimperator.statusline.updateUrl();
vimperator.statusline.updateProgress();
// if this is not delayed we get the wrong position of the old buffer
setTimeout(function() { vimperator.statusline.updateBufferPosition(); }, 100);
},
// called at the very end of a page load
asyncUpdateUI: function()
{
vimperator.statusline.updateUrl();
},
setOverLink : function(link, b)
{
var ssli = get_pref("showstatuslinks");
if (link && ssli)
{
if (ssli == 1)
vimperator.statusline.updateUrl("Link: " + link);
else if (ssli == 2)
vimperator.echo("Link: " + link);
}
if (link == "")
{
if (ssli == 1)
vimperator.statusline.updateUrl();
else if (ssli == 2)
vimperator.setMode(); // trick to reshow the mode in the command line
}
},
// stub functions for the interfaces
setJSStatus : function(status) { },
setJSDefaultStatus : function(status) { },
setDefaultStatus : function(status) { },
onLinkIconAvailable: function() { }
} }
@@ -532,7 +542,7 @@ function getLinkNodes(doc)
return links; return links;
}//}}} }//}}}
function Vimperator() function Vimperator() //{{{1
{ {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
////////////////////// PRIVATE SECTION ///////////////////////////////////////// ////////////////////// PRIVATE SECTION /////////////////////////////////////////
@@ -910,7 +920,7 @@ function Vimperator()
* Firefox 3.0, then this class should go away and their tab methods should be used * Firefox 3.0, then this class should go away and their tab methods should be used
* @deprecated * @deprecated
*/ */
function Tabs() function Tabs() //{{{1
{ {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
////////////////////// PRIVATE SECTION ///////////////////////////////////////// ////////////////////// PRIVATE SECTION /////////////////////////////////////////

View File

@@ -104,7 +104,7 @@ the terms of any one of the MPL, the GPL or the LGPL.
<keyset id="mainKeyset"> <keyset id="mainKeyset">
<key id="key_open_vimbar" key=":" oncommand="vimperator.commandline.open(':', '', MODE_EX);" modifiers=""/> <key id="key_open_vimbar" key=":" oncommand="vimperator.commandline.open(':', '', MODE_EX);" modifiers=""/>
<key id="key_stop" keycode="VK_ESCAPE" oncommand="onEscape();"/> <key id="key_stop" keycode="VK_ESCAPE" oncommand="vimperator.events.onEscape();"/>
<!-- other keys are handled inside vimperator.js event loop --> <!-- other keys are handled inside vimperator.js event loop -->
</keyset> </keyset>
</window> </window>