mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-07 03:45:42 +00:00
initial checkin for bug 10958 (exception feature), application helper pref panel.
Supports adding a new override but not editing or removing. Will work on that next.
This commit is contained in:
parent
269dfdf285
commit
5c91e66869
@ -2,6 +2,11 @@ pref-advanced.xul
|
||||
pref-imageblocking.xul
|
||||
pref-appearance.xul
|
||||
pref-applications.xul
|
||||
pref-applications.js
|
||||
pref-applications-edit.xul
|
||||
pref-applications-new.xul
|
||||
pref-applications-new.js
|
||||
overrideHandler.js
|
||||
pref-charset.js
|
||||
pref-charset.xul
|
||||
pref-cache.js
|
||||
|
@ -36,6 +36,11 @@ CHROME_CONTENT = \
|
||||
pref-imageblocking.xul \
|
||||
pref-appearance.xul \
|
||||
pref-applications.xul \
|
||||
pref-applications.js \
|
||||
pref-applications-edit.xul \
|
||||
pref-applications-new.js \
|
||||
pref-applications-new.xul \
|
||||
overrideHandler.js \
|
||||
pref-cache.xul \
|
||||
pref-cache.js \
|
||||
pref-charset.xul \
|
||||
|
@ -29,6 +29,11 @@ CHROME_CONTENT = \
|
||||
.\pref-imageblocking.xul \
|
||||
.\pref-appearance.xul \
|
||||
.\pref-applications.xul \
|
||||
.\pref-applications.js \
|
||||
.\pref-applications-edit.xul \
|
||||
.\pref-applications-new.xul \
|
||||
.\pref-applications-new.js \
|
||||
.\overrideHandler.js \
|
||||
.\pref-cache.js \
|
||||
.\pref-cache.xul \
|
||||
.\pref-colors.js \
|
||||
|
278
xpfe/components/prefwindow/resources/content/overrideHandler.js
Normal file
278
xpfe/components/prefwindow/resources/content/overrideHandler.js
Normal file
@ -0,0 +1,278 @@
|
||||
|
||||
/**
|
||||
* Datasource initialization
|
||||
**/
|
||||
|
||||
var gRDF = Components.classes["component://netscape/rdf/rdf-service"].getService();
|
||||
if (gRDF)
|
||||
gRDF = gRDF.QueryInterface(Components.interfaces.nsIRDFService);
|
||||
|
||||
/**
|
||||
* Handler Override class
|
||||
**/
|
||||
function HandlerOverride(aURI)
|
||||
{
|
||||
this.URI = aURI;
|
||||
}
|
||||
|
||||
HandlerOverride.prototype = {
|
||||
// general information
|
||||
get mimeType()
|
||||
{
|
||||
return getLiteralForContentType(this.URI, "value");
|
||||
},
|
||||
|
||||
set mimeType(aMIMETypeString)
|
||||
{
|
||||
assertMIMEStuff(MIME_URI(aMIMETypeString), "value", aMIMETypeString);
|
||||
},
|
||||
|
||||
get description()
|
||||
{
|
||||
return getLiteralForContentType(this.URI, "description");
|
||||
},
|
||||
|
||||
set description(aDescriptionString)
|
||||
{
|
||||
assertMIMEStuff(MIME_URI(this.mimeType), "description", aDescriptionString);
|
||||
},
|
||||
|
||||
get isEditable()
|
||||
{
|
||||
return getLiteralForContentType(this.URI, "editable");
|
||||
},
|
||||
|
||||
set isEditable(aIsEditableString)
|
||||
{
|
||||
assertMIMEStuff(MIME_URI(this.mimeType), "editable", aIsEditableString);
|
||||
},
|
||||
|
||||
get largeIconURL()
|
||||
{
|
||||
var url = getLiteralForContentType(this.URI, "largeIcon");
|
||||
if (!url)
|
||||
url = "chrome://communicator/skin/content-large.gif";
|
||||
return url;
|
||||
},
|
||||
|
||||
set largeIconURL(aLargeIconURL)
|
||||
{
|
||||
assertMIMEStuff(MIME_URI(this.mimeType), "largeIcon", aLargeIconURL);
|
||||
},
|
||||
|
||||
get smallIconURL()
|
||||
{
|
||||
var url = getLiteralForContentType(this.URI, "smallIcon");
|
||||
if (!url)
|
||||
url = "chrome://communicator/skin/content-small.gif";
|
||||
return url;
|
||||
},
|
||||
|
||||
set smallIconURL()
|
||||
{
|
||||
assertMIMEStuff(MIME_URI(this.mimeType), "smallIcon", aLargeIconURL);
|
||||
},
|
||||
|
||||
get extensions()
|
||||
{
|
||||
var extensionResource = gRDF.GetResource(NC_RDF("fileExtensions"));
|
||||
var contentTypeResource = gRDF.GetResource(MIME_URI(this.mimeType));
|
||||
var extensionTargets = gDS.GetTargets(contentTypeResource, extensionResource, true);
|
||||
var extString = "";
|
||||
if (extensionTargets) {
|
||||
extensionTargets = extensionTargets.QueryInterface(Components.interfaces.nsISimpleEnumerator);
|
||||
while (extensionTargets.hasMoreElements()) {
|
||||
var currentExtension = extensionTargets.getNext();
|
||||
if (currentExtension) {
|
||||
currentExtension = currentExtension.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
||||
extString += currentExtension.Value.toUpperCase() + " ";
|
||||
}
|
||||
}
|
||||
}
|
||||
return extString;
|
||||
},
|
||||
|
||||
addExtension: function (aExtensionString)
|
||||
{
|
||||
assertMIMEStuff(MIME_URI(this.mimeType), "fileExtensions", aExtensionString);
|
||||
},
|
||||
|
||||
removeExtension: function (aExtensionString)
|
||||
{
|
||||
unassertMIMEStuff(MIME_URI(this.mimeType), "fileExtensions", aExtensionString);
|
||||
},
|
||||
|
||||
// content handling
|
||||
get saveToDisk()
|
||||
{
|
||||
return getHandlerInfoForType(this.URI, "saveToDisk");
|
||||
},
|
||||
|
||||
set saveToDisk(aSavedToDisk)
|
||||
{
|
||||
assertMIMEStuff(HANDLER_URI(this.mimeType), "saveToDisk", aSavedToDisk);
|
||||
},
|
||||
|
||||
get handleInternal()
|
||||
{
|
||||
return getHandlerInfoForType(this.URI, "handleInternal");
|
||||
},
|
||||
|
||||
set handleInternal(aHandledInternally)
|
||||
{
|
||||
assertMIMEStuff(HANDLER_URI(this.mimeType), "handleInternal", aHandledInternally);
|
||||
},
|
||||
|
||||
get alwaysAsk()
|
||||
{
|
||||
return getHandlerInfoForType(this.URI, "alwaysAsk");
|
||||
},
|
||||
|
||||
set alwaysAsk(aAlwaysAsk)
|
||||
{
|
||||
assertMIMEStuff(HANDLER_URI(this.mimeType), "alwaysAsk", aAlwaysAsk);
|
||||
},
|
||||
|
||||
// helper application
|
||||
get appDisplayName()
|
||||
{
|
||||
return getHelperAppInfoForType(this.URI, "prettyName");
|
||||
},
|
||||
|
||||
set appDisplayName(aDisplayName)
|
||||
{
|
||||
assertMIMEStuff(APP_URI(this.mimeType), "prettyName", aDisplayName);
|
||||
},
|
||||
|
||||
get appPath()
|
||||
{
|
||||
return getHelperAppInfoForType(this.URI, "path");
|
||||
},
|
||||
|
||||
set appPath(aAppPath)
|
||||
{
|
||||
assertMIMEStuff(APP_URI(this.mimeType), "path", aAppPath);
|
||||
},
|
||||
|
||||
/**
|
||||
* After setting the various properties on this override, we need to
|
||||
* build the links between the mime type resource, the handler for that
|
||||
* resource, and the helper app (if any) associated with the resource.
|
||||
* We also need to add this mime type to the RDF seq (list) of types.
|
||||
**/
|
||||
buildLinks: function()
|
||||
{
|
||||
// assert the handler resource
|
||||
var mimeSource = gRDF.GetResource(MIME_URI(this.mimeType));
|
||||
var handlerProperty = gRDF.GetResource(NC_RDF("handlerProp"));
|
||||
var handlerResource = gRDF.GetResource(HANDLER_URI(this.mimeType));
|
||||
gDS.Assert(mimeSource, handlerProperty, handlerResource, true);
|
||||
// assert the helper app resource
|
||||
var helperAppProperty = gRDF.GetResource(NC_RDF("externalApplication"));
|
||||
var helperAppResource = gRDF.GetResource(APP_URI(this.mimeType));
|
||||
gDS.Assert(handlerResource, helperAppProperty, helperAppResource, true);
|
||||
// add the mime type to the MIME types seq
|
||||
var container = Components.classes["component://netscape/rdf/container"].createInstance();
|
||||
if (container) {
|
||||
container = container.QueryInterface(Components.interfaces.nsIRDFContainer);
|
||||
if (container) {
|
||||
var containerRes = gRDF.GetResource("urn:mimetypes:root");
|
||||
container.Init(gDS, containerRes);
|
||||
var element = gRDF.GetResource(MIME_URI(this.mimeType));
|
||||
if (container.IndexOf(element) == -1)
|
||||
container.AppendElement(element);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Utility functions for building URIs easily
|
||||
**/
|
||||
function NC_RDF(aProperty)
|
||||
{
|
||||
return "http://home.netscape.com/NC-rdf#" + aProperty;
|
||||
}
|
||||
|
||||
function HANDLER_URI(aHandler)
|
||||
{
|
||||
return "urn:mimetype:handler:" + aHandler;
|
||||
}
|
||||
|
||||
function APP_URI(aType)
|
||||
{
|
||||
return "urn:mimetype:externalApplication:" + aType;
|
||||
}
|
||||
|
||||
function MIME_URI(aType)
|
||||
{
|
||||
return "urn:mimetype:" + aType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility functions for reading data from the RDF datasource
|
||||
**/
|
||||
function getLiteralForContentType(aURI, aProperty)
|
||||
{
|
||||
var contentTypeResource = gRDF.GetResource(aURI);
|
||||
var propertyResource = gRDF.GetResource(NC_RDF(aProperty));
|
||||
return getLiteral(contentTypeResource, propertyResource);
|
||||
}
|
||||
|
||||
function getLiteral(aSource, aProperty)
|
||||
{
|
||||
var node = gDS.GetTarget(aSource, aProperty, true);
|
||||
if (node) {
|
||||
node = node.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
||||
return node.Value;
|
||||
}
|
||||
}
|
||||
|
||||
function getHandlerInfoForType(aURI, aPropertyString)
|
||||
{
|
||||
// get current selected type
|
||||
var handler = HANDLER_URI(getLiteralForContentType(aURI, "value"));
|
||||
var source = gRDF.GetResource(handler);
|
||||
var property = gRDF.GetResource(NC_RDF(aPropertyString));
|
||||
var target = gDS.GetTarget(source, property, true);
|
||||
if (target) {
|
||||
target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
||||
return target.Value;
|
||||
}
|
||||
}
|
||||
|
||||
function getHelperAppInfoForType(aURI, aPropertyString)
|
||||
{
|
||||
var appURI = APP_URI(getLiteralForContentType(aURI, "value"));
|
||||
var appRes = gRDF.GetResource(appURI);
|
||||
var appProperty = gRDF.GetResource(NC_RDF(aPropertyString));
|
||||
return getLiteral(appRes, appProperty);
|
||||
}
|
||||
|
||||
function mimeHandlerExists(aMIMEType)
|
||||
{
|
||||
var valueProperty = gRDF.GetResource(NC_RDF("value"));
|
||||
var mimeSource = gRDF.GetResource(MIME_URI(aMIMEType));
|
||||
var mimeLiteral = gRDF.GetLiteral(gMIMEField.value);
|
||||
return gDS.HasAssertion(mimeSource, valueProperty, mimeLiteral, true);
|
||||
}
|
||||
|
||||
// write to the ds
|
||||
function assertMIMEStuff(aMIMEString, aPropertyString, aValueString)
|
||||
{
|
||||
var mimeSource = gRDF.GetResource(aMIMEString);
|
||||
var valueProperty = gRDF.GetResource(NC_RDF(aPropertyString));
|
||||
var mimeLiteral = gRDF.GetLiteral(aValueString);
|
||||
gDS.Assert(mimeSource, valueProperty, mimeLiteral, true);
|
||||
}
|
||||
|
||||
function unassertMIMEStuff(aMIMEString, aPropertyString, aValueString)
|
||||
{
|
||||
var mimeSource = gRDF.GetResource(aMIMEString);
|
||||
var valueProperty = gRDF.GetResource(NC_RDF(aPropertyString));
|
||||
var mimeLiteral = gRDF.GetLiteral(aValueString);
|
||||
gDS.Unassert(mimeSource, valueProperty, mimeLiteral, true);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,276 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
The contents of this file are subject to the Netscape Public
|
||||
License Version 1.1 (the "License"); you may not use this file
|
||||
except in compliance with the License. You may obtain a copy of
|
||||
the License at http://www.mozilla.org/NPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS
|
||||
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
implied. See the License for the specific language governing
|
||||
rights and limitations under the License.
|
||||
|
||||
The Original Code is Mozilla Communicator client code, released
|
||||
March 31, 1998.
|
||||
|
||||
The Initial Developer of the Original Code is Netscape
|
||||
Communications Corporation. Portions created by Netscape are
|
||||
Copyright (C) 1998-1999 Netscape Communications Corporation. All
|
||||
Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
Ben Goodger <ben@netscape.com>, original implementor
|
||||
-->
|
||||
|
||||
<?xml-stylesheet href="chrome://communicator/skin/"?>
|
||||
|
||||
<?xul-overlay href="chrome://global/content/dialogOverlay.xul"?>
|
||||
|
||||
<!DOCTYPE window SYSTEM "chrome://communicator/locale/pref/pref-applications-edit.dtd">
|
||||
|
||||
<window id="pickAppHandler"
|
||||
class="dialog" style="width: 30em; user-focus: ignore;"
|
||||
orient="vertical"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
title="&editType.label;"
|
||||
onload="Startup();">
|
||||
|
||||
<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>
|
||||
<script language="JavaScript">
|
||||
<![CDATA[
|
||||
var gExtensionLabel = null;
|
||||
var gMIMEField = null;
|
||||
var gHandlerGroup = null;
|
||||
var gAppPath = null;
|
||||
var gAskBeforeOpen = null;
|
||||
var gIcon = null;
|
||||
var gContentType = null;
|
||||
|
||||
var gBundle = null;
|
||||
|
||||
var gOldMIME = null;
|
||||
|
||||
function Startup()
|
||||
{
|
||||
doSetOKCancel(onOK);
|
||||
|
||||
gIcon = document.getElementById("largeIcon");
|
||||
gContentType = document.getElementById("contentType");
|
||||
gExtensionLabel = document.getElementById("extension");
|
||||
gMIMEField = document.getElementById("mimeType");
|
||||
gHandlerGroup = document.getElementById("handler");
|
||||
gAppPath = document.getElementById("appPath");
|
||||
gAskBeforeOpen = document.getElementById("askBeforeOpen");
|
||||
|
||||
gBundle = srGetStrBundle("chrome://communicator/locale/pref/pref-applications.properties");
|
||||
|
||||
var handlerInfo = window.arguments[0];
|
||||
|
||||
gExtensionLabel.setAttribute("value", handlerInfo.extensions);
|
||||
gMIMEField.value = handlerInfo.mimeType;
|
||||
gOldMIME = handlerInfo.mimeType;
|
||||
|
||||
// figure out how this type is handled
|
||||
var data = 0;
|
||||
if (handlerInfo.handleInternal == "true")
|
||||
data = 0;
|
||||
else if (handlerInfo.saveToDisk == "true")
|
||||
data = 1;
|
||||
else
|
||||
data = 2;
|
||||
|
||||
gHandlerGroup.selectedItem = gHandlerGroup.getElementsByAttribute("data", data)[0];
|
||||
doEnabling();
|
||||
|
||||
var appPath = handlerInfo.appPath;
|
||||
if (appPath != undefined)
|
||||
gAppPath.value = appPath;
|
||||
gAskBeforeOpen.checked = handlerInfo.alwaysAsk == "true" ? true : false;
|
||||
|
||||
gContentType.setAttribute("value", handlerInfo.description);
|
||||
gIcon.setAttribute("src", handlerInfo.largeIconURL);
|
||||
|
||||
gMIMEField.focus();
|
||||
}
|
||||
|
||||
function doEnabling()
|
||||
{
|
||||
if (gHandlerGroup.data != "2")
|
||||
gAskBeforeOpen.setAttribute("disabled", "true");
|
||||
else
|
||||
gAskBeforeOpen.removeAttribute("disabled");
|
||||
}
|
||||
|
||||
function chooseApp()
|
||||
{
|
||||
var filePicker = Components.classes["component://mozilla/filepicker"].createInstance();
|
||||
if (filePicker)
|
||||
filePicker = filePicker.QueryInterface(Components.interfaces.nsIFilePicker);
|
||||
if (filePicker) {
|
||||
const FP = Components.interfaces.nsIFilePicker
|
||||
var windowTitle = gBundle.GetStringFromName("chooseHandler");
|
||||
var programsFilter = gBundle.GetStringFromName("programsFilter");
|
||||
filePicker.init(window, windowTitle, FP.modeOpen);
|
||||
dump("*** navigator.platform = " + navigator.platform + "\n");
|
||||
if (navigator.platform == "Windows")
|
||||
filePicker.appendFilter(programsFilter, "*.exe; *.com");
|
||||
else
|
||||
filePicker.appendFilters(FP.filterAll);
|
||||
filePicker.show();
|
||||
var file = filePicker.file.QueryInterface(Components.interfaces.nsILocalFile);
|
||||
gAppPath.value = file.path;
|
||||
gAppPath.select();
|
||||
selectAppRadio();
|
||||
}
|
||||
}
|
||||
|
||||
function selectAppRadio()
|
||||
{
|
||||
if (gHandlerGroup.data != "2")
|
||||
gHandlerGroup.selectedItem = gHandlerGroup.getElementsByAttribute("data", "2")[0];
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
// now save the information
|
||||
var handlerInfo = new HandlerOverride(MIME_URI(gMIMEField.value));
|
||||
handlerInfo.mimeType = gMIMEField.value;
|
||||
|
||||
// other info we need to set (not reflected in UI)
|
||||
if (gHandlerGroup.data == "2")
|
||||
handlerInfo.appPath = gAppPath.value;
|
||||
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>
|
||||
|
||||
<keyset id="keyset"/>
|
||||
|
||||
<box autostretch="never">
|
||||
<image id="largeIcon" src="chrome://communicator/skin/content-large.gif" style="width: 32px; height: 32px;"/>
|
||||
<text class="label" id="contentType" crop="right"/>
|
||||
</box>
|
||||
|
||||
<separator class="thin"/>
|
||||
|
||||
<separator class="groove"/>
|
||||
|
||||
<separator class="thin"/>
|
||||
|
||||
<grid flex="1">
|
||||
<columns>
|
||||
<column/>
|
||||
<column flex="1"/>
|
||||
</columns>
|
||||
|
||||
<rows>
|
||||
<row>
|
||||
<text class="label" value="&extension.label;"/>
|
||||
<text class="label" id="extension"/>
|
||||
</row>
|
||||
<row>
|
||||
<text class="label" value="&mimetype.label;" accesskey="&mimetype.accesskey;"
|
||||
for="mimeType"/>
|
||||
<textfield id="mimeType" flex="1"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
|
||||
<box autostretch="never">
|
||||
<checkbox id="outgoingDefault" value="&outgoingDefault.label;" accesskey="&outgoingDefault.accesskey;" disabled="true"/>
|
||||
</box>
|
||||
|
||||
<separator class="thin"/>
|
||||
|
||||
<titledbox orient="vertical">
|
||||
<title><text value="&handledby.label;"/></title>
|
||||
|
||||
<radiogroup id="handler" orient="vertical">
|
||||
<box orient="vertical" autostretch="never">
|
||||
<radio data="0" value="&navigator.label;" accesskey="&navigator.accesskey;" oncommand="doEnabling();"/>
|
||||
<radio data="1" value="&saveToDisk.label;" accesskey="&saveToDisk.accesskey;" oncommand="doEnabling();"/>
|
||||
</box>
|
||||
<box autostretch="never">
|
||||
<radio data="2" value="&application.label;" accesskey="&application.accesskey;" oncommand="doEnabling();"/>
|
||||
<textfield id="appPath" flex="1" onchange="selectAppRadio();"/>
|
||||
</box>
|
||||
<box autostretch="never" halign="right">
|
||||
<button value="&browse.label;" accesskey="&browse.accesskey;"
|
||||
oncommand="chooseApp();"/>
|
||||
</box>
|
||||
</radiogroup>
|
||||
|
||||
</titledbox>
|
||||
|
||||
<box autostretch="never">
|
||||
<checkbox id="askBeforeOpen" value="&askBeforeOpen.label;" accesskey="&askBeforeOpen.accesskey;"/>
|
||||
</box>
|
||||
|
||||
<separator/>
|
||||
|
||||
<box id="okCancelButtonsRight"/>
|
||||
|
||||
</window>
|
||||
|
@ -0,0 +1,113 @@
|
||||
var gDescriptionField = null;
|
||||
var gExtensionField = null;
|
||||
var gMIMEField = null;
|
||||
var gAppPath = null;
|
||||
var gOutgoingMIME = null;
|
||||
|
||||
var gBundle = null;
|
||||
|
||||
function Startup()
|
||||
{
|
||||
doSetOKCancel(onOK);
|
||||
|
||||
gDescriptionField = document.getElementById("description");
|
||||
gExtensionField = document.getElementById("extensions");
|
||||
gMIMEField = document.getElementById("mimeType");
|
||||
gAppPath = document.getElementById("appPath");
|
||||
gOutgoingMime = document.getElementById("outgoingDefault");
|
||||
|
||||
gBundle = srGetStrBundle("chrome://communicator/locale/pref/pref-applications.properties");
|
||||
|
||||
gDescriptionField.focus();
|
||||
}
|
||||
|
||||
function chooseApp()
|
||||
{
|
||||
var filePicker = Components.classes["component://mozilla/filepicker"].createInstance();
|
||||
if (filePicker)
|
||||
filePicker = filePicker.QueryInterface(Components.interfaces.nsIFilePicker);
|
||||
if (filePicker) {
|
||||
const FP = Components.interfaces.nsIFilePicker
|
||||
var windowTitle = gBundle.GetStringFromName("chooseHandler");
|
||||
var programsFilter = gBundle.GetStringFromName("programsFilter");
|
||||
filePicker.init(window, windowTitle, FP.modeOpen);
|
||||
if (navigator.platform == "Windows")
|
||||
filePicker.appendFilter(programsFilter, "*.exe; *.com");
|
||||
else
|
||||
filePicker.appendFilters(FP.filterAll);
|
||||
filePicker.show();
|
||||
var file = filePicker.file.QueryInterface(Components.interfaces.nsILocalFile);
|
||||
gAppPath.value = file.path;
|
||||
gAppPath.select();
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
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.mimeType = gMIMEField.value;
|
||||
handlerInfo.description = gDescriptionField.value;
|
||||
|
||||
var extensionString = gExtensionField.value.replace(/[*.;]/g, "");
|
||||
var extensions = extensionString.split(" ");
|
||||
for (var i = 0; i < extensions.length; i++) {
|
||||
var currExtension = extensions[i];
|
||||
handlerInfo.addExtension(currExtension);
|
||||
}
|
||||
handlerInfo.appPath = gAppPath.value;
|
||||
|
||||
// other info we need to set (not reflected in UI)
|
||||
handlerInfo.isEditable = true;
|
||||
handlerInfo.saveToDisk = false;
|
||||
handlerInfo.handleInternal = false;
|
||||
handlerInfo.alwaysAsk = true;
|
||||
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.gNewTypeRV = true;
|
||||
window.close();
|
||||
}
|
||||
|
@ -0,0 +1,94 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
The contents of this file are subject to the Netscape Public
|
||||
License Version 1.1 (the "License"); you may not use this file
|
||||
except in compliance with the License. You may obtain a copy of
|
||||
the License at http://www.mozilla.org/NPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS
|
||||
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
implied. See the License for the specific language governing
|
||||
rights and limitations under the License.
|
||||
|
||||
The Original Code is Mozilla Communicator client code, released
|
||||
March 31, 1998.
|
||||
|
||||
The Initial Developer of the Original Code is Netscape
|
||||
Communications Corporation. Portions created by Netscape are
|
||||
Copyright (C) 1998-1999 Netscape Communications Corporation. All
|
||||
Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
Ben Goodger <ben@netscape.com>, original implementor
|
||||
-->
|
||||
|
||||
<?xml-stylesheet href="chrome://communicator/skin/"?>
|
||||
|
||||
<?xul-overlay href="chrome://global/content/dialogOverlay.xul"?>
|
||||
|
||||
<!DOCTYPE window SYSTEM "chrome://communicator/locale/pref/pref-applications-edit.dtd">
|
||||
|
||||
<window id="newFileType"
|
||||
class="dialog" style="width: 30em; user-focus: ignore;"
|
||||
orient="vertical"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
title="&newTypeTitle.label;"
|
||||
onload="Startup();">
|
||||
|
||||
<script language="JavaScript" src="chrome://global/content/strres.js"></script>
|
||||
<script language="JavaScript" src="chrome://global/content/nsJSComponentManager.js"></script>
|
||||
<script language="JavaScript" src="chrome://communicator/content/pref/overrideHandler.js"></script>
|
||||
<script language="JavaScript" src="chrome://communicator/content/pref/pref-applications-new.js"></script>
|
||||
|
||||
<keyset id="keyset"/>
|
||||
|
||||
<grid flex="1">
|
||||
<columns>
|
||||
<column/>
|
||||
<column flex="1"/>
|
||||
</columns>
|
||||
|
||||
<rows>
|
||||
<row>
|
||||
<text class="label" value="&newDescription.label;" accesskey="&newDescription.accesskey;"
|
||||
for="description"/>
|
||||
<textfield id="description" flex="1"/>
|
||||
</row>
|
||||
<row>
|
||||
<text class="label" value="&newExtensions.label;" accesskey="&newExtensions.accesskey;"
|
||||
for="extensions"/>
|
||||
<textfield id="extensions" flex="1"/>
|
||||
</row>
|
||||
<row>
|
||||
<text class="label" value="&newMIME.label;" accesskey="&newMIME.accesskey;"
|
||||
for="mimeType"/>
|
||||
<textfield id="mimeType" flex="1"/>
|
||||
</row>
|
||||
<row>
|
||||
<text class="label" value="&newAppPath.label;" accesskey="&newAppPath.accesskey;"
|
||||
for="appPath"/>
|
||||
<textfield id="appPath" flex="1"/>
|
||||
</row>
|
||||
<row>
|
||||
<spring/>
|
||||
<box>
|
||||
<spring flex="1"/>
|
||||
<button value="&browse.label;" accesskey="&browse.accesskey;"
|
||||
oncommand="chooseApp();"/>
|
||||
</box>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
|
||||
<separator class="thin"/>
|
||||
|
||||
<box autostretch="never">
|
||||
<checkbox id="outgoingDefault" value="&outgoingDefault.label;" accesskey="&outgoingDefault.accesskey;" disabled="true"/>
|
||||
</box>
|
||||
|
||||
<separator/>
|
||||
|
||||
<box id="okCancelButtonsRight"/>
|
||||
|
||||
</window>
|
||||
|
@ -0,0 +1,88 @@
|
||||
|
||||
var gNewTypeRV = null;
|
||||
var gRemoveTypeRV = null;
|
||||
var gUpdateTypeRV = null;
|
||||
|
||||
function newType()
|
||||
{
|
||||
window.openDialog("chrome://communicator/content/pref/pref-applications-new.xul", "appEdit", "chrome,modal=yes,resizable=no");
|
||||
if (gNewTypeRV) {
|
||||
//gTree.builder.rebuild();
|
||||
gTree.setAttribute("ref", "urn:mimetypes");
|
||||
gNewTypeRV = null;
|
||||
}
|
||||
}
|
||||
|
||||
function removeType()
|
||||
{
|
||||
// implement me
|
||||
if (gRemoveTypeRV) {
|
||||
//gTree.builder.rebuild();
|
||||
gTree.setAttribute("ref", "urn:mimetypes");
|
||||
gRemoveTypeRV = null;
|
||||
}
|
||||
}
|
||||
|
||||
function editType()
|
||||
{
|
||||
if (gTree.selectedItems && gTree.selectedItems[0]) {
|
||||
var uri = gTree.selectedItems[0].id;
|
||||
var handlerOverride = new HandlerOverride(uri);
|
||||
window.openDialog("chrome://communicator/content/pref/pref-applications-edit.xul", "appEdit", "chrome,modal=yes,resizable=no", handlerOverride);
|
||||
}
|
||||
}
|
||||
|
||||
var gTree = null;
|
||||
var gDS = null;
|
||||
var gBundle = null;
|
||||
|
||||
var gExtensionField = null;
|
||||
var gMIMETypeField = null;
|
||||
var gHandlerField = null;
|
||||
|
||||
function Startup()
|
||||
{
|
||||
// set up the string bundle
|
||||
gBundle = srGetStrBundle("chrome://communicator/locale/pref/pref-applications.properties");
|
||||
|
||||
// set up the elements
|
||||
gTree = document.getElementById("appTree");
|
||||
gExtensionField = document.getElementById("extension");
|
||||
gMIMETypeField = document.getElementById("mimeType");
|
||||
gHandlerField = document.getElementById("handler");
|
||||
|
||||
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);
|
||||
|
||||
// intialise the tree
|
||||
gTree.database.AddDataSource(gDS);
|
||||
gTree.setAttribute("ref", "urn:mimetypes");
|
||||
}
|
||||
|
||||
function selectApplication()
|
||||
{
|
||||
if (gTree.selectedItems && gTree.selectedItems[0]) {
|
||||
var uri = gTree.selectedItems[0].id;
|
||||
var handlerOverride = new HandlerOverride(uri);
|
||||
gExtensionField.setAttribute("value", handlerOverride.extensions);
|
||||
gMIMETypeField.setAttribute("value", handlerOverride.mimeType);
|
||||
|
||||
// figure out how this type is handled
|
||||
if (handlerOverride.handleInternal == "true")
|
||||
gHandlerField.setAttribute("value", "Handled Internally"); // gBundle.GetStringFromName("handleInternally"));
|
||||
else if (handlerOverride.saveToDisk == "true")
|
||||
gHandlerField.setAttribute("value", "Save to Disk"); // gBundle.GetStringFromName("saveToDisk"));
|
||||
else
|
||||
gHandlerField.setAttribute("value", handlerOverride.appDisplayName);
|
||||
|
||||
delete handlerOverride;
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@
|
||||
Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
Ben Goodger <ben@netscape.com>, original implementor
|
||||
-->
|
||||
|
||||
<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?>
|
||||
@ -28,51 +29,93 @@
|
||||
|
||||
<window xmlns:html="http://www.w3.org/1999/xhtml"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
class="color-dialog"
|
||||
style="user-focus: ignore;"
|
||||
title="&window.title;" align="vertical"
|
||||
onload="parent.initPanel('chrome://communicator/content/pref/pref-applications.xul');">
|
||||
|
||||
<!-- NOTE to owner of this panel
|
||||
- this panel is quite complex. It will probably require a getfields
|
||||
and setfields function for getting and setting appropriate data.
|
||||
|
||||
you will need to write some JS to get the correct names and values
|
||||
from the list as appropriate to pass to the Data Manager
|
||||
-->
|
||||
|
||||
<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>
|
||||
|
||||
<box class="box-smallheader" title="&lHeader;"/>
|
||||
|
||||
<titledbox>
|
||||
<title><text value="&descript;"/></title>
|
||||
|
||||
<box orient="vertical">
|
||||
<box orient="vertical" flex="1">
|
||||
<text class="label" value="&fileTypes.label;"/>
|
||||
<tree id="appTree" class="inset" flex="1">
|
||||
<tree id="appTree" class="inset" flex="1"
|
||||
datasources="rdf:null" ref="urn:mimetypes"
|
||||
onselect="selectApplication();">
|
||||
<treecolgroup>
|
||||
<treecol flex="1"/>
|
||||
</treecolgroup>
|
||||
<treechildren flex="1">
|
||||
<treeitem>
|
||||
<treerow>
|
||||
<treecell value="&aimLaunchSelect.label;"/>
|
||||
</treerow>
|
||||
</treeitem>
|
||||
</treechildren>
|
||||
<template>
|
||||
<rule>
|
||||
<conditions>
|
||||
<content uri="?uri"/>
|
||||
<!-- the RDF Seq of MIME types -->
|
||||
<triple subject="?uri" object="?MIME-types"
|
||||
predicate="http://home.netscape.com/NC-rdf#MIME-types"/>
|
||||
<!-- each MIME type -->
|
||||
<member container="?MIME-types" child="?type"/>
|
||||
<!-- MIME type value -->
|
||||
<triple subject="?type" object="?value"
|
||||
predicate="http://home.netscape.com/NC-rdf#value"/>
|
||||
<triple subject="?type" object="?editable"
|
||||
predicate="http://home.netscape.com/NC-rdf#editable"/>
|
||||
</conditions>
|
||||
<action>
|
||||
<treechildren flex="1">
|
||||
<treeitem uri="?type">
|
||||
<treerow>
|
||||
<treecell value="?description"/>
|
||||
</treerow>
|
||||
</treeitem>
|
||||
</treechildren>
|
||||
</action>
|
||||
</rule>
|
||||
</template>
|
||||
</tree>
|
||||
</box>
|
||||
|
||||
<box orient="vertical" halign="top">
|
||||
<button class="dialog push" id="newTypeButton" value="&newTypeButton.label;" accesskey="&newTypeButton.accesskey;" />
|
||||
<button class="dialog push" id="editButton" value="&editButton.label;" accesskey="&editButton.accesskey;" />
|
||||
<button class="dialog push" id="removeButton" value="&removeButton.label;" accesskey="&removeButton.accesskey;" />
|
||||
<box orient="vertical">
|
||||
<button id="newTypeButton"
|
||||
value="&newTypeButton.label;" accesskey="&newTypeButton.accesskey;"
|
||||
oncommand="newType();"/>
|
||||
<button id="editButton"
|
||||
value="&editButton.label;" accesskey="&editButton.accesskey;"
|
||||
oncommand="editType();"/>
|
||||
<button id="removeButton"
|
||||
value="&removeButton.label;" accesskey="&removeButton.accesskey;"
|
||||
oncommand="removeType();"/>
|
||||
</box>
|
||||
</titledbox>
|
||||
|
||||
<titledbox orient="vertical">
|
||||
<title><text value="&file;"/></title>
|
||||
<text class="label" value="&exten;"/>
|
||||
<text class="label" value="&mimeType;"/>
|
||||
<text class="label" value="&handle;"/>
|
||||
<grid flex="1">
|
||||
<columns>
|
||||
<column/>
|
||||
<column flex="1"/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row>
|
||||
<text class="label" value="&exten;"/>
|
||||
<text class="label" id="extension"/>
|
||||
</row>
|
||||
<row>
|
||||
<text class="label" value="&mimeType;"/>
|
||||
<text class="label" id="mimeType"/>
|
||||
</row>
|
||||
<row>
|
||||
<text class="label" value="&handle;"/>
|
||||
<text class="label" id="handler"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
</titledbox>
|
||||
|
||||
</window>
|
||||
|
@ -30,6 +30,24 @@
|
||||
prefattribute="checked"/>
|
||||
</titledbox>
|
||||
|
||||
<titledbox orient="vertical" autostretch="never">
|
||||
<title><text value="Installed Packages"/></title>
|
||||
|
||||
<script>
|
||||
<![CDATA[
|
||||
function InstallPackage()
|
||||
{
|
||||
var chromeRegistry = Components.classes["component://netscape/chrome/chrome-registry"].getService();
|
||||
if ( chromeRegistry )
|
||||
chromeRegistry = chromeRegistry.QueryInterface( Components.interfaces.nsIChromeRegistry );
|
||||
var packageURI = prompt('give the resource uri of the package to install','');
|
||||
if (packageURI)
|
||||
chromeRegistry.installPackage(packageURI, false);
|
||||
}
|
||||
]]>
|
||||
</script>
|
||||
<button value="Install Package" oncommand="InstallPackage();"/>
|
||||
</titledbox>
|
||||
<!--
|
||||
<html:fieldset style="width: 100%; height: 100%">
|
||||
<html:div class="hspace-both">&selectUninstall.label;</html:div>
|
||||
|
@ -2,6 +2,8 @@ pref-advanced.dtd
|
||||
pref-imageblocking.dtd
|
||||
pref-appearance.dtd
|
||||
pref-applications.dtd
|
||||
pref-applications.properties
|
||||
pref-applications-edit.dtd
|
||||
pref-cache.dtd
|
||||
pref-charset.dtd
|
||||
pref-cookies.dtd
|
||||
|
@ -34,6 +34,8 @@ CHROME_L10N = \
|
||||
pref-imageblocking.dtd \
|
||||
pref-appearance.dtd \
|
||||
pref-applications.dtd \
|
||||
pref-applications.properties \
|
||||
pref-applications-edit.dtd \
|
||||
pref-cache.dtd \
|
||||
pref-colors.dtd \
|
||||
pref-themes.dtd \
|
||||
|
@ -29,6 +29,8 @@ CHROME_L10N = \
|
||||
.\pref-imageblocking.dtd \
|
||||
.\pref-appearance.dtd \
|
||||
.\pref-applications.dtd \
|
||||
.\pref-applications.properties \
|
||||
.\pref-applications-edit.dtd \
|
||||
.\pref-cache.dtd \
|
||||
.\pref-charset.dtd \
|
||||
.\pref-colors.dtd \
|
||||
|
@ -0,0 +1,33 @@
|
||||
|
||||
<!ENTITY editType.label "Edit Type">
|
||||
<!ENTITY extension.label "Extension:">
|
||||
<!ENTITY mimetype.label "MIME Type:">
|
||||
<!ENTITY mimetype.accesskey "m">
|
||||
<!ENTITY outgoingDefault.label "Use this MIME as the outgoing type for these file extensions">
|
||||
<!ENTITY outgoingDefault.accesskey "d">
|
||||
|
||||
<!ENTITY handledby.label "Handled By">
|
||||
|
||||
<!ENTITY navigator.label "Navigator">
|
||||
<!ENTITY navigator.accesskey "n">
|
||||
<!ENTITY saveToDisk.label "Save to Disk">
|
||||
<!ENTITY saveToDisk.accesskey "s">
|
||||
<!ENTITY application.label "Application">
|
||||
<!ENTITY application.accesskey "a">
|
||||
|
||||
<!ENTITY browse.label "Choose...">
|
||||
<!ENTITY browse.accesskey "c">
|
||||
|
||||
<!ENTITY askBeforeOpen.label "Ask me before opening downloaded files of this type">
|
||||
<!ENTITY askBeforeOpen.accesskey "k">
|
||||
|
||||
<!ENTITY newDescription.label "Description of type:">
|
||||
<!ENTITY newDescription.accesskey "d">
|
||||
<!ENTITY newExtensions.label "File extension:">
|
||||
<!ENTITY newExtensions.accesskey "e">
|
||||
<!ENTITY newMIME.label "MIME type:">
|
||||
<!ENTITY newMIME.accesskey "m">
|
||||
<!ENTITY newAppPath.label "Application to use:">
|
||||
<!ENTITY newAppPath.accesskey "a">
|
||||
<!ENTITY newTypeTitle.label "New Type">
|
||||
|
@ -0,0 +1,10 @@
|
||||
# foo
|
||||
|
||||
saveToDisk=Save to Disk
|
||||
handleInternally=Handled Internally
|
||||
|
||||
chooseHandler=Choose Application Helper
|
||||
programsFilter=Programs
|
||||
|
||||
handlerExists=A helper already exists for the MIME type '%mime%'. Do you want to replace it?
|
||||
handlerExistsTitle=Helper Application Exists
|
Loading…
Reference in New Issue
Block a user