[Pkg-mozext-commits] [itsalltext] 187/459: * fixed badeditor catching. It's much better now. * default Mac OS X using /usr/bin/open out of the box.
David Prévot
taffit at moszumanska.debian.org
Tue Feb 24 23:26:20 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository itsalltext.
commit c0b1f8328c45aca59663191634694a32be318c70
Author: docwhat at gerf.org <docwhat at gerf.org>
Date: Wed Apr 4 14:49:57 2007 -0400
* fixed badeditor catching. It's much better now.
* default Mac OS X using /usr/bin/open out of the box.
---
chrome/content/badeditor.js | 16 +++++++-----
chrome/content/cacheobj.js | 14 +++++++----
chrome/content/itsalltext.js | 39 +++++++++++++++++++++++++-----
chrome/locale/en-US/badeditor.properties | 7 +++---
chrome/locale/en-US/preferences.properties | 2 +-
defaults/preferences/itsalltext.js | 2 +-
6 files changed, 58 insertions(+), 22 deletions(-)
diff --git a/chrome/content/badeditor.js b/chrome/content/badeditor.js
index 32eb415..00e4e15 100644
--- a/chrome/content/badeditor.js
+++ b/chrome/content/badeditor.js
@@ -10,12 +10,16 @@ function onOK() {
function doOnload() {
var locale = document.getElementById("strings");
var params = window['arguments'][0];
- var r=document.getElementById('reason');
- if(params.exists) {
- var textnode = document.createTextNode(locale.getFormattedString('eexecute'));
+ var reason = document.getElementById('reason');
+ var textnode = '**error**';
+ if(params.path === null) {
+ textnode = locale.getFormattedString('bad.noset',[]);
} else {
- var textnode = document.createTextNode(locale.getFormattedString('enoent', [params.path]));
-
- r.appendChild(textnode);
+ if(params.exists) {
+ textnode = locale.getFormattedString('bad.noexec', []);
+ } else {
+ textnode = locale.getFormattedString('bad.noent', [params.path]);
+ }
}
+ reason.appendChild(document.createTextNode(textnode));
}
diff --git a/chrome/content/cacheobj.js b/chrome/content/cacheobj.js
index 828a436..9cc6e13 100644
--- a/chrome/content/cacheobj.js
+++ b/chrome/content/cacheobj.js
@@ -100,8 +100,7 @@ CacheObj.prototype.setExtension = function(ext) {
}
/* Create the nsIFile object */
- var file = Components.classes["@mozilla.org/file/local;1"].
- createInstance(Components.interfaces.nsILocalFile);
+ var file = ItsAllText.factoryFile();
file.initWithFile(ItsAllText.getEditDir());
file.append([this.base_filename,ext].join(''));
@@ -237,6 +236,11 @@ CacheObj.prototype.edit = function(extension) {
var program = ItsAllText.getEditor();
try {
+ // checks
+ if (program === null) { throw "Editor is not set."; }
+ if (!program.exists()) { throw "Editor does not exists."; }
+ if (!program.isExecutable()) { throw "Editor is not executable."; }
+
// create an nsIProcess
var process = Components.
classes["@mozilla.org/process/util;1"].
@@ -254,13 +258,13 @@ CacheObj.prototype.edit = function(extension) {
this._is_watching = true;
} catch(e) {
var params = {out:null,
- exists: program.exists(),
- path: program.path};
+ exists: program ? program.exists() : false,
+ path: program ? program.path : null };
window.openDialog('chrome://itsalltext/chrome/badeditor.xul',
null,
"chrome,titlebar,toolbar,centerscreen,modal",
params);
- if(params.out.do_preferences) {
+ if(params.out !== null && params.out.do_preferences) {
ItsAllText.openPreferences(true);
this.edit(extension);
}
diff --git a/chrome/content/itsalltext.js b/chrome/content/itsalltext.js
index 7823044..1eacfa6 100644
--- a/chrome/content/itsalltext.js
+++ b/chrome/content/itsalltext.js
@@ -143,6 +143,21 @@ var ItsAllText = function() {
};
/**
+ * A factory method to make an nsILocalFile object.
+ * @param {String} path A path to initialize the object with (optional).
+ * @returns {nsILocalFile}
+ */
+ that.factoryFile = function(path) {
+ var file = Components.
+ classes["@mozilla.org/file/local;1"].
+ createInstance(Components.interfaces.nsILocalFile);
+ if (typeof(path) == 'string' && path !== '') {
+ file.initWithPath(path);
+ }
+ return file;
+ }
+
+ /**
* Returns the directory where we put files to edit.
* @returns nsILocalFile The location where we should write editable files.
*/
@@ -310,13 +325,25 @@ var ItsAllText = function() {
that.getEditor = function() {
var editor = that.preferences.editor;
- // create an nsILocalFile for the executable
- var file = Components.
- classes["@mozilla.org/file/local;1"].
- createInstance(Components.interfaces.nsILocalFile);
+ if (editor === '') {
+ var checks = ['/System','/Applications','/Library', '/Network', '/Volumes'];
+ var is_mac = true;
+ var dir;
+ for(var i=0; i<checks.length; i++) {
+ dir = that.factoryFile(checks[i]);
+ is_mac = is_mac && dir.exists() && dir.isDirectory();
+ }
+ if (is_mac) {
+ editor = '/usr/bin/open';
+ that.preferences._set('editor', editor);
+ }
+ }
- file.initWithPath(editor);
- return file;
+ if (editor === '') {
+ return null;
+ } else {
+ return that.factoryFile(editor);
+ }
};
/**
diff --git a/chrome/locale/en-US/badeditor.properties b/chrome/locale/en-US/badeditor.properties
index 5551f4b..d0196c4 100644
--- a/chrome/locale/en-US/badeditor.properties
+++ b/chrome/locale/en-US/badeditor.properties
@@ -1,3 +1,4 @@
-enoent=The path '%1$S' does not exist.
-eexitcode=Your editor exited with an error or failed to run.
-eexecute=Unable to execute your editor.
+bad.noent=The path '%1$S' does not exist.
+bad.noexec=Unable to execute your editor.
+bad.noset=Your editor has not been set.
+
diff --git a/chrome/locale/en-US/preferences.properties b/chrome/locale/en-US/preferences.properties
index 1bd75b3..1d76bc8 100644
--- a/chrome/locale/en-US/preferences.properties
+++ b/chrome/locale/en-US/preferences.properties
@@ -1,3 +1,3 @@
picker.window.title=Choose your editor
problem.editor=I was unable to run your editor, '%1$S'. Use the browse button to choose another editor and try again.
-mac.hint=If you use Mac OS X, then you'll need to use the binary installed by your editor in /usr/bin OR you can try to find the binary in the NAME.app/Contents/MacOS/ directory.
+mac.hint=If you use Mac OS X then you probably want to use '/usr/bin/open' -- it will open the file using the default application for that file.
diff --git a/defaults/preferences/itsalltext.js b/defaults/preferences/itsalltext.js
index a385078..0a77d26 100644
--- a/defaults/preferences/itsalltext.js
+++ b/defaults/preferences/itsalltext.js
@@ -1,5 +1,5 @@
pref("extensions.itsalltext.charset", "UTF-8");
-pref("extensions.itsalltext.editor", "Please Choose An Editor");
+pref("extensions.itsalltext.editor", "");
pref("extensions.itsalltext.refresh", 7);
pref("extensions.itsalltext.debug", false);
pref("extensions.itsalltext.disable_gumdrops", false);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/itsalltext.git
More information about the Pkg-mozext-commits
mailing list