use nsIFilePicker instead of nsIFileSpecWithUI

This commit is contained in:
pavlov%netscape.com 2000-03-31 10:27:17 +00:00
Родитель 92dfb2370e
Коммит 825e5b1127
4 изменённых файлов: 55 добавлений и 50 удалений

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

@ -66,14 +66,11 @@ function chooseProfileFolder( aRootFolder )
{
if( !aRootFolder ) {
try {
var fileSpec = Components.classes["component://netscape/filespecwithui"].createInstance();
if(fileSpec) {
fileSpec = fileSpec.QueryInterface(Components.interfaces.nsIFileSpecWithUI);
fileSpec.URLString = fileSpec.chooseDirectory( bundle.GetStringFromName("chooseFolder"));
aRootFolder = fileSpec.nativePath;
}
else
aRootFolder = null;
var fp = Components.classes["component://mozilla/filepicker"].createInstance(Components.interfaces.nsIFilePicker);
fp.init(window, bundle.GetStringFromName("chooseFolder"), Components.interfaces.nsIFilePicker.modeGetFolder);
fp.setFilters(Components.interfaces.nsIFilePicker.filterAll);
fp.show();
aRootFolder = fp.file.path;
}
catch(e) {
aRootFolder = null;

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

@ -119,31 +119,31 @@ function createInstance( progid, iidName ) {
var iid = eval( "Components.interfaces." + iidName );
return Components.classes[ progid ].createInstance( iid );
}
const nsIFilePicker = Components.interfaces.nsIFilePicker;
function PrefNavSelectFile(prefID) {
// Get filespecwithui component.
var fileSpec = createInstance( "component://netscape/filespecwithui", "nsIFileSpecWithUI" );
try {
var url = fileSpec.chooseFile( "" );
var fp = Components.classes["component://mozilla/filepicker"].createInstance(nsIFilePicker);
/* XXX no title here */
fp.init(window, "", nsIFilePicker.modeOpen);
fp.setFilters(nsIFilePicker.filterAll);
fp.show();
var field = document.getElementById(prefID);
field.setAttribute( "value", fileSpec.nativePath );
}
catch( exception ) {
// Just a cancel, probably.
}
field.setAttribute("value", fp.file.path);
} catch(ex) { }
}
function PrefCacheSelectFolder() {
// Get filespecwithui component.
var fileSpec = createInstance( "component://netscape/filespecwithui", "nsIFileSpecWithUI" );
try {
var url = fileSpec.chooseDirectory( "" );
var field = document.getElementById( "pref:string:browser.cache.directory" );
field.setAttribute( "value", fileSpec.nativePath );
}
catch( exception ) {
// Just a cancel, probably.
}
var fp = Components.classes["component://mozilla/filepicker"].createInstance(nsIFilePicker);
/* XXX no title here */
fp.init(window, "", nsIFilePicker.modeGetFolder);
fp.setFilters(nsIFilePicker.filterAll);
fp.show();
var field = document.getElementById "pref:string:browser.cache.directory");
field.setAttribute("value", fp.file.path);
} catch(ex) { }
}
function OpenProxyManualDialog() {

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

@ -2,9 +2,9 @@ function prefCacheSelectFolder()
{
bundle = srGetStrBundle("chrome://pref/locale/prefutilities.properties");
var folderField = document.getElementById("browserCacheDirectory");
var url = getFileOrFolderSpec( bundle.GetStringFromName("cachefolder"), true );
if( url != -1 )
folderField.value = url.URLString;
var file = getFileOrFolderSpec( bundle.GetStringFromName("cachefolder"), true );
if ( file && file != -1 )
folderField.value = file.path;
}
function prefClearMemCache()

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

@ -1,4 +1,4 @@
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
@ -22,43 +22,51 @@
*/
var bundle = srGetStrBundle("chrome://pref/locale/prefutilities.properties");
const nsIFilePicker = Components.interfaces.nsIFilePicker;
function getFileOrFolderSpec( aTitle, aFolder )
{
try {
var fileSpecWithUI = Components.classes["component://netscape/filespecwithui"].createInstance();
if( fileSpecWithUI )
fileSpecWithUI = fileSpecWithUI.QueryInterface( Components.interfaces.nsIFileSpecWithUI );
var fp = Components.classes["component://mozilla/filepicker"].createInstance(nsIFilePicker);
}
catch(e) {
dump("*** failed to create fileSpecWithUI or fileSpec objects\n");
return false;
}
try {
var value;
if( aFolder )
value = fileSpecWithUI.chooseDirectory( aTitle );
var mode;
if (aFolder)
mode = nsIFilePicker.modeGetFolder;
else
value = fileSpecWithUI.chooseFile( aTitle );
dump("filespecWithUI.path = " + value + "\n");
fileSpecWithUI.URLString = value;
mode = nsIFilePicker.modeOpen;
fp.init(window, aTitle, mode);
fp.setFilters(nsIFilePicker.filterAll);
fp.show();
}
catch(e) {
dump("Error: " + e + "\n");
return -1;
}
return fileSpecWithUI;
return fp.file;
}
function prefNavSelectFile(folderFieldId, stringId, useNative)
{
var folderField = document.getElementById(folderFieldId);
var spec = getFileOrFolderSpec( bundle.GetStringFromName(stringId), false );
if( spec != -1 ) {
var file = getFileOrFolderSpec( bundle.GetStringFromName(stringId), false );
if( file != -1 ) {
/* XXX nsILocalFile doesn't have a URL string */
/*
if (useNative)
folderField.value = spec.nativePath;
folderField.value = file.nativePath;
else
folderField.value = spec.URLString;
folderField.value = file.URLString;
*/
folderField.value = file.path;
}
}