From 64c6c5c0f19e715d47b39a23f2f22cf3cd7fa3a1 Mon Sep 17 00:00:00 2001 From: "ben%netscape.com" Date: Sat, 8 Jul 2000 03:21:23 +0000 Subject: [PATCH] more Application Helper Pref panel stuff (supporting removal of handlers) --- .../resources/content/overrideHandler.js | 39 +++++ .../content/pref-applications-edit.xul | 146 +++++++++--------- .../resources/content/pref-applications.js | 15 +- .../resources/content/pref-applications.xul | 1 + .../locale/en-US/pref-applications.properties | 3 + 5 files changed, 126 insertions(+), 78 deletions(-) diff --git a/xpfe/components/prefwindow/resources/content/overrideHandler.js b/xpfe/components/prefwindow/resources/content/overrideHandler.js index 0065184bedc..b008a8cd8d0 100644 --- a/xpfe/components/prefwindow/resources/content/overrideHandler.js +++ b/xpfe/components/prefwindow/resources/content/overrideHandler.js @@ -346,3 +346,42 @@ function unassertMIMEStuff(aMIMEString, aPropertyString, aValueString) gDS.Unassert(mimeSource, valueProperty, mimeLiteral, true); } +function removeOverride(aMIMEType) +{ + dump("*** mimeType = " + aMIMEType + "\n"); + // remove entry from seq + var rdfc = Components.classes["component://netscape/rdf/container"].createInstance(); + if (rdfc) { + rdfc = rdfc.QueryInterface(Components.interfaces.nsIRDFContainer); + if (rdfc) { + var containerRes = gRDF.GetResource("urn:mimetypes:root"); + rdfc.Init(gDS, containerRes); + var element = gRDF.GetResource(MIME_URI(aMIMEType)); + if (rdfc.IndexOf(element) != -1) + rdfc.RemoveElement(element, true); + } + } + + // remove items from the graph + var urns = [ [MIME_URI, ["description", "editable", "value", "smallIcon", "largeIcon"], [HANDLER_URI, "handlerProp"]], + [HANDLER_URI, ["handleInternal", "saveToDisk", "alwaysAsk"], [APP_URI, "externalApplication"]], + [APP_URI, ["path", "prettyName"]] ]; + for (var i = 0; i < urns.length; i++) { + var mimeRes = gRDF.GetResource(urns[i][0](aMIMEType)); + dump("*** mimeRes = " + mimeRes + "\n"); + // unassert the toplevel properties + var properties = urns[i][1]; + for (var j = 0; j < properties.length; j++) { + var propertyRes = gRDF.GetResource(NC_RDF(properties[j]), true); + dump("*** propertyRes = " + propertyRes + "\n"); + var mimeValue = gDS.GetTarget(mimeRes, propertyRes, true); + dump("*** mimeValue = " + mimeValue + "\n"); + gDS.Unassert(mimeRes, propertyRes, mimeValue, true); + } + if (urns[i][2]) { + var linkRes = gRDF.GetResource(NC_RDF(urns[i][2][1]), true); + var linkTarget = gRDF.GetResource(urns[i][2][0](aMIMEType), true); + gDS.Unassert(mimeRes, linkRes, linkTarget); + } + } +} \ No newline at end of file diff --git a/xpfe/components/prefwindow/resources/content/pref-applications-edit.xul b/xpfe/components/prefwindow/resources/content/pref-applications-edit.xul index 5f00207ee2e..53de5a4e2ba 100644 --- a/xpfe/components/prefwindow/resources/content/pref-applications-edit.xul +++ b/xpfe/components/prefwindow/resources/content/pref-applications-edit.xul @@ -133,80 +133,80 @@ doEnabling(); } -var gDS = null; -function onOK() -{ - const mimeTypes = 66638; - var fileLocator = Components.classes["component://netscape/filelocator"].getService(); - if (fileLocator) - fileLocator = fileLocator.QueryInterface(Components.interfaces.nsIFileLocator); - var file = fileLocator.GetFileLocation(mimeTypes); - if (file) - file = file.QueryInterface(Components.interfaces.nsIFileSpec); - gDS = gRDF.GetDataSource(file.URLString); - if (gDS) - gDS = gDS.QueryInterface(Components.interfaces.nsIRDFDataSource); - - // figure out if this mime type already exists. - if (gMIMEField.value != gOldMIME) { - var exists = mimeHandlerExists(gMIMEField.value); - if (exists) { - var titleMsg = gBundle.GetStringFromName("handlerExistsTitle"); - var dialogMsg = gBundle.GetStringFromName("handlerExists"); - dialogMsg = dialogMsg.replace(/%mime%/g, gMIMEField.value); - var commonDialogService = nsJSComponentManager.getService("component://netscape/appshell/commonDialogs", - "nsICommonDialogs"); - var replace = commonDialogService.Confirm(window, titleMsg, dialogMsg); - if (!replace) - window.close(); + var gDS = null; + function onOK() + { + const mimeTypes = 66638; + var fileLocator = Components.classes["component://netscape/filelocator"].getService(); + if (fileLocator) + fileLocator = fileLocator.QueryInterface(Components.interfaces.nsIFileLocator); + var file = fileLocator.GetFileLocation(mimeTypes); + if (file) + file = file.QueryInterface(Components.interfaces.nsIFileSpec); + gDS = gRDF.GetDataSource(file.URLString); + if (gDS) + gDS = gDS.QueryInterface(Components.interfaces.nsIRDFDataSource); + + // figure out if this mime type already exists. + if (gMIMEField.value != gOldMIME) { + var exists = mimeHandlerExists(gMIMEField.value); + if (exists) { + var titleMsg = gBundle.GetStringFromName("handlerExistsTitle"); + var dialogMsg = gBundle.GetStringFromName("handlerExists"); + dialogMsg = dialogMsg.replace(/%mime%/g, gMIMEField.value); + var commonDialogService = nsJSComponentManager.getService("component://netscape/appshell/commonDialogs", + "nsICommonDialogs"); + var replace = commonDialogService.Confirm(window, titleMsg, dialogMsg); + if (!replace) + window.close(); + } + } + + // now save the information + var handlerInfo = new HandlerOverride(MIME_URI(gMIMEField.value)); + handlerInfo.mUpdateMode = mimeHandlerExists(gMIMEField.value); + handlerInfo.mimeType = gMIMEField.value; + + // other info we need to set (not reflected in UI) + if (gHandlerGroup.data == "2") { + handlerInfo.appPath = gAppPath.value; + handlerInfo.setHandlerProcedure("saveToDisk", "false"); + handlerInfo.setHandlerProcedure("handleInternal", "false"); + } + else if (gHandlerGroup.data == "1") + handlerInfo.saveToDisk = true; + else + handlerInfo.handleInternal = true; + + handlerInfo.alwaysAsk = gAskBeforeOpen.checked; + + // need to make the following dynamic to track changes. otherwise the + // app pretty name remains the same. + // better still, find a way to XP dynamically discover the pretty name of the app + // from the OS. + var file = Components.classes["component://mozilla/file/local"].createInstance(); + if (file) + file = file.QueryInterface(Components.interfaces.nsILocalFile); + if (file) { + try { + file.initWithPath(gAppPath.value); + handlerInfo.appDisplayName = file.unicodeLeafName; + } + catch(e) { + handlerInfo.appDisplayName = gAppPath.value; + } + } + // do the rest of the work (ugly yes, but it works) + handlerInfo.buildLinks(); + + // flush the ds to disk. + gDS = gDS.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource); + if (gDS) + gDS.Flush(); + + window.opener.gUpdateTypeRV = true; + window.close(); } - } - - // now save the information - var handlerInfo = new HandlerOverride(MIME_URI(gMIMEField.value)); - handlerInfo.mUpdateMode = mimeHandlerExists(gMIMEField.value); - handlerInfo.mimeType = gMIMEField.value; - - // other info we need to set (not reflected in UI) - if (gHandlerGroup.data == "2") { - handlerInfo.appPath = gAppPath.value; - handlerInfo.setHandlerProcedure("saveToDisk", "false"); - handlerInfo.setHandlerProcedure("handleInternal", "false"); - } - else if (gHandlerGroup.data == "1") - handlerInfo.saveToDisk = true; - else - handlerInfo.handleInternal = true; - - handlerInfo.alwaysAsk = gAskBeforeOpen.checked; - - // need to make the following dynamic to track changes. otherwise the - // app pretty name remains the same. - // better still, find a way to XP dynamically discover the pretty name of the app - // from the OS. - var file = Components.classes["component://mozilla/file/local"].createInstance(); - if (file) - file = file.QueryInterface(Components.interfaces.nsILocalFile); - if (file) { - try { - file.initWithPath(gAppPath.value); - handlerInfo.appDisplayName = file.unicodeLeafName; - } - catch(e) { - handlerInfo.appDisplayName = gAppPath.value; - } - } - // do the rest of the work (ugly yes, but it works) - handlerInfo.buildLinks(); - - // flush the ds to disk. - gDS = gDS.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource); - if (gDS) - gDS.Flush(); - - window.opener.gUpdateTypeRV = true; - window.close(); -} ]]> diff --git a/xpfe/components/prefwindow/resources/content/pref-applications.js b/xpfe/components/prefwindow/resources/content/pref-applications.js index c8336336de7..7cb3c18a002 100644 --- a/xpfe/components/prefwindow/resources/content/pref-applications.js +++ b/xpfe/components/prefwindow/resources/content/pref-applications.js @@ -1,6 +1,5 @@ var gNewTypeRV = null; -var gRemoveTypeRV = null; var gUpdateTypeRV = null; function newType() @@ -16,11 +15,17 @@ function newType() function removeType() { - // implement me - if (gRemoveTypeRV) { - //gTree.builder.rebuild(); + var titleMsg = gBundle.GetStringFromName("removeHandlerTitle"); + var dialogMsg = gBundle.GetStringFromName("removeHandler"); + dialogMsg = dialogMsg.replace(/%n/g, "\n"); + var commonDialogService = nsJSComponentManager.getService("component://netscape/appshell/commonDialogs", + "nsICommonDialogs"); + var remove = commonDialogService.Confirm(window, titleMsg, dialogMsg); + if (remove) { + var uri = gTree.selectedItems[0].id; + var handlerOverride = new HandlerOverride(uri); + removeOverride(handlerOverride.mimeType); gTree.setAttribute("ref", "urn:mimetypes"); - gRemoveTypeRV = null; } } diff --git a/xpfe/components/prefwindow/resources/content/pref-applications.xul b/xpfe/components/prefwindow/resources/content/pref-applications.xul index 873297234d4..1823ae42e32 100644 --- a/xpfe/components/prefwindow/resources/content/pref-applications.xul +++ b/xpfe/components/prefwindow/resources/content/pref-applications.xul @@ -38,6 +38,7 @@ + diff --git a/xpfe/components/prefwindow/resources/locale/en-US/pref-applications.properties b/xpfe/components/prefwindow/resources/locale/en-US/pref-applications.properties index 28075430e85..e70bb087ef7 100644 --- a/xpfe/components/prefwindow/resources/locale/en-US/pref-applications.properties +++ b/xpfe/components/prefwindow/resources/locale/en-US/pref-applications.properties @@ -8,3 +8,6 @@ programsFilter=Programs handlerExists=A helper already exists for the MIME type '%mime%'. Do you want to replace it? handlerExistsTitle=Helper Application Exists + +removeHandlerTitle=Remove File Type +removeHandler=If you remove a registered type, the helper will no longer be able to automatically handle files of this type. %n%nAre you sure you want to remove this file type? \ No newline at end of file