WPF binding to syntax tree

SyntaxEditor for WPF Forum

Posted 8 years ago by Jerome Haltom
Avatar
Bit unclear what the proper way to bind to the SyntaxEditor's AST from another WPF control is?

Basically, I want to write a treeview, that shows the XML nodes of the XML document I'm writing. I'd imagine there would be some top-level property I could simply establish a Binding to, which would have DependencyObject children of some sort. Could then build a hierarchal TreeView off of that.

Also, I want to figure out a way to bind to the currently focused node. So that I can show it's properties in a property grid.

The whole Snapshot thing is making me think that some of this isn't going to be very possible. If an entire snapshot is created for each edit, then I'm not going to be able to do this as easily as I'd hoped.

Am I right?

[Modified at 02/16/2012 08:04 PM]

Comments (3)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Jerome,

We don't have anything at the moment designed for data binding. I've added an item to our TODO list. However you don't normally want to just bind to raw AST data since there's a lot of info that is unncessary in it that users don't care about. Maybe not as much in XML, but moreso in other languages.

So we need some way to effectively filter down an AST to some other type of nodes that would be databindable for a TreeView. We're open to any design ideas you have for that sort of thing.

On a side note, the AST is rebuilt with each edit. So ideally whatever we come up with would somehow know how to make some form of incremental updates to the node tree.


Actipro Software Support

Answer - Posted 8 years ago by Boyd - Automated Software Testing Consultant / Developer, Patterson Consulting, LLC
Avatar

I did something similar to what you are describing, but did not bind directly to the AST due to the refresh issue already noted. I created my own hierarchy of objects that were derived from the AST. When the AST changed, I would attempt to match up my items with those in the AST. Then I would update, add, delete as necessary. Each entry also tracked the offsets of the element represented in the AST so that I could monitor changes in caret position and then adjust my document tree accordingly.

I don't have any sample code to offer, and this was completed over 12 months ago (so it's not fresh in my mind). I just wanted to add this comment to let you know that it certainly can be done with the current feature set of Syntax Editor.

[Modified 8 years ago]

Posted 8 years ago by Jerome Haltom
Avatar

That's pretty much the option I've come up with. I guess what I might ask then is that Actipro consider exposing such a synchronized tree them selves. I'm pretty sure implementing a tree-view of a document in progress is something nearly everybody writing a source code editor will eventually do. Having it easily available in the core API would prevent us from all writing our own.

The latest build of this product (v2019.1 build 0683) was released 14 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.