[Pkg-mozext-commits] [requestpolicy] 23/257: [ref] xul-trees: reorganize tree structure

David Prévot taffit at moszumanska.debian.org
Thu Jan 28 03:19:52 UTC 2016


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository requestpolicy.

commit 1720b57abeab04e49814fd1f4dfb905ceb9c2341
Author: Martin Kimmerle <dev at 256k.de>
Date:   Sat Aug 8 22:24:48 2015 +0200

    [ref] xul-trees: reorganize tree structure
    
    * Create an object for the attributes.
    * Change the Coding Style of the tree.
---
 src/content/lib/utils/xul.jsm                    |  46 ++-
 src/content/main/window-manager-toolbarbutton.js |  17 +-
 src/content/ui/xul-trees.js                      | 451 ++++++++++++++++-------
 3 files changed, 349 insertions(+), 165 deletions(-)

diff --git a/src/content/lib/utils/xul.jsm b/src/content/lib/utils/xul.jsm
index 8faf6a7..aabc853 100644
--- a/src/content/lib/utils/xul.jsm
+++ b/src/content/lib/utils/xul.jsm
@@ -80,32 +80,38 @@ function getParentElement(aDocument, aElementSpec) {
   }
 }
 
-function isAttribute(aElementSpec, aAttributeName) {
-  return aAttributeName !== "children" && aAttributeName !== "parent" &&
-      aAttributeName !== "tag" && aElementSpec.hasOwnProperty(aAttributeName);
-}
+/**
+ * Get the localized value of an attribute.
+ */
+function getLocalizedValue(aRawValue) {
+  if (typeof aRawValue !== "string") {
+    return aRawValue;
+  }
 
-function getAttrValue(aElementSpec, aAttrName) {
-  if (!isAttribute(aElementSpec, aAttrName)) {
-    return false;
+  if (aRawValue.charAt(0) !== "&" ||
+      aRawValue.slice(-1) !== ";") {
+    return aRawValue;
   }
-  let value = aElementSpec[aAttrName];
-  if (value.charAt(0) == "&" && value.charAt(value.length-1) == ";") {
-    try {
-      value = StringUtils.$str(value.substr(1, value.length-2));
-    } catch (e) {
-      Logger.severe(Logger.TYPE_ERROR, e, e);
-      return false;
-    }
+
+  try {
+    let name = aRawValue.slice(1, -1);
+    return StringUtils.$str(name);
+  } catch (e) {
+    Logger.severe(Logger.TYPE_INTERNAL, "It was not possible to get the " +
+                  "localized value for '" + aRawValue + "'. " +
+                  "The error was: " + e, e);
+    return aRawValue;
   }
-  return value;
 }
 
 function setAttributes(aElement, aElementSpec) {
-  for (let attr in aElementSpec) {
-    let value = getAttrValue(aElementSpec, attr);
+  if (!aElementSpec.hasOwnProperty("attributes")) {
+    return;
+  }
+  for (let attributeName in aElementSpec.attributes) {
+    let value = getLocalizedValue(aElementSpec.attributes[attributeName]);
     if (value) {
-      aElement.setAttribute(attr, value);
+      aElement.setAttribute(attributeName, value);
     }
   }
 }
@@ -152,7 +158,7 @@ function getElementIDsToRemove(aTreeName) {
   let ids = elementIDsToRemove[aTreeName] = [];
   let tree = xulTrees[aTreeName];
   for (let i in tree) {
-    ids.push(tree[i].id);
+    ids.push(tree[i].attributes.id);
   }
   return ids;
 }
diff --git a/src/content/main/window-manager-toolbarbutton.js b/src/content/main/window-manager-toolbarbutton.js
index 9b0c664..2842be2 100644
--- a/src/content/main/window-manager-toolbarbutton.js
+++ b/src/content/main/window-manager-toolbarbutton.js
@@ -53,17 +53,22 @@ let rpWindowManager = (function(self) {
   }
 
   function removeToolbarButtonFromAustralis() {
-    let tbb = XULUtils.xulTrees.toolbarbutton[0];
-    CustomizableUI.destroyWidget(tbb.id);
+    const {
+      attributes: {id}
+    } = XULUtils.xulTrees.toolbarbutton[0];
+    CustomizableUI.destroyWidget(id);
   }
 
   function addToolbarButtonToAustralis() {
-    let tbb = XULUtils.xulTrees.toolbarbutton[0];
+    const {
+      attributes: {id, label, tooltiptext}
+    } = XULUtils.xulTrees.toolbarbutton[0];
+
     CustomizableUI.createWidget({
-      id: tbb.id,
+      id: id,
       defaultArea: CustomizableUI.AREA_NAVBAR,
-      label: tbb.label,
-      tooltiptext: tbb.tooltiptext,
+      label: label,
+      tooltiptext: tooltiptext,
       onCommand : function(aEvent) {
         // Bad smell
         let win = aEvent.target.ownerDocument.defaultView;
diff --git a/src/content/ui/xul-trees.js b/src/content/ui/xul-trees.js
index ce51b85..70aa4b1 100644
--- a/src/content/ui/xul-trees.js
+++ b/src/content/ui/xul-trees.js
@@ -27,158 +27,331 @@ let isSeamonkey = appID === C.SEAMONKEY_ID;
 
 
 exports.toolbarbutton = [
-  {parent: {special: {type: "subobject", id: "navigator-toolbox",
-      tree: ["palette"]}}, // ("#navigator-toolbox".palette)
-    tag: "toolbarbutton", id: "rpcontinuedToolbarButton",
-    label: "RequestPolicy", tooltiptext: "RequestPolicy Continued",
-    popup: "rpc-popup"
+  {
+    parent: {
+      // $("#navigator-toolbox").palette
+      special: {
+        type: "subobject",
+        id: "navigator-toolbox",
+        tree: ["palette"]
+      }
+    },
+
+    tag: "toolbarbutton",
+    attributes: {
+      id: "rpcontinuedToolbarButton",
+      label: "RequestPolicy",
+      tooltiptext: "RequestPolicy Continued",
+      popup: "rpc-popup"
+    }
   }
 ];
 
 exports.mainTree = [
-  {parent: {id: (isSeamonkey ? "taskPopup" : "menu_ToolsPopup")},
-      tag: "menu", label: "RequestPolicy Continued", accesskey: "r",
-  children: [
-    {tag: "menupopup",
+  {
+    parent: {id: (isSeamonkey ? "taskPopup" : "menu_ToolsPopup")},
+
+    tag: "menu",
+    attributes: {label: "RequestPolicy Continued",
+                 accesskey: "r"},
     children: [
-      {tag: "menuitem", label: "&rp.menu.managePolicies;", accesskey: "m",
-          oncommand: "rpcontinued.overlay.openPolicyManager();"},
-      {tag: "menuitem", label: "&rp.requestLog.title;", accesskey: "l",
-          oncommand: "rpcontinued.overlay.toggleRequestLog(event);"},
-      {tag: "menuitem", label: "&rp.menu.preferences;", accesskey: "p",
-          oncommand: "rpcontinued.overlay.openPrefs(event);"}
-    ]}
-  ]},
+      {
+        tag: "menupopup",
+        children: [
+          {
+            tag: "menuitem",
+            attributes: {label: "&rp.menu.managePolicies;",
+                         accesskey: "m",
+                         oncommand: "rpcontinued.overlay.openPolicyManager();"}
+          },
+          {
+            tag: "menuitem",
+            attributes: {label: "&rp.requestLog.title;",
+                         accesskey: "l",
+                         oncommand: "rpcontinued.overlay.toggleRequestLog(event);"}
+          },
+          {
+            tag: "menuitem",
+            attributes: {label: "&rp.menu.preferences;",
+                         accesskey: "p",
+                         oncommand: "rpcontinued.overlay.openPrefs(event);"}
+          }
+        ]
+      }
+    ]
+  },
+
 
+  {
+    parent: {special: {type: "__window__"}},
+
+    tag: "keyset",
+    attributes: {id: "rpcontinuedKeyset"},
+    children: [
+      {
+        tag: "key",
+        attributes: {key: "r",
+                     modifiers: "accel alt",
+                     oncommand: "rpcontinued.overlay.openMenuByHotkey()"}
+      }
+    ]
+  },
 
-  {parent: {special: {type: "__window__"}},
-      tag: "keyset", id: "rpcontinuedKeyset",
-  children: [
-    {tag: "key", key: "r", modifiers: "accel alt",
-        oncommand: "rpcontinued.overlay.openMenuByHotkey()"}
-  ]},
 
+  {
+    parent: {special: {type: "__window__"}},
 
-  {parent: {special: {type: "__window__"}},
-      tag: "popupset", id: "rpcontinuedPopupset",
-  children: [
-    {tag: "menupopup", id: "rpcontinuedRedirectAddRuleMenu"},
-    {tag: "menupopup", id: "rpc-popup", noautohide: "true",
-        position: "after_start",
-        onpopupshowing: "rpcontinued.overlay.onPopupShowing(event);",
-        onpopuphidden: "rpcontinued.overlay.onPopupHidden(event);",
+    tag: "popupset",
+    attributes: {id: "rpcontinuedPopupset"},
     children: [
-      {tag: "vbox", id: "rpc-contents",
-      children: [
-        {tag: "hbox", id: "rpc-main",
+      {
+        tag: "menupopup",
+        attributes: {id: "rpcontinuedRedirectAddRuleMenu"}
+      }, {
+        tag: "menupopup",
+        attributes: {id: "rpc-popup",
+                     noautohide: "true",
+                     position: "after_start",
+                     onpopupshowing: "rpcontinued.overlay.onPopupShowing(event);",
+                     onpopuphidden: "rpcontinued.overlay.onPopupHidden(event);"},
         children: [
-          {tag: "vbox", id: "rpc-origins-destinations",
-          children: [
-            {tag: "hbox", id: "rpc-origin", "class": "rpc-od-item",
-                onclick: "rpcontinued.menu.itemSelected(event);",
-            children: [
-              {tag: "label", id: "rpc-origin-domainname", "class": "domainname",
-                  flex: "2"},
-              {tag: "label", id: "rpc-origin-num-requests",
-                  "class": "numRequests"}
-            ]},
-            {tag: "vbox", id: "rpc-other-origins",
-            children: [
-              {tag: "label", id: "rpc-other-origins-title",
-                  value: "&rp.menu.otherOrigins;"},
-              {tag: "vbox", id: "rpc-other-origins-list",
-                  "class": "rpc-label-list"}
-            ]},
-            {tag: "vbox", id: "rpc-blocked-destinations",
+          {
+            tag: "vbox",
+            attributes: {id: "rpc-contents"},
             children: [
-              {tag: "label", id: "rpc-blocked-destinations-title",
-                  value: "&rp.menu.blockedDestinations;"},
-              {tag: "vbox", id: "rpc-blocked-destinations-list",
-                  "class": "rpc-label-list"}
-            ]},
-            {tag: "vbox", id: "rpc-mixed-destinations",
-            children: [
-              {tag: "label", id: "rpc-mixed-destinations-title",
-                  value: "&rp.menu.mixedDestinations;"},
-              {tag: "vbox", id: "rpc-mixed-destinations-list",
-                  "class": "rpc-label-list"}
-            ]},
-            {tag: "vbox", id: "rpc-allowed-destinations",
-            children: [
-              {tag: "label", id: "rpc-allowed-destinations-title",
-                  value: "&rp.menu.allowedDestinations;"},
-              {tag: "vbox", id: "rpc-allowed-destinations-list",
-                  "class": "rpc-label-list"}
-            ]}
-          ]},
-          {tag: "vbox", id: "rpc-details",
-          children: [
-            {tag: "vbox", id: "rpc-rules-remove"},
-            {tag: "vbox", id: "rpc-rules-add"},
-            {tag: "vbox", id: "rpc-rules-info"}
-          ]}
-        ]},
-        {tag: "hbox", id: "rpc-revoke-temporary-permissions", hidden: "true",
-        children: [
-          {tag: "label", value: "&rp.menu.revokeTemporaryPermissions;",
-              onclick: "rpcontinued.overlay.revokeTemporaryPermissions();"}
-        ]},
-        {tag: "hbox", id: "rpc-footer",
-        children: [
-          {tag: "hbox", id: "rpc-footer-links",
-          children: [
-            {tag: "label", id: "rpc-link-enable-blocking",
-                "class": "rpc-footer-link", value: "&rp.menu.enableBlocking;",
-                onclick: "rpcontinued.overlay.toggleTemporarilyAllowAll();"},
-            {tag: "label", id: "rpc-link-disable-blocking",
-                "class": "rpc-footer-link", value: "&rp.menu.disableBlocking;",
-                onclick: "rpcontinued.overlay.toggleTemporarilyAllowAll();"},
-            {tag: "label", id: "rpc-link-help", "class": "rpc-footer-link",
-                value: "&rp.menu.help;",
-                onclick: "rpcontinued.overlay.openHelp();"},
-            {tag: "label", id: "rpc-link-prefs", "class": "rpc-footer-link",
-                value: "&rp.menu.preferences;",
-                onclick: "rpcontinued.overlay.openPrefs(event);"},
-            {tag: "label", id: "rpc-link-policies", "class": "rpc-footer-link",
-                value: "&rp.menu.managePolicies;",
-                onclick: "rpcontinued.overlay.openPolicyManager();"},
-            {tag: "label", id: "rpc-link-request-log",
-                "class": "rpc-footer-link", value: "&rp.requestLog.title;",
-                onclick: "rpcontinued.overlay.toggleRequestLog(event);"}
-          ]}
-        ]}
-      ]}
-    ]}
-  ]},
+              {
+                tag: "hbox",
+                attributes: {id: "rpc-main"},
+                children: [
+                  // [BEGIN] LEFT MENU COLUMN
+                  {
+                    tag: "vbox",
+                    attributes: {id: "rpc-origins-destinations"},
+                    children: [
+                      {
+                        tag: "hbox",
+                        attributes: {id: "rpc-origin",
+                                     "class": "rpc-od-item",
+                                     onclick: "rpcontinued.menu.itemSelected(event);"},
+                        children: [
+                          {
+                            tag: "label",
+                            attributes: {id: "rpc-origin-domainname",
+                                         "class": "domainname",
+                                         flex: "2"}
+                          }, {
+                            tag: "label",
+                            attributes: {id: "rpc-origin-num-requests",
+                                         "class": "numRequests"}
+                          }
+                        ]
+                      },
+                      {
+                        tag: "vbox",
+                        attributes: {id: "rpc-other-origins"},
+                        children: [
+                          {
+                            tag: "label",
+                            attributes: {id: "rpc-other-origins-title",
+                                         value: "&rp.menu.otherOrigins;"}
+                          }, {
+                            tag: "vbox",
+                            attributes: {id: "rpc-other-origins-list",
+                                         "class": "rpc-label-list"}
+                          }
+                        ]
+                      },
+                      {
+                        tag: "vbox",
+                        attributes: {id: "rpc-blocked-destinations"},
+                        children: [
+                          {
+                            tag: "label",
+                            attributes: {id: "rpc-blocked-destinations-title",
+                                         value: "&rp.menu.blockedDestinations;"}
+                          }, {
+                            tag: "vbox",
+                            attributes: {id: "rpc-blocked-destinations-list",
+                                         "class": "rpc-label-list"}
+                          }
+                        ]
+                      }, {
+                        tag: "vbox",
+                        attributes: {id: "rpc-mixed-destinations"},
+                        children: [
+                          {
+                            tag: "label",
+                            attributes: {id: "rpc-mixed-destinations-title",
+                                         value: "&rp.menu.mixedDestinations;"}
+                          }, {
+                            tag: "vbox",
+                            attributes: {id: "rpc-mixed-destinations-list",
+                                         "class": "rpc-label-list"}
+                          }
+                        ]
+                      }, {
+                        tag: "vbox",
+                        attributes: {id: "rpc-allowed-destinations"},
+                        children: [
+                          {
+                            tag: "label",
+                            attributes: {id: "rpc-allowed-destinations-title",
+                                         value: "&rp.menu.allowedDestinations;"}
+                          }, {
+                            tag: "vbox",
+                            attributes: {id: "rpc-allowed-destinations-list",
+                                         "class": "rpc-label-list"}
+                          }
+                        ]
+                      }
+                    ]
+                  },
+                  // [END] LEFT MENU COLUMN
+                  // [BEGIN] RIGHT MENU COLUMN
+                  {
+                    tag: "vbox",
+                    attributes: {id: "rpc-details"},
+                    children: [
+                      {
+                        tag: "vbox",
+                        attributes: {id: "rpc-rules-remove"}
+                      }, {
+                        tag: "vbox",
+                        attributes: {id: "rpc-rules-add"}
+                      }, {
+                        tag: "vbox",
+                        attributes: {id: "rpc-rules-info"}
+                      }
+                    ]
+                  }
+                  // [END] RIGHT MENU COLUMN
+                ]
+              }, {
+                tag: "hbox",
+                attributes: {id: "rpc-revoke-temporary-permissions",
+                             hidden: "true"},
+                children: [
+                  {
+                    tag: "label",
+                    attributes: {value: "&rp.menu.revokeTemporaryPermissions;",
+                                 onclick: "rpcontinued.overlay.revokeTemporaryPermissions();"}
+                  }
+                ]
+              },
+              // [BEGIN] MENU FOOTER
+              {
+                tag: "hbox",
+                attributes: {id: "rpc-footer"},
+                children: [
+                  {
+                    tag: "hbox",
+                    attributes: {id: "rpc-footer-links"},
+                    children: [
+                      {
+                        tag: "label",
+                        attributes: {id: "rpc-link-enable-blocking",
+                                     "class": "rpc-footer-link",
+                                     value: "&rp.menu.enableBlocking;",
+                                     onclick: "rpcontinued.overlay.toggleTemporarilyAllowAll();"}
+                      }, {
+                        tag: "label",
+                        attributes: {id: "rpc-link-disable-blocking",
+                                     "class": "rpc-footer-link",
+                                     value: "&rp.menu.disableBlocking;",
+                                     onclick: "rpcontinued.overlay.toggleTemporarilyAllowAll();"}
+                      }, {
+                        tag: "label",
+                        attributes: {id: "rpc-link-help",
+                                     "class": "rpc-footer-link",
+                                     value: "&rp.menu.help;",
+                                     onclick: "rpcontinued.overlay.openHelp();"}
+                      }, {
+                        tag: "label",
+                        attributes: {id: "rpc-link-prefs",
+                                     "class": "rpc-footer-link",
+                                     value: "&rp.menu.preferences;",
+                                     onclick: "rpcontinued.overlay.openPrefs(event);"}
+                      }, {
+                        tag: "label",
+                        attributes: {id: "rpc-link-policies",
+                                     "class": "rpc-footer-link",
+                                     value: "&rp.menu.managePolicies;",
+                                     onclick: "rpcontinued.overlay.openPolicyManager();"}
+                      }, {
+                        tag: "label",
+                        attributes: {id: "rpc-link-request-log",
+                                     "class": "rpc-footer-link",
+                                     value: "&rp.requestLog.title;",
+                                     onclick: "rpcontinued.overlay.toggleRequestLog(event);"}
+                      }
+                    ]
+                  }
+                ]
+              }
+              // [END] MENU FOOTER
+            ]
+          }
+        ]
+      }
+    ]
+  },
 
 
-  {parent: {id: "appcontent"},
-      tag: "splitter", id: "rpcontinued-requestLog-splitter", hidden: "true"},
-
-  {parent: {id: "appcontent"},
-      tag: "vbox", id: "rpcontinued-requestLog", height: "300",
-      hidden: "true", persist: "height",
-  children: [
-    {tag: "toolbox", id: "rpcontinued-requestLog-header",
+  {
+    parent: {id: "appcontent"},
+    tag: "splitter",
+    attributes: {id: "rpcontinued-requestLog-splitter",
+                 hidden: "true"}
+  },
+  {
+    parent: {id: "appcontent"},
+    tag: "vbox",
+    attributes: {id: "rpcontinued-requestLog",
+                 height: "300",
+                 hidden: "true",
+                 persist: "height"},
     children: [
-      {tag: "toolbar", id: "rpcontinued-requestLog-toolbar",
-          align: "center",
-      children: [
-        {tag: "label", id: "rpcontinued-requestLog-title",
-            control: "rpcontinued-requestLog-frame",
-            value: "&rp.requestLog.title;", crop: "end"},
-        {tag: "button", id: "rpcontinued-requestLog-clear",
-            label: "&rp.requestLog.clear;",
-            oncommand: "rpcontinued.overlay.clearRequestLog();"},
-        {tag: "vbox", flex: "1"},
-        {tag: "toolbarbutton", id: "rpcontinued-requestLog-close",
-            align: "right",
-            oncommand: "rpcontinued.overlay.toggleRequestLog()"}
-      ]}
-    ]},
-    // The src of this iframe is set to
-    // chrome://rpcontinued/content/ui/request-log.xul in overlay.js
-    {tag: "iframe", id: "rpcontinued-requestLog-frame", type: "chrome",
-        flex: "1"}
-  ]}
+      {
+        tag: "toolbox",
+        attributes: {id: "rpcontinued-requestLog-header"},
+        children: [
+          {
+            tag: "toolbar",
+            attributes: {id: "rpcontinued-requestLog-toolbar",
+                         align: "center"},
+            children: [
+              {
+                tag: "label",
+                attributes: {id: "rpcontinued-requestLog-title",
+                             control: "rpcontinued-requestLog-frame",
+                             value: "&rp.requestLog.title;",
+                             crop: "end"}
+              }, {
+                tag: "button",
+                attributes: {id: "rpcontinued-requestLog-clear",
+                             label: "&rp.requestLog.clear;",
+                             oncommand: "rpcontinued.overlay.clearRequestLog();"}
+              }, {
+                tag: "vbox",
+                attributes: {flex: "1"}
+              }, {
+                tag: "toolbarbutton",
+                attributes: {id: "rpcontinued-requestLog-close",
+                             align: "right",
+                             oncommand: "rpcontinued.overlay.toggleRequestLog()"}
+              }
+            ]
+          }
+        ]
+      },
+      // The src of this iframe is set to
+      // chrome://rpcontinued/content/ui/request-log.xul in overlay.js
+      {
+        tag: "iframe",
+        attributes: {id: "rpcontinued-requestLog-frame",
+                     type: "chrome",
+                     flex: "1"}
+      }
+    ]
+  }
 ];

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/requestpolicy.git



More information about the Pkg-mozext-commits mailing list