зеркало из https://github.com/mozilla/gecko-dev.git
Save default file dirs for HTML and Images, b=93487, r=syd, sr=hewitt
This commit is contained in:
Родитель
9fc64d2378
Коммит
0336a6e359
|
@ -301,6 +301,8 @@ var nsOpenCommand =
|
||||||
fp.appendFilters(nsIFilePicker.filterText);
|
fp.appendFilters(nsIFilePicker.filterText);
|
||||||
fp.appendFilters(nsIFilePicker.filterAll);
|
fp.appendFilters(nsIFilePicker.filterAll);
|
||||||
|
|
||||||
|
SetFilePickerDirectory(fp, "html");
|
||||||
|
|
||||||
/* doesn't handle *.shtml files */
|
/* doesn't handle *.shtml files */
|
||||||
try {
|
try {
|
||||||
fp.show();
|
fp.show();
|
||||||
|
@ -312,9 +314,10 @@ var nsOpenCommand =
|
||||||
|
|
||||||
/* This checks for already open window and activates it...
|
/* This checks for already open window and activates it...
|
||||||
* note that we have to test the native path length
|
* note that we have to test the native path length
|
||||||
* since fileURL.spec will be "file:///" if no filename picked (Cancel button used)
|
* since file.URL will be "file:///" if no filename picked (Cancel button used)
|
||||||
*/
|
*/
|
||||||
if (fp.file && fp.file.path.length > 0) {
|
if (fp.file && fp.file.path.length > 0) {
|
||||||
|
SaveFilePickerDirectory(fp, "html");
|
||||||
EditorOpenUrl(fp.fileURL.spec);
|
EditorOpenUrl(fp.fileURL.spec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -441,8 +444,19 @@ function PromptForSaveLocation(aDoSaveAsText, aEditorType, aMIMEType, ahtmlDocum
|
||||||
fileLocation.URL = aDocumentURLString;
|
fileLocation.URL = aDocumentURLString;
|
||||||
var parentLocation = fileLocation.parent;
|
var parentLocation = fileLocation.parent;
|
||||||
if (parentLocation)
|
if (parentLocation)
|
||||||
|
{
|
||||||
|
// Save current filepicker's default location
|
||||||
|
if ("gFilePickerDirectory" in window)
|
||||||
|
gFilePickerDirectory = fp.displayDirectory;
|
||||||
|
|
||||||
fp.displayDirectory = parentLocation;
|
fp.displayDirectory = parentLocation;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Initialize to the last-used directory for the particular type (saved in prefs)
|
||||||
|
SetFilePickerDirectory(fp, aEditorType);
|
||||||
|
}
|
||||||
|
}
|
||||||
catch(e) {}
|
catch(e) {}
|
||||||
|
|
||||||
dialogResult.filepickerClick = fp.show();
|
dialogResult.filepickerClick = fp.show();
|
||||||
|
@ -451,7 +465,10 @@ function PromptForSaveLocation(aDoSaveAsText, aEditorType, aMIMEType, ahtmlDocum
|
||||||
// reset urlstring to new save location
|
// reset urlstring to new save location
|
||||||
dialogResult.resultingURIString = fp.file.URL;
|
dialogResult.resultingURIString = fp.file.URL;
|
||||||
dialogResult.resultingLocalFile = fp.file;
|
dialogResult.resultingLocalFile = fp.file;
|
||||||
|
SaveFilePickerDirectory(fp, aEditorType);
|
||||||
}
|
}
|
||||||
|
else if ("gFilePickerDirectory" in window && gFilePickerDirectory)
|
||||||
|
fp.displayDirectory = gFilePickerDirectory;
|
||||||
|
|
||||||
return dialogResult;
|
return dialogResult;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1424,8 +1424,8 @@ function BuildRecentMenu(savePrefs)
|
||||||
}
|
}
|
||||||
for (i = 0; i < historyCount; i++)
|
for (i = 0; i < historyCount; i++)
|
||||||
{
|
{
|
||||||
var title = getUnicharPref("editor.history_title_"+i);
|
var title = GetUnicharPref("editor.history_title_"+i);
|
||||||
var url = getUnicharPref("editor.history_url_"+i);
|
var url = GetUnicharPref("editor.history_url_"+i);
|
||||||
|
|
||||||
// Continue if URL pref is missing because
|
// Continue if URL pref is missing because
|
||||||
// a URL not found during loading may have been removed
|
// a URL not found during loading may have been removed
|
||||||
|
@ -1458,8 +1458,8 @@ function BuildRecentMenu(savePrefs)
|
||||||
{
|
{
|
||||||
if (!urlArray[i])
|
if (!urlArray[i])
|
||||||
break;
|
break;
|
||||||
setUnicharPref("editor.history_title_"+i, titleArray[i]);
|
SetUnicharPref("editor.history_title_"+i, titleArray[i]);
|
||||||
setUnicharPref("editor.history_url_"+i, urlArray[i]);
|
SetUnicharPref("editor.history_url_"+i, urlArray[i]);
|
||||||
savePrefs = true;
|
savePrefs = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1511,34 +1511,6 @@ function AppendRecentMenuitem(menupopup, title, url, menuIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setUnicharPref(aPrefName, aPrefValue)
|
|
||||||
{
|
|
||||||
if (!gPrefs) return;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var str = Components.classes["@mozilla.org/supports-wstring;1"]
|
|
||||||
.createInstance(Components.interfaces.nsISupportsWString);
|
|
||||||
str.data = aPrefValue;
|
|
||||||
gPrefs.setComplexValue(aPrefName, Components.interfaces.nsISupportsWString, str);
|
|
||||||
}
|
|
||||||
catch(e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getUnicharPref(aPrefName, aDefVal)
|
|
||||||
{
|
|
||||||
if (!gPrefs) return "";
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return gPrefs.getComplexValue(aPrefName, Components.interfaces.nsISupportsWString).data;
|
|
||||||
}
|
|
||||||
catch(e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
function EditorInitFormatMenu()
|
function EditorInitFormatMenu()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -51,6 +51,7 @@ const gOutputEncodeEntities = 256;
|
||||||
var gStringBundle;
|
var gStringBundle;
|
||||||
var gIOService;
|
var gIOService;
|
||||||
var gPrefsService;
|
var gPrefsService;
|
||||||
|
var gFilePickerDirectory;
|
||||||
|
|
||||||
var gOS = "";
|
var gOS = "";
|
||||||
const gWin = "Win";
|
const gWin = "Win";
|
||||||
|
@ -101,7 +102,9 @@ function GetString(name)
|
||||||
{
|
{
|
||||||
if (editorShell)
|
if (editorShell)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
return editorShell.GetString(name);
|
return editorShell.GetString(name);
|
||||||
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -112,7 +115,9 @@ function GetString(name)
|
||||||
if (!gStringBundle)
|
if (!gStringBundle)
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
return gStringBundle.GetStringFromName(name);
|
return gStringBundle.GetStringFromName(name);
|
||||||
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -273,6 +278,73 @@ function GetPrefs()
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function SetUnicharPref(aPrefName, aPrefValue)
|
||||||
|
{
|
||||||
|
var prefs = GetPrefs();
|
||||||
|
if (prefs)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var str = Components.classes["@mozilla.org/supports-wstring;1"]
|
||||||
|
.createInstance(Components.interfaces.nsISupportsWString);
|
||||||
|
str.data = aPrefValue;
|
||||||
|
prefs.setComplexValue(aPrefName, Components.interfaces.nsISupportsWString, str);
|
||||||
|
}
|
||||||
|
catch(e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function GetUnicharPref(aPrefName, aDefVal)
|
||||||
|
{
|
||||||
|
var prefs = GetPrefs();
|
||||||
|
if (prefs)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return prefs.getComplexValue(aPrefName, Components.interfaces.nsISupportsWString).data;
|
||||||
|
}
|
||||||
|
catch(e) {}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set initial directory for a filepicker from URLs saved in prefs
|
||||||
|
function SetFilePickerDirectory(filePicker, fileType)
|
||||||
|
{
|
||||||
|
if (filePicker)
|
||||||
|
{
|
||||||
|
var location = GetUnicharPref("editor.lastFileLocation."+fileType);
|
||||||
|
if (location)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
var lastLocation = Components.classes["@mozilla.org/file/local;1"].createInstance().QueryInterface(Components.interfaces.nsIFile);
|
||||||
|
lastLocation.URL = location;
|
||||||
|
// Save current directory so we can reset it in SaveFilePickerDirectory
|
||||||
|
gFilePickerDirectory = filePicker.displayDirectory;
|
||||||
|
|
||||||
|
filePicker.displayDirectory = lastLocation;
|
||||||
|
}
|
||||||
|
catch(e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the directory of the selected file to prefs
|
||||||
|
function SaveFilePickerDirectory(filePicker, fileType)
|
||||||
|
{
|
||||||
|
if (filePicker && filePicker.file && filePicker.file.parent)
|
||||||
|
{
|
||||||
|
SetUnicharPref("editor.lastFileLocation."+fileType, filePicker.file.parent.URL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore the directory used before SetFilePickerDirectory was called;
|
||||||
|
// This reduces interference with Browser and other module directory defaults
|
||||||
|
if (gFilePickerDirectory)
|
||||||
|
filePicker.displayDirectory = gFilePickerDirectory;
|
||||||
|
|
||||||
|
gFilePickerDirectory = "";
|
||||||
|
}
|
||||||
|
|
||||||
function GetDefaultBrowserColors()
|
function GetDefaultBrowserColors()
|
||||||
{
|
{
|
||||||
var prefs = GetPrefs();
|
var prefs = GetPrefs();
|
||||||
|
@ -586,3 +658,4 @@ function GetOS()
|
||||||
|
|
||||||
return gOS;
|
return gOS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -664,11 +664,13 @@ const nsIFilePicker = Components.interfaces.nsIFilePicker;
|
||||||
function GetLocalFileURL(filterType)
|
function GetLocalFileURL(filterType)
|
||||||
{
|
{
|
||||||
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
|
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
|
||||||
|
var fileType = "html";
|
||||||
|
|
||||||
if (filterType == "img")
|
if (filterType == "img")
|
||||||
{
|
{
|
||||||
fp.init(window, GetString("SelectImageFile"), nsIFilePicker.modeOpen);
|
fp.init(window, GetString("SelectImageFile"), nsIFilePicker.modeOpen);
|
||||||
fp.appendFilters(nsIFilePicker.filterImages);
|
fp.appendFilters(nsIFilePicker.filterImages);
|
||||||
|
fileType = "image";
|
||||||
}
|
}
|
||||||
// Current usage of this is in Link dialog,
|
// Current usage of this is in Link dialog,
|
||||||
// where we always want HTML first
|
// where we always want HTML first
|
||||||
|
@ -689,6 +691,10 @@ function GetLocalFileURL(filterType)
|
||||||
// Default or last filter is "All Files"
|
// Default or last filter is "All Files"
|
||||||
fp.appendFilters(nsIFilePicker.filterAll);
|
fp.appendFilters(nsIFilePicker.filterAll);
|
||||||
|
|
||||||
|
// set the file picker's current directory to last-opened location saved in prefs
|
||||||
|
SetFilePickerDirectory(fp, fileType);
|
||||||
|
|
||||||
|
|
||||||
/* doesn't handle *.shtml files */
|
/* doesn't handle *.shtml files */
|
||||||
try {
|
try {
|
||||||
var ret = fp.show();
|
var ret = fp.show();
|
||||||
|
@ -699,8 +705,10 @@ function GetLocalFileURL(filterType)
|
||||||
dump("filePicker.chooseInputFile threw an exception\n");
|
dump("filePicker.chooseInputFile threw an exception\n");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
SaveFilePickerDirectory(fp, fileType);
|
||||||
|
|
||||||
return fp.fileURL.spec;
|
// Note: fp.file.URL = fp.fileURL.spec
|
||||||
|
return fp.file ? fp.file.URL : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetMetaElement(name)
|
function GetMetaElement(name)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче