Make nsIFileURL scriptable and QueryInterfaceable. fix bug #34335 and 34328 and 34470. Minor cleanups on unix file picker dialog

This commit is contained in:
pavlov%netscape.com 2000-04-04 23:50:41 +00:00
Родитель 541cd0bd42
Коммит ad8f59cb37
12 изменённых файлов: 73 добавлений и 19 удалений

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

@ -310,13 +310,13 @@ function EditorOpen()
/* check for already open window and activate it... */
if (fp.file) {
var found = FindAndSelectEditorWindowWithURL(fp.file.path);
var found = FindAndSelectEditorWindowWithURL(fp.fileURL.spec);
if (!found) {
/* open new window */
window.openDialog("chrome://editor/content",
"_blank",
"chrome,dialog=no,all",
fp.file.path);
fp.fileURL.spec);
}
}
}

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

@ -142,6 +142,7 @@ interface nsIFile;
* nsIFileURL is used for the file: protocol, and gives access to the
* underlying nsIFile object.
*/
[scriptable, uuid(d26b2e2e-1dd1-11b2-88f3-8545a7ba7949)]
interface nsIFileURL : nsIURL
{
attribute nsIFile file;

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

@ -197,7 +197,8 @@ nsStdURL::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
*aInstancePtr = GetInner();
else if (aIID.Equals(kThisStdURLImplementationCID) || // used by Equals
aIID.Equals(NS_GET_IID(nsIURL)) ||
aIID.Equals(NS_GET_IID(nsIURI)))
aIID.Equals(NS_GET_IID(nsIURI)) ||
aIID.Equals(NS_GET_IID(nsIFileURL)))
*aInstancePtr = NS_STATIC_CAST(nsIURL*, this);
else {
*aInstancePtr = nsnull;

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

@ -22,6 +22,7 @@
*/
#include "nsISupports.idl"
#include "nsIURL.idl"
#include "nsILocalFile.idl"
interface nsIDOMWindow;
@ -85,12 +86,19 @@ interface nsIFilePicker : nsISupports
/**
* Get the nsFileSpec for the file or directory.
* Get the nsILocalFile for the file or directory.
*
* @return Returns the file currently selected
*/
readonly attribute nsILocalFile file;
/**
* Get the nsIFileURL for the file or directory.
*
* @return Returns the file currently selected
*/
readonly attribute nsIFileURL fileURL;
/**
* Show File Dialog. The dialog is displayed modally.
*

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

@ -27,6 +27,7 @@
#include "nsIComponentManager.h"
#include "nsILocalFile.h"
#include "nsILocalFileMac.h"
#include "nsIURL.h"
#include "nsStringUtil.h"
@ -499,6 +500,17 @@ NS_IMETHODIMP nsFilePicker::GetFile(nsILocalFile **aFile)
return NS_OK;
}
//-------------------------------------------------------------------------
NS_IMETHODIMP nsFilePicker::GetFileURL(nsIFileURL **aFileURL)
{
nsCOMPtr<nsIFileURL> file(do_CreateInstance("component://netscape/network/standard-url"));
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
file->SetFile(mFile);
NS_ADDREF(*aFileURL = file);
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Get the file + path

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

@ -33,6 +33,7 @@
#undef NS_IMPL_IDS
#include "nsFilePicker.h"
#include "nsILocalFile.h"
#include "nsIURL.h"
#include "nsIStringBundle.h"
#include <windows.h>
#include <SHLOBJ.H>
@ -234,6 +235,22 @@ NS_IMETHODIMP nsFilePicker::GetFile(nsILocalFile **aFile)
return NS_OK;
}
//-------------------------------------------------------------------------
NS_IMETHODIMP nsFilePicker::GetFileURL(nsIFileURL **aFileURL)
{
nsCOMPtr<nsILocalFile> file(do_CreateInstance("component://mozilla/file/local"));
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
file->InitWithPath(nsCAutoString(mFile));
nsCOMPtr<nsIFileURL> fileURL(do_CreateInstance("component://netscape/network/standard-url"));
NS_ENSURE_TRUE(fileURL, NS_ERROR_FAILURE);
fileURL->SetFile(file);
NS_ADDREF(*aFileURL = fileURL);
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Get the file + path

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

@ -96,6 +96,8 @@ NS_IMETHODIMP nsBaseFilePicker::Init(nsIDOMWindow *aParent,
if (NS_SUCCEEDED(rv)) {
return InitNative(widget, aTitle, aMode);
} else {
return InitNative(nsnull, aTitle, aMode);
}
return rv;

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

@ -714,12 +714,8 @@ function RevealSearchPanel()
fp.init(window, bundle.GetStringFromName("openFile"), nsIFilePicker.modeOpen);
fp.setFilters(nsIFilePicker.filterAll);
fp.show();
// Hack to get a file: url from an nsIFile
var tempFileSpec = Components.classes["component://netscape/filespec"].createInstance(Components.interfaces.nsIFileSpec);
tempFileSpec.nativePath = fp.file.path;
openNewWindowWith(tempFileSpec.URLString);
openNewWindowWith(fp.fileURL.spec);
} catch (ex) { }
}

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

@ -45,7 +45,7 @@ function onLoad()
{
// No browser supplied - we are calling from Composer
dialog.openAppList.selectedItem = dialog.openEditWindow;
dialog.openTopWindow.disabled = true;
dialog.openTopWindow.setAttribute("disabled", "true");
}
else
dialog.openAppList.selectedItem = dialog.openTopWindow;
@ -125,13 +125,9 @@ function onChooseFile()
fp.setFilters(nsIFilePicker.filterAll);
fp.show();
if (fp.file.path && fp.file.path.length > 0)
if (fp.fileURL.spec && fp.fileURL.spec.length > 0)
{
// Hack to get a file: url from an nsIFile
var tempFileSpec = Components.classes["component://netscape/filespec"].createInstance(Components.interfaces.nsIFileSpec);
tempFileSpec.nativePath = fp.file.path;
dialog.input.value = tempFileSpec.URLString;
dialog.input.value = fp.fileURL.spec;
}
} catch(ex) { }

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

@ -20,8 +20,7 @@
<menupopup id="lookInMenu"/>
</menulist>
<button value="up" onclick="goUp();"/>
<button value="n"/>
<button value=".." onclick="goUp();"/>
</box>
<box align="horizontal">

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

@ -39,6 +39,7 @@ const DEBUG = true; /* set to false to suppress debug messages */
const FILEPICKER_PROGID = "component://mozilla/filepicker";
const FILEPICKER_CID = Components.ID("{54ae32f8-1dd2-11b2-a209-df7c505370f8}");
const nsILocalFile = Components.interfaces.nsILocalFile;
const nsIFileURL = Components.interfaces.nsIFileURL;
const nsISupports = Components.interfaces.nsISupports;
const nsIFactory = Components.interfaces.nsIFactory;
const nsIFilePicker = Components.interfaces.nsIFilePicker;
@ -65,6 +66,16 @@ nsFilePicker.prototype = {
set file(a) { throw "readonly property"; },
get file() { return this.mFile; },
/* readonly attribute nsIFileURL fileURL; */
set fileURL(a) { throw "readonly property"; },
get fileURL() {
if (this.mFile) {
var url = Components.classes["component://netscape/network/standard-url"].createInstance(nsIFileURL);
url.file = this.mFile;
return url;
}
},
/* attribute wstring defaultString; */
set defaultString(a) { this.mSelectedFilter = a; },
get defaultString() { return this.mSelectedFilter; },

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

@ -39,6 +39,7 @@ const DEBUG = true; /* set to false to suppress debug messages */
const FILEPICKER_PROGID = "component://mozilla/filepicker";
const FILEPICKER_CID = Components.ID("{54ae32f8-1dd2-11b2-a209-df7c505370f8}");
const nsILocalFile = Components.interfaces.nsILocalFile;
const nsIFileURL = Components.interfaces.nsIFileURL;
const nsISupports = Components.interfaces.nsISupports;
const nsIFactory = Components.interfaces.nsIFactory;
const nsIFilePicker = Components.interfaces.nsIFilePicker;
@ -65,6 +66,16 @@ nsFilePicker.prototype = {
set file(a) { throw "readonly property"; },
get file() { return this.mFile; },
/* readonly attribute nsIFileURL fileURL; */
set fileURL(a) { throw "readonly property"; },
get fileURL() {
if (this.mFile) {
var url = Components.classes["component://netscape/network/standard-url"].createInstance(nsIFileURL);
url.file = this.mFile;
return url;
}
},
/* attribute wstring defaultString; */
set defaultString(a) { this.mSelectedFilter = a; },
get defaultString() { return this.mSelectedFilter; },