opendir has moved servers and i cant be assed to reconfigure the clusterfuck that is Histoire, enjoy the new look!

if you're missing any directory headers or footers then try with these: header / footer

Compona SyntaxBox

 

Compona SyntaxBox
for Microsoft .NET Windows forms

 

Developer guide

 

 

 

This guide provides information for Compona SyntaxBoxTM
 

 

 

 

 

 

 


March 2003

 

Nordic Compona Solutions

http://www.Compona.com

mailto:[email protected]

 

 

 


This document currently only includes the most common tasks.
More samples will be included later.

1.    SyntaxDocument 2

SyntaxDocument 2

Set and Get text 3

Get / Insert / Delete text ranges. 3

Applying a Language/Syntax. 5

Undo Actions. 6

Rows. 8

Printing / Print Preview. 9

HTML Export 10

2.    SyntaxBoxControl 11

SyntaxBoxControl 11

Code Completion / Autolists. 11

Method Info / InfoTips. 12

Find / Replace Dialog. 13

GoTo Line Dialog. 15

Keyboard Actions (Shortcuts) 16

Gutter Margin. 18

Document 19

3.    Caret 20

Caret 20

Placing the caret 20

4.    Selection  23

Selection. 23

 

 

 


 

1. SyntaxDocument

SyntaxDocument

The SyntaxDocument is a powerfull text parsing component  , with capability to highlight words and fold source code/text.

The SyntaxDocument can be used in various scenarios eg:

·        Together with the SyntaxBox to create a powerfull text editor .

·        As a standalone component in a website to allow realtime html export of highlighted and folded code to web pages.

·        Pretty printing , the SyntaxDocument can be used with a print preview or print dialog.

·        Code analysis , the SyntaxDocument is fully aware of what kind of code sections all parts of a text belongs to , it can tell you if a word is inside a comment , code or inside a string etc.

Set and Get text

 

This section shows how to assign a text to a SyntaxDocument.

 

Property

Description

Text 

Gets or Sets the text of the SyntaxDocument.

Lines[ ]

Gets or Sets the rows (string array) of the SyntaxDocument.

 

C# sample – Set Document Text

//Set the text of the document
Compona.SourceCode.SyntaxDocument MyDoc=MySyntaxBox.Document;
MyDoc.Text="hello world";

VB.NET sample– Set Document Text

'Set the text of the document
Dim MyDoc As Compona.SourceCode.SyntaxDocument = MySyntaxBox.Document
MyDoc.Text="hello world"

 


 

Get / Insert / Delete text ranges


This section shows how to Insert , Delete and Get a range of text from a SyntaxDocument.

Method

Description

InsertText (string,int,int,bool)

Inserts a text at a given position in the document

Param:StoreUndo determines if the action should be stored on the Undo Stack

DeleteRange(TextRange,bool)

Deletes a range of text from the document

Param:StoreUndo determines if the action should be stored on the Undo Stack

GetRange(TextRange)

Gets the content of a given TextRange in the document.


 

C# sample – Insert Text

//Insert Hello World at col 3 , row 10

//and store the action on the undo stack

MySyntaxBox.Document.InsertText ("Hello World",3,10,true);

 

VB.NET sample – Insert Text

'Insert Hello World at col 3 , row 10

'and store the action on the undo stack

MySyntaxBox.Document.InsertText ("Hello World",3,10,True)

 

 


 

C# sample – Delete Range

//delete from column 10 ,row 10 to column 20 row 23

//and store the action on the undo stack

TextRange tr          =new TextRange ();

tr.FirstRow                      =10;

tr.FirstColumn        =10;

tr.LastRow            =23;

tr.LastColumn         =20;

MySyntaxBox.Document.DeleteRange (tr,true);

 

VB.NET sample – Delete Range

'delete from column 10 ,row 10 to column 20 row 23

'and store the action on the undo stack

Dim tr As TextRange =new TextRange ()

tr.FirstRow                      =10

tr.FirstColumn        =10

tr.LastRow            =23

tr.LastColumn         =20

MySyntaxBox.Document.DeleteRange (tr,True)

 

C# sample – Get Range

//get text from column 10 ,row 10 to column 20 row 23

TextRange tr          =new TextRange ();

tr.FirstRow                      =10;

tr.FirstColumn        =10;

tr.LastRow            =23;

tr.LastColumn         =20;

string text=sBox.Document.GetRange (tr);

 

VB.NET sample – Get Range

'get text from column 10 ,row 10 to column 20 row 23

Dim tr As TextRange =new TextRange ()

tr.FirstRow                      =10

tr.FirstColumn        =10

tr.LastRow            =23

tr.LastColumn         =20

Dim text As String =sBox.Document.GetRange (tr)

 

 

 

Applying a Language/Syntax

 

There are multiple ways of assigning a syntax to a SyntaxDocument.

You can either set the path of a syntaxfile (.syn file) in the SyntaxDocument.SyntaxFile.

Or , You can create a syntax via code and apply the syntax directly to the parser.

In this section we will only use the syntaxfile approach.
See the “DynSyntax” sample for information on how to build a language via code.

 

Property

Description

SyntaxFile 

Gets or Sets the FileName of the SyntaxFile to use.

 

C# sample – Apply Syntax

//Set the text of the document

Compona.SourceCode.SyntaxDocument MyDoc=MySyntaxBox.Document;

MyDoc.SyntaxFile="C#.syn";
MyDoc.Text="public const int ABC=123;";

 

VB.NET sample – Apply Sytnax

'Set the text of the document

Dim MyDoc As Compona.SourceCode.SyntaxDocument = MySyntaxBox.Document

MyDoc.SyntaxFile ="VB6.syn"
MyDoc.Text="Public Const ABC=123"

 

 


 

Undo Actions

This Section shows how to group multiple text edit actions into a single undo action before it is placed on the Undo Stack.

 

Method

Description

StartUndoCapture()

Puts the SyntaxDocument in Capture mode , all edit actions are pushed to a temporairy UndoActionGroup

EndUndoCapture()

Terminates Capture mode and pushes the temporairy UndoActionGroup onto the UndoStack.

 

C# sample – Undo Action Grouping

//Group multiple edit actions

MySyntaxBox.Document.StartUndoCapture ();

MySyntaxBox.Document.InsertText("hello1",10,10,true);

MySyntaxBox.Document.InsertText("hello2",10,13,true);

MySyntaxBox.Document.InsertText("hello3",10,13,true);
MySyntaxBox.Document.EndUndoCapture ();

VB.NET sample – Undo Action Grouping

'Group multiple edit actions

MySyntaxBox.Document.StartUndoCapture ()

MySyntaxBox.Document.InsertText("hello1",10,10,True)

MySyntaxBox.Document.InsertText("hello2",10,13,True)

MySyntaxBox.Document.InsertText("hello3",10,13,True)
MySyntaxBox.Document.EndUndoCapture ()

 

 


 

Rows

This Section shows how to access a specific row in the SyntaxDocument.

 

C# sample – Print a SyntaxDocument

//get row #11 (document is 0 based)

Row row = sBox.Document[10];

//make the row bookmarked

row.Bookmarked =true;

//set a breakpoint on the row

row.Breakpoint =true;

//apply a new text to the row...

row.Text ="this row is both bookmarked and has a breakpoint";         

VB.NET sample – Print a SyntaxDocument

'get row #11 (document is 0 based)

Dim row As Row = sBox.Document(10)

'make the row bookmarked

row.Bookmarked =True

'set a breakpoint on the row

row.Breakpoint =True

'apply a new text to the row...

row.Text ="this row is both bookmarked and has a breakpoint"

 




 

Printing / Print Preview

This Section shows how to print and print preview a SyntaxDocument.

 

C# sample – Print a SyntaxDocument

//Print a document

Compona.SourceCode.SourceCodePrintDocument pd;

pd=new Compona.SourceCode.SourceCodePrintDocument (MySyntaxBox.Document);

PrintDialog1.Document = pd;

if (PrintDialog1.ShowDialog (this)==DialogResult.OK)

           pd.Print ();                    

VB.NET sample – Print a SyntaxDocument

' Print a document

Dim pd As Compona.SourceCode.SourceCodePrintDocument
pd=New Compona.SourceCode.SourceCodePrintDocument (MySyntaxBox.Document)

PrintDialog1.Document = pd

If PrintDialog1.ShowDialog (this)=DialogResult.OK Then
           pd.Print ()
End If




 

C# sample – Print Preview a SyntaxDocument

//Show a print preview dialog

Compona.SourceCode.SourceCodePrintDocument pd;

pd=new Compona.SourceCode.SourceCodePrintDocument (MySyntaxBox.Document);

PrintPreviewDialog1.Document = pd;

PrintPreviewDialog1.ShowDialog ();                   

VB.NET sample – Print Preview a SyntaxDocument

'Show a print preview dialog

Dim pd As Compona.SourceCode.SourceCodePrintDocument
pd=New Compona.SourceCode.SourceCodePrintDocument (MySyntaxBox.Document)

PrintPreviewDialog1.Document = pd

PrintPreviewDialog1.ShowDialog ()

 

HTML Export

 

C# sample – Export SyntaxDocument to HTML

//Export document to html and write it

//to output buffer (asp.net)

Compona.SourceCode.SyntaxDocumentExporers.HTMLExporter htmlx=new Compona.SourceCode.SyntaxDocumentExporers.HTMLExporter();

string html=htmlx.Export (MySyntaxBox,"");

Response.Write(html);           

VB.NET sample – Export SyntaxDocument to HTML

'Export document to html and write it

'to output buffer (asp.net)

Dim htmlx As New  Compona.SourceCode.SyntaxDocumentExporers.HTMLExporter()


Dim html As String
html=htmlx.Export (MySyntaxBox,"")

Response.Write(html)


2. SyntaxBoxControl

SyntaxBoxControl

Code Completion / Autolists

 

Property

Description

.AutoList_Icons 

Get or Sets the ImageList to use in the AutoList.

.AutoList_Visible

Gets or Sets if the AutoList is visible.

 

Method

Description

AutoList_Clear()

Clears the content of the AutoList

AutoList_BeginLoad()

Disables drawing and Prepares the AutoList to load data.

AutoList_Add(string,int)

Adds an item to the AutoList.

AutoList_EndLoad()

Auto sizes and resumes drawing of the AutoList

 

C# sample – Show AutoList

//Attach an ImageList

//And fill the AutoList with items

MySyntaxBox.AutoList_Icons=MyImageList;

MySyntaxBox.AutoList_Clear();

MySyntaxBox.AutoList_BeginLoad();

MySyntaxBox.AutoList_Add("Func1",1);

MySyntaxBox.AutoList_Add("Func2",2);

MySyntaxBox.AutoList_Add("Func3",3);

MySyntaxBox.AutoList_Add("Func4",4);

MySyntaxBox.AutoList_EndLoad();

MySyntaxBox.AutoList_Visible=true;

VB.NET sample – Show InfoTip

'Attach an ImageList

'And fill the AutoList with items

MySyntaxBox.AutoList_Icons=MyImageList

MySyntaxBox.AutoList_Clear()

MySyntaxBox.AutoList_BeginLoad()

MySyntaxBox.AutoList_Add("Func1",1)

MySyntaxBox.AutoList_Add("Func2",2)

MySyntaxBox.AutoList_Add("Func3",3)

MySyntaxBox.AutoList_Add("Func4",4)

MySyntaxBox.AutoList_EndLoad()

MySyntaxBox.AutoList_Visible=True



Method Info / InfoTips

 

Property

Description

InfoTip_Text 

Gets or Sets the text of the InfoTip.

InfoTip_Image

Gets or Sets the image of the InfoTip.

InfoTip_Count

Gets or Sets the number of overloads to show in the InfoTip.

InfoTip_Visible

Gets or Sets if the InfoTip is visible.

 

C# sample – Show InfoTip


//Display a formatted string

//in the InfoTip

MySyntaxBox.InfoTip_Text="Hello <b>World!</b>";

MySyntaxBox.InfoTip_Count=0;       //0 overloads

MySyntaxBox.InfoTip_Image=null; //no image

MySyntaxBox.InfoTip_Visible=true;

VB.NET sample – Show InfoTip


'Display a formatted string

'in the InfoTip

MySyntaxBox.InfoTip_Text="Hello <b>World!</b>"

MySyntaxBox.InfoTip_Count=0           '0 overloads

MySyntaxBox.InfoTip_Image=Nothing  'no image

MySyntaxBox.InfoTip_Visible=true

 

 

 

 


 

Find / Replace Dialog

 

Method

Description

ShowFind ()

Shows the Find dialog.

ShowReplace()

Sgows the Replace dialog.

FindNext()

Selects the next occurance of the pattern used in the Find dialog.

 

Key(s)

Description

CTRL + F

Shows the Find dialog.

CRTL + H

Shows the Replace dialog.

F3

Selects the next occurance of the pattern used in the Find dialog.

 

C# sample – Find Next


//Find next

//(based on selections made in the find dialog)

MySyntaxBox.FindNext();

VB.NET sample – Find Next


'Find next

'(based on selections made in the find dialog)

MySyntaxBox.FindNext()


 

C# sample – Show Find


//Show the Find dialog

MySyntaxBox.ShowFind();

VB.NET sample – Show Find


'Show the Find dialog

MySyntaxBox.ShowFind()



C# sample – Show Replace


//Show the Replace dialog

MySyntaxBox.ShowReplace();

VB.NET sample – Show Replace


'Show the Replace dialog

MySyntaxBox.ShowReplace ()








 

GoTo Line Dialog

 

Method

Description

ShowGotoLine()

Shows the Goto Line dialog.

 

Key(s)

Description

CTRL + G

Shows the Goto Line dialog.




C# sample – Show GotoLine


//Show the GotoLine dialog

MySyntaxBox. ShowGotoLine ();

VB.NET sample – Show GotoLine


'Show the GotoLine dialog

MySyntaxBox.ShowGotoLine ()



 


 

Keyboard Actions (Shortcuts)

 

Full list of predefined keyboard shortcuts:

 

Key(s)

Description

CTRL + Z

Undo

CTRL + Y

Redo.

CTRL + G

Shows the Goto Line dialog.

CTRL + F

Shows the Find dialog.

CTRL + H

Shows the Replace dialog.

CTRL + C

Copy current selection to clipboard.

CTRL + X

Cut current selection to clipboard.

CTRL + V

Paste clipboard content to current Caret position.

CTRL + A

Select all.

ESC

Clear selection.

F2

Goto next bookmark.

SHIFT + F2

Goto previous bookmark.

CRTL + F2

Toggle bookmark

F3

Find next.

TAB

Indent selection.

SHIFT + TAB

Outdent selection.

 




 

C# sample – Add a keyboard action

//Create a shortcut for the F5 key (no  shift,ctrl,alt)

//to the "SomeMethod" method

ActionDelegate ad = new ActionDelegate(this.SomeMethod);

KeyboardAction ka =new KeyboardAction (Keys.F5,false,false,false,false,ad);

MySyntaxBox.KeyboadActions.Add (ka);

VB.NET sample – Add a keyboard action

'Create a shortcut for the F5 key (no  shift,ctrl,alt)

'to the "SomeMethod" method

Dim ad As New ActionDelegate(Me.SomeMethod)

Dim ka As New KeyboardAction(Keys.F5, False, False, False, False, ad)

MySyntaxBox.KeyboadActions.Add(ka)



C# sample – Remove a keyboard action

//Remove shortcut assigned to CTRL + Z

sBox.KeyboadActions.Remove (Keys.Z,false,true,false);

VB.NET sample – Remove a keyboard action

'Remove shortcut assigned to CTRL + Z

MySyntaxBox.KeyboadActions.Remove (Keys.Z,False,True,False)



Gutter Margin

 

Property

Description

GutterMarginWidth

Gets or Sets the width of the Gutter margin in pixels.

GutterMarginColor

Gets or Sets the Color of the Gutter margin.

GutterMarginBorderColor

Gets or Sets the Color of the Gutter margin border.

GutterIcons

ImageList containing images that can be displayed in the gutter margin.

ShowGutterMargin

Gets or Sets if the Gutter margin is visible.

 

C# sample – Using Gutter icons

private void MySyntaxBox_RowMouseDown(object sender, Compona.Windows.Forms.SyntaxBox.RowMouseEventArgs e)

{

           //did the user click the gutter area?

           if (e.Area == RowArea.GutterArea)

           {

                      //is image "3" visible on the clicked rows

                      //gutter margin?

                      if (e.Row.Images.Contains (3))

                      {

                                 //yes , so we remove it

                                 e.Row.Images.Remove (3);

                      }

                      else

                      {

                                 //no , lets add it--

                                 e.Row.Images.Add (3);

                      }

                      //redraw the screen

                      sBox.Refresh ();

           }

}

VB.NET sample - Using Gutter icons





 

 

 

 

Document

 

Property

Description

Document

Gets or Sets the SyntaxDocument in a SyntaxBoxControl

 

C# sample – Attach a SyntaxDocument

//attach a new document to a syntaxbox
SyntaxDocument Doc=new SyntaxDocument ();
Doc.Text ="hello world";
MySyntaxBox.Document = Doc;

VB.NET sample – Attach a SyntaxDocument

'attach a new document to a syntaxbox
Dim Doc As SyntaxDocument = New SyntaxDocument();
Doc.Text ="hello world"
MySyntaxBox.Document = Doc



 

 

 


3. Caret

Caret

 

Placing the caret

 

Property

Description

Position

Gets or Sets the position of the Caret.

LogicalPosition

Gets or Sets the position of the Caret.
Logical Position treats “TAB” charactes as 1-n “SPACE” characters , depending on the location of the tabs.

 

Method

Description

MoveAbsoluteEnd (bool)

Places the Caret at the last char of the document.

Param:Select determines if a selection form the selection start to the new position should be made:

MoveAbsoluteHome (bool)

Places the Caret at position 0,0

Param:Select determines if a selection form the selection start to the new position should be made:

MoveDown(bool)

Moves the Caret DOWN 1 row.

Param:Select determines if a selection form the selection start to the new position should be made:

MoveDown(int,bool)

Moves the Caret DOWN n rows.

Param:Select determines if a selection form the selection start to the new position should be made:

MoveEnd(bool)

Moves the Caret to the last column of the current row.

Param:Select determines if a selection form the selection start to the new position should be made:

MoveHome(bool)

Moves the Caret to either the first non-whitespace character of the row or column 0 on that row, depending on the current position.

Param:Select determines if a selection form the selection start to the new position should be made:

MoveLeft(bool)

Moves the Caret LEFT by one column , if start of line is reached the caret is placed at the end of the previous row.

Param:Select determines if a selection form the selection start to the new position should be made:

MoveRight(bool)

Moves the Caret RIGHT by one column , if end of line is reached the caret moves to the start of the next row.

Param:Select determines if a selection form the selection start to the new position should be made:

MoveUp(bool)

Moves the Caret UP 1 row.

Param:Select determines if a selection form the selection start to the new position should be made:

MoveUp(int,bool)

Moves the Caret UP n rows.

Param:Select determines if a selection form the selection start to the new position should be made:

 

C# sample – Move Caret

//move the Caret one step right and make a

//selection from selection start to the new position

MySyntaxBox.Caret.MoveRight (true);

VB.NET sample – Move Caret

'move the Caret one step right and make a

'selection from selection start to the new position

MySyntaxBox.Caret.MoveRight (True)

 

 

 


 

4. Selection

Selection



Property

Description

Bounds

Gets or Sets bounds of the selection

IsValid

Gets if the selection covers 1 char or more.

LogicalBounds

Get normalized bounds .

SelStart is always less than SelEnd.

LogicalSelStart

Get normalized SelStart

SelStart is always less than SelEnd.

SelEnd

Index in the text where the selection ends.

SelLength

Length of the selection.

SelStart

Index in the text where the selection starts.

Text

The selected text.

 

Method

Description

Indent()

Indents the selected text.

Outdent()

Outdents the selected text.

DeleteSelection()

Deletes the selected text.

ClearSelection()

Clears the selection.

MakeSelection()

Creates a selection from the current selection start to the current Caret position.

SelectAll()

Select everything in the document.