Nexen
Nexen

Reputation: 1892

How to handle an event dispatched by a Firefox add-on?

I installed TST-plugin for Firefox 29.0. It's perfect for me almost in full, but there is some option I wanna change.

When I close the current tab, TST focuses on the left tab. I wish, it focuses on previous in history of last opened tab after closing current (like Ctrl+Tab).

As developers said, I should catch their event, prevent it and... what? Snippet provided by the developer:

window.addEventListener(
  "TreeStyleTabFocusNextTab",
  function(aEvent) {
    if (Prefs.getCharPref('myextension.focus.mode') != 'default')
      aEvent.preventDefault();
  },
  false
);

I don't know, what I should do and even there I should do this. Where can I write the code to catch events? How can I dispatch ctrl+tab event to TST and only after that close the current tab?

Upvotes: 0

Views: 80

Answers (1)

nmaier
nmaier

Reputation: 33192

The TST developer put up the docs for other extension developers that like to modify or interact with TST, not for "regular" users. You'd have to write your add-on, where you'd use the code snippet you referenced in an overlay script to browser.js.

I had a fast look at the code of the add-on itself, to check if there is an equivalent preference to control this without writing code, but and EDIT there is one: browser.tabs.selectOwnerOnClose. See onFocusNextTab in modules/window.js... Not sure if it is exposed in the add-on preferences window anywhere... But you can use about:config (open this in a tab) to set it to true (you might have to create it first in about:config as a Boolean preference).

So your options here are:

  • Use the preference.
  • Modify the add-on itself (_tryMoveFocusFromClosingCurrentTab in modules/browser.js from what I gather).
  • Write a short XUL-overlay add-on that uses the snippet the TST author proposes in a browser.xul overlay script.

If you decide to change/write add-on code yourself, see info page and section for further information.

Upvotes: 1

Related Questions