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
for Microsoft .NET Windows forms
Developer guide
This guide provides information for Compona
SyntaxBoxTM
March
2003
Nordic Compona
Solutions
http://www.Compona.com
This document currently only includes the most
common tasks.
More samples will be included later.
Get / Insert /
Delete text ranges
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.
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 |
VB.NET sample Set Document Text |
'Set
the text of the document |
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 |
DeleteRange(TextRange,bool) |
Deletes a range of text from the document |
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) |
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"; |
VB.NET sample Apply Sytnax |
'Set the text of the
document Dim MyDoc As Compona.SourceCode.SyntaxDocument
= MySyntaxBox.Document MyDoc.SyntaxFile ="VB6.syn" |
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); |
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) |
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" |
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 PrintDialog1.Document
= pd If PrintDialog1.ShowDialog
(this)=DialogResult.OK Then |
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 PrintPreviewDialog1.Document = pd PrintPreviewDialog1.ShowDialog () |
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()
Response.Write(html) |
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 |
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. |
//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 |
'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 |
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 |
//(based on selections made
in the find dialog) MySyntaxBox.FindNext(); |
VB.NET sample Find Next |
'(based on selections made
in the find dialog) MySyntaxBox.FindNext() |
C# sample Show Find |
MySyntaxBox.ShowFind(); |
VB.NET sample Show Find |
MySyntaxBox.ShowFind() |
C# sample Show Replace |
MySyntaxBox.ShowReplace(); |
VB.NET sample Show Replace |
MySyntaxBox.ShowReplace () |
Method |
Description |
ShowGotoLine() |
Shows the Goto Line dialog. |
Key(s) |
Description |
CTRL + G |
Shows the Goto Line dialog. |
C# sample Show GotoLine |
MySyntaxBox. ShowGotoLine (); |
VB.NET sample Show GotoLine |
MySyntaxBox.ShowGotoLine () |
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) |
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 |
|
Property |
Description |
Document |
Gets or Sets the SyntaxDocument in a SyntaxBoxControl |
C# sample Attach a SyntaxDocument |
//attach
a new document to a syntaxbox |
VB.NET sample Attach a
SyntaxDocument |
'attach
a new document to a syntaxbox |
Property |
Description |
Position |
Gets or Sets the position of the Caret. |
LogicalPosition |
Gets or Sets the position of the Caret. |
Method |
Description |
MoveAbsoluteEnd (bool) |
Places the Caret at the last char of the document. |
MoveAbsoluteHome (bool) |
Places the Caret at position 0,0 |
MoveDown(bool) |
Moves the Caret DOWN 1 row. |
MoveDown(int,bool) |
Moves the Caret DOWN n rows. |
MoveEnd(bool) |
Moves the Caret to the last column of the current row. |
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. |
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. |
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. |
MoveUp(bool) |
Moves the Caret UP 1 row. |
MoveUp(int,bool) |
Moves the Caret UP n rows. |
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) |
Property |
Description |
Bounds |
Gets or Sets bounds of the selection |
IsValid |
Gets if the selection covers 1 char or more. |
LogicalBounds |
Get normalized bounds . |
LogicalSelStart |
Get normalized SelStart |
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. |