mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-22 12:04:38 +00:00
parent
c00f3b6094
commit
190b061f3f
@ -22,15 +22,19 @@
|
||||
<!ENTITY default.set.label "Set Default...">
|
||||
<!ENTITY default.set.accesskey "e">
|
||||
|
||||
<!ENTITY alwaysAsk.label "Always show this dialog for this type of file">
|
||||
<!ENTITY alwaysAsk.label "Always ask before opening this type of file">
|
||||
<!ENTITY alwaysAsk.accesskey "a">
|
||||
|
||||
<!ENTITY saveToDisk.label "Save this file to Disk">
|
||||
<!ENTITY saveToDisk.accesskey "d">
|
||||
|
||||
<!ENTITY openUsing.label "Open with application">
|
||||
<!-- LOCALIZATION NOTE: do not localize "#1" -->
|
||||
<!ENTITY openUsing.label "Open using #1">
|
||||
<!ENTITY openUsing.accesskey "o">
|
||||
|
||||
<!-- LOCALIZATION NOTE: do not localize "<" and ">" -->
|
||||
<!ENTITY noApplicationSpecified.label " <no application specified>">
|
||||
|
||||
<!ENTITY chooseApp.label "Choose...">
|
||||
<!ENTITY chooseApp.accesskey "c">
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
*
|
||||
* Contributors:
|
||||
* Bill Law <law@netscape.com>
|
||||
* Scott MacGregor <mscott@netscape.com>
|
||||
*/
|
||||
|
||||
/* This file implements the nsIHelperAppLauncherDialog interface.
|
||||
@ -42,6 +43,7 @@ function nsHelperAppDialog() {
|
||||
this.mSourcePath = null;
|
||||
this.choseApp = false;
|
||||
this.chosenApp = null;
|
||||
this.givenDefaultApp = false;
|
||||
this.strings = new Array;
|
||||
this.elements = new Array;
|
||||
}
|
||||
@ -50,6 +52,8 @@ nsHelperAppDialog.prototype = {
|
||||
// Turn this on to get debugging messages.
|
||||
debug: false,
|
||||
|
||||
nsIMIMEInfo : Components.interfaces.nsIMIMEInfo,
|
||||
|
||||
// Dump text (if debug is on).
|
||||
dump: function( text ) {
|
||||
if ( this.debug ) {
|
||||
@ -190,11 +194,21 @@ nsHelperAppDialog.prototype = {
|
||||
fname = this.mLauncher.source.path;
|
||||
this.mSourcePath += url.path;
|
||||
}
|
||||
|
||||
var title = this.replaceInsert( win.getAttribute( "title" ), 1, fname);
|
||||
win.setAttribute( "title", title );
|
||||
|
||||
// Put content type and location into intro.
|
||||
this.initIntro();
|
||||
this.initIntro(url);
|
||||
|
||||
var iconString = "moz-icon://" + fname + "?size=32&contentType=" + this.mLauncher.MIMEInfo.MIMEType;
|
||||
|
||||
this.dialogElement("contentTypeImage").setAttribute("src", iconString);
|
||||
|
||||
this.initAppAndSaveToDiskValues();
|
||||
|
||||
// always make sure the window starts off with this checked....
|
||||
this.dialogElement( "alwaysAskMe" ).checked = true;
|
||||
|
||||
// Add special debug hook.
|
||||
if ( this.debug ) {
|
||||
@ -202,22 +216,6 @@ nsHelperAppDialog.prototype = {
|
||||
prompt.setAttribute( "onclick", "dialog.doDebug()" );
|
||||
}
|
||||
|
||||
// Put explanation of default action into text box.
|
||||
this.initExplanation();
|
||||
|
||||
// Set default selection (always the "default").
|
||||
this.dialogElement( "default" ).checked = true;
|
||||
|
||||
// If default is not to save to disk, then make that the alternative.
|
||||
if ( this.mLauncher.MIMEInfo.preferredAction != Components.interfaces.nsIMIMEInfo.saveToDisk ) {
|
||||
this.dialogElement( "saveToDisk" ).checked = true;
|
||||
} else {
|
||||
this.dialogElement( "openUsing" ).checked = true;
|
||||
}
|
||||
|
||||
// Disable selection under "different action".
|
||||
this.option();
|
||||
|
||||
// Set up dialog button callbacks.
|
||||
var object = this; // "this.onOK()" doesn't work!
|
||||
this.mDialog.doSetOKCancel( function () { return object.onOK(); },
|
||||
@ -232,90 +230,152 @@ nsHelperAppDialog.prototype = {
|
||||
},
|
||||
|
||||
// initIntro:
|
||||
initIntro: function() {
|
||||
initIntro: function(url) {
|
||||
var intro = this.dialogElement( "intro" );
|
||||
var desc = this.mLauncher.MIMEInfo.Description;
|
||||
var modified;
|
||||
if ( desc != "" ) {
|
||||
if ( desc != "" )
|
||||
{
|
||||
// Use intro with descriptive text.
|
||||
modified = this.replaceInsert( this.getString( "intro.withDesc" ), 1, this.mLauncher.MIMEInfo.Description );
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use intro without descriptive text.
|
||||
modified = this.getString( "intro.noDesc" );
|
||||
}
|
||||
|
||||
modified = this.replaceInsert( modified, 2, this.mLauncher.MIMEInfo.MIMEType );
|
||||
modified = this.replaceInsert( modified, 3, this.mSourcePath );
|
||||
|
||||
// if mSourcePath is a local file, then let's use the pretty path name instead of an ugly
|
||||
// url...
|
||||
var pathString = this.mSourcePath;
|
||||
try
|
||||
{
|
||||
var fileURL = url.QueryInterface( Components.interfaces.nsIFileURL);
|
||||
if (fileURL)
|
||||
{
|
||||
var fileObject = fileURL.file;
|
||||
if (fileObject)
|
||||
{
|
||||
var parentObject = fileObject.parent;
|
||||
if (parentObject)
|
||||
{
|
||||
pathString = parentObject.unicodePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(ex) {}
|
||||
|
||||
|
||||
modified = this.replaceInsert( modified, 3, pathString );
|
||||
intro.firstChild.nodeValue = "";
|
||||
intro.firstChild.nodeValue = modified;
|
||||
},
|
||||
|
||||
// initExplanation:
|
||||
initExplanation: function() {
|
||||
var expl = this.dialogElement( "explanation" );
|
||||
var text;
|
||||
if ( this.mLauncher.MIMEInfo.preferredAction == Components.interfaces.nsIMIMEInfo.saveToDisk ) {
|
||||
text = this.getString( "explanation.saveToDisk" );
|
||||
initAppAndSaveToDiskValues: function() {
|
||||
|
||||
// Pre-select the choice the user made last time.
|
||||
this.chosenApp = this.mLauncher.MIMEInfo.preferredApplicationHandler;
|
||||
var applicationDescription = this.mLauncher.MIMEInfo.applicationDescription;
|
||||
|
||||
if (applicationDescription != "")
|
||||
{
|
||||
this.updateApplicationName(applicationDescription);
|
||||
this.givenDefaultApp = true;
|
||||
}
|
||||
else if (this.chosenApp)
|
||||
{
|
||||
// If a user-chosen application, show its path.
|
||||
this.updateApplicationName(this.chosenApp.unicodePath);
|
||||
this.chooseApp = true;
|
||||
}
|
||||
else
|
||||
this.updateApplicationName(this.getString("noApplicationSpecified"));
|
||||
|
||||
if ( applicationDescription && this.mLauncher.MIMEInfo.preferredAction != this.nsIMIMEInfo.saveToDisk )
|
||||
this.dialogElement( "openUsing" ).checked = true;
|
||||
else
|
||||
{
|
||||
// Save to disk.
|
||||
this.dialogElement( "saveToDisk" ).checked = true;
|
||||
// Disable choose app button.
|
||||
this.dialogElement( "chooseApp" ).setAttribute( "disabled", "true" );
|
||||
}
|
||||
},
|
||||
|
||||
updateApplicationName: function(newValue)
|
||||
{
|
||||
var applicationText = this.getString( "openUsingString" );
|
||||
applicationText = this.replaceInsert( applicationText, 1, newValue );
|
||||
var expl = this.dialogElement( "openUsing" );
|
||||
expl.label = applicationText;
|
||||
},
|
||||
|
||||
// Enable pick app button if the user chooses that option.
|
||||
toggleChoice : function () {
|
||||
// See what option is checked.
|
||||
if ( this.dialogElement( "openUsing" ).checked ) {
|
||||
// We can enable the pick app button.
|
||||
this.dialogElement( "chooseApp" ).removeAttribute( "disabled" );
|
||||
} else {
|
||||
// Default is to "open with system default."
|
||||
text = this.getString( "explanation.defaultApp" );
|
||||
if ( this.mLauncher.MIMEInfo.preferredAction != Components.interfaces.nsIMIMEInfo.useSystemDefault ) {
|
||||
// If opening using the app, we prefer to use the app description.
|
||||
var appDesc = this.mLauncher.MIMEInfo.applicationDescription;
|
||||
if ( appDesc != "" ) {
|
||||
// Use application description.
|
||||
text = this.replaceInsert( this.getString( "explanation.openUsing" ), 1, appDesc );
|
||||
} else {
|
||||
// If no description, use the app executable name.
|
||||
var app = this.mLauncher.MIMEInfo.preferredApplicationHandler;
|
||||
if ( app ) {
|
||||
// Use application path.
|
||||
text = this.replaceInsert( this.getString( "explanation.openUsing" ), 1, app.unicodePath );
|
||||
// We can disable the pick app button.
|
||||
this.dialogElement( "chooseApp" ).setAttribute( "disabled", "true" );
|
||||
}
|
||||
|
||||
this.updateOKButton();
|
||||
},
|
||||
|
||||
processAlwaysAskState : function ()
|
||||
{
|
||||
// if the user deselected the always ask checkbox, then store that on the mime object for future use...
|
||||
if (!this.dialogElement( "alwaysAskMe" ).checked)
|
||||
{
|
||||
// we first need to rest the user action if the user selected save to disk instead of open...
|
||||
// reset the preferred action in this case...we need to do this b4 setting the always ask before handling state
|
||||
|
||||
if (!this.dialogElement( "openUsing" ).checked)
|
||||
this.mLauncher.MIMEInfo.preferredAction = this.nsIMIMEInfo.saveToDisk;
|
||||
|
||||
|
||||
this.mLauncher.MIMEInfo.alwaysAskBeforeHandling = false;
|
||||
}
|
||||
},
|
||||
updateOKButton: function() {
|
||||
var ok = false;
|
||||
if ( this.dialogElement( "saveToDisk" ).checked )
|
||||
{
|
||||
// This is always OK.
|
||||
ok = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// only enable the OK button if we have a default app to use or if
|
||||
// the user chose an app....
|
||||
if (this.choseApp || this.givenDefaultApp)
|
||||
ok = true;
|
||||
}
|
||||
// Put text into dialog field.
|
||||
expl.value = text;
|
||||
|
||||
// Enable Ok button if ok to press.
|
||||
this.dialogElement( "ok" ).disabled = !ok;
|
||||
},
|
||||
|
||||
// onOK:
|
||||
onOK: function() {
|
||||
// Do what the user asked...
|
||||
if ( this.dialogElement( "default" ).checked ) {
|
||||
var nsIMIMEInfo = Components.interfaces.nsIMIMEInfo;
|
||||
// Get action from MIMEInfo...
|
||||
if ( this.mLauncher.MIMEInfo.preferredAction == nsIMIMEInfo.saveToDisk ) {
|
||||
this.mLauncher.saveToDisk( null, false );
|
||||
} else {
|
||||
this.mLauncher.launchWithApplication( this.mLauncher.MIMEInfo.preferredApplicationHandler, false );
|
||||
}
|
||||
} else {
|
||||
// Something different for this file...
|
||||
if ( this.dialogElement( "openUsing" ).checked ) {
|
||||
|
||||
this.processAlwaysAskState();
|
||||
|
||||
if ( this.dialogElement( "openUsing" ).checked )
|
||||
{
|
||||
// If no app "chosen" then convert input string to file.
|
||||
if ( !this.chosenApp ) {
|
||||
var app = Components.classes[ "@mozilla.org/file/local;1" ].createInstance( Components.interfaces.nsILocalFile );
|
||||
app.initWithUnicodePath( this.dialogElement( "appName" ).value );
|
||||
if ( !app.exists() ) {
|
||||
// Show alert and try again.
|
||||
var msg = this.replaceInsert( this.getString( "badApp" ), 1, app.unicodePath );
|
||||
var svc = Components.classes[ "@mozilla.org/embedcomp/prompt-service;1" ]
|
||||
.getService( Components.interfaces.nsIPromptService );
|
||||
svc.alert( this.mDialog, this.getString( "badApp.title" ), msg );
|
||||
// Disable the OK button.
|
||||
this.dialogElement( "ok" ).disabled = true;
|
||||
// Leave dialog up.
|
||||
return false;
|
||||
} else {
|
||||
// Use that app.
|
||||
this.chosenApp = app;
|
||||
}
|
||||
}
|
||||
if (this.chosenApp)
|
||||
this.mLauncher.launchWithApplication( this.chosenApp, false );
|
||||
} else {
|
||||
else
|
||||
this.mLauncher.launchWithApplication( null, false );
|
||||
}
|
||||
else
|
||||
this.mLauncher.saveToDisk( null, false );
|
||||
}
|
||||
}
|
||||
|
||||
// Unhook dialog from this object.
|
||||
this.mDialog.dialog = null;
|
||||
@ -340,40 +400,6 @@ nsHelperAppDialog.prototype = {
|
||||
return true;
|
||||
},
|
||||
|
||||
// option:
|
||||
option: function() {
|
||||
// If "different" option is checked, then enable selections under it.
|
||||
var state = this.dialogElement( "different" ).checked;
|
||||
this.dialogElement( "saveToDisk" ).disabled = !state;
|
||||
this.dialogElement( "openUsing" ).disabled = !state;
|
||||
// Propagate state change to subfields.
|
||||
this.differentOption();
|
||||
},
|
||||
|
||||
// focusAppName:
|
||||
focusAppName: function() {
|
||||
var appName = this.dialogElement( "appName" );
|
||||
appName.focus();
|
||||
appName.select();
|
||||
},
|
||||
|
||||
// differentOption:
|
||||
differentOption: function() {
|
||||
// If openUsing checkbox is disabled or not selected, then disable subfields.
|
||||
var openUsing = this.dialogElement( "openUsing" );
|
||||
var state = !openUsing.disabled && openUsing.checked;
|
||||
this.dialogElement( "appName" ).disabled = !state;
|
||||
this.dialogElement( "chooseApp" ).disabled = !state;
|
||||
|
||||
// If "openUsing" is enabled and checked, then focus there.
|
||||
if ( state ) {
|
||||
this.mDialog.setTimeout( "dialog.focusAppName()", 0 );
|
||||
}
|
||||
|
||||
// Update Ok button.
|
||||
this.updateOKButton();
|
||||
},
|
||||
|
||||
// dialogElement: Try cache; obtain from document if not there.
|
||||
dialogElement: function( id ) {
|
||||
// Check if we've already fetched it.
|
||||
@ -384,27 +410,6 @@ nsHelperAppDialog.prototype = {
|
||||
return this.elements[ id ];
|
||||
},
|
||||
|
||||
// updateOKButton: Disable/enable Ok button depending on whether we've got all we need.
|
||||
updateOKButton: function() {
|
||||
var ok = false;
|
||||
if ( this.dialogElement( "default" ).checked ) {
|
||||
// This is always OK.
|
||||
ok = true;
|
||||
} else {
|
||||
if ( this.dialogElement( "saveToDisk" ).checked ) {
|
||||
// Save to disk is always Ok.
|
||||
ok = true;
|
||||
} else {
|
||||
if ( this.chosenApp || this.dialogElement( "appName" ).value != "" ) {
|
||||
// Open using is OK if app selected.
|
||||
ok = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Enable Ok button if ok to press.
|
||||
this.dialogElement( "ok" ).disabled = !ok;
|
||||
},
|
||||
|
||||
// chooseApp: Open file picker and prompt user for application.
|
||||
chooseApp: function() {
|
||||
var nsIFilePicker = Components.interfaces.nsIFilePicker;
|
||||
@ -418,10 +423,11 @@ nsHelperAppDialog.prototype = {
|
||||
|
||||
if ( fp.show() == nsIFilePicker.returnOK && fp.file ) {
|
||||
// Remember the file they chose to run.
|
||||
this.userChoseApp = true;
|
||||
this.choseApp = true;
|
||||
this.chosenApp = fp.file;
|
||||
// Update dialog.
|
||||
this.dialogElement( "appName" ).value = this.chosenApp.unicodePath;
|
||||
|
||||
this.updateApplicationName(this.chosenApp.unicodePath);
|
||||
}
|
||||
},
|
||||
|
||||
@ -482,7 +488,6 @@ nsHelperAppDialog.prototype = {
|
||||
// presses OK. Take the updated MIMEInfo and have the helper app service
|
||||
// "write" it back out to the RDF datasource.
|
||||
updateMIMEInfo: function() {
|
||||
this.dump( "updateMIMEInfo called...\n" );
|
||||
this.dumpObjectProperties( "\tMIMEInfo", this.mLauncher.MIMEInfo );
|
||||
},
|
||||
|
||||
|
@ -44,57 +44,50 @@
|
||||
class="dialog"
|
||||
align="vertical">
|
||||
|
||||
|
||||
<keyset id="dialogKeys"/>
|
||||
|
||||
<vbox>
|
||||
<hbox flex="1">
|
||||
<vbox flex="1">
|
||||
<html id="intro">&intro.label;</html>
|
||||
|
||||
<separator orient="horizontal" class="thin"/>
|
||||
<html id="prompt">&prompt.label;</html>
|
||||
|
||||
<radiogroup id="option" orient="vertical" oncommand="dialog.option()">
|
||||
<radio id="default"
|
||||
group="option"
|
||||
label="&default.label;"
|
||||
accesskey="&default.accesskey;"/>
|
||||
<vbox class="indent">
|
||||
<hbox>
|
||||
<textbox id="explanation" readonly="true" flex="1"/>
|
||||
<button id="default.set"
|
||||
label="&default.set.label;"
|
||||
accesskey="&default.set.accesskey;"
|
||||
oncommand="dialog.setDefault()"/>
|
||||
</hbox>
|
||||
<!-- Make user go to Set Default... for this (for now)
|
||||
<checkbox id="alwaysAsk"
|
||||
label="&alwaysAsk.label;"
|
||||
accesskey="&alwaysAsk.accesskey;"
|
||||
checked="true"/>
|
||||
-->
|
||||
</vbox>
|
||||
<radio id="different"
|
||||
group="option"
|
||||
label="&different.label;"
|
||||
accesskey="&different.accesskey;"/>
|
||||
</radiogroup>
|
||||
<vbox class="indent">
|
||||
<radiogroup id="different-option" orient="vertical" oncommand="dialog.differentOption()">
|
||||
<radio id="saveToDisk"
|
||||
group="different-option"
|
||||
label="&saveToDisk.label;"
|
||||
accesskey="&saveToDisk.accesskey;"/>
|
||||
<hbox>
|
||||
<radio id="openUsing"
|
||||
group="different-option"
|
||||
<image id="contentTypeImage"/>
|
||||
</hbox>
|
||||
|
||||
<separator orient="horizontal" class="thin"/>
|
||||
<radiogroup id="mode" orient="vertical" oncommand="dialog.toggleChoice()">
|
||||
<hbox flex="1">
|
||||
<box autostretch="never" flex = "1">
|
||||
<radio id="openUsing" flex="1"
|
||||
group="mode"
|
||||
label="&openUsing.label;"
|
||||
accesskey="&openUsing.accesskey;"/>
|
||||
<textbox id="appName" flex="1" oninput="dialog.updateOKButton()"/>
|
||||
</box>
|
||||
|
||||
<box class="indent">
|
||||
<button id="chooseApp"
|
||||
class="dialog"
|
||||
label="&chooseApp.label;"
|
||||
accesskey="&chooseApp.accesskey;"
|
||||
oncommand="dialog.chooseApp()"/>
|
||||
</box>
|
||||
</hbox>
|
||||
</radiogroup>
|
||||
<vbox>
|
||||
<box autostretch="never">
|
||||
<radio id="saveToDisk"
|
||||
group="mode"
|
||||
label="&saveToDisk.label;"
|
||||
accesskey="&saveToDisk.accesskey;"/>
|
||||
</box>
|
||||
</vbox>
|
||||
</radiogroup>
|
||||
<separator orient="horizontal" class="thin"/>
|
||||
<box autostretch="never">
|
||||
<checkbox id="alwaysAskMe" label="&alwaysAsk.label;" accesskey="&alwaysAsk.accesskey;"/>
|
||||
</box>
|
||||
</vbox>
|
||||
|
||||
<separator class="groove"/>
|
||||
@ -106,10 +99,9 @@
|
||||
<string id="brandShortName"> &brandShortName; </string>
|
||||
<string id="intro.withDesc"> &intro.label; </string>
|
||||
<string id="intro.noDesc"> &intro.noDesc.label; </string>
|
||||
<string id="explanation.saveToDisk"> &explanation.saveToDisk; </string>
|
||||
<string id="explanation.openUsing"> &explanation.openUsing; </string>
|
||||
<string id="explanation.defaultApp"> &explanation.defaultApp; </string>
|
||||
<string id="openUsingString"> &openUsing.label; </string>
|
||||
<string id="badApp"> &badApp; </string>
|
||||
<string id="badApp.title"> &badApp.title; </string>
|
||||
<string id="noApplicationSpecified"> &noApplicationSpecified.label;</string>
|
||||
</strings>
|
||||
</window>
|
||||
|
Loading…
x
Reference in New Issue
Block a user