Posted 20 years ago by Carl Schneider - Boca Raton, Florida
Avatar
I've looked all over for how to auto indent. I see the reference to the editor.smartindent event but it contains no code for doing the indent.

The comment in the event statement reads....
' By default, SyntaxEditor initializes the e.IndentAmount properly for Block formatting.
' You can change e.IndentAmount to provide "smart" indenting based on language context.

I'm not sure what this means since the editor isn't autoindenting.

I see that the event arg accepts an indentAmount value and that setting it works. I also found the OutliningNode class and see that is exposes a nesting depth. So I'm guessing that it's just a matter of finding the object that exposes my current outline and setting indentcount to the vaule of the current outline's nestingdepth.

For the life of me I can't find out how to obtain the current outline object.

Can anybody enlighten me on this one?

Thanks

Carl

Comments (4)

Posted 20 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
For the SmartIndent property that fires when you press the ENTER key. You can use it to tell how many tabs to indent the next line by setting e.IndentAmount to something like 4 to indicate 4 tabs. By default SyntaxEditor calculates the indent amount based on the tab stop on the previous line.

What you can do is get a TextStream at the current caret location then move backwards and examine each Token. If for instance you are writing this for C# and you see a Token representing a { character you probably want to do something like:
e.IndentAmount++;

That would bump up the indent amount by one tab stop since you are starting a scope.

We'll expose a DocumentLine.GetTabStopLevel method for the next release that will also tell you the tabstop level of a DocumentLine.

To get the current OutliningNode, do this:
OutliningNode currentNode = editor.Document.Outlining.RootNode.FindNodeRecursive(currentOffset);


Actipro Software Support

Posted 20 years ago by Carl Schneider - Boca Raton, Florida
Avatar
Ok I hate asking stupid questions but how to I get the contents of the current line in a string. I see GetCurrentWordText but I don't see how to select a range.

[ 04-23-2004: Message edited by: Carl Schneider ]
Posted 20 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
You can get any range with Document.GetSubstring().

You can also do this:
int lineIndex = editor.Document.Lines.IndexOf(offset);
string lineText = editor.Document.Lines[lineIndex].Text;


Actipro Software Support

Posted 20 years ago by Carl Schneider - Boca Raton, Florida
Avatar
Here's what I have incase somebody else wants it.....
'---------------------------------------------------------------------
Private Sub editor_SmartIndent(ByVal sender As Object, ByVal e As ActiproSoftware.SyntaxEditor.SmartIndentEventArgs) Handles editor.SmartIndent

Dim CurrentEndOffset As Integer = editor.Document.CurrentView.Selection.EndOffset
Dim CurrentStartOffset As Integer = editor.Document.CurrentView.Selection.StartOffset
editor.Document.CurrentView.Selection.MoveToLineStart()
Dim LineOffset As Integer = editor.Document.CurrentView.Selection.EndOffset
Dim LineText As String = editor.Document.GetSubstring(LineOffset, CurrentEndOffset - LineOffset)

Dim KeyWordEndOffset As Integer = LineText.IndexOf(" ")
If KeyWordEndOffset < 0 Then KeyWordEndOffset = LineText.Length

Select Case LineText.ToUpper.Substring(0, KeyWordEndOffset)
Case "NAMESPACE", "CLASS", "#REGION", "SUB", "FUNCTION", "IF", "ELSE", "FOR", "WHILE", "DO"
e.IndentAmount += 1
Case "ENDNAMESPACE", "ENDCLASS", "#ENDREGION", "ENDSUB", "ENDFUNCTION", "ENDIF", "ELSE", "NEXT", "ENDWHILE", "LOOP"

editor.Document.CurrentView.Outdent()
e.IndentAmount -= 1

End Select

editor.Document.CurrentView.Selection.StartOffset = CurrentStartOffset
editor.Document.CurrentView.Selection.EndOffset = CurrentEndOffset

End Sub
'---------------------------------------------------------------------------------

If figure this code can be done better but it shows the concept and that's where I'm at now. I would think that an "IndentPattern/OutdentPattern" section would be best implemented in the language Definition File since it seems so portable. Anywhoo, keep up the great work!

[ 04-23-2004: Message edited by: Carl Schneider ]

[ 04-23-2004: Message edited by: Carl Schneider ]
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.