[Pkg-mozext-commits] [itsalltext] 122/459: * Finally. Working control-click menus. * Extensions are a preference. * Extensions are selectable.

David Prévot taffit at moszumanska.debian.org
Tue Feb 24 23:26:13 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 a4c68b77fde6d41d1858e520a0d32372725659cc
Author: Christian Höltje <docwhat at gerf.org>
Date:   Sun Feb 11 20:02:38 2007 -0500

    * Finally.  Working control-click menus.
    * Extensions are a preference.
    * Extensions are selectable.
---
 chrome/content/cacheobj.js         |  28 +++++--
 chrome/content/itsalltext.js       | 155 +++++++++++++++++++++++++++++++++----
 chrome/content/itsalltext.xul      |  28 +++++--
 chrome/content/newextension.js     |  10 +++
 chrome/content/newextension.xul    |  22 ++++++
 chrome/content/preferences.xul     |   9 ++-
 defaults/preferences/itsalltext.js |   1 +
 7 files changed, 222 insertions(+), 31 deletions(-)

diff --git a/chrome/content/cacheobj.js b/chrome/content/cacheobj.js
index 0383253..9c661c1 100644
--- a/chrome/content/cacheobj.js
+++ b/chrome/content/cacheobj.js
@@ -216,12 +216,12 @@ CacheObj.prototype.edit = function(extension, retried) {
 /**
  * Delete the file from disk.
  */
-CacheObj.prototype.delete = function() {
+CacheObj.prototype.remove = function() {
     if(this.file.exists()) {
         try {
             this.file.remove();
         } catch(e) {
-            that.debug('delete(',this.file.path,'): ',e);
+            that.debug('remove(',this.file.path,'): ',e);
             return false;
         }
     }
@@ -362,11 +362,29 @@ CacheObj.prototype.addGumDrop = function() {
     
     gumdrop.style.width            = this.gumdrop_width+'px';
     gumdrop.style.height           = this.gumdrop_height+'px';
+
+    gumdrop.setAttribute(ItsAllText.MYSTRING+'_UID', cache_object.uid);
+
+    var clickfun = function(event) {
+        var use_context  = event.ctrlKey || event.altKey;
+        var use_cutpaste = event.shiftKey;
+        if (use_context) {
+            var w = document.getElementById("main-window");
+            ItsAllText.debug('mouse: use_context',event.screenX,event.screenY);
+            var target = ItsAllText.rebuildOptionMenu(cache_object.uid);
+            target.showPopup(w, event.screenX, event.screenY,
+                             "popup", null, null);
+        } else if(use_cutpaste) {
+            ItsAllText.debug('mouse: use_cutpaste');
+        } else {
+            cache_object.edit('.txt');
+        }
+        event.stopPropagation();
+        return false;
+    };
     
     // Click event handler
-    gumdrop.addEventListener("click",
-                             function(ev){ cache_object.edit('.txt'); },
-                             false);
+    gumdrop.addEventListener("click", clickfun, false);
     
     // Insert it into the document
     var parent = node.parentNode;
diff --git a/chrome/content/itsalltext.js b/chrome/content/itsalltext.js
index 4689607..be9cbe8 100644
--- a/chrome/content/itsalltext.js
+++ b/chrome/content/itsalltext.js
@@ -1,6 +1,6 @@
 /*
  *  It's All Text - Easy external editing of web forms.
- *  Copyright (C) 2006 Christian Höltje
+ *  Copyright 2006 Christian Höltje
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -143,7 +143,28 @@ var ItsAllText = function() {
      * Dictionary for storing the preferences in.
      * @type Hash
      */
-    that.preferences = {};
+    that.preferences = {
+        /**
+         * Fetches the current value of the preference.
+         * @private
+         * @param {String} aData The name of the pref to fetch.
+         * @returns {Object} The value of the preference.
+         */
+        _get: function(aData) {
+            var po = that.preference_observer;
+            return po._branch['get'+(po.types[aData])+'Pref'](aData);
+        },
+
+        /**
+         * Sets the current preference.
+         * @param {String} aData The name of the pref to change.
+         * @param {Object} value The value to set.
+         */
+        _set: function(aData, value) {
+            var po = that.preference_observer;
+            return po._branch['set'+(po.types[aData])+'Pref'](aData, value);
+        }
+    };
 
     /**
      * A Preference Observer.
@@ -155,10 +176,11 @@ var ItsAllText = function() {
          * @type Hash
          */
         types: {
-            'charset': 'Char',
-            'editor':  'Char',
-            'refresh': 'Int',
-            'debug':   'Bool'
+            'charset':      'Char',
+            'editor':       'Char',
+            'refresh':      'Int',
+            'debug':        'Bool',
+            'extensions':   'Char'
         },
 
         /**
@@ -170,10 +192,11 @@ var ItsAllText = function() {
                 getService(Components.interfaces.nsIPrefService);
             this._branch = prefService.getBranch("extensions."+that.MYSTRING+".");
             this._branch.QueryInterface(Components.interfaces.nsIPrefBranch2);
+            this._branch.addObserver("", this, false);
+            /* setup the preferences */
             for(var type in this.types) {
-                that.preferences[type] = this._branch['get'+(this.types[type])+'Pref'](type);
+                that.preferences[type] = that.preferences._get(type);
             }
-            this._branch.addObserver("", this, false);
         },
 
         /**
@@ -194,12 +217,12 @@ var ItsAllText = function() {
         observe: function(aSubject, aTopic, aData) {
             if (aTopic != "nsPref:changed") {return;}
             if (that.preferences) {
-                that.preferences[aData] = this._branch['get'+(this.types[aData])+'Pref'](aData);
+                that.preferences[aData] = that.preferences._get(aData);
                 if (aData == 'refresh') {
                     that.monitor.restart();
                 }
             }
-        }
+        }        
     };
 
     /**
@@ -245,6 +268,37 @@ var ItsAllText = function() {
         return that.preferences.debug;
     };
 
+    /**
+     * A Preference Option: The list of extensions
+     * @returns Array
+     */
+    that.getExtensions = function() {
+        var e = that.preferences.extensions.replace(/[\n\t ]+/g,'');
+        return e.split(',');
+    };
+
+    /**
+     * A Preference Option: Append an extension
+     * @returns Array
+     */
+    that.appendExtensions = function(ext) {
+        ext = ext.replace(/[\n\t ]+/g,'');
+        var current = that.getExtensions();
+        for(var i=0; i<current.length; i++) {
+            if(ext == current[i]) {
+                return; // Don't add a duplicate.
+            }
+        }
+        
+        var value = that.preferences.extensions;
+        if(value.replace(/[\t\n ]+/g) === '') {
+            value = ext;
+        } else {
+            value = [value,',',ext].join('');
+        }
+        that.preferences._set('extensions', value);
+    };
+
     // @todo [3] Profiling and optimization.
     
     /**
@@ -455,10 +509,13 @@ var ItsAllText = function() {
      * @param {Object} event The event passed in by the event handler.
      */
     that.onContextMenu = function(event) {
-        that.debug('onContextMenu',document.popupNode.nodeName);
-        document.getElementById("its-all-text-edit").
-            setAttribute('disabled', (document.popupNode.nodeName != "TEXTAREA"));
-        return;
+        var tag = document.popupNode.nodeName.toLowerCase();
+
+        that.debug('onContextMenu', tag);
+        document.getElementById("itsalltext-menuitem").
+            setAttribute('hidden', (tag != "textarea" &&
+                                    tag != "textbox"));
+        return true;
     };
 
     /**
@@ -467,6 +524,9 @@ var ItsAllText = function() {
      */
     var startup = function(event) {
         that.debug("startup(): It's All Text! is watching this window...");
+        // Start watching the preferences.
+        that.preference_observer.register();
+
         var appcontent = document.getElementById("appcontent"); // The Browser
         if (appcontent) {
             // Normal web-page.
@@ -483,9 +543,6 @@ var ItsAllText = function() {
         }
     };
   
-    // Start watching the preferences.
-    that.preference_observer.register();
-
     // Do the startup when things are loaded.
     window.addEventListener("load", startup, true);
     // Do the startup when things are unloaded.
@@ -495,5 +552,69 @@ var ItsAllText = function() {
     that.monitor.restart();
 };
 
+/**
+ * The command that is called when picking a new extension.
+ * @param {Event} event
+ */
+ItsAllText.prototype.menuNewExtEdit = function(event) {
+    // @todo [1] menuNewExtEdit is non-functional
+    var that = this;
+    var uid = this._current_uid;
+    var cobj = that.tracker[uid];
+
+    var params = {out:null};       
+    window.openDialog("chrome://itsalltext/chrome/newextension.xul", "",
+    "chrome, dialog, modal, resizable=yes", params).focus();
+    if (params.out) {
+        var ext = params.out.extension.replace(/[\n\t ]+/g,'');
+        if(params.out.do_save) {
+            that.appendExtensions(ext);
+        }
+        cobj.edit(ext);
+    }
+};
+
+/**
+ * The command that is called when selecting an existing extension.
+ * @param {Event} event
+ */
+ItsAllText.prototype.menuExtEdit = function(event) {
+    var that = this;
+    var uid = this._current_uid;
+    var ext = event.target.getAttribute('label');
+    var cobj = that.tracker[uid];
+    cobj.edit(ext);
+};
+
+/**
+ * Rebuilds the option menu, to reflect the current list of extensions.
+ * @private
+ * @param {String} uid The UID to show in the option menu.
+ */
+ItsAllText.prototype.rebuildOptionMenu = function(uid) {
+    var i;
+    var that = this;
+    var exts = that.getExtensions();
+    var menu = document.getElementById('itsalltext-optionmenu');
+    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--) {
+        menu.removeChild(items[i]);
+    }
+    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);
+
+    }
+    return menu;
+};
+
 ItsAllText = new ItsAllText();
 
diff --git a/chrome/content/itsalltext.xul b/chrome/content/itsalltext.xul
index aa4ae90..e4a79d5 100644
--- a/chrome/content/itsalltext.xul
+++ b/chrome/content/itsalltext.xul
@@ -2,20 +2,32 @@
 
 <overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <script type="application/x-javascript" src="itsalltext.js"/>
+
   <!-- The merge point is contentAreaContextMenu -->
   <popup id="contentAreaContextMenu">
-     <menuitem id="its-all-text-edit" label="It's All Text" 
+     <menuitem id="itsalltext-menuitem" label="It's All Text!" 
                oncommand="itsAllTextOverlay.onEditNode(document.popupNode)"
                accesskey="i" />
   </popup>
 
-  <popupset>
-    <menupopup id="its-all-text-menu">
-      <menuitem label="Cut"/>
-      <menuitem label="Copy"/>
-      <menuitem label="Paste"/>
-    </menupopup>
-  </popupset>
+
+  <!-- The merge point is main-window -->
+  <window id="main-window">
+    <popupset id="itsalltext-optionmenu-set">
+      <popup id="itsalltext-optionmenu">
+        <menuitem label="New edit extension..."
+                  accesskey="n"
+                  oncommand="ItsAllText.menuNewExtEdit(event);" />
+        <menuseparator/>
+        <menuitem label=".txt" oncommand="ItsAllText.menuExtEdit(event);"/>
+        <menuseparator/>
+        <menuitem label="Preferences"
+                  accesskey="p"
+                  oncommand="window.openDialog('chrome://itsalltext/chrome/preferences.xul', 'Preferences', 'chrome,titlebar,toolbar,centerscreen,modal', 'badeditor');"/>
+      </popup>
+    </popupset>
+  </window>
+
 </overlay>
 <!-- Local Variables: -->
 <!-- mode: xml -->
diff --git a/chrome/content/newextension.js b/chrome/content/newextension.js
new file mode 100644
index 0000000..9df2fdf
--- /dev/null
+++ b/chrome/content/newextension.js
@@ -0,0 +1,10 @@
+/**
+ * Pass back the values that that the user selected.
+ */
+function onOK() {
+    window['arguments'][0].out = {
+        extension: document.getElementById('new_ext').value,
+        do_save: document.getElementById('do_save').checked
+    };
+   return true;
+}
diff --git a/chrome/content/newextension.xul b/chrome/content/newextension.xul
new file mode 100644
index 0000000..684f797
--- /dev/null
+++ b/chrome/content/newextension.xul
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
+<dialog
+  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+  id="ItsAllTextNewExtension"
+  title="It's All Text! New Extension"
+  ondialogaccept="return onOK();"
+  persist="screenX screenY width height"
+  windowtype="ItsAllTextWindowType">
+
+  <script type="application/x-javascript" src="chrome://itsalltext/content/newextension.js"/>
+  <grid>
+    <columns><column/><column/></columns>
+    <rows>
+      <row align="center"><label value="Extension (with leading dot):"/><textbox id="new_ext" value=".txt"/></row>
+      <row align="center"><spacer/><checkbox id="do_save" label="Save for future use"/></row>
+    </rows>
+  </grid>
+</dialog>
+<!-- Local Variables: -->
+<!-- mode: xml -->
+<!-- End: -->
diff --git a/chrome/content/preferences.xul b/chrome/content/preferences.xul
index 5eccc95..efc6936 100644
--- a/chrome/content/preferences.xul
+++ b/chrome/content/preferences.xul
@@ -16,6 +16,8 @@
                 name="extensions.itsalltext.editor" type="string"/>
     <preference id="pref_seconds"
                 name="extensions.itsalltext.refresh" type="int"/>
+    <preference id="pref_extensions"
+                name="extensions.itsalltext.extensions" type="string"/>
     <preference id="pref_debug"
                 name="extensions.itsalltext.debug" type="bool"/>
   </preferences>
@@ -40,9 +42,14 @@
         <textbox preference="pref_charset" id="charset" size="8" tabindex="3"/>
       </hbox>
       <hbox align="right">
+        <label control="charset"
+               value="File Extensions: "/>
+        <textbox preference="pref_extensions" id="extensions" size="30" tabindex="4"/>
+      </hbox>
+      <hbox align="right">
         <label control="debug"
                value="Enable Debugging: "/>
-        <checkbox preference="pref_debug" id="debug" tabindex="4"/>
+        <checkbox preference="pref_debug" id="debug" tabindex="5"/>
       </hbox>
       <spacer flex="2"/>
     </vbox>
diff --git a/defaults/preferences/itsalltext.js b/defaults/preferences/itsalltext.js
index e0fe9ea..e945242 100644
--- a/defaults/preferences/itsalltext.js
+++ b/defaults/preferences/itsalltext.js
@@ -2,3 +2,4 @@ pref("extensions.itsalltext.charset",  "UTF-8");
 pref("extensions.itsalltext.editor",   "/usr/bin/gedit");
 pref("extensions.itsalltext.refresh",  7);
 pref("extensions.itsalltext.debug",  false);
+pref("extensions.itsalltext.extensions",  '.txt,.html,.css,.xml,.xsl,.js');

-- 
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