Undoable Canvas Listbox

Hi. I am going to write a custom listbox class based on a canvas and just wanted to get some advice on a few things:

  1. What is the best way to store listbox data?
  2. What is the best way to link the listbox data storage to the canvas?
  3. What would be the best way to manage undo/redo of listbox events such as add/remove row, drag reorder row, change contents etc?

Thanks!

Is there any reason why you could not simply add undo to a ListBox subclass ? That would save a huge amount of work.

Hi Michel. Yes, that is what I have at the moment but the listbox can only do so much and I need to be able to do things that it can’t handle, like hide/show rows by maybe setting an individual row height to 0 etc.

If you uncouple data and display, hiding a row becomes rather easy. especially since the ListBox does not have smooth scrolling, so addressing rows is rather straightforward.
Of course if you are in to have variable height rows altogether, you might as well brew your own.

Showing and hiding rows in the Xojo Listbox would not hard, after all that is basically how it handles hierarchical listboxes, as Michel said it;s a matter of how you handle your data storage.

It can’t do variable infinitely row height but I did write a subclass that allows merging cells, so rows can be multiples of the base row height.

Writing your own listbox may seem not too difficult at first glance … and for a very limited set of specific features it’s not… BUT writing a general purpose one that approaches the feature richness of the Xojo listbox is FAR from trivial.

With some ingenuity the Xojo listbox can be made to do a lot, with a lot less work then writing your own.

  • Karen

Thanks, Karen and Michel. Yes, I agree that if you uncouple the data storage and display a listbox may work.

What are your recommendations for a separate data storage and managing undo/redo system?

Data storage: depends on how much data you have. An array would be the most simple solution. A database if you got lots and lots of data.
Undo: there are a couple of undo systems around (for instance http://www.pidog.com/TheBigUndo/). Undo basically contains a stack of things you have done. Each part of the stack also knows what do do for undo. When an undo is done you pop the stack.

Thanks, Beatrix. An array would probably be sufficient for my needs. I’ll check out the Big Undo.