gptmayank
gptmayank

Reputation: 46

Restoring sidebar state in xul

I am creating a sidebar extension which contains a new tab button which adds a new tab containing some elements to the box contained in my sidebar using javascript with the help of document.createElement() function. Now i want to restore the new tabs added by the user while working with the extension the next time my sidebar is loaded after closing along with all the previous values filled in the textboxes. something like the session restore feature of firefox

Upvotes: 1

Views: 127

Answers (1)

Chorn
Chorn

Reputation: 49

As i understand, you are talking about tabbox elements. You actually have two different XUL documents - one redefined in overlay.xul and sidebar's xul document. I have solved exactly the same issue with sidebar data storing by the following: All javascript code is stored as main window's object using something like:

var your_javascript_module = (function () {
//your code here
})();

Put module initialization into scripts.js, reference it from overlay.xul When you open sidebar (and load, let's say sidebar.xul), you can access this object with the following code:

var your_javascript_module =window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindow).your_javascript_module;

Using this, you will have access to all of code from within sidebar.xul scope. To store taboxe's state - just create some 'storage' object within your_javascript_module and refresh sidebar.xul contents every time sidebar is getting opened.

I'm suggesting putting all javascript into overlay, as it will be always present (until FF is open of course), contrary to the sidebar's scripts that are unloaded on close. Hope this can still be useful-)

Upvotes: 0

Related Questions