Bug 1341211 - Get rid of nsIFilePicker.show() use in c-c (editor part). r=jorgk,frg
This commit is contained in:
Родитель
4545763dd2
Коммит
eb1f892c3e
|
@ -485,15 +485,16 @@ var nsOpenCommand =
|
|||
fp.appendFilters(nsIFilePicker.filterText);
|
||||
fp.appendFilters(nsIFilePicker.filterAll);
|
||||
|
||||
/* doesn't handle *.shtml files */
|
||||
if (fp.show() == nsIFilePicker.returnCancel)
|
||||
return;
|
||||
|
||||
// editPage checks for already open window and activates it.
|
||||
if (fp.fileURL.spec) {
|
||||
SaveFilePickerDirectory(fp, fileType);
|
||||
editPage(fp.fileURL.spec, fileType);
|
||||
}
|
||||
fp.open(rv => {
|
||||
if (rv != nsIFilePicker.returnOK || !fp.file) {
|
||||
return;
|
||||
}
|
||||
// editPage checks for already open window and activates it.
|
||||
if (fp.fileURL.spec) {
|
||||
SaveFilePickerDirectory(fp, fileType);
|
||||
editPage(fp.fileURL.spec, fileType);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -534,15 +535,13 @@ var nsSaveCommand =
|
|||
|
||||
doCommand: function(aCommand)
|
||||
{
|
||||
var result = false;
|
||||
var editor = GetCurrentEditor();
|
||||
if (editor)
|
||||
{
|
||||
if (IsHTMLEditor())
|
||||
SetEditMode(gPreviousNonSourceDisplayMode);
|
||||
result = SaveDocument(IsUrlAboutBlank(GetDocumentUrl()), false, editor.contentsMIMEType);
|
||||
SaveDocument(IsUrlAboutBlank(GetDocumentUrl()), false, editor.contentsMIMEType);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -558,15 +557,13 @@ var nsSaveAsCommand =
|
|||
|
||||
doCommand: function(aCommand)
|
||||
{
|
||||
var result = false;
|
||||
var editor = GetCurrentEditor();
|
||||
if (editor)
|
||||
{
|
||||
if (IsHTMLEditor())
|
||||
SetEditMode(gPreviousNonSourceDisplayMode);
|
||||
result = SaveDocument(true, false, editor.contentsMIMEType);
|
||||
SaveDocument(true, false, editor.contentsMIMEType);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -585,10 +582,8 @@ var nsExportToTextCommand =
|
|||
if (GetCurrentEditor())
|
||||
{
|
||||
SetEditMode(gPreviousNonSourceDisplayMode);
|
||||
var result = SaveDocument(true, true, "text/plain");
|
||||
return result;
|
||||
SaveDocument(true, true, "text/plain");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -617,16 +612,14 @@ var nsSaveAndChangeEncodingCommand =
|
|||
{
|
||||
if (window.exportToText)
|
||||
{
|
||||
window.ok = SaveDocument(true, true, "text/plain");
|
||||
SaveDocument(true, true, "text/plain");
|
||||
}
|
||||
else
|
||||
{
|
||||
var editor = GetCurrentEditor();
|
||||
window.ok = SaveDocument(true, false, editor ? editor.contentsMIMEType : null);
|
||||
SaveDocument(true, false, editor ? editor.contentsMIMEType : null);
|
||||
}
|
||||
}
|
||||
|
||||
return window.ok;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -778,7 +771,9 @@ function GetSuggestedFileName(aDocumentURLString, aMIMEType)
|
|||
return title + extension;
|
||||
}
|
||||
|
||||
// returns file picker result
|
||||
/**
|
||||
* @return {Promise} dialogResult
|
||||
*/
|
||||
function PromptForSaveLocation(aDoSaveAsText, aEditorType, aMIMEType, aDocumentURLString)
|
||||
{
|
||||
var dialogResult = {};
|
||||
|
@ -847,18 +842,22 @@ function PromptForSaveLocation(aDoSaveAsText, aEditorType, aMIMEType, aDocumentU
|
|||
}
|
||||
catch(e) {}
|
||||
|
||||
dialogResult.filepickerClick = fp.show();
|
||||
if (dialogResult.filepickerClick != nsIFilePicker.returnCancel)
|
||||
{
|
||||
// reset urlstring to new save location
|
||||
dialogResult.resultingURIString = fileHandler.getURLSpecFromFile(fp.file);
|
||||
dialogResult.resultingLocalFile = fp.file;
|
||||
SaveFilePickerDirectory(fp, aEditorType);
|
||||
}
|
||||
else if ("gFilePickerDirectory" in window && gFilePickerDirectory)
|
||||
fp.displayDirectory = gFilePickerDirectory;
|
||||
|
||||
return dialogResult;
|
||||
return new Promise(resolve => {
|
||||
fp.open(rv => {
|
||||
dialogResult.filepickerClick = rv;
|
||||
if (rv != nsIFilePicker.returnCancel) {
|
||||
// reset urlstring to new save location
|
||||
dialogResult.resultingURIString = fileHandler.getURLSpecFromFile(fp.file);
|
||||
dialogResult.resultingLocalFile = fp.file;
|
||||
SaveFilePickerDirectory(fp, aEditorType);
|
||||
resolve(dialogResult);
|
||||
}
|
||||
else if ("gFilePickerDirectory" in window && gFilePickerDirectory) {
|
||||
fp.displayDirectory = gFilePickerDirectory;
|
||||
resolve(null);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1582,10 +1581,10 @@ function IsSupportedTextMimeType(aMimeType)
|
|||
}
|
||||
|
||||
// throws an error or returns true if user attempted save; false if user canceled save
|
||||
function SaveDocument(aSaveAs, aSaveCopy, aMimeType)
|
||||
async function SaveDocument(aSaveAs, aSaveCopy, aMimeType)
|
||||
{
|
||||
var editor = GetCurrentEditor();
|
||||
if (!aMimeType || aMimeType == "" || !editor)
|
||||
if (!aMimeType || !editor)
|
||||
throw Components.results.NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
var editorDoc = editor.document;
|
||||
|
@ -1629,8 +1628,8 @@ function SaveDocument(aSaveAs, aSaveCopy, aMimeType)
|
|||
return false;
|
||||
}
|
||||
|
||||
var dialogResult = PromptForSaveLocation(saveAsTextFile, editorType, aMimeType, urlstring);
|
||||
if (dialogResult.filepickerClick == nsIFilePicker.returnCancel)
|
||||
var dialogResult = await PromptForSaveLocation(saveAsTextFile, editorType, aMimeType, urlstring);
|
||||
if (!dialogResult)
|
||||
return false;
|
||||
|
||||
replacing = (dialogResult.filepickerClick == nsIFilePicker.returnReplace);
|
||||
|
@ -2045,11 +2044,11 @@ var nsCloseCommand =
|
|||
}
|
||||
};
|
||||
|
||||
function CloseWindow()
|
||||
async function CloseWindow()
|
||||
{
|
||||
// Check to make sure document is saved. "true" means allow "Don't Save" button,
|
||||
// so user can choose to close without saving
|
||||
if (CheckAndSaveDocument("cmd_close", true))
|
||||
if (await CheckAndSaveDocument("cmd_close", true))
|
||||
{
|
||||
if (window.InsertCharWindow)
|
||||
SwitchInsertCharToAnotherEditorOrClose();
|
||||
|
@ -2121,11 +2120,11 @@ var nsPreviewCommand =
|
|||
getCommandStateParams: function(aCommand, aParams, aRefCon) {},
|
||||
doCommandParams: function(aCommand, aParams, aRefCon) {},
|
||||
|
||||
doCommand: function(aCommand)
|
||||
doCommand: async function(aCommand)
|
||||
{
|
||||
// Don't continue if user canceled during prompt for saving
|
||||
// DocumentHasBeenSaved will test if we have a URL and suppress "Don't Save" button if not
|
||||
if (!CheckAndSaveDocument("cmd_preview", DocumentHasBeenSaved()))
|
||||
if (!(await CheckAndSaveDocument("cmd_preview", DocumentHasBeenSaved())))
|
||||
return;
|
||||
|
||||
// Check if we saved again just in case?
|
||||
|
@ -2176,11 +2175,11 @@ var nsSendPageCommand =
|
|||
getCommandStateParams: function(aCommand, aParams, aRefCon) {},
|
||||
doCommandParams: function(aCommand, aParams, aRefCon) {},
|
||||
|
||||
doCommand: function(aCommand)
|
||||
doCommand: async function(aCommand)
|
||||
{
|
||||
// Don't continue if user canceled during prompt for saving
|
||||
// DocumentHasBeenSaved will test if we have a URL and suppress "Don't Save" button if not
|
||||
if (!CheckAndSaveDocument("cmd_editSendPage", DocumentHasBeenSaved()))
|
||||
if (!(await CheckAndSaveDocument("cmd_editSendPage", DocumentHasBeenSaved())))
|
||||
return;
|
||||
|
||||
// Check if we saved again just in case?
|
||||
|
@ -2366,13 +2365,13 @@ var nsValidateCommand =
|
|||
getCommandStateParams: function(aCommand, aParams, aRefCon) {},
|
||||
doCommandParams: function(aCommand, aParams, aRefCon) {},
|
||||
|
||||
doCommand: function(aCommand)
|
||||
doCommand: async function(aCommand)
|
||||
{
|
||||
// If the document hasn't been modified,
|
||||
// then just validate the current url.
|
||||
if (IsDocumentModified() || IsHTMLSourceChanged())
|
||||
{
|
||||
if (!CheckAndSaveDocument("cmd_validate", false))
|
||||
if (!(await CheckAndSaveDocument("cmd_validate", false)))
|
||||
return;
|
||||
|
||||
// Check if we saved again just in case?
|
||||
|
|
|
@ -219,7 +219,7 @@ function EditorShutdown()
|
|||
|
||||
// Check for changes to document and allow saving before closing
|
||||
// This is hooked up to the OS's window close widget (e.g., "X" for Windows)
|
||||
function EditorCanClose(aCancelQuit, aTopic, aData)
|
||||
async function EditorCanClose(aCancelQuit, aTopic, aData)
|
||||
{
|
||||
if (aTopic == "quit-application-requested" &&
|
||||
aCancelQuit instanceof Components.interfaces.nsISupportsPRBool &&
|
||||
|
@ -229,7 +229,7 @@ function EditorCanClose(aCancelQuit, aTopic, aData)
|
|||
// Returns FALSE only if user cancels save action
|
||||
|
||||
// "true" means allow "Don't Save" button
|
||||
var canClose = CheckAndSaveDocument("cmd_close", true);
|
||||
var canClose = await CheckAndSaveDocument("cmd_close", true);
|
||||
|
||||
// This is our only hook into closing via the "X" in the caption
|
||||
// or "Quit" (or other paths?)
|
||||
|
|
|
@ -504,7 +504,7 @@ function DocumentHasBeenSaved()
|
|||
return true;
|
||||
}
|
||||
|
||||
function CheckAndSaveDocument(command, allowDontSave)
|
||||
async function CheckAndSaveDocument(command, allowDontSave)
|
||||
{
|
||||
var document;
|
||||
try {
|
||||
|
@ -590,7 +590,7 @@ function CheckAndSaveDocument(command, allowDontSave)
|
|||
}
|
||||
|
||||
// Save to local disk
|
||||
return SaveDocument(false, false, editor.contentsMIMEType);
|
||||
return await SaveDocument(false, false, editor.contentsMIMEType);
|
||||
}
|
||||
|
||||
if (result == 2) // "Don't Save"
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
onload="EditorOnLoad()"
|
||||
onunload="EditorShutdown()"
|
||||
onclose="return EditorCanClose()"
|
||||
onclose="return await EditorCanClose()"
|
||||
onfocus="EditorOnFocus()"
|
||||
title="&editorWindow.titlemodifier;"
|
||||
titlemodifier="&editorWindow.titlemodifier;"
|
||||
|
|
|
@ -165,12 +165,15 @@ function ChooseImageFile()
|
|||
var title = editorBundle.getString("SelectImageFile");
|
||||
fp.init(window, title, nsIFilePicker.modeOpen);
|
||||
fp.appendFilters(nsIFilePicker.filterImages);
|
||||
if (fp.show() == nsIFilePicker.returnOK)
|
||||
fp.open(rv => {
|
||||
if (rv != nsIFilePicker.returnOK || !fp.file) {
|
||||
return;
|
||||
}
|
||||
document.getElementById("editor.default_background_image").value = fp.fileURL.spec;
|
||||
|
||||
var textbox = document.getElementById("backgroundImageInput");
|
||||
textbox.focus();
|
||||
textbox.select();
|
||||
let textbox = document.getElementById("backgroundImageInput");
|
||||
textbox.focus();
|
||||
textbox.select();
|
||||
});
|
||||
}
|
||||
|
||||
function WindowOnUnload()
|
||||
|
|
|
@ -305,20 +305,17 @@ function UseDefaultColors()
|
|||
function chooseFile()
|
||||
{
|
||||
// Get a local image file, converted into URL format
|
||||
var fileName = GetLocalFileURL("img");
|
||||
if (fileName)
|
||||
{
|
||||
GetLocalFileURL("img").then(fileURL => {
|
||||
// Always try to relativize local file URLs
|
||||
if (gHaveDocumentUrl)
|
||||
fileName = MakeRelativeUrl(fileName);
|
||||
fileURL = MakeRelativeUrl(fileURL);
|
||||
|
||||
gDialog.BackgroundImageInput.value = fileName;
|
||||
gDialog.BackgroundImageInput.value = fileURL;
|
||||
|
||||
SetRelativeCheckbox();
|
||||
|
||||
ValidateAndPreviewImage(true);
|
||||
}
|
||||
SetTextboxFocus(gDialog.BackgroundImageInput);
|
||||
SetTextboxFocus(gDialog.BackgroundImageInput);
|
||||
});
|
||||
}
|
||||
|
||||
function ChangeBackgroundImage()
|
||||
|
|
|
@ -387,6 +387,9 @@ function SwitchToValidatePanel()
|
|||
|
||||
const nsIFilePicker = Components.interfaces.nsIFilePicker;
|
||||
|
||||
/**
|
||||
* @return {Promise} URL spec of the file chosen, or null
|
||||
*/
|
||||
function GetLocalFileURL(filterType)
|
||||
{
|
||||
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
|
||||
|
@ -420,21 +423,16 @@ function GetLocalFileURL(filterType)
|
|||
// set the file picker's current directory to last-opened location saved in prefs
|
||||
SetFilePickerDirectory(fp, fileType);
|
||||
|
||||
|
||||
/* doesn't handle *.shtml files */
|
||||
try {
|
||||
var ret = fp.show();
|
||||
if (ret == nsIFilePicker.returnCancel)
|
||||
return null;
|
||||
}
|
||||
catch (ex) {
|
||||
dump("filePicker.chooseInputFile threw an exception\n");
|
||||
return null;
|
||||
}
|
||||
SaveFilePickerDirectory(fp, fileType);
|
||||
|
||||
var fileHandler = GetFileProtocolHandler();
|
||||
return fp.file ? fileHandler.getURLSpecFromFile(fp.file) : null;
|
||||
return new Promise(resolve => {
|
||||
fp.open(rv => {
|
||||
if (rv != nsIFilePicker.returnOK || !fp.file) {
|
||||
resolve(null);
|
||||
return;
|
||||
}
|
||||
SaveFilePickerDirectory(fp, fileType);
|
||||
resolve(fp.fileURL.spec);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function GetMetaElementByAttribute(name, value)
|
||||
|
@ -981,21 +979,16 @@ function createMenuItem(aMenuPopup, aLabel)
|
|||
// Shared by Image and Link dialogs for the "Choose" button for links
|
||||
function chooseLinkFile()
|
||||
{
|
||||
// Get a local file, converted into URL format
|
||||
var fileName = GetLocalFileURL("html, img");
|
||||
if (fileName)
|
||||
{
|
||||
GetLocalFileURL("html, img").then(fileURL => {
|
||||
// Always try to relativize local file URLs
|
||||
if (gHaveDocumentUrl)
|
||||
fileName = MakeRelativeUrl(fileName);
|
||||
fileURL = MakeRelativeUrl(fileURL);
|
||||
|
||||
gDialog.hrefInput.value = fileName;
|
||||
gDialog.hrefInput.value = fileURL;
|
||||
|
||||
// Do stuff specific to a particular dialog
|
||||
// (This is defined separately in Image and Link dialogs)
|
||||
ChangeLinkLocation();
|
||||
}
|
||||
// Put focus into the input field
|
||||
SetTextboxFocus(gDialog.hrefInput);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -216,23 +216,21 @@ function chooseFile()
|
|||
{
|
||||
if (gTimerID)
|
||||
clearTimeout(gTimerID);
|
||||
// Get a local file, converted into URL format
|
||||
var fileName = GetLocalFileURL("img");
|
||||
if (fileName)
|
||||
{
|
||||
// Always try to relativize local file URLs
|
||||
if (gHaveDocumentUrl)
|
||||
fileName = MakeRelativeUrl(fileName);
|
||||
|
||||
gDialog.srcInput.value = fileName;
|
||||
|
||||
SetRelativeCheckbox();
|
||||
doOverallEnabling();
|
||||
}
|
||||
LoadPreviewImage();
|
||||
|
||||
// Put focus into the input field
|
||||
SetTextboxFocus(gDialog.srcInput);
|
||||
|
||||
GetLocalFileURL("img").then(fileURL => {
|
||||
// Always try to relativize local file URLs
|
||||
if (gHaveDocumentUrl)
|
||||
fileURL = MakeRelativeUrl(fileURL);
|
||||
|
||||
gDialog.srcInput.value = fileURL;
|
||||
|
||||
SetRelativeCheckbox();
|
||||
doOverallEnabling();
|
||||
LoadPreviewImage();
|
||||
});
|
||||
}
|
||||
|
||||
function PreviewImageLoaded()
|
||||
|
|
Загрузка…
Ссылка в новой задаче