From 4019129519d5fd28522c4f37afd1627c9800e8c0 Mon Sep 17 00:00:00 2001 From: Martin Stubenschrott Date: Sat, 28 Apr 2007 12:14:37 +0000 Subject: [PATCH] added goUp() and isDirectory(uri) functions gu and gU mappings for going up --- ChangeLog | 5 +++ TODO | 3 +- chrome/content/vimperator/commands.js | 59 ++++++++++++++++++++++++++- chrome/content/vimperator/help.js | 9 ++-- 4 files changed, 68 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index ea9489b1..8b24cd37 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,12 @@
 date:
 	* version 0.4
+	* extension GUID was changed to 'vimperator@mozdev.net' -> YOU WILL HAVE
+	  TO UNINSTALL ANY OLD VIMPERATOR INSTALLATION BEFORE INSTALLING THIS VERSION
 	* support for 'wildmode' completion setting
 	* changed regexp search to normal text search for completion -> massive speedup, but limited functionality
 	* support for :open ./ , :open .. and :open ... (patch from Lee Hinman)
+	  'gu' and  goes up a directory component, gU and  to the root directory 
 	* Esc now doesn't stop loading the webpage, use Ctrl-c instead, :stop command added
 	* changed hinttags to work with dict.leo.org and hintstyle to work with digg.com
 	* :back! goes to beginning of history now
@@ -13,6 +16,7 @@ date:
 	  (patch from Viktor Kojouharov)
 	* :source support, and auto-sourcing ~/.vimperatorrc on startup
 	* :javascript <)
 5 Use arrow keys in preview window, and ctrl-w+j/k to switch to from preview window
-5 Sort :open completion by date?
+5 Sort :open completion by date? (use 'wildsort')
 5 make use of the ] and [ keys to e.g. jump to the next heading ]], next image ]i, previous textbox [t and so on
 5 add tag support to adding/deleting bookmarks
-4 change :exec to behave more vim like, and add a seperate :javascript << EOF command
 4 Support multiple top-level windows?
 3 Splitting Windows with [:sp :vsp ctrl-w,s ctrl-w,v] and closing with [ctrl-w,q], moving with [ctrl-w,w or tab]
   have a look into the split browser extension
diff --git a/chrome/content/vimperator/commands.js b/chrome/content/vimperator/commands.js
index 021a3fcc..8f5939b6 100644
--- a/chrome/content/vimperator/commands.js
+++ b/chrome/content/vimperator/commands.js
@@ -124,7 +124,7 @@ var g_commands = [/*{{{*/
     [
         ["buffers", "files", "ls"],
         ["buffers"],
-        "Shows a list of all buffers",
+        "Show a list of all buffers",
         "If the list is already shown, close the preview window.",
         buffer_preview_toggle,
         null
@@ -157,7 +157,7 @@ var g_commands = [/*{{{*/
     [
         ["execute", "exe"],
         ["exe[cute] {expr1} [ ... ]"],
-        "Executes the string that results from the evaluation of {expr1} as an Ex command.",
+        "Execute the string that results from the evaluation of {expr1} as an Ex command.",
         ":execute "echo test" would show a message with the text "test".
", execute, null @@ -772,6 +772,20 @@ var g_mappings = [/*{{{*/ "Count is supported, 3L goes forward 3 steps.", function(count) { stepInHistory(count > 0 ? count : 1); } ], + [ + ["gu", ""], + ["{count}gu", "{count}"], + "Go up one directory component", + "Count is supported, 2gu on http://www.example.com/dir1/dir2/file.htm would open http://www.example.com/dir1/", + goUp + ], + [ + ["gU", ""], + ["gU", ""], + "Go up one directory component", + "gU on http://www.example.com/dir1/dir2/file.htm opens http://www.example.com/", + function(count) { openURLs("..."); } + ], /* hint managment */ [ @@ -1325,6 +1339,30 @@ function stringToURLs(str) return urls; } +/* returns true if the currently loaded URI is + * a directory or false if it is a file + * if passed 'url' is null, use current directory + */ +function isDirectory(url) +{ + if (url.match(/^file:\/\//) || url.match(/^\//)) + { + var stripedFilename = url.replace(/^(file:\/\/)?(.*)/, "$2"); + var file = fopen(stripedFilename, '<'); + if (!file) + return false; + + if (file.localFile.isDirectory()) + return true; + else + return false; + } + // for all other locations just check if the URL ends with / + if (url.match(/\/$/)) + return true; + else + return false; +} //////////////////////////////////////////////////////////////////////// // frame related functions //////////////////////////////////////// {{{1 //////////////////////////////////////////////////////////////////////// @@ -1381,6 +1419,23 @@ function getCurrentLocation() return content.document.location.href; } +function goUp(count) +{ + var gocmd = ""; + if (isDirectory(getCurrentLocation())) + gocmd = "../"; + else + gocmd = "./"; + + if (count < 1) + count = 1; + + for(var i=0; i