Bug 43583; tweaks to new helper app launch dialog; r=ben@netscape.com

This commit is contained in:
law%netscape.com 2000-07-13 00:44:26 +00:00
Родитель bc2242f4d4
Коммит 1a7cc4e5cb
3 изменённых файлов: 62 добавлений и 40 удалений

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

@ -23,8 +23,8 @@
function nsHelperAppLauncherDialog() {
// Initialize data properties.
this.chosenApp = null;
this.chosenFile = null;
this.userChoseApp = false;
this.chosenApp = null;
try {
// App launcher is passed as dialog argument.
@ -46,17 +46,39 @@ nsHelperAppLauncherDialog.prototype= {
// Fill dialog from app launcher attributes.
initDialog : function () {
// "Always ask me" is always set (or else we wouldn't have got here!).
document.getElementById( "alwaysAskMe" ).checked = true;
if ( this.appLauncher.MIMEInfo.preferredApplicationHandler ) {
// Run this app unless requested otherwise.
// Pre-select the choice the user made last time.
if ( this.appLauncher.MIMEInfo.preferredAction != this.nsIHelperAppLauncher.saveToDisk ) {
// Run app.
document.getElementById( "runApp" ).checked = true;
this.chosenApp = this.appLauncher.MIMEInfo.preferredApplicationHandler;
document.getElementById( "appName" ).value = this.chosenApp.unicodePath;
if ( this.chosenApp ) {
// If a user-chosen application, show its path.
document.getElementById( "appName" ).value = this.chosenApp.unicodePath;
} else {
// If a system-specified one, show description.
document.getElementById( "appName" ).value = this.appLauncher.MIMEInfo.applicationDescription;
}
} else {
// Save to disk.
document.getElementById( "saveToDisk" ).checked = true;
// Disable choose app button.
document.getElementById( "choseApp" ).setAttribute( "disabled", "true" );
}
// Put content type into dialog text.
var html = document.getElementById( "intro" );
if ( html && html.childNodes && html.childNodes.length ) {
// Get raw text.
var text = html.childNodes[ 0 ].nodeValue;
// Substitute content type for "#1".
text = text.replace( /#1/, this.appLauncher.MIMEInfo.MIMEType );
// Replace text in document.
html.childNodes[ 0 ].nodeValue = text;
}
// Set up dialog button callbacks.
@ -67,12 +89,17 @@ nsHelperAppLauncherDialog.prototype= {
// If the user presses OK, we do as requested...
onOK : function () {
// Get boolean switch from checkbox.
var dontAskNextTime = !document.getElementById( "alwaysAskMe" ).checked;
if ( document.getElementById( "runApp" ).checked ) {
// Update preferred action if the user chose an app.
if ( this.userChoseApp ) {
this.appLauncher.MIMEInfo.preferredAction = this.nsIHelperAppLauncher.useHelperApp;
}
this.appLauncher.launchWithApplication( this.chosenApp, dontAskNextTime );
} else {
this.appLauncher.saveToDisk( this.chosenFile, dontAskNextTime );
this.appLauncher.saveToDisk( null, dontAskNextTime );
}
window.close();
@ -81,12 +108,27 @@ nsHelperAppLauncherDialog.prototype= {
// If the user presses cancel, tell the app launcher and close the dialog...
onCancel : function () {
// Cancel app launcher.
this.appLauncher.Cancel();
try {
this.appLauncher.Cancel();
} catch( exception ) {
}
// Close up dialog by returning true.
return true;
},
// Enable pick app button if the user chooses that option.
toggleChoice : function () {
// See what option is checked.
if ( document.getElementById( "runApp" ).checked ) {
// We can enable the pick app button.
document.getElementById( "chooseApp" ).removeAttribute( "disabled" );
} else {
// We can disable the pick app button.
document.getElementById( "chooseApp" ).setAttribute( "disabled", "true" );
}
},
// Choose a new/different app...
chooseApp : function () {
var fp = Components.classes["component://mozilla/filepicker"].createInstance( this.nsIFilePicker );
@ -97,26 +139,14 @@ nsHelperAppLauncherDialog.prototype= {
fp.appendFilters( this.nsIFilePicker.filterAll );
if ( fp.show() == this.nsIFilePicker.returnOK && fp.file ) {
this.chosenApp = fp.file;
// Remember the file they chose to run.
this.userChoseApp = true;
this.chosenApp = fp.file;
// Update dialog.
document.getElementById( "appName" ).value = this.chosenApp.unicodePath;
}
},
// Choose a file to save to...
chooseFile : function () {
var fp = Components.classes["component://mozilla/filepicker"].createInstance( this.nsIFilePicker );
fp.init( window,
this.getString( "chooseFileFilePickerTitle" ),
this.nsIFilePicker.modeSave );
// XXX - Can we set this to filter on extension of file to be saved?
fp.appendFilters( this.nsIFilePicker.filterAll );
if ( fp.show() == this.nsIFilePicker.returnOK && fp.file ) {
this.chosenFile = fp.file;
document.getElementById( "fileName" ).value = this.chosenFile.unicodePath;
}
},
// Get string from bundle.
getString : function ( id ) {
// String of last resort is the id.

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

@ -37,7 +37,8 @@
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="&caption.label;"
onload="window.dialog = new nsHelperAppLauncherDialog();"
onload="window.dialog = new nsHelperAppLauncherDialog()"
onunload="window.dialog.onCancel()"
style="width: 40em;"
class="dialog"
align="vertical"
@ -58,9 +59,9 @@
</box>
<separator orient="vertical" class="thin"/>
<box orient="vertical" flex="1">
<html>&intro.label;</html>
<html id="intro">&intro.label;</html>
<separator orient="horizontal" class="thin"/>
<radiogroup id="mode" orient="vertical">
<radiogroup id="mode" orient="vertical" oncommand="window.dialog.toggleChoice()">
<box orient="vertical">
<box autostretch="never">
<radio id="runApp"
@ -70,10 +71,11 @@
</box>
<box class="indent">
<textfield id="appName" readonly="true" flex="1"/>
<button class="dialog"
<button id="chooseApp"
class="dialog"
value="&chooseApp.label;"
accesskey="&chooseApp.accesskey;"
oncommand="dialog.chooseApp();"/>
oncommand="dialog.chooseApp()"/>
</box>
</box>
<box orient="vertical">
@ -83,13 +85,6 @@
value="&saveToDisk.label;"
accesskey="&saveToDisk.accesskey;"/>
</box>
<box class="indent">
<textfield id="fileName" readonly="true" flex="1"/>
<button class="dialog"
value="&chooseFile.label;"
accesskey="&chooseFile.accesskey;"
oncommand="dialog.chooseFile();"/>
</box>
</box>
</radiogroup>
<separator orient="horizontal" class="thin"/>

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

@ -1,11 +1,11 @@
<!ENTITY caption.label "Downloading">
<!ENTITY intro.label "This file is unrecognized by Mozilla. You can save it or open it with another application.">
<!ENTITY intro.label "This file has mime type #1 and cannot be viewed using Mozilla. You can open it with another application, or save it to disk.">
<!ENTITY runApp.label "Open using">
<!ENTITY runApp.accesskey "o">
<!ENTITY saveToDisk.label "Save to file">
<!ENTITY saveToDisk.label "Save to disk">
<!ENTITY saveToDisk.accesskey "s">
<!ENTITY alwaysAskMe.label "Always ask me before opening or saving files of this type.">
@ -13,6 +13,3 @@
<!ENTITY chooseApp.label "Choose...">
<!ENTITY chooseApp.accesskey "c">
<!ENTITY chooseFile.label "Choose...">
<!ENTITY chooseFile.accesskey "h">