-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Scratchpad the default user script editor.
- Loading branch information
Showing
5 changed files
with
70 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
Components.utils.import('resource://greasemonkey/prefmanager.js'); | ||
Components.utils.import('resource://greasemonkey/util.js'); | ||
|
||
var EXPORTED_SYMBOLS = ['setEditor']; | ||
|
||
var stringBundle = Components | ||
.classes["@mozilla.org/intl/stringbundle;1"] | ||
.getService(Components.interfaces.nsIStringBundleService) | ||
.createBundle("chrome://greasemonkey/locale/gm-browser.properties"); | ||
var EDITOR_PROMPT = stringBundle.GetStringFromName("editor.prompt"); | ||
var PICK_EXE = stringBundle.GetStringFromName("editor.please_pick_executable"); | ||
|
||
function setEditor(aScratchpad) { | ||
if (aScratchpad) { | ||
GM_prefRoot.remove("editor"); | ||
return; | ||
} | ||
|
||
// Ask the user to choose a new editor. Sometimes users get confused and | ||
// pick a non-executable file, so we set this up in a loop so that if they do | ||
// that we can give them an error and try again. | ||
while (true) { | ||
var nsIFilePicker = Components.interfaces.nsIFilePicker; | ||
var filePicker = Components.classes["@mozilla.org/filepicker;1"] | ||
.createInstance(nsIFilePicker); | ||
|
||
filePicker.init( | ||
GM_util.getBrowserWindow(), EDITOR_PROMPT, nsIFilePicker.modeOpen); | ||
filePicker.appendFilters(nsIFilePicker.filterApps); | ||
|
||
var editor = GM_util.getEditor(); | ||
if (editor) { | ||
filePicker.defaultString = editor.leafName; | ||
filePicker.displayDirectory = editor.parent; | ||
} | ||
|
||
if (filePicker.show() != nsIFilePicker.returnOK) { | ||
// The user canceled, return null. | ||
return; | ||
} | ||
|
||
if (filePicker.file.exists() && filePicker.file.isExecutable()) { | ||
GM_prefRoot.setValue("editor", filePicker.file.path); | ||
return; | ||
} else { | ||
GM_util.alert(PICK_EXE); | ||
} | ||
} | ||
} |