diff --git a/common/content/buffer.js b/common/content/buffer.js index 4ce32dca..1e2d76c4 100644 --- a/common/content/buffer.js +++ b/common/content/buffer.js @@ -746,15 +746,14 @@ function Buffer() //{{{ // get file size const ACCESS_READ = Ci.nsICache.ACCESS_READ; - const cacheService = Cc["@mozilla.org/network/cache-service;1"].getService(Ci.nsICacheService); let cacheKey = doc.location.toString().replace(/#.*$/, ""); for (let proto in util.Array.iterator(["HTTP", "FTP"])) { try { - var cacheEntryDescriptor = cacheService.createSession(proto, 0, true) - .openCacheEntry(cacheKey, ACCESS_READ, false); + var cacheEntryDescriptor = service["cache"].createSession(proto, 0, true) + .openCacheEntry(cacheKey, ACCESS_READ, false); break; } catch (e) {} diff --git a/common/content/commands.js b/common/content/commands.js index 6e7bd58e..d2682d54 100644 --- a/common/content/commands.js +++ b/common/content/commands.js @@ -176,7 +176,7 @@ Command.prototype = { let matches = args.match(/(.*)<<\s*(\S+)$/); if (matches && matches[2]) { - commandline.inputMultiline(new RegExp("^" + matches[2] + "$", "m"), + commandline.inputMultiline(RegExp("^" + matches[2] + "$", "m"), function (args) { exec(matches[1] + "\n" + args); }); return; } diff --git a/common/content/completion.js b/common/content/completion.js index 7eee6591..60dc0af6 100644 --- a/common/content/completion.js +++ b/common/content/completion.js @@ -128,7 +128,7 @@ function CompletionContext(editor, name, offset) //{{{ * results. */ this.filters = [function (item) { - let text = Array.concat(this.getKey(item, "text")); + let text = Array.concat(item.text); for (let [i, str] in Iterator(text)) { if (this.match(String(str))) @@ -318,6 +318,22 @@ CompletionContext.prototype = { get message() this._message || (this.waitingForTab ? "Waiting for " : null), set message(val) this._message = val, + get proto() + { + let res = {}; + for (let i in Iterator(this.keys)) + { + let [k, v] = i; + let _k = "_" + k; + if (typeof v == "function") + res.__defineGetter__(k, function () _k in this ? this[_k] : (this[_k] = v(this.item))); + else + res.__defineGetter__(k, function () _k in this ? this[_k] : (this[_k] = this.item[v])); + res.__defineSetter__(k, function (val) this[_k] = val); + } + return res; + }, + get regenerate() this._generate && (!this.completions || !this.itemCache[this.key] || this.cache.offset != this.offset), set regenerate(val) { if (val) delete this.itemCache[this.key] }, @@ -327,7 +343,7 @@ CompletionContext.prototype = { this.itemCache = {}; this.cache.offset = this.offset; if (!this.itemCache[this.key]) - this.itemCache[this.key] = this._generate.call(this); + this.itemCache[this.key] = this._generate.call(this) || []; return this.itemCache[this.key]; }, set generate(arg) @@ -404,7 +420,8 @@ CompletionContext.prototype = { let self = this; delete this._substrings; - let filtered = this.filterFunc(items.map(function (item) ({ text: self.getKey({ item: item }, "text"), item: item }))); + let proto = this.proto; + let filtered = this.filterFunc(items.map(function (item) ({ __proto__: proto, item: item }))); if (this.maxItems) filtered = filtered.slice(0, this.maxItems); @@ -658,17 +675,10 @@ function Completion() //{{{ ////////////////////// PRIVATE SECTION ///////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - try - { - var completionService = Cc["@mozilla.org/browser/global-history;2"].getService(Ci.nsIAutoCompleteSearch); - } - catch (e) {} - const EVAL_TMP = "__liberator_eval_tmp"; function Javascript() { - let json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON); const OFFSET = 0, CHAR = 1, STATEMENTS = 2, DOTS = 3, FULL_STATEMENTS = 4, COMMA = 5, FUNCTIONS = 6; let stack = []; let functions = []; @@ -1334,9 +1344,9 @@ function Completion() //{{{ context.format = bookmarks.format; for (let val in Iterator(extra || [])) { - let [k, v] = val; // Need let block here for closure. + let [k, v] = val; // Need block scope here for the closure if (v) - context.filters.push(function (item) this._match(v, this.getKey(item, k))); + context.filters.push(function (item) this._match(v, item[k])); } // Need to make a copy because set completions() checks instanceof Array, // and this may be an Array from another window. @@ -1384,7 +1394,7 @@ function Completion() //{{{ io.getRuntimeDirectories("colors").forEach(function (dir) { context.fork(dir.path, 0, null, function (context) { context.filter = dir.path + io.pathSeparator + context.filter; - completion.file(context, true); + completion.file(context); context.title = ["Color Scheme"]; context.quote = ["", function (text) text.replace(/\.vimp$/, ""), ""]; }); @@ -1404,10 +1414,10 @@ function Completion() //{{{ context.completions = config.dialogs; }, - directory: function directory(context, tail) + directory: function directory(context, full) { - this.file(context, tail); - context.filters.push(function (item) this.getKey(item, "description") == "Directory"); + this.file(context, full); + context.filters.push(function ({ item: f }) f.isDirectory()); }, environment: function environment(context) @@ -1468,40 +1478,40 @@ function Completion() //{{{ // TODO: support file:// and \ or / path separators on both platforms // if "tail" is true, only return names without any directory components - file: function file(context, tail) + file: function file(context, full) { - let [dir] = context.filter.match(/^(?:.*[\/\\])?/); // dir == "" is expanded inside readDirectory to the current dir + let [dir] = context.filter.match(/^(?:.*[\/\\])?/); - context.title = ["Path", "Type"]; - if (tail) + if (!full) context.advance(dir.length); - context.keys = { text: 0, description: 1, icon: 2 }; + + context.title = [full ? "Path" : "Filename", "Type"]; + context.keys = { + text: !full ? "leafName" : function (f) dir + f.leafName, + description: function (f) f.isDirectory() ? "Directory" : "File", + isdir: function (f) f.isDirectory(), + icon: function (f) f.isDirectory() ? "resource://gre/res/html/folder.png" + : "moz-icon://" + f.leafName + }; + context.compare = function (a, b) + b.isdir - a.isdir || String.localeCompare(a.text, b.text); + + if (options["wildignore"]) + { + let wigRegexp = RegExp("(^" + options.get("wildignore").values.join("|") + ")$"); + context.filters.push(function ({item: f}) f.isDirectory() || !wigRegexp.test(f.leafName)); + } + // context.background = true; context.key = dir; context.generate = function generate_file() { - context.cache.dir = dir; - try { - let files = io.readDirectory(dir); - - if (options["wildignore"]) - { - let wigRegexp = RegExp("(^" + options["wildignore"].replace(",", "|", "g") + ")$"); - files = files.filter(function (f) f.isDirectory() || !wigRegexp.test(f.leafName)) - } - - return files.map( - function (file) [tail ? file.leafName : dir + file.leafName, - file.isDirectory() ? "Directory" : "File", - file.isDirectory() ? "resource://gre/res/html/folder.png" - : "moz-icon://" + file.leafName] - ); + return io.readDirectory(dir); } catch (e) {} - return []; }; }, @@ -1541,7 +1551,7 @@ function Completion() //{{{ location: function location(context) { - if (!completionService) + if (!service["autoCompleteSearch"]) return context.anchored = false; context.title = ["Smart Completions"]; @@ -1557,8 +1567,8 @@ function Completion() //{{{ for (i in util.range(0, result.matchCount)) ]; }); - completionService.stopSearch(); - completionService.startSearch(context.filter, "", context.result, { + service["autoCompleteSearch"].stopSearch(); + service["autoCompleteSearch"].startSearch(context.filter, "", context.result, { onSearchResult: function onSearchResult(search, result) { context.result = result; @@ -1638,11 +1648,10 @@ function Completion() //{{{ preference: function preference(context) { - let prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); context.anchored = false; context.title = ["Firefox Preference", "Value"]; context.keys = { text: function (item) item, description: function (item) options.getPref(item) }; - context.completions = prefs.getChildList("", { value: 0 }); + context.completions = service["pref"].getChildList("", { value: 0 }); }, search: function search(context, noSuggest) @@ -1689,12 +1698,11 @@ function Completion() //{{{ if (!context.filter) return; - let ss = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService); let engineList = (engineAliases || options["suggestengines"] || "google").split(","); let completions = []; engineList.forEach(function (name) { - let engine = ss.getEngineByAlias(name); + let engine = service["browserSearch"].getEngineByAlias(name); if (!engine) return; let [,word] = /^\s*(\S+)/.exec(context.filter) || []; @@ -1717,9 +1725,7 @@ function Completion() //{{{ context.title = ["Shell Command", "Path"]; context.generate = function () { - const environmentService = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment); - - let dirNames = environmentService.get("PATH").split(RegExp(liberator.has("Win32") ? ";" : ":")); + let dirNames = service["environment"].get("PATH").split(RegExp(liberator.has("Win32") ? ";" : ":")); let commands = []; for (let [,dirName] in Iterator(dirNames)) @@ -1780,7 +1786,7 @@ function Completion() //{{{ if (tags) context.filters.push(function (item) tags. - every(function (tag) (context.getKey(item, "tags") || []). + every(function (tag) (item.tags || []). some(function (t) !compare(tag, t)))); context.anchored = false; @@ -1799,8 +1805,8 @@ function Completion() //{{{ // and all that don't match the tokens. let tokens = context.filter.split(/\s+/); context.filters.push(function (item) tokens.every( - function (tok) contains(context.getKey(item, "url"), tok) || - contains(context.getKey(item, "title"), tok))); + function (tok) contains(item.url, tok) || + contains(item.title, tok))); let re = RegExp(tokens.filter(util.identity).map(util.escapeRegex).join("|"), "g"); function highlight(item, text, i) process[i].call(this, item, template.highlightRegexp(text, re)); diff --git a/common/content/events.js b/common/content/events.js index c1432bbe..7c7d486d 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -817,13 +817,13 @@ function Events() //{{{ if (!filter) return macros; - let re = new RegExp(filter); + let re = RegExp(filter); return ([macro, keys] for ([macro, keys] in macros) if (re.test(macro))); }, deleteMacros: function (filter) { - let re = new RegExp(filter); + let re = RegExp(filter); for (let [item,] in macros) { @@ -1300,7 +1300,7 @@ function Events() //{{{ let stop = true; // set to false if we should NOT consume this event but let Firefox handle it let win = document.commandDispatcher.focusedWindow; - if (win && win.document.designMode == "on" && !config.isComposeWindow) + if (win && win.document && win.document.designMode == "on" && !config.isComposeWindow) return false; // menus have their own command handlers @@ -1549,10 +1549,9 @@ function Events() //{{{ // XXX: function may later be needed to detect a canceled synchronous openURL() onStateChange: function (webProgress, request, flags, status) { - const nsIWebProgressListener = Ci.nsIWebProgressListener; // 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 & (nsIWebProgressListener.STATE_IS_DOCUMENT | nsIWebProgressListener.STATE_IS_WINDOW)) + if (flags & (Ci.nsIWebProgressListener.STATE_IS_DOCUMENT | Ci.nsIWebProgressListener.STATE_IS_WINDOW)) { // This fires when the load event is initiated // only thrown for the current tab, not when another tab changes @@ -1581,12 +1580,11 @@ function Events() //{{{ // for notifying the user about secure web pages onSecurityChange: function (webProgress, aRequest, aState) { - const nsIWebProgressListener = Ci.nsIWebProgressListener; - if (aState & nsIWebProgressListener.STATE_IS_INSECURE) + if (aState & Ci.nsIWebProgressListener.STATE_IS_INSECURE) statusline.setClass("insecure"); - else if (aState & nsIWebProgressListener.STATE_IS_BROKEN) + else if (aState & Ci.nsIWebProgressListener.STATE_IS_BROKEN) statusline.setClass("broken"); - else if (aState & nsIWebProgressListener.STATE_IS_SECURE) + else if (aState & Ci.nsIWebProgressListener.STATE_IS_SECURE) statusline.setClass("secure"); }, onStatusChange: function (webProgress, request, status, message) @@ -1646,9 +1644,8 @@ function Events() //{{{ prefObserver: { register: function () { - const prefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService); - this._branch = prefService.getBranch(""); // better way to monitor all changes? - this._branch.QueryInterface(Ci.nsIPrefBranch2); + this._branch = service["pref"].getBranch("") // better way to monitor all changes? + .QueryInterface(Ci.nsIPrefBranch2); this._branch.addObserver("", this, false); }, diff --git a/common/content/find.js b/common/content/find.js index 72c77388..09f02a43 100644 --- a/common/content/find.js +++ b/common/content/find.js @@ -138,9 +138,7 @@ function Search() //{{{ var highlightObj = { search: function (aWord, matchCase) { - var finder = Cc["@mozilla.org/embedcomp/rangefind;1"] - .createInstance() - .QueryInterface(Ci.nsIFind); + var finder = service.getFind(); if (matchCase !== undefined) finder.caseSensitive = matchCase; diff --git a/common/content/help.js b/common/content/help.js new file mode 100644 index 00000000..3ae6d96e --- /dev/null +++ b/common/content/help.js @@ -0,0 +1,11 @@ + +const win = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] + .getService(Components.interfaces.nsIWindowWatcher) + .activeWindow; +const liberator = win.liberator; + +let page = liberator.findHelp(decodeURIComponent(document.location.search.substr(1))); +let url = "chrome://liberator/locale/" + page; + +win.getBrowser().loadURIWithFlags(url, Components.interfaces.nsIWebNavigation.LOAD_FLAGS_REPLACE_HISTORY, null, null, null); + diff --git a/common/content/help.xul b/common/content/help.xul new file mode 100644 index 00000000..16be6018 --- /dev/null +++ b/common/content/help.xul @@ -0,0 +1,7 @@ + + + + {doctitle} @@ -73,10 +74,10 @@ HEADER=
| key=
|
-option=| -option2='|' -command=| -mapping=| +option=| +option2='|' +command=| +mapping=| argument=| argument2={|} argument3=[|] diff --git a/vimperator/locale/en-US/browsing.txt b/vimperator/locale/en-US/browsing.txt index 97f43335..10ba2231 100644 --- a/vimperator/locale/en-US/browsing.txt +++ b/vimperator/locale/en-US/browsing.txt @@ -68,7 +68,7 @@ ________________________________________________________________________________ ||:tabopen[!] [arg1], [arg2], ...|| + ||t|| ________________________________________________________________________________ -Just like help::open[browsing.html#opening], but opens the resulting web page(s) +Just like [c]:open[c], but opens the resulting web page(s) in a new tab. When used with [!], the 'tabopen' value of the 'activate' option is negated. ________________________________________________________________________________ diff --git a/vimperator/locale/en-US/help.js b/vimperator/locale/en-US/help.js new file mode 100644 index 00000000..00889f12 --- /dev/null +++ b/vimperator/locale/en-US/help.js @@ -0,0 +1,27 @@ + +function checkFragment() +{ + let frag = document.location.hash.substr(1); + if (!frag || document.getElementById(frag)) + return; + let elem = document.evaluate('//*[@class="tag" and text()="' + frag + '"]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0); + if (elem) + window.content.scrollTo(0, elem.getBoundingClientRect().top - 10); // 10px context +} + +document.addEventListener("load", checkFragment, true); +window.addEventListener("message", function (event) { + if (event.data == "fragmentChange") + checkFragment(); +}, true); + +document.addEventListener("click", function (event) { + let elem = event.target; + if (/^(option|mapping|command)$/.test(elem.className)) + var tag = elem.textContent.replace(/\s.*/, ""); + if (elem.className == "command") + tag = tag.replace(/\[.*?\]/g, ""); + if (tag) + elem.href = "chrome://liberator/content/help.xul?" + encodeURIComponent(tag); +}, true); + diff --git a/vimperator/locale/en-US/options.txt b/vimperator/locale/en-US/options.txt index 31487e54..16b93731 100644 --- a/vimperator/locale/en-US/options.txt +++ b/vimperator/locale/en-US/options.txt @@ -590,10 +590,11 @@ match being used. The patterns are case insensitive regular expressions. ____ +|$VIMPERATOR_RUNTIME| |\'rtp'| |\'runtimepath'| ||'runtimepath' 'rtp'|| stringlist ____ -(default: Unix, Mac: "\~/.vimperator", Windows: "\~/vimperator") +(default: \'$VIMPERATOR_RUNTIME' or Unix, Mac: "\~/.vimperator", Windows: "\~/vimperator") List of directories searched for runtime files: + macros/ + diff --git a/vimperator/locale/en-US/starting.txt b/vimperator/locale/en-US/starting.txt index 618820ba..e7b87b5b 100644 --- a/vimperator/locale/en-US/starting.txt +++ b/vimperator/locale/en-US/starting.txt @@ -5,20 +5,20 @@ be documented here. section:Initialization[initialization,startup] -At startup Vimperator sources a user RC file, containing Ex commands, and any -JavaScript files found in the plugin directory. The RC file may be named -[a].vimperatorrc[a] or [a]\_vimperatorrc[a]. The search order is: +At startup Vimperator can perform user initialization commands. When one of +the following is successfully located, it is executed, and no further +locations are tried. -* Unix and Mac: [a]\~/.vimperatorrc[a] then [a]\~/_vimperatorrc[a] -* Windows - [a]\~/_vimperatorrc[a] then [a]\~/.vimperatorrc[a] +|$VIMPERATOR_INIT| +1. _$VIMPERATOR_INIT_ - May contain a single ex command, usually + [c]:source {file}[c]. +2. [a]\~/_vimperatorrc[a] - Windows only. If this file exists, its contents + are executed. +3. [a]\~/.vimperatorrc[a] - If this file exists, its contents are executed. If 'exrc' is set then any RC file in the current directory is also sourced. -The plugin directory can be in any of the directories in 'runtimepath'. Using -the default value of 'runtimepath' this would be: - -* Unix and Mac - [a]\~/.vimperator/plugin[a] -* Windows - [a]\~/vimperator/plugin[a] +The plugin directory can be in any of the directories in 'runtimepath'. All directories in 'runtimepath' are searched for plugins and they are are all loaded. @@ -31,8 +31,6 @@ The user's \'$HOME'(~) directory is determined as follows: * Windows - if _%HOME%_ is set then this is used, otherwise _%USERPROFILE%_ or finally _%HOMEDRIVE%%HOMEPATH%_. -_$VIMPERATOR_HOME_ can be used to override the calculated _$HOME_ directory. - section:Saving{nbsp}settings[save-settings] |:mkv| |:mkvimperatorrc| diff --git a/vimperator/locale/en-US/xhtml11.css b/vimperator/locale/en-US/xhtml11.css index 1ff321a5..194c0557 100644 --- a/vimperator/locale/en-US/xhtml11.css +++ b/vimperator/locale/en-US/xhtml11.css @@ -335,6 +335,14 @@ fieldset.paypal { font-weight: bold; color: #106326; } + +.option, .mapping, .command { + text-decoration: none; +} +.option:hover, .mapping:hover, .command:hover { + text-decoration: underline; +} + .quoteblock { margin-left: 140px; padding-bottom: 10px;