[Pkg-mozext-commits] [itsalltext] 142/459: * fixed rebuildOptionMenu() to work generically without hardcoded numbers * context menu shows it's all text sub menus
David Prévot
taffit at moszumanska.debian.org
Tue Feb 24 23:26:15 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 25e0886c59cf4e037f5271df49765ba8d4b93fe8
Author: docwhat at gerf.org <docwhat at gerf.org>
Date: Thu Feb 15 09:27:23 2007 -0500
* fixed rebuildOptionMenu() to work generically without hardcoded
numbers
* context menu shows it's all text sub menus
---
chrome/content/cacheobj.js | 4 +--
chrome/content/itsalltext.js | 71 +++++++++++++++++++++++++++-----------
chrome/content/itsalltext.xul | 19 ++++++++--
chrome/locale/en-US/itsalltext.dtd | 7 ++--
4 files changed, 73 insertions(+), 28 deletions(-)
diff --git a/chrome/content/cacheobj.js b/chrome/content/cacheobj.js
index 9ba2418..7b5db7f 100644
--- a/chrome/content/cacheobj.js
+++ b/chrome/content/cacheobj.js
@@ -59,7 +59,7 @@ function CacheObj(node) {
/* Set the default extension and create the nsIFile object. */
var extension = node.getAttribute('itsalltext-extension');
if (typeof(extension) != 'string' || !extension.match(/^[.a-z0-9]+$/i)) {
- extension = '.txt';
+ extension = ItsAllText.getExtensions()[0];
}
that.setExtension(extension);
@@ -388,7 +388,7 @@ CacheObj.prototype.addGumDrop = function() {
gumdrop.style.position = 'absolute';
gumdrop.style.padding = '0';
gumdrop.style.border = 'none';
- gumdrop.style.zIndex = 2147483646; // Max Int - 1
+ gumdrop.style.zIndex = 1; // we want it just above normal items.
gumdrop.style.width = this.gumdrop_width+'px';
gumdrop.style.height = this.gumdrop_height+'px';
diff --git a/chrome/content/itsalltext.js b/chrome/content/itsalltext.js
index 13b7758..f167ee8 100644
--- a/chrome/content/itsalltext.js
+++ b/chrome/content/itsalltext.js
@@ -303,8 +303,13 @@ var ItsAllText = function() {
* @returns Array
*/
that.getExtensions = function() {
- var e = that.preferences.extensions.replace(/[\n\t ]+/g,'');
- return e.split(',');
+ var string = that.preferences.extensions.replace(/[\n\t ]+/g,'');
+ var extensions = string.split(',');
+ if (extensions.length === 0) {
+ return ['.txt'];
+ } else {
+ return extensions;
+ }
};
/**
@@ -526,11 +531,8 @@ var ItsAllText = function() {
*/
that.onEditNode = function(node) {
var cobj = that.getCacheObj(node);
- if(!cobj) {
- that.debug('onEditNode','missing cobj for ',node);
- } else {
- that.debug('onEditNode',cobj);
- cobj.edit('.txt');
+ if(cobj) {
+ cobj.edit();
}
return;
};
@@ -540,12 +542,21 @@ var ItsAllText = function() {
* @param {Object} event The event passed in by the event handler.
*/
that.onContextMenu = function(event) {
- var tag = document.popupNode.nodeName.toLowerCase();
-
- that.debug('onContextMenu', tag);
- document.getElementById("itsalltext-menuitem").
- setAttribute('hidden', (tag != "textarea" &&
- tag != "textbox"));
+ if(event.target && event.target.id) {
+ var id = event.target.id;
+ var node = document.popupNode;
+ var tag = node.nodeName.toLowerCase();
+ if(id == "contentAreaContextMenu") {
+ var menu = document.getElementById("itsalltext-contextmenu");
+ menu.setAttribute('hidden', (tag != "textarea" &&
+ tag != "textbox"));
+ }
+ if(id == "itsalltext-context-popup" &&
+ (tag == 'textarea' || tag == 'textbox') &&
+ node.id) {
+ that.rebuildOptionMenu(node.id, 'itsalltext-context-popup');
+ }
+ }
return true;
};
@@ -623,26 +634,44 @@ ItsAllText.prototype.menuExtEdit = function(event) {
* @private
* @param {String} uid The UID to show in the option menu.
*/
-ItsAllText.prototype.rebuildOptionMenu = function(uid) {
+ItsAllText.prototype.rebuildOptionMenu = function(uid, menu_id) {
+ menu_id = typeof(menu_id) == 'string'?menu_id:'itsalltext-optionmenu';
var i;
var that = this;
var exts = that.getExtensions();
- var menu = document.getElementById('itsalltext-optionmenu');
+ var menu = document.getElementById(menu_id);
var items = menu.childNodes;
- var len = items.length - 2; // ignore the pref and separator
- var sep = items[len];
- var start = 2;
var node;
that._current_uid = uid;
-
- for(i = len-1; i >= start; i--) {
+ var magic_stop_node = null;
+ var magic_start = null;
+ var magic_stop = null;
+
+ // Find the beginning and end of the magic replacement parts.
+ for(i=0; i<items.length; i++) {
+ node = items[i];
+ if (node.nodeName.toLowerCase() == 'menuseparator') {
+ if(magic_start === null) {
+ magic_start = i;
+ } else {
+ magic_stop = i;
+ magic_stop_node = node;
+ break;
+ }
+ }
+ }
+
+ // Remove old magic bits
+ for(i = magic_stop - 1; i > magic_start; i--) {
menu.removeChild(items[i]);
}
+
+ // Insert the new magic bits
for(i=0; i<exts.length; i++) {
node = document.createElementNS(that.XULNS, 'menuitem');
node.setAttribute('label', exts[i]);
node.addEventListener('command', function(event){return that.menuExtEdit(event);}, false);
- menu.insertBefore(node, sep);
+ menu.insertBefore(node, magic_stop_node);
}
return menu;
diff --git a/chrome/content/itsalltext.xul b/chrome/content/itsalltext.xul
index 10ed131..1f2905b 100644
--- a/chrome/content/itsalltext.xul
+++ b/chrome/content/itsalltext.xul
@@ -6,9 +6,22 @@
<!-- The merge point is contentAreaContextMenu -->
<popup id="contentAreaContextMenu">
- <menuitem id="itsalltext-menuitem" label="&top.label;"
- oncommand="ItsAllText.onEditNode(document.popupNode)"
- accesskey="&top.key;" />
+ <menu id="itsalltext-contextmenu" label="&top.label;" accesskey="&top.key;">
+ <menupopup id="itsalltext-context-popup">
+ <menuitem label="&edit.label;"
+ oncommand="ItsAllText.onEditNode(document.popupNode)"
+ accesskey="&edit.key;" />
+ <menuitem label="&newext.label;"
+ accesskey="&newext.key;"
+ oncommand="ItsAllText.menuNewExtEdit(event);" />
+ <menuseparator/>
+ <menuitem label=".txt" oncommand="ItsAllText.menuExtEdit(event);"/>
+ <menuseparator/>
+ <menuitem label="&pref.label;"
+ accesskey="&pref.key;"
+ oncommand="window.openDialog('chrome://itsalltext/chrome/preferences.xul', 'Preferences', 'chrome,titlebar,toolbar,centerscreen,modal');"/>
+ </menupopup>
+ </menu>
</popup>
diff --git a/chrome/locale/en-US/itsalltext.dtd b/chrome/locale/en-US/itsalltext.dtd
index 74fe272..a01906a 100644
--- a/chrome/locale/en-US/itsalltext.dtd
+++ b/chrome/locale/en-US/itsalltext.dtd
@@ -1,9 +1,12 @@
<!ENTITY top.label "It's All Text!">
<!ENTITY top.key "i">
-<!ENTITY newext.label "New edit extension...">
+<!ENTITY edit.label "Edit with default extension">
+<!ENTITY edit.key "e">
+
+<!ENTITY newext.label "Edit with new extension...">
<!ENTITY newext.key "n">
-<!ENTITY pref.label "Preferences">
+<!ENTITY pref.label "Preferences...">
<!ENTITY pref.key "p">
--
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