mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-30 13:45:27 +00:00
7e20285e70
The -*- file variable lines -*- establish per-file settings that Emacs will pick up. This patch makes the following changes to those lines (and touches nothing else): - Never set the buffer's mode. Years ago, Emacs did not have a good JavaScript mode, so it made sense to use Java or C++ mode in .js files. However, Emacs has had js-mode for years now; it's perfectly serviceable, and is available and enabled by default in all major Emacs packagings. Selecting a mode in the -*- file variable line -*- is almost always the wrong thing to do anyway. It overrides Emacs's default choice, which is (now) reasonable; and even worse, it overrides settings the user might have made in their '.emacs' file for that file extension. It's only useful when there's something specific about that particular file that makes a particular mode appropriate. - Correctly propagate settings that establish the correct indentation level for this file: c-basic-offset and js2-basic-offset should be js-indent-level. Whatever value they're given should be preserved; different parts of our tree use different indentation styles. - We don't use tabs in Mozilla JS code. Always set indent-tabs-mode: nil. Remove tab-width: settings, at least in files that don't contain tab characters. - Remove js2-mode settings that belong in the user's .emacs file, like js2-skip-preprocessor-directives.
124 lines
4.5 KiB
JavaScript
124 lines
4.5 KiB
JavaScript
// -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "Downloads",
|
|
"resource://gre/modules/Downloads.jsm");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "Task",
|
|
"resource://gre/modules/Task.jsm");
|
|
|
|
// -----------------------------------------------------------------------
|
|
// HelperApp Launcher Dialog
|
|
//
|
|
// For now on b2g we never prompt and just download to the default
|
|
// location.
|
|
//
|
|
// -----------------------------------------------------------------------
|
|
|
|
function HelperAppLauncherDialog() { }
|
|
|
|
HelperAppLauncherDialog.prototype = {
|
|
classID: Components.ID("{710322af-e6ae-4b0c-b2c9-1474a87b077e}"),
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIHelperAppLauncherDialog]),
|
|
|
|
show: function(aLauncher, aContext, aReason) {
|
|
aLauncher.MIMEInfo.preferredAction = Ci.nsIMIMEInfo.saveToDisk;
|
|
aLauncher.saveToDisk(null, false);
|
|
},
|
|
|
|
promptForSaveToFile: function(aLauncher,
|
|
aContext,
|
|
aDefaultFile,
|
|
aSuggestedFileExt,
|
|
aForcePrompt) {
|
|
throw Cr.NS_ERROR_NOT_AVAILABLE;
|
|
},
|
|
|
|
promptForSaveToFileAsync: function(aLauncher,
|
|
aContext,
|
|
aDefaultFile,
|
|
aSuggestedFileExt,
|
|
aForcePrompt) {
|
|
// Retrieve the user's default download directory.
|
|
Task.spawn(function() {
|
|
let file = null;
|
|
try {
|
|
let defaultFolder = yield Downloads.getPreferredDownloadsDirectory();
|
|
let dir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
|
|
dir.initWithPath(defaultFolder);
|
|
file = this.validateLeafName(dir, aDefaultFile, aSuggestedFileExt);
|
|
} catch(e) { }
|
|
aLauncher.saveDestinationAvailable(file);
|
|
}.bind(this)).then(null, Cu.reportError);
|
|
},
|
|
|
|
validateLeafName: function(aLocalFile, aLeafName, aFileExt) {
|
|
if (!(aLocalFile && this.isUsableDirectory(aLocalFile)))
|
|
return null;
|
|
|
|
// Remove any leading periods, since we don't want to save hidden files
|
|
// automatically.
|
|
aLeafName = aLeafName.replace(/^\.+/, "");
|
|
|
|
if (aLeafName == "")
|
|
aLeafName = "unnamed" + (aFileExt ? "." + aFileExt : "");
|
|
aLocalFile.append(aLeafName);
|
|
|
|
this.makeFileUnique(aLocalFile);
|
|
return aLocalFile;
|
|
},
|
|
|
|
makeFileUnique: function(aLocalFile) {
|
|
try {
|
|
// Note - this code is identical to that in
|
|
// toolkit/content/contentAreaUtils.js.
|
|
// If you are updating this code, update that code too! We can't share code
|
|
// here since this is called in a js component.
|
|
let collisionCount = 0;
|
|
while (aLocalFile.exists()) {
|
|
collisionCount++;
|
|
if (collisionCount == 1) {
|
|
// Append "(2)" before the last dot in (or at the end of) the filename
|
|
// special case .ext.gz etc files so we don't wind up with .tar(2).gz
|
|
if (aLocalFile.leafName.match(/\.[^\.]{1,3}\.(gz|bz2|Z)$/i))
|
|
aLocalFile.leafName = aLocalFile.leafName.replace(/\.[^\.]{1,3}\.(gz|bz2|Z)$/i, "(2)$&");
|
|
else
|
|
aLocalFile.leafName = aLocalFile.leafName.replace(/(\.[^\.]*)?$/, "(2)$&");
|
|
}
|
|
else {
|
|
// replace the last (n) in the filename with (n+1)
|
|
aLocalFile.leafName = aLocalFile.leafName.replace(/^(.*\()\d+\)/, "$1" + (collisionCount+1) + ")");
|
|
}
|
|
}
|
|
aLocalFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0600);
|
|
}
|
|
catch (e) {
|
|
dump("*** exception in makeFileUnique: " + e + "\n");
|
|
|
|
if (e.result == Cr.NS_ERROR_FILE_ACCESS_DENIED)
|
|
throw e;
|
|
|
|
if (aLocalFile.leafName == "" || aLocalFile.isDirectory()) {
|
|
aLocalFile.append("unnamed");
|
|
if (aLocalFile.exists())
|
|
aLocalFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0600);
|
|
}
|
|
}
|
|
},
|
|
|
|
isUsableDirectory: function(aDirectory) {
|
|
return aDirectory.exists() &&
|
|
aDirectory.isDirectory() &&
|
|
aDirectory.isWritable();
|
|
},
|
|
};
|
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([HelperAppLauncherDialog]);
|