remove unused methods; r=cmanske; sr=kin (bug #107636)

This commit is contained in:
brade%netscape.com 2001-11-27 13:59:57 +00:00
Родитель 6bdd611a13
Коммит 42b3f7502b
3 изменённых файлов: 0 добавлений и 534 удалений

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

@ -1799,242 +1799,6 @@ nsEditorShell::CheckOpenWindowForURLMatch(const PRUnichar* inFileURL, nsIDOMWind
return NS_OK;
}
// this function should move into JS
// helper function
static nsresult GetExtensionForMIMEType(const char* inMIMEType, nsACString& outExtension)
{
nsresult rv;
nsCOMPtr<nsIMIMEService> mimeService = do_GetService(NS_MIMESERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIMIMEInfo> mimeInfo;
rv = mimeService->GetFromMIMEType(inMIMEType, getter_AddRefs(mimeInfo));
if (NS_FAILED(rv)) return rv;
nsXPIDLCString fileExtension;
rv = mimeInfo->FirstExtension(getter_Copies(fileExtension));
if (NS_FAILED(rv)) return rv;
// the MIME service likes to give back ".htm" for text/html files,
// so do a special-case fix here.
nsCAutoString extensionStr(fileExtension);
if (extensionStr.EqualsIgnoreCase("htm"))
extensionStr.Assign("html");
outExtension.Assign(extensionStr);
return NS_OK;
}
// this method should move into JS
nsresult
nsEditorShell::PromptAndSetTitleIfNone(nsIDOMHTMLDocument *aHTMLDoc, PRBool *aTitleChanged, PRBool *retVal)
{
*retVal = PR_FALSE;
if (!aHTMLDoc)
return NS_ERROR_NULL_POINTER;
// Get existing document title, check its length (we don't need to prompt if there is one)
nsAutoString title;
nsresult res = aHTMLDoc->GetTitle(title);
if (NS_FAILED(res)) return res;
if (title.Length() != 0)
{
*retVal = PR_TRUE;
return NS_OK;
}
if (!mContentWindow)
return NS_ERROR_NOT_INITIALIZED;
nsCOMPtr<nsIDOMWindow> cwP = do_QueryReferent(mContentWindow);
if (!cwP) return NS_ERROR_NOT_INITIALIZED;
// Use a "prompt" common dialog to get title string from user
nsCOMPtr<nsIPromptService> dialog(do_GetService("@mozilla.org/embedcomp/prompt-service;1"));
if (!dialog)
return NS_ERROR_NULL_POINTER;
// PRUnichar *titleUnicode = ToNewUnicode(title);
PRUnichar *titleUnicode = nsnull;
nsAutoString captionStr, msgStr1, msgStr2;
GetBundleString(NS_LITERAL_STRING("DocumentTitle"), captionStr);
GetBundleString(NS_LITERAL_STRING("NeedDocTitle"), msgStr1);
GetBundleString(NS_LITERAL_STRING("DocTitleHelp"), msgStr2);
msgStr1 += PRUnichar('\n');
msgStr1 += msgStr2;
res = dialog->Prompt(cwP, captionStr.get(), msgStr1.get(),
&titleUnicode, 0, 0, retVal);
if (NS_FAILED(res)) return res;
if (*retVal == PR_FALSE)
{
// This indicates Cancel was selected
return NS_OK;
}
// This sets title in HTML node and sets title changed flag
nsDependentString temp(titleUnicode);
*aTitleChanged = temp.Length() > 0;
mEditor->SetDocumentTitle(temp);
nsCRT::free(titleUnicode);
return NS_OK;
}
// this method should move into JS
// it should be split into "ShowSaveFilePicker" and "GetSuggestedFileName"
nsresult
nsEditorShell::ShowSaveFilePicker(PRBool aDoSaveAsText, nsIURI *aDocumentURI,
nsIDOMHTMLDocument *ahtmlDocument, const char *aMIMEType,
PRInt16 *aDialogResult, nsIFile **aResultingLocation)
{
// create a file picker instance
nsresult res = NS_OK;
nsCOMPtr<nsIFilePicker> filePicker = do_CreateInstance("@mozilla.org/filepicker;1", &res);
if (!filePicker)
{
NS_ASSERTION(0, "Failed to get file picker widget");
return res;
}
// determine prompt string based on type of saving we'll do
nsAutoString promptString;
if (aDoSaveAsText && mEditorType == eHTMLTextEditorType)
GetBundleString(NS_LITERAL_STRING("ExportToText"), promptString);
else
GetBundleString(NS_LITERAL_STRING("SaveDocumentAs"), promptString);
// Initialize nsIFilePicker
nsCOMPtr<nsIDOMWindowInternal> parentWindow(do_QueryReferent(mContentWindow));
res = filePicker->Init(parentWindow, promptString.get(), nsIFilePicker::modeSave);
if (NS_FAILED(res)) return res;
// Set filters according to the type of output
if (aDoSaveAsText)
filePicker->AppendFilters(nsIFilePicker::filterText);
else
filePicker->AppendFilters(nsIFilePicker::filterHTML);
filePicker->AppendFilters(nsIFilePicker::filterAll);
// brade: pull this stuff out into a separate JS function: GetSuggestedFileName
// determine suggested file name
// this will take several steps:
// check for existing file name we can use
// check if there is a title we can use
nsCOMPtr<nsIURI>tmpURI(aDocumentURI);
if (!aDocumentURI)
{
// check the current url, use that file name if possible
// make a uri with the html document's url; then QI to an nsIURL
// from nsIURL we can get just the base name of the file which is what we want
// we'll add on the extension later
nsAutoString urlstring;
if (ahtmlDocument)
res = ahtmlDocument->GetURL(urlstring);
if (!urlstring.IsEmpty())
{
char *docURLChar = ToNewCString(urlstring);
if (docURLChar)
{
res = NS_NewURI(getter_AddRefs(tmpURI), docURLChar);
nsCRT::free(docURLChar);
if (NS_FAILED(res)) return res;
}
}
}
nsAutoString fileName;
nsCOMPtr<nsIURL> documentURL(do_QueryInterface(tmpURI));
if (tmpURI && documentURL)
{
char *fileNameChar = nsnull;
res = documentURL->GetFileBaseName(&fileNameChar);
if (NS_SUCCEEDED(res) && fileNameChar)
fileName.AssignWithConversion(fileNameChar);
if (fileNameChar)
nsCRT::free(fileNameChar);
}
// now let's try using the page title
nsAutoString title;
if (ahtmlDocument)
{
res = ahtmlDocument->GetTitle(title);
if (NS_FAILED(res)) return res;
}
// if we don't have a filename but we do have a title...
if (fileName.IsEmpty() && !title.IsEmpty())
{
// clean up the title to make it a usable filename
// Strip out quote character
PRUnichar quote = (PRUnichar)'\"';
title.StripChar(quote);
//Replace "bad" filename characteres with "_"
title.ReplaceChar(" .\\/@:", (PRUnichar)'_');
fileName.Append(title);
}
// if we still don't have a file name, let's just go with "untitled"
if (fileName.Length() == 0)
fileName.Append(NS_LITERAL_STRING("untitled"));
// now we'll add the correct extension from the MIME type
nsCAutoString fileExt(aDoSaveAsText ? "txt" : "html");
res = GetExtensionForMIMEType(aMIMEType, fileExt);
if (NS_FAILED(res)) return res;
fileName.Append(PRUnichar('.'));
fileName.AppendWithConversion(fileExt.get());
// now let's actually set the filepicker's suggested filename
if (fileName.Length() > 0)
filePicker->SetDefaultString(fileName.get());
// set the file picker's current directory
// assuming we have information needed (like prior saved location)
if (tmpURI && documentURL)
{
nsCOMPtr<nsIFileURL> fileurl(do_QueryInterface(documentURL));
if (fileurl)
{
nsCOMPtr<nsIFile> fileLocation;
res = fileurl->GetFile(getter_AddRefs(fileLocation));
if (NS_SUCCEEDED(res) && fileLocation)
{
nsCOMPtr<nsIFile> parentPath;
res = fileLocation->GetParent(getter_AddRefs(parentPath));
if (NS_SUCCEEDED(res) && parentPath)
{
nsCOMPtr<nsILocalFile> localParentPath(do_QueryInterface(parentPath));
if (localParentPath)
filePicker->SetDisplayDirectory(localParentPath);
}
}
}
}
// so everything should be setup now, lets show the dialog!!!
res = filePicker->Show(aDialogResult);
if (NS_FAILED(res)) return res;
// if the user didn't cancel, let's set the resulting file & location
if (nsIFilePicker::returnCancel != *aDialogResult)
{
nsCOMPtr<nsILocalFile> localFile;
res = filePicker->GetFile(getter_AddRefs(localFile));
if (NS_FAILED(res)) return res;
nsCOMPtr<nsIFile> tempFile(do_QueryInterface(localFile));
*aResultingLocation = tempFile;
NS_IF_ADDREF(*aResultingLocation);
}
return NS_OK;
}
nsresult
nsEditorShell::GetDocumentURI(nsIDOMDocument *aDoc, nsIURI **aDocumentURI)
{
@ -2062,156 +1826,6 @@ nsEditorShell::GetDocumentURI(nsIDOMDocument *aDoc, nsIURI **aDocumentURI)
return NS_OK;
}
// this method should move into JS
NS_IMETHODIMP
nsEditorShell::SaveDocument(PRBool aSaveAs, PRBool aSaveCopy, const PRUnichar* aMimeType, PRBool *_retval)
{
*_retval = PR_FALSE;
NS_ENSURE_ARG_POINTER((aMimeType));
if (!mEditor) return NS_ERROR_NOT_INITIALIZED;
nsCAutoString mimeTypeCStr; mimeTypeCStr.AssignWithConversion(aMimeType);
PRBool saveAsText;
IsSupportedTextType(mimeTypeCStr.get(), &saveAsText);
// Currently, we only understand plain text and html
if (!mimeTypeCStr.Equals("text/html") && !saveAsText)
return NS_ERROR_FAILURE;
// if we don't have the right editor type, bail now
if ((mEditorType != ePlainTextEditorType)
&& (mEditorType != eHTMLTextEditorType))
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsAutoString mimeType(aMimeType);
// if we're saving as text, force the text/plain MIME type (because we use this
// to get a content serializer on save)
if (saveAsText)
mimeType.Assign(NS_LITERAL_STRING("text/plain").get());
// get the editor
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
if (!editor)
return NS_NOINTERFACE;
// get the document
nsCOMPtr<nsIDOMDocument> doc;
nsresult res = editor->GetDocument(getter_AddRefs(doc));
if (NS_FAILED(res)) return res;
if (!doc) return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIDiskDocument> diskDoc = do_QueryInterface(doc);
if (!diskDoc)
return NS_ERROR_NO_INTERFACE;
// find out if the doc already has a fileSpec associated with it.
nsCOMPtr<nsIURI> docFile;
PRBool noFileSpec = (GetDocumentURI(doc, getter_AddRefs(docFile)) == NS_ERROR_NOT_INITIALIZED);
PRBool mustShowFileDialog = aSaveAs || noFileSpec;
// this is where it starts to get messy
PRBool replacing = !aSaveAs;
PRBool titleChanged = PR_FALSE;
nsCOMPtr<nsIFileURL> docFileURL(do_QueryInterface(docFile));
nsCOMPtr<nsIFile> resultingFileLocation;
if (docFileURL)
{
res = docFileURL->GetFile(getter_AddRefs(resultingFileLocation));
if (NS_FAILED(res))
mustShowFileDialog = PR_TRUE; // probably a remote url if we didn't get a file url; force save dialog for now
}
if (mustShowFileDialog)
{
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(doc);
if (!htmlDoc) return NS_ERROR_FAILURE;
// Prompt for title if we are saving to HTML
if (!mMailCompose && !saveAsText && (mEditorType == eHTMLTextEditorType))
{
PRBool userContinuing; // not cancel
res = PromptAndSetTitleIfNone(htmlDoc, &titleChanged, &userContinuing);
if (NS_FAILED(res)) return res;
if (userContinuing == PR_FALSE)
{
*_retval = PR_FALSE;
return NS_OK;
}
}
// put up file picker
PRInt16 dialogResult;
res = ShowSaveFilePicker(saveAsText, docFile, htmlDoc,
mimeTypeCStr.get(), &dialogResult,
getter_AddRefs(resultingFileLocation));
if (NS_FAILED(res)) return res;
// check if the user canceled
// if the user canceled and they set the title, we need to update
// the window title and recent menu even though they didn't save the file
if (dialogResult == nsIFilePicker::returnCancel)
{
if (titleChanged)
UpdateWindowTitleAndRecentMenu(PR_FALSE);
// Note that *_retval = PR_FALSE at this point
return NS_OK;
}
replacing = (dialogResult == nsIFilePicker::returnReplace);
char *docURLChar = nsnull;
res = resultingFileLocation->GetURL(&docURLChar);
if (NS_SUCCEEDED(res))
{
// create a new uri with result; set docFile to this new uri
nsCOMPtr<nsIURI> resultingURI;
res = NS_NewURI(getter_AddRefs(resultingURI), docURLChar);
if (NS_SUCCEEDED(res))
docFile = resultingURI;
// Set the new URL for the webshell unless we are saving a copy
if (NS_SUCCEEDED(res) && !aSaveCopy)
{
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mContentAreaDocShell));
if (webShell && resultingFileLocation)
{
nsAutoString urlstring; urlstring.AssignWithConversion(docURLChar);
res = webShell->SetURL(urlstring.get());
}
}
}
if (docURLChar) nsCRT::free(docURLChar);
if (NS_FAILED(res)) return res;
} // mustShowFileDialog
res = editor->SaveFile(docFile, replacing, aSaveCopy, mimeType);
if (NS_FAILED(res))
{
nsAutoString saveDocStr, failedStr;
GetBundleString(NS_LITERAL_STRING("SaveDocument"), saveDocStr);
GetBundleString(NS_LITERAL_STRING("SaveFileFailed"), failedStr);
Alert(saveDocStr, failedStr);
}
else
{
// File was saved successfully
*_retval = PR_TRUE;
}
// Update window title to show possibly different filename
// This also covers problem that after undoing a title change,
// window title loses the extra [filename] part that this adds
UpdateWindowTitleAndRecentMenu(PR_TRUE);
return res;
}
NS_IMETHODIMP
nsEditorShell::CloseWindowWithoutSaving()
{
@ -2239,121 +1853,6 @@ nsEditorShell::Print()
return NS_OK;
}
// this method should move into JS
NS_IMETHODIMP
nsEditorShell::GetLocalFileURL(nsIDOMWindowInternal *parent, const PRUnichar *filterType, PRUnichar **_retval)
{
nsAutoString FilterType(filterType);
PRBool htmlFilter = FilterType.EqualsIgnoreCase("html");
PRBool imgFilter = FilterType.EqualsIgnoreCase("img");
*_retval = nsnull;
// TODO: DON'T ACCEPT NULL PARENT AFTER WIDGET IS FIXED
if (/*parent||*/ !(htmlFilter || imgFilter))
return NS_ERROR_NOT_INITIALIZED;
nsAutoString HTMLTitle;
GetBundleString(NS_LITERAL_STRING("OpenHTMLFile"), HTMLTitle);
// An empty string should just result in "Open" for the dialog
nsAutoString title;
if (htmlFilter)
{
title = HTMLTitle;
} else
{
nsAutoString imageTitle;
GetBundleString(NS_LITERAL_STRING("SelectImageFile"), imageTitle);
if (imageTitle.Length() > 0 && imgFilter)
title = imageTitle;
}
nsresult res;
nsCOMPtr<nsIFilePicker> filePicker = do_CreateInstance("@mozilla.org/filepicker;1", &res);
if (filePicker)
{
res = filePicker->Init(parent, title.get(), nsIFilePicker::modeOpen);
if (NS_FAILED(res)) return res;
if (htmlFilter)
{
filePicker->AppendFilters(nsIFilePicker::filterHTML);
filePicker->AppendFilters(nsIFilePicker::filterText);
filePicker->AppendFilters(nsIFilePicker::filterAll);
}
else
{
filePicker->AppendFilters(nsIFilePicker::filterImages);
filePicker->AppendFilters(nsIFilePicker::filterAll);
}
#if 0
// get default directory from preference
nsCOMPtr<nsIPref> prefs( do_GetService( NS_PREF_CONTRACTID, &res ) );
if (prefs)
{
nsCOMPtr<nsILocalFile> defaultDir;
prefs->GetFileXPref(EDITOR_DEFAULT_DIR_PREF, getter_AddRefs(defaultDir));
if (defaultDir)
{
PRBool isValid = PR_FALSE;
defaultDir->Exists(&isValid);
if (isValid)
{
// Set file picker so startDir is used.
filePicker->SetDisplayDirectory(defaultDir);
}
}
}
#endif
PRInt16 dialogResult;
res = filePicker->Show(&dialogResult);
if (NS_FAILED(res))
return res;
if (dialogResult != nsIFilePicker::returnCancel)
{
// Get the platform-specific format
// Convert it to the string version of the URL format
nsCOMPtr<nsIFileURL> fileURL;
res = filePicker->GetFileURL(getter_AddRefs(fileURL));
if (fileURL)
{
nsXPIDLCString url;
res = fileURL->GetSpec(getter_Copies(url));
if (NS_FAILED(res)) return res;
nsAutoString returnVal;
returnVal.AssignWithConversion((const char*) url);
*_retval = ToNewUnicode(returnVal);
if (!*_retval)
res = NS_ERROR_OUT_OF_MEMORY;
}
}
#if 0
// save default directory to preference
if (NS_SUCCEEDED(res) && prefs)
{
nsCOMPtr<nsILocalFile> defaultDir;
filePicker->GetDisplayDirectory(getter_AddRefs(defaultDir));
if (defaultDir)
{
prefs->SetFileXPref(EDITOR_DEFAULT_DIR_PREF, defaultDir);
}
}
#endif
}
return res;
}
nsresult
nsEditorShell::UpdateWindowTitleAndRecentMenu(PRBool aSaveToPrefs)
{

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

@ -178,14 +178,6 @@ class nsEditorShell : public nsIEditorShell,
nsresult GetDocumentURI(nsIDOMDocument *aDoc, nsIURI **aDocumentURI);
nsresult PromptAndSetTitleIfNone(nsIDOMHTMLDocument *aHTMLDocument,
PRBool *titleChanged, PRBool *retVal);
nsresult ShowSaveFilePicker(PRBool aDoSaveAsText, nsIURI *aDocumentURI,
nsIDOMHTMLDocument *aHTMLDocument,
const char *aMIMEType,
PRInt16 *aDialogResult, nsIFile **aSaveLocation);
// Helper method which is called at the beginning of a new page load
nsresult StartPageLoad(nsIChannel *aChannel);

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

@ -134,28 +134,6 @@ interface nsIEditorShell : nsISupports
boolean checkOpenWindowForURLMatch( in wstring inFileURL, in nsIDOMWindowInternal inCheckWindow);
/* Commands */
/**
* @param saveAs false to try to save to existing file
* If document is not already saved, it is treated as true
* so filename is prompted.
* @param saveCopy
* true if we are saving off a copy of the document
* without changing the disk file associated with the doc.
* This would correspond to a 'Save Copy As' menu command
* @param mimeType
* Currently must be "text/html" or "text/plain"
* Also, we don't turn into a "plain text editor",
* after saving as a text file, where subsequent "Save"
* would also save as text.
* Thus saveCopy should always be true when using "text/plain"
*
* return value
* true if file was really saved.
* false if there is some problem with saving or user
* executed "Cancel" when prompted for a filename to save
*/
boolean saveDocument(in boolean saveAs, in boolean saveCopy, in wstring mimeType);
void Print();
void Undo();
@ -598,9 +576,6 @@ interface nsIEditorShell : nsISupports
/* Debugging: dump content tree to stdout */
void DumpContentTree();
/* Utility */
wstring GetLocalFileURL(in nsIDOMWindowInternal parent, in wstring filterType);
/**
* Tests if a node is a BLOCK element according the the HTML 4.0 DTD
* This does NOT consider CSS effect on display type