Wednesday, 15 December 2010

Seems to work

That seems to work just fine. This is how it turned out:

#
#               common code for all the narrative item buttons
#               inserts an item afte the current one (if any)
#               and then inserts a corresponding node into the
#               tree view
#
                def insert_narrative_item(typ as System.Type):
#
#                       this should never be called unless we have a current
#                       narrative
#
                        assert narrative_index != -1
#
#                       get the narrative object
#
                        n as Narrative = scene.narratives[narrative_index]
#
#                       add one to the current item index so it points at
#                       the slot where the new item will be stored
#
                        item_index++
#
#                       create the item and add it to the narrative list
#
                        it = n.Add(typ(), item_index)
#
#                       insert a node into the treeview for the snippet
#
                        tree_panel.insert(narrative_index, item_index, it)

#
#               this fires if someone clicks the "+Snippet" button
#
                button_panel.snippet.Click += def(o,e):
                        insert_narrative_item(Snippet)

#
#               fires if someone hits +thumb
#
                button_panel.thumbnail.Click += def(o,e):
                        insert_narrative_item(Thumb)



I'm pleased with that. It's going to save a lot of time, (or at least a lot of copy/paste errors), but shouldn't be too hard to figure out when I have to change it.

No comments: