MozillaZine

keyconfig 20110522

Announce and Discuss the Latest Theme and Extension Releases.
daisensou
 
Posts: 21
Joined: October 13th, 2011, 7:54 am

Post Posted October 4th, 2013, 12:50 pm

Hello, I got a question (knowing nothing about js), can this be achieved through keyconfig?

What I'm trying to do...
Open the Library in a tab and change focus to one of these items: History, Downloads or Bookmarks Menu

What I got so far...
Code: Select all
if(window.loadURI)BrowserOpenTab(); loadURI(getShortcutOrURI('chrome://browser/content/places/places.xul',{}));

I'm pretty sure I got it from a post here on Mozillazine. It opens the Library in a tab, but focus is always on "All Bookmarks" contents.

In order to achieve my goal, I ended using Autohotkey to intercept the key combo, once the Library is open, it sends Shift+Tab (to change focus to the tree list) then 'hi' to focus on History, for example. It works fairly well this way, but it would be awesome if the same could be achieved using keyconfig only, less things to keep track of :)

Thanks in advance.

Code: Select all
   #IfWinActive, ahk_class MozillaWindowClass
   ^h::
   Send ^{h}
   Sleep (200)
   Send +{Tab}
   Sleep (50)
   Send hi
   Sleep (50)
   Send {Down}
   return

morat
 
Posts: 3904
Joined: February 3rd, 2009, 6:29 pm

Post Posted October 4th, 2013, 9:17 pm

@daisensou

I do not think the library works perfectly in a tab.

Code: Select all
var url = "chrome://browser/content/places/places.xul";
gBrowser.selectedTab = gBrowser.addTab(url);

Here is how to select the bookmark menu folder in the bookmarks sidebar.

Code: Select all
var browser = document.getElementById("sidebar");
var contentDocument = browser.contentDocument;
var tree = contentDocument.getElementById("bookmarks-view");
if (tree) {
  var view = tree.view;
  for (var i = 0; i < view.rowCount; i++) {
    var name = view.getCellText(i, tree.columns.getColumnAt(0));
    if (name == "Bookmarks Menu") {
      tree.focus();
      tree.treeBoxObject.ensureRowIsVisible(i);
      view.selection.select(i);
      break;
    }
  }
} else {
  toggleSidebar("viewBookmarksSidebar");
}

Similar post: viewtopic.php?f=38&t=2743055

Zoolcar9

User avatar
 
Posts: 2225
Joined: November 9th, 2004, 6:45 pm
Location: Jakarta, Indonesia (UTC+7)

Post Posted October 4th, 2013, 10:03 pm

daisensou wrote:Open the Library in a tab and change focus to one of these items: History, Downloads or Bookmarks Menu

Revision 2.

Code: Select all
(function(aLeftPane) {
  /**
   * Select left panel in Library.
   *
   * @param aBrowser Browser object in selected tab.
   * @param aHierarchy A single container or an array of containers, sorted from
   *                   the outmost to the innermost in the hierarchy. Each
   *                   container may be either an item id, a Places URI string,
   *                   or a named query.
   *                   Supported named queries are:
   *                   - AllBookmarks         - History
   *                   - BookmarksMenu        - Tags
   *                   - BookmarksToolbar     - UnfiledBookmarks
   *                   - Downloads
   */
  function showPlacesPanel(aBrowser, aHierarchy) {
    var win = aBrowser.contentWindow;
    var PlacesOrganizer = win.wrappedJSObject.PlacesOrganizer;

    if ("selectLeftPaneContainerByHierarchy" in PlacesOrganizer)
      // Fx 25+
      PlacesOrganizer.selectLeftPaneContainerByHierarchy(aHierarchy);
    else
      PlacesOrganizer
.selectLeftPaneQuery(aHierarchy)

    win.focus();
  }

  // This will switch to the tab in aWindow having aURI, if present.
  function switchIfURIInWindow(aWindow, aURI) {
    if ("PrivateBrowsingUtils" in window) { // Fx 20+
      // Only switch to the tab if neither the source and desination window are
      // private and they are not in permanent private borwsing mode
      if ((PrivateBrowsingUtils.isWindowPrivate(window) ||
          PrivateBrowsingUtils.isWindowPrivate(aWindow)) &&
          !PrivateBrowsingUtils.permanentPrivateBrowsing) {
        return false;
      }
    }

    var browsers = aWindow.gBrowser.browsers;
    for (var i = 0; i < browsers.length; i++) {
      var browser = browsers[i];
      if (browser.currentURI.equals(aURI)) {
        // Focus the matching window & tab
        aWindow.focus();
        aWindow.gBrowser.tabContainer.selectedIndex = i;
        return true;
      }
    }
    return false;
  }

  var URI = "chrome://browser/content/places/places.xul";

  // This can be passed either nsIURI or a string.
  if (!(URI instanceof Ci.nsIURI))
    URI = Services.io.newURI(URI, null, null);

  var isBrowserWindow = !!window.gBrowser;

  // Prioritise this window.
  if (isBrowserWindow && switchIfURIInWindow(window, URI)) {
    showPlacesPanel(window.getBrowser().selectedBrowser, aLeftPane);
    return;
  }

  var winEnum = Services.wm.getEnumerator("navigator:browser");
  while (winEnum.hasMoreElements()) {
    var browserWin = winEnum.getNext();
    // Skip closed (but not yet destroyed) windows,
    // and the current window (which was checked earlier).
    if (browserWin.closed || browserWin == window) {
      openLinkIn(URI.spec, "tab", {fromChrome:true});
      browserWin.addEventListener("pageshow", function browserWinPageShow(event) {
        if (event.target.location.href != URI.spec)
          return;
        browserWin.removeEventListener("pageshow", browserWinPageShow, true);
        showPlacesPanel(browserWin.getBrowser().selectedBrowser, aLeftPane);
      }, true)
    }
    if (switchIfURIInWindow(browserWin, URI))
      return;
  }
})(
"History") // Change this with a supported a named query above    


References:
- SeaMonkey's switchToTabHavingURI function.
- selectLeftPaneContainerByHierarchy method in PlacesOrganizer object.
Last edited by Zoolcar9 on October 5th, 2013, 8:18 am, edited 1 time in total.
My Firefox information | Add-ons | GitHub

"With great power, comes great desire to show it off."

daisensou
 
Posts: 21
Joined: October 13th, 2011, 7:54 am

Post Posted October 5th, 2013, 5:05 am

Wow, that was fast, thanks for looking into it!

@morat
Eh, odd. Now focus is falling on the "Bookmarks Menu" by default o_O

That code works fine, but I'm trying to move away from the sidebar options, because the Library offers a more detailed view (titles + URLs and I was looking to force it into tabs because it's easier for me to change between tabs than to change focus between the browser and the library in a separated window). Anyway, thanks! More options to access the mess I have here :D

@Zoolcar9
That's a really complex code, but it does it!

The only downside is that after you customize it to different items (History and Downloads for example), when you open one of them, you will need to close it before trying to trigger the other.
Otherwise it'll simply activate the Library tab, but focus will not move between the two items. But I can live with that :)

Thanks again!

Zoolcar9

User avatar
 
Posts: 2225
Joined: November 9th, 2004, 6:45 pm
Location: Jakarta, Indonesia (UTC+7)

Post Posted October 5th, 2013, 8:23 am

daisensou wrote:The only downside is that after you customize it to different items (History and Downloads for example), when you open one of them, you will need to close it before trying to trigger the other.
Otherwise it'll simply activate the Library tab, but focus will not move between the two items.

You're right.
I've fixed it and updated the code above.

Also for Custom Buttons extension
Open Library in Tab.xml
Last edited by Zoolcar9 on November 4th, 2013, 5:00 am, edited 1 time in total.
My Firefox information | Add-ons | GitHub

"With great power, comes great desire to show it off."

PacoH
 
Posts: 2
Joined: October 18th, 2013, 8:42 am

Post Posted October 18th, 2013, 8:47 am

I posted about this (https://support.mozilla.org/en-US/questions/974590) and was directed to this thread.

I am trying to change ctrl-Tab to go to Previous Tab but it will not work. See thread for details.

daisensou
 
Posts: 21
Joined: October 13th, 2011, 7:54 am

Post Posted October 18th, 2013, 8:02 pm

Zoolcar9 wrote:
daisensou wrote:The only downside is that after you customize it to different items (History and Downloads for example), when you open one of them, you will need to close it before trying to trigger the other.
Otherwise it'll simply activate the Library tab, but focus will not move between the two items.

You're right.
I've fixed it and updated the code above.

Also for Custom Buttons extension
http://loucypher.googlecode.com/svn/cus ... ibrary.xml


Thanks again :D


PacoH wrote:I posted about this (https://support.mozilla.org/en-US/questions/974590) and was directed to this thread.

I am trying to change ctrl-Tab to go to Previous Tab but it will not work. See thread for details.


Take a look a this dorando post: viewtopic.php?p=3245225#p3245225

I tried it (on Windows and Ubuntu) and it worked, with some adjustments:

- Following the instructions there and editing it a little:

Code: Select all
<script><![CDATA[
var ctrl = {
 init: function(){
  gBrowser.mTabBox.handleCtrlTab = false;
  window.addEventListener("keydown", ctrl._keyEventHandler, false);
 },
 _keyEventHandler: function(event){
  if(event.ctrlKey && event.keyCode == 9) {
   gBrowser.mTabBox.handleCtrlTab = false;
   gBrowser.mTabContainer.advanceSelectedTab(-1,true);

   event.stopPropagation();
   event.preventDefault();
  }
 }
}

window.addEventListener("load",ctrl.init,false);

]]></script>


- Grab the xpi linked in that post
- Unzip it somewhere, look in the overlays folder and open the main.xul file
- Edit it to add the script above, as per instructions (between <overlay> </overlay>)
- Zip the overlays folder + install.rdf + chrome.manifest again (only these 3 items, not the parent folder holding them)
- Rename it from zip to xpi
- Install on Firefox

Ctrl+Tab should now focus previous tabs, rather than move forward. :-k


EDIT: Tested on Snow Leopard, works! Thanks dorando :D

Image

meeotch
 
Posts: 53
Joined: November 11th, 2002, 9:16 pm

Post Posted October 21st, 2013, 5:45 pm

Question for the keyconfig gurus out there: How would I map a key to "go to first message in the current folder"? I can't seem to find a command() for it, and using the "getCommand" code to try and trap the T-bird default goto-first-message (Home) key produces no results.

morat
 
Posts: 3904
Joined: February 3rd, 2009, 6:29 pm

Post Posted October 21st, 2013, 10:24 pm

@meeotch

Try these:

Code: Select all
// move thread pane selection to top
var treeBoxObject = document.getElementById("threadTree").treeBoxObject;
treeBoxObject.ensureRowIsVisible(0);
treeBoxObject.view.selection.select(0);

Code: Select all
// move thread pane selection to bottom
var treeBoxObject = document.getElementById("threadTree").treeBoxObject;
var rowCount = treeBoxObject.view.rowCount;
treeBoxObject.ensureRowIsVisible(rowCount - 1);
treeBoxObject.view.selection.select(rowCount - 1);

Code: Select all
// home key
var utils = document.commandDispatcher.focusedWindow.
  QueryInterface(Components.interfaces.nsIInterfaceRequestor).
  getInterface(Components.interfaces.nsIDOMWindowUtils);
var flags = Components.interfaces.nsIDOMWindowUtils.
  KEY_FLAG_PREVENT_DEFAULT;
utils.sendKeyEvent("keypress", KeyEvent.DOM_VK_HOME, 0, 0, flags);

Code: Select all
// end key
var utils = document.commandDispatcher.focusedWindow.
  QueryInterface(Components.interfaces.nsIInterfaceRequestor).
  getInterface(Components.interfaces.nsIDOMWindowUtils);
var flags = Components.interfaces.nsIDOMWindowUtils.
  KEY_FLAG_PREVENT_DEFAULT;
utils.sendKeyEvent("keypress", KeyEvent.DOM_VK_END, 0, 0, flags);
Last edited by morat on October 21st, 2013, 11:16 pm, edited 1 time in total.

meeotch
 
Posts: 53
Joined: November 11th, 2002, 9:16 pm

Post Posted October 21st, 2013, 11:11 pm

Bingo - that first one seems to do the trick. Thanks!

mantra
 
Posts: 330
Joined: September 29th, 2010, 7:21 am

Post Posted October 25th, 2013, 8:58 am

Hi
may i know where can find the list of command/id , the code ?

thanks
http://www.pcmech.com/article/clearing- ... he-how-to/
windows firefox 49.0.2 ,thunderbird 45.4 and under linux , firefox and thunderbird are always updated

Zoolcar9

User avatar
 
Posts: 2225
Joined: November 9th, 2004, 6:45 pm
Location: Jakarta, Indonesia (UTC+7)

Post Posted October 26th, 2013, 3:37 am

Tools > Keyconfig
or Ctrl+F12
My Firefox information | Add-ons | GitHub

"With great power, comes great desire to show it off."

WildcatRay

User avatar
 
Posts: 7477
Joined: October 18th, 2007, 7:03 pm
Location: Columbus, OH

Post Posted October 26th, 2013, 3:49 am

Do you think he is asking where to find commands like these for how to check for updates to the browser?
Code: Select all
    var um = Cc['@mozilla.org/updates/update-manager;1'].
             getService(Ci.nsIUpdateManager);
    var prompter = Cc['@mozilla.org/updates/update-prompt;1'].
                   createInstance(Ci.nsIUpdatePrompt);
    if (um.activeUpdate && um.activeUpdate.state == "pending") {
      prompter.showUpdateDownloaded(um.activeUpdate);
    } else {
      prompter.checkForUpdates();
    }
Ray

OS'es: 4 computers with Win10 Pro 64-bit; Current Firefox, Beta, Nightly, Chrome, Vivaldi

Zoolcar9

User avatar
 
Posts: 2225
Joined: November 9th, 2004, 6:45 pm
Location: Jakarta, Indonesia (UTC+7)

Post Posted October 26th, 2013, 8:03 am

No?
My Firefox information | Add-ons | GitHub

"With great power, comes great desire to show it off."

bugblatter
 
Posts: 59
Joined: June 21st, 2005, 12:31 am

Post Posted October 30th, 2013, 1:16 pm

Hello all,
I was hoping someone here could help with this.
I have keyboard shortcut that opens a url from a bookmark by its keyword. It's worked forever but was recently broken by firefox 25:

Code: Select all
var url = getShortcutOrURI('mykeyword',{});
gBrowser.selectedTab = gBroser.addTab(url);


But getShortcutOrURI(url) has now been replaced by getShortcutOrURIAndPostData(url), which is returning some kind of object rather than just the plain url. I tried a simple fix but it didn't work. I googled it without much luck (relatively new issue I guess), though I noticed dorando mentioning patching his Search Type B extension for the same reason. Anyone have any ideas? Thanks for any help.

Return to Extension/Theme Releases


Who is online

Users browsing this forum: No registered users and 2 guests