Toolbar Button On Install

Talk about add-ons and extension development.
User avatar
TheBaker
Posts: 193
Joined: October 20th, 2004, 9:20 am

Toolbar Button On Install

Post by TheBaker »

I want to get the button for my extension put into the toolbar when my extension is installed (or if that's not possible, the first time it is run). How would I do that?
User avatar
TheBaker
Posts: 193
Joined: October 20th, 2004, 9:20 am

Post by TheBaker »

Ok then, a different question. How do I programatically insert a button onto the toolbar from my extension?
User avatar
Lee_Dailey
Posts: 14194
Joined: July 27th, 2004, 4:33 pm
Location: milky way galaxy, sol system, terra, north america, usa, tx, bedford

Post by Lee_Dailey »

howdy thebaker,

have you looked at the install routine for this ...
http://www.extensionsmirror.nl/index.php?showtopic=1342

doesn't QUITE do what ya want, but it seems to get right close ...

hope that helps,
lee
User avatar
TheBaker
Posts: 193
Joined: October 20th, 2004, 9:20 am

Post by TheBaker »

Hey Lee, not quite what I want, but it has given me an idea. I like the way it opens a Side Bar when it's run for the first time, so I think I'll nab that. Thanks for showing me that extension!
User avatar
Lee_Dailey
Posts: 14194
Joined: July 27th, 2004, 4:33 pm
Location: milky way galaxy, sol system, terra, north america, usa, tx, bedford

Post by Lee_Dailey »

howdy thebaker,

you are welcome! i thot it might be a useful - and diffferent - approach.

if you are determined to do teh auto-add-button-to-toolbar bit, you might wanna try a brute force approach.

- setup ff as vanilla as possible
- xcopy the set of folders for app AND profile
- add ONE button to a toolbar
- xcopy the current set of folders for app & profil
- compare ...

[*grin*] it will at least let ya see what was done. once you have that you can look at ways to automate the process. graceless, but it might help.

take care,
lee
asqueella
Posts: 4019
Joined: November 16th, 2003, 3:05 am
Location: Russia, Moscow

Post by asqueella »

beter yet, look at how it's done in customizeToolbar.js (lxr it or look in chrome/toolkit.jar)
User avatar
Lee_Dailey
Posts: 14194
Joined: July 27th, 2004, 4:33 pm
Location: milky way galaxy, sol system, terra, north america, usa, tx, bedford

Post by Lee_Dailey »

howdy asqueella,

i KNEW there had to be a better way ... [*grin*] thanks!

take care,
lee
User avatar
Sephirot
Posts: 247
Joined: June 15th, 2004, 7:56 am

Post by Sephirot »

asqueella wrote:beter yet, look at how it's done in customizeToolbar.js (lxr it or look in chrome/toolkit.jar)

thanks for this hint ;)

this will add the button on the outer right side, next to the searchbar and saves the postitions.
this should be done only once!

Code: Select all

var currentset = document.getElementById("nav-bar").currentSet;
currentset=currentset + ",your-button-id";
document.getElementById("nav-bar").setAttribute("currentset",currentset);   //not needed I suppose
document.getElementById("nav-bar").currentSet = currentset;
document.persist("nav-bar","currentset");
Author of Bookmarks Menu Button, Autoclose Bookmark&History Folders and more

Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.19pre) Gecko/20110701 Firefox/3.6.19pre <-- build with MS VC++ 2010 SP1 and PGO on Win 7 x64
asqueella
Posts: 4019
Joined: November 16th, 2003, 3:05 am
Location: Russia, Moscow

Post by asqueella »

that should be ok, but I think calling toolbar's insertItem() method is more appropriate. Care to add this to the knowledge base?
User avatar
TheBaker
Posts: 193
Joined: October 20th, 2004, 9:20 am

Post by TheBaker »

Hey, thanks for your help everyone. I'm currently using:

Code: Select all

var navToolbar = document.getElementById("nav-bar")
navToolbar.insertItem("smxtra-button", null, null, false);

To insert the toolbar button. However, this doesn't save the state of the toolbar, so when I run it again (it only adds the toolbar button the first time) the button doesn't appear.

How would I save the state of the toolbar so that it remembers the button?
asqueella
Posts: 4019
Joined: November 16th, 2003, 3:05 am
Location: Russia, Moscow

Post by asqueella »

The set of buttons is persisted on OK of Customize toolbars only. You need to persist it yourself.

I'd guess something like this (didn't try it):

Code: Select all

document.persist("nav-bar", "currentset");


Tell me if that works (along with as much code as possible - I might add it to kb).
User avatar
TheBaker
Posts: 193
Joined: October 20th, 2004, 9:20 am

Post by TheBaker »

Nope that didn't work. Here's a summary of what I've tried so far.

Started with

Code: Select all

var navToolbar = document.getElementById("nav-bar")
navToolbar.insertItem("smxtra-button", null, null, false);

Inserted toolbar button fine, but didn't persist

Next tried

Code: Select all

var navToolbar = document.getElementById("nav-bar")
navToolbar.insertItem("smxtra-button", null, null, false);
document.persist("nav-bar", "currentset");

Still didn't persist.

Tried

Code: Select all

var currentset = document.getElementById("nav-bar").currentSet;
currentset=currentset + ",smxtra-button";
document.getElementById("nav-bar").setAttribute("currentset",currentset);   //not needed I suppose
document.getElementById("nav-bar").currentSet = currentset;
document.persist("nav-bar","currentset");

This inserted and persisted, but screwed up firefox (address bar didn't work, about:config didn't work and probably some other stuff).

Any ideas?
asqueella
Posts: 4019
Joined: November 16th, 2003, 3:05 am
Location: Russia, Moscow

Post by asqueella »

ok, Sephirot's variant was better, it should work. Try with a clean profile and if it doesn't work tell me what is in your localstore.rdf in profile (resource with uri chrome://browser/content/browser.xul#nav-bar)

Code: Select all

var navbar = document.getElementById("nav-bar");
var newset = navbar.currentSet + ",your-button-id";
navbar.currentSet = newset;
navbar.setAttribute("currentset", newset );
document.persist("nav-bar", "currentset");


edit: changed code
User avatar
TheBaker
Posts: 193
Joined: October 20th, 2004, 9:20 am

Post by TheBaker »

Ok, I started a fresh profile, installed my extension, restarted. The button appeared on the toolbar like it should, but the still address bar wouldn't work (all the other buttons on the toolbar did, but the addressbar was blank and didn't change when i went to sites (via bookmarks, because the address bar wasn't working). It wouldn't allow me to type in and click go either. Which means I couldn't enter the URL you gave me. But you mentioned that it was called localstore.rdf, so I'm assuming you meant the file localstore.rdf that's in my profile directory, which contained:

Code: Select all

<?xml version="1.0"?>
<RDF:RDF xmlns:NC="http://home.netscape.com/NC-rdf#"
         xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <RDF:Description RDF:about="chrome://browser/content/bookmarks/bookmarksPanel.xul">
    <NC:persist RDF:resource="chrome://browser/content/bookmarks/bookmarksPanel.xul#bookmarks-view"/>
  </RDF:Description>
  <RDF:Description RDF:about="chrome://browser/content/browser.xul#main-window"
                   width="994"
                   height="984"
                   screenX="4"
                   screenY="4"
                   sizemode="normal" />
  <RDF:Description RDF:about="chrome://browser/content/browser.xul">
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#main-window"/>
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#sidebar-box"/>
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#sidebar-title"/>
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#nav-bar"/>
  </RDF:Description>
  <RDF:Description RDF:about="chrome://browser/content/browser.xul#sidebar-box"
                   sidebarcommand=""
                   width=""
                   src="" />
  <RDF:Description RDF:about="chrome://browser/content/browser.xul#nav-bar"
                   currentset="back-button,forward-button,reload-button,stop-button,home-button,urlbar-container,go-container,search-container,smxtra-button" />
  <RDF:Description RDF:about="chrome://browser/content/bookmarks/bookmarksPanel.xul#bookmarks-view"
                   colinfo=" col:Name?width=&amp;hidden=&amp;ordinal=1" />
  <RDF:Description RDF:about="chrome://mozapps/content/extensions/extensions.xul?type=extensions">
    <NC:persist RDF:resource="chrome://mozapps/content/extensions/extensions.xul?type=extensions#extensionsManager"/>
  </RDF:Description>
  <RDF:Description RDF:about="chrome://mozapps/content/extensions/extensions.xul?type=extensions#extensionsManager"
                   width="400"
                   height="300" />
</RDF:RDF>


Hope that's what you wanted.
asqueella
Posts: 4019
Joined: November 16th, 2003, 3:05 am
Location: Russia, Moscow

Post by asqueella »

Looks like localstore is ok (tried it on my pc and it worked without a problem). Are you sure it's not your startup code? Can you post XPI?
Post Reply