From cdccba167a027fb14d7fc17de99e111c67530082 Mon Sep 17 00:00:00 2001 From: "brade%netscape.com" Date: Fri, 17 Mar 2000 15:27:05 +0000 Subject: [PATCH] bug #25396; don't use title for default page name if it's a remote file with a file name (r=jst@netscape.com) git-svn-id: svn://10.0.0.236/trunk@63293 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/editor/base/nsEditorShell.cpp | 26 ++++++++++++++++++- mozilla/editor/composer/src/nsEditorShell.cpp | 26 ++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/mozilla/editor/base/nsEditorShell.cpp b/mozilla/editor/base/nsEditorShell.cpp index e3a85002a7a..852e91eb8ef 100644 --- a/mozilla/editor/base/nsEditorShell.cpp +++ b/mozilla/editor/base/nsEditorShell.cpp @@ -1416,8 +1416,31 @@ nsEditorShell::SaveDocument(PRBool saveAs, PRBool saveCopy, PRBool *_retval) if (noFileSpec) { + // check the current url, use that file name if possible + nsString urlstring; + res = HTMLDoc->GetURL(urlstring); + + // ????? + // res = HTMLDoc->GetSourceDocumentURL(jscx, uri); + // do a QI to get an nsIURL and then call GetFileName() + + // if it's not a local file already, grab the current file name + if ( (urlstring.Compare("file", PR_TRUE, 4) != 0 ) + && (urlstring.Compare("about:blank", PR_TRUE, -1) != 0) ) + { + PRInt32 index = urlstring.RFindChar((PRUnichar)'/', PR_FALSE, -1, -1 ); + if ( index != -1 ) + { + // remove cruft before file name including '/' + // if the url ends with a '/' then the whole string will be cut + urlstring = urlstring.Cut(0, index + 1); + if (urlstring.Length() > 0) + fileName = urlstring; + } + } + // Use page title as suggested name for new document - if (title.Length() > 0) + if (fileName.Length() == 0 && title.Length() > 0) { //Replace "bad" filename characteres with "_" PRUnichar space = (PRUnichar)' '; @@ -1448,6 +1471,7 @@ nsEditorShell::SaveDocument(PRBool saveAs, PRBool saveCopy, PRBool *_retval) } if (fileName.Length() > 0) fileWidget->SetDefaultString(fileName); +// Why is SkipFilters here? Shouldn't it be before if (noFileSpec)??? SkipFilters: nsFileDlgResults dialogResult; // 1ST PARAM SHOULD BE nsIDOMWindow*, not nsIWidget* diff --git a/mozilla/editor/composer/src/nsEditorShell.cpp b/mozilla/editor/composer/src/nsEditorShell.cpp index e3a85002a7a..852e91eb8ef 100644 --- a/mozilla/editor/composer/src/nsEditorShell.cpp +++ b/mozilla/editor/composer/src/nsEditorShell.cpp @@ -1416,8 +1416,31 @@ nsEditorShell::SaveDocument(PRBool saveAs, PRBool saveCopy, PRBool *_retval) if (noFileSpec) { + // check the current url, use that file name if possible + nsString urlstring; + res = HTMLDoc->GetURL(urlstring); + + // ????? + // res = HTMLDoc->GetSourceDocumentURL(jscx, uri); + // do a QI to get an nsIURL and then call GetFileName() + + // if it's not a local file already, grab the current file name + if ( (urlstring.Compare("file", PR_TRUE, 4) != 0 ) + && (urlstring.Compare("about:blank", PR_TRUE, -1) != 0) ) + { + PRInt32 index = urlstring.RFindChar((PRUnichar)'/', PR_FALSE, -1, -1 ); + if ( index != -1 ) + { + // remove cruft before file name including '/' + // if the url ends with a '/' then the whole string will be cut + urlstring = urlstring.Cut(0, index + 1); + if (urlstring.Length() > 0) + fileName = urlstring; + } + } + // Use page title as suggested name for new document - if (title.Length() > 0) + if (fileName.Length() == 0 && title.Length() > 0) { //Replace "bad" filename characteres with "_" PRUnichar space = (PRUnichar)' '; @@ -1448,6 +1471,7 @@ nsEditorShell::SaveDocument(PRBool saveAs, PRBool saveCopy, PRBool *_retval) } if (fileName.Length() > 0) fileWidget->SetDefaultString(fileName); +// Why is SkipFilters here? Shouldn't it be before if (noFileSpec)??? SkipFilters: nsFileDlgResults dialogResult; // 1ST PARAM SHOULD BE nsIDOMWindow*, not nsIWidget*