зеркало из https://github.com/mozilla/gecko-dev.git
use persist constants, set persist flags for no base tag mods, set linebreaks to crlf if we aren't saving (file scheme), set replace flag; bugs 125070 and 126672; r=adamlock, sr=sfraser, a=asa
This commit is contained in:
Родитель
30d5e58872
Коммит
e957add476
|
@ -713,6 +713,7 @@ var gPersistObj;
|
|||
// if (!aSaveCopy && success)
|
||||
// window.editorShell.editor.ResetModificationCount(); // this should cause notification to listeners that document has changed
|
||||
|
||||
const webPersist = Components.interfaces.nsIWebBrowserPersist;
|
||||
function OutputFileWithPersistAPI(editorDoc, aDestinationLocation, aRelatedFilesParentDir, aMimeType)
|
||||
{
|
||||
gPersistObj = null;
|
||||
|
@ -722,14 +723,39 @@ function OutputFileWithPersistAPI(editorDoc, aDestinationLocation, aRelatedFiles
|
|||
imeEditor.ForceCompositionEnd();
|
||||
} catch (e) {}
|
||||
|
||||
var isLocalFile = false;
|
||||
try {
|
||||
var tmp1 = aDestinationLocation.QueryInterface(Components.interfaces.nsIFile);
|
||||
isLocalFile = true;
|
||||
}
|
||||
catch (e) {
|
||||
try {
|
||||
var tmp = aDestinationLocation.QueryInterface(Components.interfaces.nsIURI);
|
||||
isLocalFile = tmp.schemeIs("file");
|
||||
}
|
||||
catch (e) {}
|
||||
}
|
||||
|
||||
try {
|
||||
// we should supply a parent directory if/when we turn on functionality to save related documents
|
||||
var persistObj = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Components.interfaces.nsIWebBrowserPersist);
|
||||
var persistObj = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(webPersist);
|
||||
persistObj.progressListener = gEditorOutputProgressListener;
|
||||
|
||||
var wrapColumn = GetWrapColumn();
|
||||
var outputFlags = GetOutputFlags(aMimeType, wrapColumn);
|
||||
|
||||
// for 4.x parity as well as improving readability of file locally on server
|
||||
// this will always send crlf for upload (http/ftp)
|
||||
if (!isLocalFile) // if we aren't saving locally then send both cr and lf
|
||||
outputFlags |= webPersist.ENCODE_FLAGS_CR_LINEBREAKS | webPersist.ENCODE_FLAGS_LF_LINEBREAKS;
|
||||
|
||||
// note: we always want to set the replace existing files flag since we have
|
||||
// already given user the chance to not replace an existing file (file picker)
|
||||
// or the user picked an option where the file is implicitly being replaced (save)
|
||||
persistObj.persistFlags = persistObj.persistFlags
|
||||
| webPersist.PERSIST_FLAGS_NO_BASE_TAG_MODIFICATIONS
|
||||
| webPersist.PERSIST_FLAGS_REPLACE_EXISTING_FILES
|
||||
| webPersist.PERSIST_FLAGS_FIXUP_ORIGINAL_DOM;
|
||||
persistObj.saveDocument(editorDoc, aDestinationLocation, aRelatedFilesParentDir,
|
||||
aMimeType, outputFlags, wrapColumn);
|
||||
gPersistObj = persistObj;
|
||||
|
@ -742,11 +768,11 @@ function OutputFileWithPersistAPI(editorDoc, aDestinationLocation, aRelatedFiles
|
|||
// returns output flags based on mimetype, wrapCol and prefs
|
||||
function GetOutputFlags(aMimeType, aWrapColumn)
|
||||
{
|
||||
var outputFlags = 256; // nsIDocumentEncoder.OutputEncodeEntities
|
||||
var outputFlags = webPersist.ENCODE_FLAGS_ENCODE_ENTITIES;
|
||||
if (aMimeType == "text/plain")
|
||||
{
|
||||
// When saving in "text/plain" format, always do formatting
|
||||
outputFlags |= 2; // nsIDocumentEncoder.OutputFormatted
|
||||
outputFlags |= webPersist.ENCODE_FLAGS_FORMATTED;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -754,13 +780,13 @@ function GetOutputFlags(aMimeType, aWrapColumn)
|
|||
try {
|
||||
var prefs = GetPrefs();
|
||||
if (prefs.getBoolPref("editor.prettyprint"))
|
||||
outputFlags |= 2; // nsIDocumentEncoder.OutputFormatted
|
||||
outputFlags |= webPersist.ENCODE_FLAGS_FORMATTED;
|
||||
}
|
||||
catch (e) {}
|
||||
}
|
||||
|
||||
if (aWrapColumn > 0)
|
||||
outputFlags |= 32; // nsIDocumentEncoder.OutputWrap;
|
||||
outputFlags |= webPersist.ENCODE_FLAGS_WRAP;
|
||||
|
||||
return outputFlags;
|
||||
}
|
||||
|
@ -1193,7 +1219,7 @@ function SaveDocument(aSaveAs, aSaveCopy, aMimeType)
|
|||
if (oldLocation == curParentString || IsUrlAboutBlank(oldLocation))
|
||||
parentDir = null;
|
||||
else
|
||||
parentDir = tempLocalFile.parent;
|
||||
parentDir = tempLocalFile.parent; // this is wrong if parent is the root!
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
Загрузка…
Ссылка в новой задаче