From 9266c7831e5e4d0f4e123bd62e6cc0a2d114038f Mon Sep 17 00:00:00 2001 From: Einar Egilsson Date: Thu, 15 Oct 2009 09:49:49 +0000 Subject: Del and Enter keys work in redirect list. git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@268 119bf307-c92d-0410-89bd-8f53e6181181 --- chrome/content/code/editRedirect.xul.js | 3 ++- chrome/content/code/redirector.prototype.js | 11 +++++++++-- chrome/content/code/settings.xul.js | 16 +++++++++++++++- chrome/content/ui/settings.xul | 4 ++-- chrome/skin/redirector.css | 3 ++- 5 files changed, 30 insertions(+), 7 deletions(-) (limited to 'chrome') diff --git a/chrome/content/code/editRedirect.xul.js b/chrome/content/code/editRedirect.xul.js index e497245..100a7a0 100644 --- a/chrome/content/code/editRedirect.xul.js +++ b/chrome/content/code/editRedirect.xul.js @@ -53,7 +53,8 @@ var EditRedirect = { redirect.excludePattern = this.txtExcludePattern.value; redirect.redirectUrl = this.txtRedirectUrl.value; redirect.patternType = this.rdoRegex.getAttribute('selected') == 'true' ? Redirect.REGEX : Redirect.WILDCARD; - redirect.unescapeMatches = this.chkUnescapeMatches.getAttribute('checked'); + var val = this.chkUnescapeMatches.getAttribute('checked'); + redirect.unescapeMatches = val === 'true' || val === true; //Disabled cannot be set here }, diff --git a/chrome/content/code/redirector.prototype.js b/chrome/content/code/redirector.prototype.js index 4e39fa6..b69a52f 100644 --- a/chrome/content/code/redirector.prototype.js +++ b/chrome/content/code/redirector.prototype.js @@ -166,7 +166,8 @@ Redirector.prototype = { var importCount = 0, existsCount = 0; var lines = []; var line = {value: null}; - while (stream.readLine(line)) { + stream.readLine(line); + while (line.value) { var redirect = new Redirect(); redirect.deserialize(line.value.replace('\n', '')); if (this.containsRedirect(redirect)) { @@ -175,6 +176,7 @@ Redirector.prototype = { this.list.push(redirect); importCount++; } + stream.readLine(line); } stream.close(); this.save(); @@ -183,6 +185,12 @@ Redirector.prototype = { containsRedirect : function(redirect) { for each (var existing in this.list) { + this.debug("EXAMPLEURL: " + (redirect.exampleUrl == existing.exampleUrl)); + this.debug("INCLUDEPATTERN: " + (redirect.includePattern == existing.includePattern)); + this.debug("EXCLUDEPATTERN: " + (redirect.excludePattern == existing.excludePattern)); + this.debug("unescape: " + (redirect.unescapeMatches == existing.unescapeMatches)); + this.debug("REDIRECTTO: " + (redirect.redirectUrl == existing.redirectUrl)); + this.debug("PATTERNTYPE: " + (redirect.patternType == existing.patternType)); if (existing.equals(redirect)) { return true; } @@ -207,7 +215,6 @@ Redirector.prototype = { } var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); - //this.debug(currentUrl); var uri = ioService.newURI(currentUrl, null, null); return uri.resolve(relativeUrl); diff --git a/chrome/content/code/settings.xul.js b/chrome/content/code/settings.xul.js index c7b375c..f85c1ee 100644 --- a/chrome/content/code/settings.xul.js +++ b/chrome/content/code/settings.xul.js @@ -12,6 +12,8 @@ var Settings = { btnEdit : null, btnUp : null, btnDown : null, + btnExport : null, + btnImport : null, chkEnableRedirector : null, chkShowStatusBarIcon : null, chkShowContextMenu : null, @@ -25,6 +27,8 @@ var Settings = { this.btnEdit = document.getElementById('btnEdit'); this.btnUp = document.getElementById('btnUp'); this.btnDown = document.getElementById('btnDown'); + this.btnExport = document.getElementById('btnExport'); + this.btnImport = document.getElementById('btnImport'); this.chkEnableRedirector = document.getElementById('chkEnableRedirector'); this.chkShowStatusBarIcon = document.getElementById('chkShowStatusBarIcon'); this.chkShowContextMenu = document.getElementById('chkShowContextMenu'); @@ -39,7 +43,8 @@ var Settings = { this.template = document.getElementsByTagName('richlistitem')[0]; this.lstRedirects.removeChild(this.template); this.addItemsToListBox(Redirector.list); - + this.selectionChange(); + this.strings = document.getElementById('redirector-strings'); this.strings.getPluralized = function(id, number) { id += number == 1 ? 'Singular' : ''; @@ -188,6 +193,14 @@ var Settings = { alert(e); } }, + + listKeypress : function(event) { + if (event.keyCode == 13) { //Enter button + this.editRedirect(); + } else if (event.keyCode == 46) { //Del button + this.deleteRedirect(); + } + }, selectionChange : function() { if (!this.lstRedirects) { @@ -199,6 +212,7 @@ var Settings = { this.btnDelete.disabled = (index == -1); this.btnUp.disabled = (index <= 0); this.btnDown.disabled = (index == -1 || index >= Redirector.list.length-1); + this.btnExport.disabled = (Redirector.list.length == 0); }, importExport : function(mode, captionKey, func) { diff --git a/chrome/content/ui/settings.xul b/chrome/content/ui/settings.xul index d61e893..141c5ef 100644 --- a/chrome/content/ui/settings.xul +++ b/chrome/content/ui/settings.xul @@ -31,7 +31,7 @@ - + @@ -93,7 +93,7 @@ - +