Collapsing all regions

SyntaxEditor for Windows Forms Forum

Posted 10 months ago by YEVGENIY A GRIGORYEV
Version: 23.1.0
Avatar

Dear Actipro, is there a shortcut or a way to implement a shortcut to "collapse all regions" for the .net languages add-on?

Similar to Ctl-M+O chord in Visual Studio?

Thank you!

[Modified 10 months ago]

Comments (9)

Posted 10 months ago by YEVGENIY A GRIGORYEV
Avatar

Apologies, this should be moved to WinForms section of the control. Thank you.

Posted 10 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

We have a built-in EditorCommands.CollapseToDefinitions command, but it's not automatically bound to a hotkey.  You could add a key binding with code like this:

editor.InputBindings.Add(new CommandLink(EditorCommands.CollapseToDefinitions, Keys.O, ModifierKeys.Control | ModifierKeys.Shift));

Or if you are in WPF, it's:

editor.InputBindings.Add(new KeyBinding(EditorCommands.CollapseToDefinitions, Key.O, ModifierKeys.Control | ModifierKeys.Shift));


Actipro Software Support

Posted 10 months ago by YEVGENIY A GRIGORYEV
Avatar

Thank you!

Posted 10 months ago by YEVGENIY A GRIGORYEV
Avatar

Hi,

I have a follow-up question:

this command seems to be able to only expand a collapsed #region at the cursor, but not collapse, and it does not affect multiple regions.

We are looking to be able to collapse all #regions in large method bodies like the Ctl-M+O chord in Visual Studio.

Possibly we are doing something wrong. We are in WinForms. I appreciate any comments. Thank you!

Posted 10 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Our implementation of the CollapseToDefinitions edit action does not collapse region markers.  We modeled our command after the default Visual Studio behavior which also does not collapse region markers. Unfortunately, there is not currently a way to change the default behavior.

You could implement a custom edit action to achieve exactly what you want, though. You can find details on that here:

https://www.actiprosoftware.com/docs/controls/winforms/syntaxeditor/user-interface/input-output/edit-actions

As part of your action you could call our pre-defined CollapseToDefinitions edit action and then manually iterate and collapse the region nodes. You can find more details about outlining nodes here:

https://www.actiprosoftware.com/docs/controls/winforms/syntaxeditor/user-interface/outlining/index


Actipro Software Support

Posted 10 months ago by YEVGENIY A GRIGORYEV
Avatar

Thank you. Understood about needing to iterate.

On the CollapseToDefinitions edit action, what is the expected result, as opposed to ToggleOutliningExpansion (which we are currently using already)? It seems to be able to expand outlining collapsed by ToggleOutliningExpansion or by clicking the "-" in outlining, but nothing else. We are using C# code inside the editor.

[Modified 10 months ago]

Answer - Posted 10 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

The CollapseToDefinitions edit action will collapse any node whose definition has defined "IsImplementation = true".  You can find more about that property discussed here:

https://www.actiprosoftware.com/docs/controls/winforms/syntaxeditor/user-interface/outlining/outlining-nodes#is-implementation

For the C# Language Add-on, the outlining node definitions with that property (and which will be collapsed) are:

  • External alias directive section
  • Using directive section
  • Constructor declaration
  • Event declaration
  • Method declaration
  • Operator declaration
  • Property declaration
  • Accessor declaration

The CollapseToDefinition action always collapses those nodes and should not expand anything.  The ToggleOutliningExpansion action will find the outlining node most closely associated with the caret location and toggle it between expanded/collapsed.


Actipro Software Support

Posted 10 months ago by YEVGENIY A GRIGORYEV
Avatar

Thank you. This makes sense. Since in our context we are ony exposing method bodies to the editor, lack of results makes sense. But it does appear to expand, I have bound it to Ctrl-O and debugged it to send the action, expansion does take place. Possibly this a bug? Thank you for all the comments.

Posted 10 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

I tried running our Sample Browser application and the SDI Code Editor sample (which defaults to C# Language Add-on).  If I select "Outlining > Collapse to Definitions" (which executes the same edit action we've been talking about), it collapses as expected. If I execute the same action again, nothing happens.  I'm not sure why you are seeing a node expand in your scenario.

If this is something you would like us to look into, could you please try to reproduce in our SDI Code Editor sample or provide us with simple sample project to reproduce the behavior? If you need to send a sample project, please remove any BIN/OBJ folders before zipping and send to our support email with a link back to this thread for reference.


Actipro Software Support

The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.