more Application Helper Pref panel stuff (supporting removal of handlers)

This commit is contained in:
ben%netscape.com 2000-07-08 03:21:23 +00:00
Родитель c99fd7394b
Коммит 64c6c5c0f1
5 изменённых файлов: 126 добавлений и 78 удалений

Просмотреть файл

@ -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);
}
}
}

Просмотреть файл

@ -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();
}
]]>
</script>

Просмотреть файл

@ -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;
}
}

Просмотреть файл

@ -38,6 +38,7 @@
<script language="JavaScript" src="chrome://communicator/content/pref/pref-applications.js"></script>
<script language="JavaScript" src="chrome://communicator/content/pref/overrideHandler.js"></script>
<script language="JavaScript" src="chrome://global/content/strres.js"></script>
<script language="JavaScript" src="chrome://global/content/nsJSComponentManager.js"></script>
<box class="box-smallheader" title="&lHeader;"/>

Просмотреть файл

@ -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?