[Pkg-mozext-commits] [tabmixplus] 57/147: Add options to open Synced tabs, from sidebar, in current tab or in new foreground or background tab

David Prévot taffit at moszumanska.debian.org
Sat Aug 5 15:27:36 UTC 2017


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

taffit pushed a commit to branch master
in repository tabmixplus.

commit 4f28b87e36606a130c4a62bf3ed2278476a41cfe
Author: onemen <tabmix.onemen at gmail.com>
Date:   Sun Dec 11 19:07:38 2016 +0200

    Add options to open Synced tabs, from sidebar, in current tab or in new foreground or background tab
---
 chrome/content/preferences/events.js  |  44 ++++++++++---
 chrome/content/preferences/events.xul |  33 +++++++---
 defaults/preferences/tabmix.js        |   5 +-
 modules/TabmixSvc.jsm                 |   7 +++
 modules/syncedTabs.jsm                | 114 ++++++++++++++++++++++++++++++++++
 5 files changed, 185 insertions(+), 18 deletions(-)

diff --git a/chrome/content/preferences/events.js b/chrome/content/preferences/events.js
index 046cbf1..81afa46 100644
--- a/chrome/content/preferences/events.js
+++ b/chrome/content/preferences/events.js
@@ -39,18 +39,46 @@ var gEventsPane = {
       focusTab[5].label = focusTab[5].getAttribute("rtlLabel");
     }
 
-    // align Tab opening group boxes
-    var vbox1 = $("tabopening1");
-    var vbox2 = $("tabopening2");
-    var vbox3 = $("tabopening3");
-    var max = Math.max(vbox1.boxObject.width, vbox2.boxObject.width, vbox3.boxObject.width);
-    vbox1.style.setProperty("width", max + "px", "important");
-    vbox2.style.setProperty("width", max + "px", "important");
-    vbox3.style.setProperty("width", max + "px", "important");
+    // bug 1210586 - Create a Synced tabs sidebar
+    if (Tabmix.isVersion(470)) {
+      const {label: syncedTabs} = browserWindow.document.getElementById("menu_tabsSidebar");
+      $("syncedTabs").label = syncedTabs;
+      $("selectSyncedTabs").label = syncedTabs;
+    } else {
+      $("syncedTabs").hidden = true;
+      $("selectSyncedTabs").hidden = true;
+    }
+
+    this.alignTabOpeningBoxes();
 
     gPrefWindow.initPane("paneEvents");
   },
 
+  // align Tab opening group boxes
+  // add setWidth attribute to columns that need to be aligned
+  alignTabOpeningBoxes: function() {
+    const widths = {};
+    const rows = $("tabopening").querySelectorAll("hbox");
+    function updateGrid(fn) {
+      for (let row of rows) {
+        let id = 0;
+        const cols = row.querySelectorAll("vbox");
+        for (let col of cols) {
+          if (++id && col.hasAttribute("setWidth")) {
+            fn(col, id);
+          }
+        }
+      }
+    }
+    updateGrid((col, id) => {
+      widths[id] = Math.max(widths[id] || 0, col.boxObject.width);
+    });
+
+    updateGrid((col, id) => {
+      col.style.setProperty("width", widths[id] + "px", "important");
+    });
+  },
+
   disableShowTabList: function() {
     var ctrlTabPv = $("pref_ctrltab.tabPreviews");
     var disableShowTabList = $("pref_ctrltab").value &&
diff --git a/chrome/content/preferences/events.xul b/chrome/content/preferences/events.xul
index 3fcff88..dd7871a 100644
--- a/chrome/content/preferences/events.xul
+++ b/chrome/content/preferences/events.xul
@@ -37,16 +37,20 @@
                   type="bool"/>
       <preference id="pref_openBookmarks"       name="extensions.tabmix.opentabfor.bookmarks" type="bool"/>
       <preference id="pref_openUrl"             name="extensions.tabmix.opentabfor.urlbar"    type="bool"/>
+      <preference id="pref_syncedTabs"          name="extensions.tabmix.opentabfor.syncedTabs"
+                  type="bool"/>
       <preference id="pref_openBMKGroups"       name="extensions.tabmix.loadBookmarksAndReplace"
                   type="bool" inverted="true"/>
       <preference id="pref_openSearch"          name="browser.search.openintab"               type="bool"/>
       <preference id="pref_openHistory"         name="extensions.tabmix.opentabfor.history"   type="bool"/>
       <preference id="pref_midcurrent"          name="extensions.tabmix.middlecurrent" type="bool"/>
       <preference id="pref_selectTab"           name="browser.tabs.loadInBackground"
-                                                                              inverted="true" type="bool"
+                  inverted="true" type="bool"
                   onchange="if (typeof gMenuPane == 'object') gMenuPane.setInverseLinkLabel();"/>
       <preference id="pref_selectTabUrl"        name="extensions.tabmix.loadUrlInBackground"
                   type="bool" inverted="true"/>
+      <preference id="pref_selectSyncedTabs"    name="extensions.tabmix.loadSyncedTabsInBackground"
+                  type="bool" inverted="true"/>
       <preference id="pref_selectDivertedTab"   name="browser.tabs.loadDivertedInBackground"
                   type="bool" inverted="true"/>
       <preference id="pref_selectTabFromExternal"   name="extensions.tabmix.loadExternalInBackground"
@@ -174,11 +178,11 @@
           </groupbox>
         </tabpanel>
 <!-- ======================================================== -->
-        <tabpanel>
+        <tabpanel id="tabopening">
           <groupbox flex="1">
             <caption label="&openNewTab.label;"/>
             <hbox>
-              <vbox align="start" id="tabopening1">
+              <vbox align="start" setWidth="true">
                 <!-- Bookmarks open in new tab -->
                 <checkbox_tmp id="openBookmarks" label="&openBookmarks.label;"
                           preference="pref_openBookmarks"/>
@@ -186,7 +190,7 @@
                 <checkbox_tmp id="openHistory" label="&openHistory.label;"
                           preference="pref_openHistory"/>
               </vbox>
-              <vbox>
+              <vbox setWidth="true">
                 <!-- URL open in new tab -->
                 <checkbox_tmp id="openUrl" label="&openUrl.label;"
                           preference="pref_openUrl"/>
@@ -194,6 +198,11 @@
                 <checkbox_tmp id="openSearch" label="&openSearch.label;"
                           preference="pref_openSearch"/>
               </vbox>
+              <vbox>
+                <!-- Synced tabs open in new tab -->
+                <checkbox_tmp id="syncedTabs"
+                              preference="pref_syncedTabs"/>
+              </vbox>
             </hbox>
             <!-- Groups of Bookmarks/History open in new tabs -->
             <checkbox_tmp id="openBMKGroups" label="&openPlacesGroups.label;"
@@ -207,7 +216,7 @@
           <groupbox flex="1">
             <caption label="&tabFocus.caption;"/>
             <hbox>
-              <vbox align="start" id="tabopening2">
+              <vbox align="start" setWidth="true">
                 <!-- select Links -->
                 <checkbox_tmp id="selectTab" label="&selectTab.label;" preference="pref_selectTab"/>
                 <!-- Select Diverted Windows -->
@@ -221,7 +230,7 @@
                 <!-- duplicate tab -->
                 <checkbox_tmp id="selectDuplicate" label="&duplicateTab.label;" preference="pref_selectDuplicate"/>
               </vbox>
-              <vbox align="start">
+              <vbox align="start" setWidth="true">
                 <!-- Select from url bar -->
                 <checkbox_tmp id="selectTabUrl" label="&openUrl.label;" preference="pref_selectTabUrl"/>
                 <!-- Select from Search Bar-->
@@ -233,16 +242,22 @@
                 <!-- Select first tab from Bookmark Groups -->
                 <checkbox_tmp id="selectBMKGroups" label="&openPlacesGroups.label;" preference="pref_selectBMKGroups"/>
               </vbox>
+              <vbox align="start">
+                <!-- Select from synced tabs -->
+                <checkbox_tmp id="selectSyncedTabs" preference="pref_selectSyncedTabs"/>
+              </vbox>
             </hbox>
             <spacer flex="1"/>
             <separator class="groove"/>
             <label value="&inversefocus2.label;"/>
             <hbox align="start">
-              <vbox id="tabopening3">
+              <vbox setWidth="true">
                 <checkbox_tmp id="inverselinks" label="&selectTab.label;" preference="pref_inverselinks"/>
               </vbox>
-              <checkbox_tmp id="inverseother" label="&selectTabBH.label;, &openUrl.label;, &openSearch.label;"
-                            style="width: 19em;" align="start" preference="pref_inverseother"/>
+              <vbox>
+                <checkbox_tmp id="inverseother" label="&selectTabBH.label;, &openUrl.label;, &openSearch.label;"
+                              style="width: 19em;" align="start" preference="pref_inverseother"/>
+              </vbox>
             </hbox>
           </groupbox>
         </tabpanel>
diff --git a/defaults/preferences/tabmix.js b/defaults/preferences/tabmix.js
index 0b53179..5d0a375 100644
--- a/defaults/preferences/tabmix.js
+++ b/defaults/preferences/tabmix.js
@@ -15,6 +15,9 @@ pref("extensions.tabmix.opentabfor.bookmarks", false);
 // pref("extensions.tabmix.opentabfor.search", false); - replace with Firefox pref
 pref("extensions.tabmix.opentabfor.history", false);
 pref("extensions.tabmix.opentabfor.urlbar", false);
+pref("extensions.tabmix.loadBookmarksAndReplace", false);
+pref("extensions.tabmix.opentabfor.syncedTabs", false);
+
 pref("extensions.tabmix.middlecurrent", false);
 pref("extensions.tabmix.inversefocusLinks", false);
 pref("extensions.tabmix.inversefocusOther", false);
@@ -25,7 +28,7 @@ pref("extensions.tabmix.loadExternalInBackground", false);
 pref("extensions.tabmix.loadSearchInBackground", false);
 pref("extensions.tabmix.loadDuplicateInBackground", false);
 pref("extensions.tabmix.loadBookmarksGroupInBackground", false);
-pref("extensions.tabmix.loadBookmarksAndReplace", false);
+pref("extensions.tabmix.loadSyncedTabsInBackground", false);
 
 pref("extensions.tabmix.loadOnNewTab.type", 4); // 2012-03-21 changed default from 0 to 4
 pref("extensions.tabmix.replaceLastTabWith.type", 4); // 2012-03-21 changed default from 0 to 4
diff --git a/modules/TabmixSvc.jsm b/modules/TabmixSvc.jsm
index 15cbaeb..3145b87 100644
--- a/modules/TabmixSvc.jsm
+++ b/modules/TabmixSvc.jsm
@@ -11,6 +11,9 @@ Cu.import("resource://gre/modules/Services.jsm", this);
 XPCOMUtils.defineLazyModuleGetter(this, "TabmixPlacesUtils",
   "resource://tabmixplus/Places.jsm");
 
+XPCOMUtils.defineLazyModuleGetter(this, "SyncedTabs",
+  "resource://tabmixplus/syncedTabs.jsm");
+
 var tabStateCache;
 var _versions = {};
 function isVersion(aVersionNo) {
@@ -188,6 +191,9 @@ this.TabmixSvc = {
       Cu.import("resource://tabmixplus/DownloadLastDir.jsm", {});
 
       TabmixPlacesUtils.init(aWindow);
+      if (TabmixSvc.version(470)) {
+        SyncedTabs.init(aWindow);
+      }
 
       TabmixSvc.tabStylePrefs = {};
       let tmp = {};
@@ -216,6 +222,7 @@ this.TabmixSvc = {
       switch (aTopic) {
         case "quit-application":
           TabmixPlacesUtils.onQuitApplication();
+          SyncedTabs.onQuitApplication();
           for (let id of Object.keys(TabmixSvc.console._timers)) {
             let timer = TabmixSvc.console._timers[id];
             timer.cancel();
diff --git a/modules/syncedTabs.jsm b/modules/syncedTabs.jsm
new file mode 100644
index 0000000..02e8694
--- /dev/null
+++ b/modules/syncedTabs.jsm
@@ -0,0 +1,114 @@
+/* eslint object-shorthand: "error" */
+"use strict";
+
+this.EXPORTED_SYMBOLS = ["SyncedTabs"];
+
+const {utils: Cu} = Components;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
+
+XPCOMUtils.defineLazyModuleGetter(this, "Services",
+  "resource://gre/modules/Services.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this,
+  "TabmixSvc", "resource://tabmixplus/TabmixSvc.jsm");
+
+const {getChromeWindow} = Cu.import("resource:///modules/syncedtabs/util.js", {});
+const {TabListView} = Cu.import("resource:///modules/syncedtabs/TabListView.js", {});
+
+const Tabmix = {};
+
+this.SyncedTabs = {
+  _initialized: false,
+
+  init(aWindow) {
+    if (this._initialized)
+      return;
+    this._initialized = true;
+
+    Tabmix._debugMode = aWindow.Tabmix._debugMode;
+    Tabmix.gIeTab = aWindow.Tabmix.extensions.gIeTab;
+    Services.scriptloader.loadSubScript("chrome://tabmixplus/content/changecode.js");
+
+    this.tabListView(aWindow);
+  },
+
+  onQuitApplication() {
+    this.functions.forEach(aFn => {
+      TabListView.prototype[aFn] = TabListView.prototype["tabmix_" + aFn];
+      delete TabListView.prototype["tabmix_" + aFn];
+    });
+    delete TabListView.prototype.tabmix_whereToOpen;
+    delete TabListView.prototype.tabmix_inBackground;
+  },
+
+  functions: ["onClick", "onOpenSelected", "adjustContextMenu", "onOpenSelectedFromContextMenu"],
+  tabListView() {
+    this.functions.forEach(aFn => {
+      TabListView.prototype["tabmix_" + aFn] = TabListView.prototype[aFn];
+    });
+
+    TabListView.prototype.tabmix_whereToOpen = function(event) {
+      let window = getChromeWindow(this._window);
+      let where = window.whereToOpenLink(event);
+      if (where == "current") {
+        let pref = "extensions.tabmix.opentabfor.syncedTabs";
+        if (window.Tabmix.whereToOpen(pref).inNew) {
+          where = "tab";
+        }
+      }
+      let inBackground = this.tabmix_inBackground;
+      return {where, inBackground};
+    };
+
+    Object.defineProperty(TabListView.prototype, "tabmix_inBackground", {
+      get() {
+        return TabmixSvc.prefBranch.getBoolPref("loadSyncedTabsInBackground");
+      },
+      enumerable: true,
+      configurable: true
+    });
+
+    if (TabmixSvc.version(510)) {
+      Tabmix.changeCode(TabListView.prototype, "TabListView.prototype.onClick")._replace(
+        'this.props.onOpenTabs(urls, where, {});',
+        `if (/^tab/.test(where)) {
+            let window = getChromeWindow(this._window);
+            let whereFirst = window.Tabmix.whereToOpen(true).inNew ? where : "current";
+            // make sure other tabs are inBackground
+            where = "tab";
+            let inBackground = this.tabmix_inBackground;
+            this.props.onOpenTab(urls.shift(), whereFirst, {inBackground});
+          }
+          this.props.onOpenTabs(urls, where, {inBackground: true})`
+      ).toCode();
+    }
+
+    TabListView.prototype.onOpenSelected = function(url, event) {
+      let {where, inBackground} = this.tabmix_whereToOpen(event);
+      this.props.onOpenTab(url, where, {inBackground});
+    };
+
+    Tabmix.changeCode(TabListView.prototype, "TabListView.prototype.onOpenSelectedFromContextMenu")._replace(
+      'private:',
+      'inBackground: this.tabmix_inBackground,\n' +
+      '        $&'
+    ).toCode();
+
+    TabListView.prototype.adjustContextMenu = function(menu) {
+      this.tabmix_adjustContextMenu(menu);
+      if (menu.id == "SyncedTabsSidebarContext") {
+        let window = getChromeWindow(this._window);
+        let doc = window.document;
+        let where = "syncedTabsOpenSelected";
+        let open = doc.getElementById(where);
+        let openInWindow = doc.getElementById(`${where}InWindow`);
+        let openInPrivateWindow =
+            doc.getElementById(`${where}InPrivateWindow`) || {hidden: true};
+        let openInTab = doc.getElementById(`${where}InTab`);
+        let pref = "extensions.tabmix.opentabfor.syncedTabs";
+        window.TMP_Places.contextMenu.update(open, openInWindow, openInPrivateWindow, openInTab, pref);
+      }
+    };
+  },
+};

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



More information about the Pkg-mozext-commits mailing list