Is there a way reset persist data?

Talk about add-ons and extension development.
Post Reply
User avatar
Vano
Posts: 403
Joined: December 26th, 2007, 8:21 pm

Is there a way reset persist data?

Post by Vano »

Hello.

Is there a way reset/remove persist data (not "persist" attribute) for a specific XUL element?

For example I have this:

Code: Select all

<textbox id="test" value="12345" persist="value"/>

Every time user changes text in this textbox it will be stored in localstore.rdf. Is there a way reset to default "12345" without storing that default value elsewhere?

Thank you.
max1million
Posts: 2810
Joined: November 15th, 2004, 5:03 am

Re: Is there a way reset persist data?

Post by max1million »

persist=""
in xul, or in javascript
document.getElementById("test").setAttribute("persist","")
User avatar
Vano
Posts: 403
Joined: December 26th, 2007, 8:21 pm

Re: Is there a way reset persist data?

Post by Vano »

Oh, I forgot to mention, that I need this without reinitializing XUL, meaning without reopening window...
User avatar
Vano
Posts: 403
Joined: December 26th, 2007, 8:21 pm

Re: Is there a way reset persist data?

Post by Vano »

Ok, I got a little problem.
I have a <tabbox> with persist="selectedIndex"
Now I would like to remove persist attribute all together, not just on demand, but from .xul file so it would display first tab by default.

After persist="selectedIndex" was removed it still displays the last tab I had opened before the change, and no matter which tab I select now it still opens that tab.
So, I went and added empty persist="", but it did not remove the selectedIndex from localstore.rdf and still shows another tab by default no matter what.
Even when I added selectedIndex="0" it didn't do anything, it still uses old persist value.
Any other solutions?

Thank you.
max1million
Posts: 2810
Joined: November 15th, 2004, 5:03 am

Re: Is there a way reset persist data?

Post by max1million »

maybe use persist= "space or tab" or "notanatribute" (so it has something)

set the persist="selectedIndex" open and close on correct tab then remove it while closed

dump localstore start over or edit manually while closed

best i got
max1million
Posts: 2810
Joined: November 15th, 2004, 5:03 am

Re: Is there a way reset persist data?

Post by max1million »

Change the id of the element and update anything else that refers to it, for the new id. It may not remove the store but will make it irrelevant. Mozilla does stuff like that all the time.
User avatar
Vano
Posts: 403
Joined: December 26th, 2007, 8:21 pm

Re: Is there a way reset persist data?

Post by Vano »

Very old topic and just now I found a solution.
As of FF34 we can use this component to manage persist data:

Code: Select all

Cc["@mozilla.org/xul/xulstore;1"].getService(Ci.nsIXULStore);
This component provides the following functions:

Code: Select all

hasValue(docURI, id, attr)
getValue(docURI, id, attr)
setValue(docURI, id, attr, value)
removeValue(docURI, id, attr)
getIDsEnumerator(docURI)
getAttributeEnumerator(docURI, id)
Where docURI is window's uri, i.e. chrome://myextension/content/example.xul
id is element's ID
attr is attribute name
(http://wbamberg.github.io/idl-reference ... Store.html)

For example for my original inquiry this could be used:

Code: Select all

var XULStore = Cc["@mozilla.org/xul/xulstore;1"].getService(Ci.nsIXULStore);
//var uri = "chrome://myextension/content/example.xul";
var uri = window.location.href;
var id = "test";

XULStore.removeValue(uri, id, "value");

To list all stored perist data in current window you can use:

Code: Select all

var XULStore = Cc["@mozilla.org/xul/xulstore;1"].getService(Ci.nsIXULStore);
var uri = window.location.href;
var enumerator = XULStore.getIDsEnumerator(uri);
while(enumerator.hasMore())
{
	let id = enumerator.getNext();
	let attrEnum = XULStore.getAttributeEnumerator(uri, id);
	while(attrEnum.hasMore())
	{
		let attr = attrEnum.getNext();
		let val = XULStore.getValue(uri, id, attr);
		dump(id + ": " + attr + " = " + val, 1);
	}
}
Noitidart
Posts: 1168
Joined: September 16th, 2007, 8:01 am

Re: Is there a way reset persist data?

Post by Noitidart »

Wow fantastic solution thanks so much for sharing this nugget of gold!
Post Reply