views:

79

answers:

1

Hi!

I'm new to this.

How do I store a TreeStore to a file? I can store specific values from the underlaying TreeStore through the TreeModel interface, but is there any way of "grabbing" the whole underlaying TreeStore as a value, or do I have to traverse the TreeStore, storing a row at a time?

/J

+1  A: 

You have to traverse the TreeStore yourself.

The problem is that the store doesn't have any external representations. Haskell types often have a Read and Show instances which can be used for serialization (assuming that read . show === id for that type, which it's rude for it not to be). Read and Show aren't suitable for all serialization needs (they're not particularly efficient in either time or size of serialization), but in those cases you can use Data.Binary.

Foreign data types, including GLib and Gtk types, tend not to have Read, Show or Binary instances, so you need to write your own instance, or just write a function that generates a String or a ByteString by traversing the store manually.

daf