CodeExplorer - robmcmullen/peppy GitHub Wiki
The Code Explorer is a minor mode (that can also be used in a springtab) that displays a hierarchy based on the current major mode. The hierarchy is designed to be automatically determined based on information Scintilla uses to create the code folding. However, it can be customized if Scintilla doesn't create folding for a major mode.
The code for the minor mode is in [source:trunk/peppy/plugins/code_explorer.py]; basically it's a wx.TreeCtrl that has a few additional methods to populate the data.
The replaceChildren() method is the workhorse of the minor mode. It is called by update() when the tree is initially populated (either way the code explorer is used -- minor mode or springtab), and whenever the folding state is changed. The folding state gets modified by Scintilla itself and then propagated back up to this code via a pubsub call fold_changed.
replaceChildren() walks the current state of the tree and replaces, adds, or removes items from the displayed state of the tree based on the updated folding information.
The folding information used to populate the tree is determined based on Stani Michiels fold explorer code in [source:trunk/peppy/lib/foldexplorer.py] that he posted to the pyxides mailing list way back in 2007. It walks the scintilla folding information and creates a tree of nodes including the starting line of the current fold block, the ending line, the folding level, and the text of the first line of the folding block.