From 18628591d8bad26265a5a16055285b50e0184b11 Mon Sep 17 00:00:00 2001 From: Einar Egilsson Date: Thu, 8 Oct 2009 11:41:58 +0000 Subject: Tooltips and accesskeys git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@257 119bf307-c92d-0410-89bd-8f53e6181181 --- chrome/content/code/browserOverlay.xul.js | 24 ++++++------- chrome/content/code/redirectList.xul.js | 51 ++++++++++++++++++---------- chrome/content/ui/browserOverlay.xul | 6 ---- chrome/content/ui/redirectList.xul | 37 ++++++++++---------- chrome/locale/en-US/redirectList.xul.dtd | 56 ++++++++++++++++++++++++++++++- chrome/skin/redirector.css | 5 +-- 6 files changed, 122 insertions(+), 57 deletions(-) diff --git a/chrome/content/code/browserOverlay.xul.js b/chrome/content/code/browserOverlay.xul.js index 5c84859..129da48 100644 --- a/chrome/content/code/browserOverlay.xul.js +++ b/chrome/content/code/browserOverlay.xul.js @@ -4,30 +4,21 @@ var Redirector = Components.classes["@einaregilsson.com/redirector;1"].getServic var RedirectorOverlay = { - name : "Redirector", - initialized : false, strings : null, onLoad : function(event) { try { // initialization code - Redirector.debug("Initializing..."); document.getElementById('contentAreaContextMenu') .addEventListener("popupshowing", function(e) { RedirectorOverlay.showContextMenu(e); }, false); - if (!Redirector.getBoolPref('showContextMenu')) { - document.getElementById('redirector-context').hidden = true; - } - if (!Redirector.getBoolPref('showStatusBarIcon')) { - document.getElementById('redirector-status').hidden = true; - } + document.getElementById('redirector-status').hidden = !Redirector.getBoolPref('showStatusBarIcon'); + document.getElementById('redirector-context').hidden = !Redirector.getBoolPref('showContextMenu'); + this.strings = document.getElementById("redirector-strings"); this.prefObserver.register(); this.setStatusBarImg(); - - Redirector.debug("Finished initialization"); - this.initialized = true; } catch(e) { if (this.strings) { @@ -123,8 +114,15 @@ var RedirectorOverlay = { }, observe : function(subject, topic, data) { - if (topic == 'nsPref:changed' && data == 'extensions.redirector.enabled') { + if (topic != 'nsPref:changed') { + return; + } + if (data == 'extensions.redirector.enabled') { RedirectorOverlay.setStatusBarImg(); + } else if (data == 'extensions.redirector.showStatusBarIcon') { + document.getElementById('redirector-status').hidden = !Redirector.getBoolPref('showStatusBarIcon'); + } else if (data == 'extensions.redirector.showContextMenu') { + document.getElementById('redirector-context').hidden = !Redirector.getBoolPref('showContextMenu'); } } } diff --git a/chrome/content/code/redirectList.xul.js b/chrome/content/code/redirectList.xul.js index c980178..76b450f 100644 --- a/chrome/content/code/redirectList.xul.js +++ b/chrome/content/code/redirectList.xul.js @@ -12,6 +12,23 @@ var RedirectList = { btnUp : null, btnDown : null, + onLoad : function() { + try { + this.lstRedirects = document.getElementById('lstRedirects'); + this.lstRedirects.selType = 'single'; + this.template = document.getElementsByTagName('richlistitem')[0]; + this.lstRedirects.removeChild(this.template); + this.btnDelete = document.getElementById('btnDelete'); + this.btnEdit = document.getElementById('btnEdit'); + this.btnUp = document.getElementById('btnUp'); + this.btnDown = document.getElementById('btnDown'); + this.addItemsToListBox(Redirector.list); + this.strings = document.getElementById('redirector-strings'); + } catch(e) { + alert(e); + } + }, + addItemsToListBox : function(items) { var item, row, value, newItem; @@ -44,23 +61,6 @@ var RedirectList = { },false); }, - onLoad : function() { - try { - this.lstRedirects = document.getElementById('lstRedirects'); - this.lstRedirects.selType = 'single'; - this.template = document.getElementsByTagName('richlistitem')[0]; - this.lstRedirects.removeChild(this.template); - this.btnDelete = document.getElementById('btnDelete'); - this.btnEdit = document.getElementById('btnEdit'); - this.btnUp = document.getElementById('btnUp'); - this.btnDown = document.getElementById('btnDown'); - this.addItemsToListBox(Redirector.list); - this.strings = document.getElementById('redirector-strings'); - } catch(e) { - alert(e); - } - }, - moveUp : function(){ if (this.lstRedirects.selectedIndex <= 0) { return; @@ -123,6 +123,12 @@ var RedirectList = { Redirector.save(); } }, + + buttonKeyPress : function(event) { + if (event.keyCode == 13 && !event.originalTarget.disabled) { + event.originalTarget.click(); + } + }, deleteRedirect : function() { var index = this.lstRedirects.selectedIndex; @@ -148,6 +154,9 @@ var RedirectList = { }, selectionChange : function() { + if (!this.lstRedirects) { + return; + } var index = this.lstRedirects.selectedIndex; this.btnEdit.disabled = (index == -1); @@ -156,6 +165,14 @@ var RedirectList = { this.btnDown.disabled = (index == -1 || index >= Redirector.list.length-1); }, + redirectListKeyDown : function(event) { + if (event.keyCode == 46) { //Del key + this.deleteRedirect(); + } else if (event.keyCode == 13) { //Enter key + this.editRedirect(); + } + }, + importExport : function(mode, captionKey, func) { //Mostly borrowed from Adblock Plus var picker = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker); diff --git a/chrome/content/ui/browserOverlay.xul b/chrome/content/ui/browserOverlay.xul index f12d0ff..77bab92 100644 --- a/chrome/content/ui/browserOverlay.xul +++ b/chrome/content/ui/browserOverlay.xul @@ -23,12 +23,6 @@ - @@ -21,15 +22,15 @@ - - - - + + + + - + @@ -55,35 +56,35 @@ -