diff --git a/mozilla/editor/base/nsComposerCommands.cpp b/mozilla/editor/base/nsComposerCommands.cpp index e32719c31b0..185b28918be 100644 --- a/mozilla/editor/base/nsComposerCommands.cpp +++ b/mozilla/editor/base/nsComposerCommands.cpp @@ -169,6 +169,7 @@ nsBaseStateUpdatingCommand::UpdateCommandState(const PRUnichar *aCommandName, ns } +/* #ifdef XP_MAC #pragma mark - #endif @@ -202,6 +203,8 @@ nsCloseCommand::DoCommand(const PRUnichar *aCommand, nsISupports * refCon) return rv; } +*/ + #ifdef XP_MAC #pragma mark - diff --git a/mozilla/editor/base/nsEditorController.cpp b/mozilla/editor/base/nsEditorController.cpp index 97d5558a1eb..16ab2e48c01 100644 --- a/mozilla/editor/base/nsEditorController.cpp +++ b/mozilla/editor/base/nsEditorController.cpp @@ -291,8 +291,6 @@ nsresult nsComposerController::RegisterComposerCommands(nsIControllerCommandMana nsresult rv; // File menu - NS_REGISTER_ONE_COMMAND(nsCloseCommand, "cmd_close"); - NS_REGISTER_FIRST_COMMAND(nsPrintingCommands, "cmd_print"); NS_REGISTER_NEXT_COMMAND(nsPrintingCommands, "cmd_printSetup"); NS_REGISTER_LAST_COMMAND(nsPrintingCommands, "cmd_printPreview"); diff --git a/mozilla/editor/base/nsEditorShell.cpp b/mozilla/editor/base/nsEditorShell.cpp index 971ebd62796..5556317951e 100644 --- a/mozilla/editor/base/nsEditorShell.cpp +++ b/mozilla/editor/base/nsEditorShell.cpp @@ -1587,67 +1587,6 @@ nsEditorShell::CheckOpenWindowForURLMatch(const PRUnichar* inFileURL, nsIDOMWind return NS_OK; } -NS_IMETHODIMP -nsEditorShell::CheckAndSaveDocument(const PRUnichar *reasonToSave, PRBool *_retval) -{ - *_retval = PR_FALSE; - - nsCOMPtr theDoc; - nsresult rv = GetEditorDocument(getter_AddRefs(theDoc)); - if (NS_SUCCEEDED(rv) && theDoc) - { - nsCOMPtr diskDoc = do_QueryInterface(theDoc); - if (diskDoc) - { - PRInt32 modCount = 0; - diskDoc->GetModCount(&modCount); - - // Return true unless user cancels an action - *_retval = PR_TRUE; - - if (modCount > 0) - { - // Ask user if they want to save current changes - nsAutoString reasonToSaveStr(reasonToSave); - nsAutoString tmp1, tmp2, title; - GetBundleString(NS_ConvertASCIItoUCS2("Save"), tmp1); - GetBundleString(NS_ConvertASCIItoUCS2("DontSave"), tmp2); - GetDocumentTitleString(title); - // If title is empty, use "untitled" - if (title.Length() == 0) - GetBundleString(NS_ConvertASCIItoUCS2("untitled"), title); - - nsAutoString saveMsg; - GetBundleString(NS_ConvertASCIItoUCS2("SaveFilePrompt"), saveMsg); - saveMsg.ReplaceSubstring(NS_ConvertASCIItoUCS2("%title%"), title); - saveMsg.ReplaceSubstring(NS_ConvertASCIItoUCS2("%reason%"), reasonToSaveStr); - - nsAutoString saveDocString; - GetBundleString(NS_ConvertASCIItoUCS2("SaveDocument"), saveDocString); - EConfirmResult result = ConfirmWithCancel(saveDocString, saveMsg, &tmp1, &tmp2); - if (result == eCancel) - { - *_retval = PR_FALSE; - } else if (result == eYes) - { - FinishHTMLSource(); - - // Either save to existing file or prompt for name (as for SaveAs) - // We don't continue if we failed to save file (_retval is set to FALSE) - rv = SaveDocument(PR_FALSE, PR_FALSE, _retval); - } - else if (mHTMLSourceMode) // result == eNo - { - // User doesn't want to save document, so we just cancel source mode - nsAutoString command(NS_LITERAL_STRING("cmd_CancelHTMLSource")); - rv = DoControllerCommand(command); - } - } - } - } - return rv; -} - NS_IMETHODIMP nsEditorShell::SaveDocument(PRBool saveAs, PRBool saveCopy, PRBool *_retval) { @@ -1901,24 +1840,12 @@ nsEditorShell::SaveDocument(PRBool saveAs, PRBool saveCopy, PRBool *_retval) } NS_IMETHODIMP -nsEditorShell::CloseWindow( PRBool *_retval ) +nsEditorShell::CloseWindowWithoutSaving() { - nsAutoString beforeClosingStr; - GetBundleString(NS_ConvertASCIItoUCS2("BeforeClosing"), beforeClosingStr); - - nsresult rv = CheckAndSaveDocument(beforeClosingStr.GetUnicode(), _retval); - - // Don't close the window if there was an error saving file or - // user canceled an action along the way - if (NS_SUCCEEDED(rv) && *_retval) - { - nsCOMPtr baseWindow; - GetTreeOwner(mDocShell, getter_AddRefs(baseWindow)); - NS_ENSURE_TRUE(baseWindow, NS_ERROR_FAILURE); - baseWindow->Destroy(); - } - - return rv; + nsCOMPtr baseWindow; + GetTreeOwner(mDocShell, getter_AddRefs(baseWindow)); + NS_ENSURE_TRUE(baseWindow, NS_ERROR_FAILURE); + return baseWindow->Destroy(); } NS_IMETHODIMP diff --git a/mozilla/editor/composer/src/nsComposerCommands.cpp b/mozilla/editor/composer/src/nsComposerCommands.cpp index e32719c31b0..185b28918be 100644 --- a/mozilla/editor/composer/src/nsComposerCommands.cpp +++ b/mozilla/editor/composer/src/nsComposerCommands.cpp @@ -169,6 +169,7 @@ nsBaseStateUpdatingCommand::UpdateCommandState(const PRUnichar *aCommandName, ns } +/* #ifdef XP_MAC #pragma mark - #endif @@ -202,6 +203,8 @@ nsCloseCommand::DoCommand(const PRUnichar *aCommand, nsISupports * refCon) return rv; } +*/ + #ifdef XP_MAC #pragma mark - diff --git a/mozilla/editor/composer/src/nsEditorShell.cpp b/mozilla/editor/composer/src/nsEditorShell.cpp index 971ebd62796..5556317951e 100644 --- a/mozilla/editor/composer/src/nsEditorShell.cpp +++ b/mozilla/editor/composer/src/nsEditorShell.cpp @@ -1587,67 +1587,6 @@ nsEditorShell::CheckOpenWindowForURLMatch(const PRUnichar* inFileURL, nsIDOMWind return NS_OK; } -NS_IMETHODIMP -nsEditorShell::CheckAndSaveDocument(const PRUnichar *reasonToSave, PRBool *_retval) -{ - *_retval = PR_FALSE; - - nsCOMPtr theDoc; - nsresult rv = GetEditorDocument(getter_AddRefs(theDoc)); - if (NS_SUCCEEDED(rv) && theDoc) - { - nsCOMPtr diskDoc = do_QueryInterface(theDoc); - if (diskDoc) - { - PRInt32 modCount = 0; - diskDoc->GetModCount(&modCount); - - // Return true unless user cancels an action - *_retval = PR_TRUE; - - if (modCount > 0) - { - // Ask user if they want to save current changes - nsAutoString reasonToSaveStr(reasonToSave); - nsAutoString tmp1, tmp2, title; - GetBundleString(NS_ConvertASCIItoUCS2("Save"), tmp1); - GetBundleString(NS_ConvertASCIItoUCS2("DontSave"), tmp2); - GetDocumentTitleString(title); - // If title is empty, use "untitled" - if (title.Length() == 0) - GetBundleString(NS_ConvertASCIItoUCS2("untitled"), title); - - nsAutoString saveMsg; - GetBundleString(NS_ConvertASCIItoUCS2("SaveFilePrompt"), saveMsg); - saveMsg.ReplaceSubstring(NS_ConvertASCIItoUCS2("%title%"), title); - saveMsg.ReplaceSubstring(NS_ConvertASCIItoUCS2("%reason%"), reasonToSaveStr); - - nsAutoString saveDocString; - GetBundleString(NS_ConvertASCIItoUCS2("SaveDocument"), saveDocString); - EConfirmResult result = ConfirmWithCancel(saveDocString, saveMsg, &tmp1, &tmp2); - if (result == eCancel) - { - *_retval = PR_FALSE; - } else if (result == eYes) - { - FinishHTMLSource(); - - // Either save to existing file or prompt for name (as for SaveAs) - // We don't continue if we failed to save file (_retval is set to FALSE) - rv = SaveDocument(PR_FALSE, PR_FALSE, _retval); - } - else if (mHTMLSourceMode) // result == eNo - { - // User doesn't want to save document, so we just cancel source mode - nsAutoString command(NS_LITERAL_STRING("cmd_CancelHTMLSource")); - rv = DoControllerCommand(command); - } - } - } - } - return rv; -} - NS_IMETHODIMP nsEditorShell::SaveDocument(PRBool saveAs, PRBool saveCopy, PRBool *_retval) { @@ -1901,24 +1840,12 @@ nsEditorShell::SaveDocument(PRBool saveAs, PRBool saveCopy, PRBool *_retval) } NS_IMETHODIMP -nsEditorShell::CloseWindow( PRBool *_retval ) +nsEditorShell::CloseWindowWithoutSaving() { - nsAutoString beforeClosingStr; - GetBundleString(NS_ConvertASCIItoUCS2("BeforeClosing"), beforeClosingStr); - - nsresult rv = CheckAndSaveDocument(beforeClosingStr.GetUnicode(), _retval); - - // Don't close the window if there was an error saving file or - // user canceled an action along the way - if (NS_SUCCEEDED(rv) && *_retval) - { - nsCOMPtr baseWindow; - GetTreeOwner(mDocShell, getter_AddRefs(baseWindow)); - NS_ENSURE_TRUE(baseWindow, NS_ERROR_FAILURE); - baseWindow->Destroy(); - } - - return rv; + nsCOMPtr baseWindow; + GetTreeOwner(mDocShell, getter_AddRefs(baseWindow)); + NS_ENSURE_TRUE(baseWindow, NS_ERROR_FAILURE); + return baseWindow->Destroy(); } NS_IMETHODIMP diff --git a/mozilla/editor/idl/nsIEditorShell.idl b/mozilla/editor/idl/nsIEditorShell.idl index 03a08479667..36263794a8c 100644 --- a/mozilla/editor/idl/nsIEditorShell.idl +++ b/mozilla/editor/idl/nsIEditorShell.idl @@ -131,7 +131,7 @@ interface nsIEditorShell : nsISupports */ PRInt32 ConfirmWithTitle(in wstring title, in wstring question, in wstring yesButtonText, in wstring noButtonText); - + /* check a particular window's URL to see if it matches the given URL */ boolean checkOpenWindowForURLMatch( in wstring inFileURL, in nsIDOMWindow inCheckWindow); @@ -152,17 +152,6 @@ interface nsIEditorShell : nsISupports */ boolean saveDocument(in boolean saveAs, in boolean saveCopy); - /** Check if current document has changes and prompt to save if it does. - * return value: - * false ONLY if user executed "Cancel" in the SaveAs dialog - * true if no changes in doc, or file was saved successfully - * @param reasonToSave - * A string to append after "Save changes to " - * If null, just the question mark will be appended - */ - boolean CheckAndSaveDocument(in wstring reasonToSave); - - boolean CloseWindow(); void Print(); void Undo(); @@ -625,4 +614,5 @@ interface nsIEditorShell : nsISupports void StartLogging(in nsIFileSpec logFile); void StopLogging(); + void CloseWindowWithoutSaving(); }; diff --git a/mozilla/editor/libeditor/base/nsEditorController.cpp b/mozilla/editor/libeditor/base/nsEditorController.cpp index 97d5558a1eb..16ab2e48c01 100644 --- a/mozilla/editor/libeditor/base/nsEditorController.cpp +++ b/mozilla/editor/libeditor/base/nsEditorController.cpp @@ -291,8 +291,6 @@ nsresult nsComposerController::RegisterComposerCommands(nsIControllerCommandMana nsresult rv; // File menu - NS_REGISTER_ONE_COMMAND(nsCloseCommand, "cmd_close"); - NS_REGISTER_FIRST_COMMAND(nsPrintingCommands, "cmd_print"); NS_REGISTER_NEXT_COMMAND(nsPrintingCommands, "cmd_printSetup"); NS_REGISTER_LAST_COMMAND(nsPrintingCommands, "cmd_printPreview"); diff --git a/mozilla/editor/ui/composer/content/ComposerCommands.js b/mozilla/editor/ui/composer/content/ComposerCommands.js index b428f836438..f6c7fd6d0e8 100644 --- a/mozilla/editor/ui/composer/content/ComposerCommands.js +++ b/mozilla/editor/ui/composer/content/ComposerCommands.js @@ -48,7 +48,8 @@ function SetupControllerCommands() gComposerCommandManager.registerCommand("cmd_openRemote", nsOpenRemoteCommand); gComposerCommandManager.registerCommand("cmd_preview", nsPreviewCommand); gComposerCommandManager.registerCommand("cmd_quit", nsQuitCommand); - + gComposerCommandManager.registerCommand("cmd_close", nsCloseCommand); + gComposerCommandManager.registerCommand("cmd_find", nsFindCommand); gComposerCommandManager.registerCommand("cmd_findNext", nsFindNextCommand); gComposerCommandManager.registerCommand("cmd_spelling", nsSpellingCommand); @@ -197,7 +198,7 @@ dump("*** nsOpenCommand: doCommand\n"); /* This checks for already open window and activates it... * note that we have to test the native path length * since fileURL.spec will be "file:///" if no filename picked (Cancel button used) - */ + */ if (fp.file && fp.file.path.length > 0) { EditorOpenUrl(fp.fileURL.spec); } @@ -248,7 +249,7 @@ var nsSaveAsCharsetCommand = return (window.editorShell && window.editorShell.documentEditable); }, doCommand: function(aCommand) - { + { window.ok = false; // In editor.js FinishHTMLSource(); @@ -260,6 +261,7 @@ var nsSaveAsCharsetCommand = return false; } }; + //----------------------------------------------------------------------------------- var nsRevertCommand = { @@ -313,6 +315,30 @@ var nsRevertCommand = } }; +//----------------------------------------------------------------------------------- +var nsCloseCommand = +{ + isCommandEnabled: function(aCommand, dummy) + { + return window.editorShell; + }, + + doCommand: function(aCommand) + { + CloseWindow(); + } +}; + +function CloseWindow() +{ + // Close window; check to make sure document is saved + var result = CheckAndSaveDocument(window.editorShell.GetString("BeforeClosing")); + if (result == true) // If they saved the document, or it is unchanged, exit + { + window.editorShell.CloseWindowWithoutSaving(); + } +} + //----------------------------------------------------------------------------------- var nsNewEditorCommand = { @@ -358,7 +384,7 @@ var nsPreviewCommand = doCommand: function(aCommand) { FinishHTMLSource(); - if (!editorShell.CheckAndSaveDocument(window.editorShell.GetString("BeforePreview"))) + if (CheckAndSaveDocument(window.editorShell.GetString("BeforePreview"))) return; var fileurl = ""; diff --git a/mozilla/editor/ui/composer/content/editor.js b/mozilla/editor/ui/composer/content/editor.js index 2819ce4a878..2ec3e92a9ba 100644 --- a/mozilla/editor/ui/composer/content/editor.js +++ b/mozilla/editor/ui/composer/content/editor.js @@ -186,7 +186,7 @@ function EditorStartup(editorType, editorElement) // set up our global prefs object GetPrefsService(); - + // Get url for editor content and load it. // the editor gets instantiated by the editor shell when the URL has finished loading. var url = document.getElementById("args").getAttribute("value"); @@ -336,6 +336,57 @@ function sendPageMustSave() } } +function CheckAndSaveDocument(reasonToSave) +{ + var document = editorShell.editorDocument; + if (!editorShell.documentModified) + return true; + + var title = window.editorShell.editorDocument.title; + if (title.length == 0) + var title = GetString("untitled"); + + var dialogTitle = window.editorShell.GetString("SaveDocument"); + var dialogMsg = window.editorShell.GetString("SaveFilePrompt"); + dialogMsg = (dialogMsg.replace(/%title%/,title)).replace(/%reason%/,reasonToSave); + + var result = {value:0}; + commonDialogsService.UniversalDialog( + window, + null, + dialogTitle, + dialogMsg, + null, + window.editorShell.GetString("Save"), // Save Button + window.editorShell.GetString("Cancel"), // Cancel Button + window.editorShell.GetString("DontSave"), // Don't Save Button + null, + null, + null, + {value:0}, + {value:0}, + "chrome://global/skin/question-icon.gif", + {value:"false"}, + 3, + 0, + 0, + result + ); + + if (result.value == 0) + { + // Save + var success = window.editorShell.saveDocument(false, false); + return success; + } + + if (result.value == 1) // "Cancel" + return false; + + if (result.value == 2) // "Don't Save" + return true; +} + // --------------------------- File menu --------------------------- @@ -363,7 +414,7 @@ function EditorCanClose() // Returns FALSE only if user cancels save action dump("Calling EditorCanClose\n"); - return editorShell.CheckAndSaveDocument(GetString("BeforeClosing")); + return CheckAndSaveDocument(GetString("BeforeClosing")); } // --------------------------- View menu --------------------------- @@ -372,7 +423,7 @@ function EditorViewSource() { // Temporary hack: save to a file and call up the source view window // using the local file url. - if (!editorShell.CheckAndSaveDocument(GetString("BeforeViewSource"))) + if (CheckAndSaveDocument(GetString("BeforeViewSource"))) return; fileurl = "";