[Phoenix-commits] rev 20510 - public/yulup/src/trunk/yulup/prototypes/prototype1/src/chrome/content

andi at wyona.com andi at wyona.com
Fri Dec 1 17:57:17 CET 2006


Author: andi
Date: 2006-12-01 17:57:16 +0100 (Fri, 01 Dec 2006)
New Revision: 20510

Modified:
   public/yulup/src/trunk/yulup/prototypes/prototype1/src/chrome/content/editor.xul
   public/yulup/src/trunk/yulup/prototypes/prototype1/src/chrome/content/view.js
Log:
Implemented a command key bindings listener for commands like save, save-temporary, etc.


Modified: public/yulup/src/trunk/yulup/prototypes/prototype1/src/chrome/content/editor.xul
===================================================================
--- public/yulup/src/trunk/yulup/prototypes/prototype1/src/chrome/content/editor.xul	2006-12-01 16:46:23 UTC (rev 20509)
+++ public/yulup/src/trunk/yulup/prototypes/prototype1/src/chrome/content/editor.xul	2006-12-01 16:57:16 UTC (rev 20510)
@@ -126,6 +126,13 @@
     <broadcaster id="broadcaster_yulup_neutronfromcheckout" disabled="true"/>
   </broadcasterset>
 
+  <!-- Note that you have to handle these keys as well in the CommandKeyBindingsListener,
+       otherwise they won't work if the focus is inside the editor element. -->
+  <keyset>
+    <key id="key_yulup_savetmp" modifiers="accel shift" key="T" oncommand="Editor.saveDispatcher('savetemp')"/>
+    <key id="key_yulup_save"    modifiers="accel shift" key="S" oncommand="Editor.saveDispatcher('savecms')"/>
+  </keyset>
+
   <popupset>
     <popup id="uiYulupEditorToolboxContextMenu"
            onpopupshowing="Editor.updateToolboxContextMenu()">
@@ -175,10 +182,12 @@
             <menuitem id="uiFileOperationSaveTempMenuitem"
                       oncommand="Editor.saveDispatcher('savetemp')"
                       label="&fileOperationSaveTempMenuitem.label;" tooltiptext="&fileOperationSaveTempMenuitem.tooltip;"
+                      key="key_yulup_savetmp"
                       disabled="true"/>
             <menuitem id="uiFileOperationSaveCMSMenuitem"
                       oncommand="Editor.saveDispatcher('savecms')"
                       label="&fileOperationSaveCMSMenuitem.label;" tooltiptext="&fileOperationSaveCMSMenuitem.tooltip;"
+                      key="key_yulup_save"
                       disabled="true"
                       hidden="true"/>
             <menuitem id="uiFileOperationCheckinCMSAndExitMenuitem"

Modified: public/yulup/src/trunk/yulup/prototypes/prototype1/src/chrome/content/view.js
===================================================================
--- public/yulup/src/trunk/yulup/prototypes/prototype1/src/chrome/content/view.js	2006-12-01 16:46:23 UTC (rev 20509)
+++ public/yulup/src/trunk/yulup/prototypes/prototype1/src/chrome/content/view.js	2006-12-01 16:57:16 UTC (rev 20510)
@@ -702,6 +702,8 @@
                 }
             }
 
+            sourceEditor.contentWindow.addEventListener("keypress", new CommandKeyListener(), true);
+
             sourceEditor.contentWindow.addEventListener("keypress", new TextEditorKeyListener(this.view, useTabSpaces, noOfTabSpaces), true);
             sourceEditor.contentWindow.addEventListener("keypress", new GuidedTagInserterKeyListener(this), true);
 
@@ -919,6 +921,8 @@
              * http://lxr.mozilla.org/mozilla1.8.0/source/editor/libeditor/html/nsHTMLEditor.cpp#1209). */
             this.view.updateBaseURL();
 
+            wysiwygEditor.contentWindow.addEventListener("keypress", new CommandKeyListener(), true);
+
             if ((keyBinding = YulupPreferences.getCharPref("editor.", "keybinding")) != null) {
                 switch (keyBinding) {
                     case "readline":
@@ -1206,6 +1210,8 @@
              * http://lxr.mozilla.org/mozilla1.8.0/source/editor/libeditor/html/nsHTMLEditor.cpp#1209). */
             this.view.updateBaseURL();
 
+            wysiwygXSLTEditor.contentWindow.addEventListener("keypress", new CommandKeyListener(), true);
+
             wysiwygXSLTEditor.contentWindow.addEventListener("keyup", new WYSIWYGXSLTKeyListener(this), true);
 
             if ((keyBinding = YulupPreferences.getCharPref("editor.", "keybinding")) != null) {
@@ -2832,6 +2838,61 @@
 };
 
 
+function CommandKeyListener() {
+    /* DEBUG */ dump("Yulup:view.js:CommandKeyListener() invoked\n");
+
+    /* Detect platform to set accel key correctly. This is a
+     * workaround until https://bugzilla.mozilla.org/show_bug.cgi?id=180840
+     * gets fixed. */
+    if ((new RegExp("Mac")).test(navigator.platform)) {
+        this.__accelCmd = true;
+    } else {
+        this.__accelCmd = false;
+    }
+}
+
+CommandKeyListener.prototype = {
+    __accelCmd  : null,
+
+    handleEvent: function (aKeyEvent) {
+        var controller = null;
+
+        /* DEBUG */ dump("Yulup:view.js:CommandKeyListener.handleEvent() invoked\n");
+
+        if ((this.__accelCmd  && aKeyEvent.metaKey) ||
+            (!this.__accelCmd && aKeyEvent.ctrlKey)) {
+            /* DEBUG */ dump("Yulup:view.js:CommandKeyListener.handleEvent: char code = " + String.fromCharCode(aKeyEvent.charCode) + "\n");
+
+            switch (String.fromCharCode(aKeyEvent.charCode)) {
+                case "s":
+                case "S":
+                    if (aKeyEvent.shiftKey) {
+                        Editor.saveDispatcher("savecms");
+
+                        // we consumed this event
+                        aKeyEvent.preventDefault();
+                        return true;
+                    }
+
+                    break;
+                case "t":
+                case "T":
+                    if (aKeyEvent.shiftKey) {
+                        Editor.saveDispatcher("savetemp");
+
+                        // we consumed this event
+                        aKeyEvent.preventDefault();
+                        return true;
+                    }
+
+                    break;
+                default:
+            }
+        }
+    }
+};
+
+
 function ReadlineKeyBindingsListener(aEditorElem) {
     /* DEBUG */ dump("Yulup:view.js:ReadlineKeyBindingsListener() invoked\n");
 




More information about the Phoenix-commits mailing list