diff --git a/mozilla/toolkit/mozapps/handling/content/dialog.js b/mozilla/toolkit/mozapps/handling/content/dialog.js index de4271a17d4..abd1126c056 100644 --- a/mozilla/toolkit/mozapps/handling/content/dialog.js +++ b/mozilla/toolkit/mozapps/handling/content/dialog.js @@ -171,17 +171,28 @@ var dialog = { let uri = Cc["@mozilla.org/network/util;1"]. getService(Ci.nsIIOService). newFileURI(fp.file); - let elm = document.createElement("richlistitem"); - elm.setAttribute("type", "handler"); - elm.setAttribute("name", fp.file.leafName); - elm.setAttribute("image", "moz-icon://" + uri.spec + "?size=32"); let handlerApp = Cc["@mozilla.org/uriloader/local-handler-app;1"]. createInstance(Ci.nsILocalHandlerApp); handlerApp.executable = fp.file; + + // if this application is already in the list, select it and don't add it again + let parent = document.getElementById("items"); + for (let i = 0; i < parent.childNodes.length; ++i) { + let elm = parent.childNodes[i]; + if (elm.obj instanceof Ci.nsILocalHandlerApp && elm.obj.equals(handlerApp)) { + parent.selectedItem = elm; + parent.ensureSelectedElementIsVisible(); + return; + } + } + + let elm = document.createElement("richlistitem"); + elm.setAttribute("type", "handler"); + elm.setAttribute("name", fp.file.leafName); + elm.setAttribute("image", "moz-icon://" + uri.spec + "?size=32"); elm.obj = handlerApp; - let parent = document.getElementById("items"); parent.selectedItem = parent.insertBefore(elm, parent.firstChild); parent.ensureSelectedElementIsVisible(); }