How do I expand or collapse ALL outlining nodes

SyntaxEditor for Windows Forms Forum

Posted 11 years ago by Michael Dempsey - Sr. Developer, Teradata Corp
Version: 13.1.0311
Avatar

I am trying to implement the equivalent of Visual Studio's

Toggle Outlining Expansion
Toggle All Outlining

commands.

For the first one I can use:
   OutliningNode node = Document.Outlining.RootNode.FindNodeRecursive(Caret.Offset);
   if (node != null)  node.ToggleExpansion();

But I have not found an obvious way to handle 'Toggle All Outlining'.

I can loop through the children of the RootNode and toggle each ones outlining state, but that only handles the first level.
Do I really have to recursively go through every level and handle each node separately?

I was hoping there would be a method somewhere that can toggle all nodes to the specified state. (Expanded or Collapsed)

If I have to handle each node manualy is there a way to simply get all outline nodes without reguard to their heirachy?

Comments (6)

Posted 11 years ago by Justin Harrell
Avatar

We did this in a context menu in the editor here is the code to implement the menu clicks:

        protected void ExpandXmlMenu_Click(object sender, EventArgs e)
        {
            this.Document.Outlining.RootNode.ExpandDescendants();
        }

        protected void CollapseXmlMenu_Click(object sender, EventArgs e)
        {
            this.Document.Outlining.RootNode.CollapseDescendants();
        }
Posted 11 years ago by Michael Dempsey - Sr. Developer, Teradata Corp
Avatar

Yes that works if you have separate commands for Expand All and Collapse All but I was trying to handle just a 'Toggle All Outlining'.

Since the RootNode is virtual it does not have a meaningful 'Expanded' property to test so I dont see a way to use these methods to do what i want.

The only thing I can think of is to add my own property to keep track of the 'top level' state so that i can base the decision on that. (But that means trying to keep it in sync with user actions etc.)

Posted 11 years ago by Justin Harrell
Avatar

Your right I read your post too fast. I just modifed mine to behaive similar to the VS toggle all with a recursive function:

private bool AnyCollapsed(OutliningNode Node)
{
	if (!Node.Expanded)
		return true;
	foreach (OutliningNode childNode in Node)
	{
		if(AnyCollapsed(childNode))
			return true;
	}
	return false;
}

protected void CollapseXmlMenu_Click(object sender, EventArgs e)
{
	if(AnyCollapsed(this.Document.Outlining.RootNode))
		this.Document.Outlining.RootNode.ExpandDescendants();
	else
		this.Document.Outlining.RootNode.CollapseDescendants();
}

[Modified 11 years ago]

Posted 11 years ago by Michael Dempsey - Sr. Developer, Teradata Corp
Avatar

Thanks. I was hoping to avoid a recursive search but I guess we can't.

Thanks for the code.

Answer - Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Mike,

All of the VS outlining menu commands are demoed in the main SDI Editor sample.  Please check out the code in that sample's MainForm.ExecuteAppAction method.  It shows how to do what you are trying to do.


Actipro Software Support

Posted 11 years ago by Justin Harrell
Avatar

Looking at the sample it seems you toggle based on the root being expanded or that the cursor is positioned in a expanded node, this seems to be slightly different than VS where it just seems to be based on if any node is collapsed regardless of cursor position it expands all otherwise if all nodes are expanded it collapses all. Basically I would get the opposite toggle in VS2012 with the same file open from the sample depending on where my cursor was at.

My code does a single recursion to find any collapsed nodes in the document as soon as it finds the first it returns and expands all, if it finds none it collapses, this seems to be VS behaivor. Also the sample still does a recursive search twice (FindNodeRecursive) so if performance or stack depth is a concern either one will recurse.

[Modified 11 years ago]

The latest build of this product (v24.1.1) was released 26 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.