checkins for Hurricane

translation of all C++ functions to JS which included SaveDocument
which eventually will allow for the completeion of autosave
r: brade, anthonyd
a: waterson, cmanske


git-svn-id: svn://10.0.0.236/trunk@75726 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
anthonyd%netscape.com
2000-08-07 21:12:18 +00:00
parent 0c3b99a0c1
commit 81c7739c51
9 changed files with 102 additions and 179 deletions

View File

@@ -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 -

View File

@@ -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");

View File

@@ -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<nsIDOMDocument> theDoc;
nsresult rv = GetEditorDocument(getter_AddRefs(theDoc));
if (NS_SUCCEEDED(rv) && theDoc)
{
nsCOMPtr<nsIDiskDocument> 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<nsIBaseWindow> baseWindow;
GetTreeOwner(mDocShell, getter_AddRefs(baseWindow));
NS_ENSURE_TRUE(baseWindow, NS_ERROR_FAILURE);
baseWindow->Destroy();
}
return rv;
nsCOMPtr<nsIBaseWindow> baseWindow;
GetTreeOwner(mDocShell, getter_AddRefs(baseWindow));
NS_ENSURE_TRUE(baseWindow, NS_ERROR_FAILURE);
return baseWindow->Destroy();
}
NS_IMETHODIMP

View File

@@ -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 -

View File

@@ -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<nsIDOMDocument> theDoc;
nsresult rv = GetEditorDocument(getter_AddRefs(theDoc));
if (NS_SUCCEEDED(rv) && theDoc)
{
nsCOMPtr<nsIDiskDocument> 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<nsIBaseWindow> baseWindow;
GetTreeOwner(mDocShell, getter_AddRefs(baseWindow));
NS_ENSURE_TRUE(baseWindow, NS_ERROR_FAILURE);
baseWindow->Destroy();
}
return rv;
nsCOMPtr<nsIBaseWindow> baseWindow;
GetTreeOwner(mDocShell, getter_AddRefs(baseWindow));
NS_ENSURE_TRUE(baseWindow, NS_ERROR_FAILURE);
return baseWindow->Destroy();
}
NS_IMETHODIMP

View File

@@ -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 <URL>"
* 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();
};

View File

@@ -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");

View File

@@ -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 = "";

View File

@@ -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 = "";