Scintilla TextArea replacement (WIP)

BlitzMax Forums/MaxGUI Module/Scintilla TextArea replacement (WIP)

klepto2(Posted 2009) [#1]
Hi, maybe some of you remember my posted linenumbering screen in the maxide CE thread. Well why to reinvent the wheel if there are alternatives :)


Screen:



it works exactly like the Textarea gadget but also offers everything scintilla does plus a Blitzmax lexer ;)

Currently i'm in the final stage, so next week i will have a download ready :)


[Edit]
Direct Download : http://code.google.com/p/scintillabmx/downloads/list
SVN : http://scintillabmx.googlecode.com/svn/trunk/
Latest Version: Revision 9 http://scintillabmx.googlecode.com/files/ScintillaRev9.zip
[/Edit]


Ked(Posted 2009) [#2]
Looks good!

Cross-platform?


degac(Posted 2009) [#3]
From the home page of Scintilla's project I read
A free source code editing component for Win32 and GTK+
...so no cross-platform unfortunately.


See my post below, Ked pointed me to the 'truh' (...or - in another way - I need to read carefully all the text...)


Ked(Posted 2009) [#4]
From the home page of Scintilla's project I read <Insert Quote Here> ...so no cross-platform unfortunately.

Actually, I heard from Brucey that it runs on Mac also.

EDIT: Also, here:
Version 1.74 runs natively on OS X.

Also on the front page of Scintilla's project. :)


degac(Posted 2009) [#5]

Also, here:
Version 1.74 runs natively on OS X.

Also on the front page of Scintilla's project. :)


Oh!!! This is a GOOD news!
Thank you!


Ked(Posted 2009) [#6]
Glad I could help.


JoshK(Posted 2009) [#7]
It's next week now.


Grisu(Posted 2009) [#8]
Linenumbering for the default ide would be great...


Ked(Posted 2009) [#9]
It's next week now.

?


klepto2(Posted 2009) [#10]
Hi, sorry for the delay. I was on a small boat trip.

Currently it is win only. It would be really nice if it goes multiplattform but as I don't have a mac and as far as i know it only works via gtk on linux I need to find others to built it into maxgui for those plattforms.

A short status report:

Scintilla Version used: 1.79 + modified Blitzbasic Lexer to support Blitzmax
TextArea compatibility: 99% just printing isn't working at the moment
Added Event_GADGETACTION to return an event containing Scintilla Notification Data.

The code will be available next week. (Maybe via GoogleCode)

thx for the feedback :)


xlsior(Posted 2009) [#11]
Oooooooh. Interesting!


JoshK(Posted 2009) [#12]
Want.


klepto2(Posted 2009) [#13]
Hi

A first Version is now available here :

http://code.google.com/p/scintillabmx/

Today I will add SVN support and tidy up some things in the code.

The TScintillaGadget extends TWindowsGadget and is compatible to the TextArea gadget delivered by maxgui. It currently lacks of printing support as well as the event handling isn't managed like the original one. Currently there is only 1 event fired : EVENT_GADGETACTION which contains a TScintillaNotification object in the extra field.

And a small proof of concept image ;) MaxIDECE with Scintilla:




xlsior(Posted 2009) [#14]
Very interesting... Would love to see this in the community IDE.

Did notice one small bug: If you collapse a function at the very end of the source, it still keeps the 'end function' line visible, but when you collapse a function elsewhere those do disappear.


JoshK(Posted 2009) [#15]
Does anyone know how to disable the antialiasing? It does not look good in a code editor.


JoshK(Posted 2009) [#16]
I think it's just due to the weird Blitz color scheme.

Here is my sample:
format_codebox('SuperStrict

Framework maxgui.drivers
Import brl.eventqueue
Import "ScintillaCtrl.bmx"


'**************************Sample***************************
Local window:TGadget
Local textarea:TScintillaGadget ' TGadget works as well, but then we need to cast when using scintilla specific stuff

window=CreateWindow("My Window",130,20,800,600,,15|WINDOW_ACCEPTFILES)

textarea = CreateScintillaArea(,,,,Window)
SetGadgetLayout textarea , 1 , 1 , 1 , 1
Local text:String = LoadText("ScintillaCtrl.bmx")
Print "Text length: " + textarea.charcount();
SetTextAreaText textarea,text
textarea.SetLineNumbering(0 , True)
textarea.SetMarginType(1, SC_MARGIN_SYMBOL, 20)
textarea.SetMarginSensitive(1 , True)

SetGadgetLayout textarea,1,1,1,1
ActivateGadget textarea

Local keys:String = ""

Local cmds:TStream = ReadStream("commands.txt")

While Not Eof(cmds)
Local L:String = ReadLine(cmds)
Local Key:String = l[l.FindLast("#")+1..]
keys:+ Key.toLower() + " "

Wend


'Highlighting stuff
textarea.SetLexer(SCLEX_BLITZMAX)
textarea.SetLexerKeywords(0 , keys)

Local background:Int=EncodeColor(255 , 255 , 255)

For Local I:Int = 0 To 19
textarea.SetLexerStyle(SCI_STYLESETFORE , I , EncodeColor(0,0,0))
textarea.SetLexerStyle(SCI_STYLESETBACK , I , background )
Next

textarea.SendEditor(SCI_SETCARETFORE,EncodeColor(192,192,192))

textarea.SetLexerStyle(SCI_STYLESETFORE , SCE_B_KEYWORD , EncodeColor(0,0,255))
textarea.SetLexerStyle(SCI_STYLESETBACK , SCE_B_KEYWORD, background)
textarea.SetLexerStyle(SCI_STYLESETFORE , SCE_B_MULTILINECOMMENT , EncodeColor(0,128,0))
textarea.SetLexerStyle(SCI_STYLESETFORE , SCE_B_COMMENT , EncodeColor(0 , 128 , 0) )
textarea.SetLexerStyle(SCI_STYLESETFORE , SCE_B_NUMBER , EncodeColor(0 , 0 , 255) )
textarea.SetLexerStyle(SCI_STYLESETFORE , SCE_B_STRING , EncodeColor(128 , 0 , 128 ) )
textarea.SetLexerStyle(SCI_STYLESETBACK , STYLE_DEFAULT , background )

'textarea.SendEditor(SCI_SETMARGINMASKN , 1 , SC_MASK_FOLDERS) ;

'textarea.SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDER, SC_MARK_PLUS);
'textarea.SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPEN, SC_MARK_MINUS);
'textarea.SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEREND, SC_MARK_EMPTY);
'textarea.SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERMIDTAIL, SC_MARK_EMPTY);
'textarea.SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPENMID, SC_MARK_EMPTY);
'textarea.SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERSUB, SC_MARK_EMPTY);
'textarea.SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERTAIL, SC_MARK_EMPTY);
'textarea.SendEditor(SCI_SETFOLDFLAGS , 16 , 0)

'textarea.SendEditor(SCI_SETINDENTATIONGUIDES,SC_IV_LOOKBOTH)

'textarea.SetProperty("fold","1")
'textarea.SetProperty("fold.compact" , "0")

'textarea.DoPrint()

Print textarea.GetLexer()

SelectTextAreaText textarea,1,3,TEXTAREA_LINES

Print TextAreaCursor(textarea,TEXTAREA_LINES)
Print TextAreaSelLen(textarea,TEXTAREA_LINES)


Print TextAreaText(textarea)


While WaitEvent()
'Print CurrentEvent.ToString()+" "+EventSourceHandle()
Select EventID()
Case EVENT_WINDOWCLOSE
End
Case EVENT_APPTERMINATE
End
Case EVENT_GADGETACTION
If EventSource() = textarea Then
Print EventExtra().ToString()
End If
End Select
Wend')


jsp(Posted 2009) [#17]
This looks really nice.
Nevertheless it crashes here when i run the sample.bmx and copy paste several times some text(wanted to get some text in to see how fast the highlight works).
It just says process complete. :(
Only once it stopped at the WaitEvent() command, but i can't reproduce it. The crash itself was always reproducable after some copy and paste. With bigger text i had the feeling it was earlier.


xlsior(Posted 2009) [#18]
I also got an 'application stopped responding' error after expanding/collapsing a bunch of the nodes. :-/


JoshK(Posted 2009) [#19]
Are you using any callbacks with the lexer DLL? That could cause problems if not handled correctly.


Mark Tiffany(Posted 2009) [#20]
Nice one - I presume it's just a case of calling a new CreateScintillaTextArea first, then use all existing commands?

If so, very happy to add it is an optional (and probably default for windows) option into CE IDE code, like with turning on gtk or not.


klepto2(Posted 2009) [#21]
@Mark:
That is exactly the way to do. Due to its nature of being an extended TWindowsGadget you can use it with just replacing CreateTextArea with CreateScintillaArea. To get the highlighting cast it to TScintillaGadget and the you can access the additional options. It takes around 20 lines of code
to get it to work with linenumbers, folding and highlighting.

@Josh:
There are no callbacks, everything is handled via messaging.

@All:
the random crashes may be caused by a last minute fix I have done and scintilla hardly unforgives wrong parameters like wrong charpositions.


JoshK(Posted 2009) [#22]
This is one of the coolest things I have ever seen for MaxGUI. Maybe I will make my own code editor.


klepto2(Posted 2009) [#23]
hi, revision 4 is up and includes the following changes:

-The scintilla events(notifications) must now be handled by the user completely. eg previously MARGIN_CLICK was handled in the control.
-The internal eventsystem is now is handled like the standard textarea
eg: Eventfilter for Keys, GadgetMenu behaviour.
-several bugs fixed
-wrong selection
-ctd on folding (hopefully)
-and some other things



TODO:
-testing some behaviour doesn't work like the standard textarea. Notified in maxides manual undo/redo
-implement an easier communication system with scintilla
eg: instead of textarea.SendEditor(SCI_UNDO) it should be textarea.Undo()
- bug fixes ;)


xlsior(Posted 2009) [#24]
hi, revision 4 is up and includes the following changes:


Up where?

http://code.google.com/p/scintillabmx/downloads/list still shows that it was last uploaded 3 days ago...

EDIT: Nevermind, the SVN branch appears to contain the REV 4.


klepto2(Posted 2009) [#25]
thx, for the hint :)

I've edited the first post to include the link to the download and the SVN repo.


JoshK(Posted 2009) [#26]
In Windows XP this crashes as soon as it builds when the debugger is off. If the debugger is on, it crashes if the first thing I do is click on one of the fold nodes to collapse a section of code. I am using your sample code, with the latest version downloaded via SVN.


SebHoll(Posted 2009) [#27]
Just had a quick look and this is looking nice.

Have just tidied up the first few lines of TScintillaGadget which you might like to commit:

format_code('Type TScintillaGadget Extends TWindowsGadget

Field _oldSelPos% , _oldSelLen% = 0
Field readonly:Byte = False
Field numbers:Byte = False
Global _pagemargin# = 0.5

Function Create:TScintillaGadget(x:Int = 0 , y:Int = 0 , w:Int = - 1 , h:Int = - 1 , group:TGadget = Null, style:Int = 0)

If w = -1 Then w = ClientWidth(group)-x
If h = -1 Then h = ClientHeight(group)-y
Return New TScintillaGadget.Initialize(x,y,w,h,group,style)

End Function

Method Initialize:TScintillaGadget(x:Int, y:Int, w:Int, h:Int, group:TGadget, style:Int)

Local wstyle:Int, hwnd:Int, parent:Int

Self.style = style
wstyle=WS_CHILD|WS_TABSTOP|WS_CLIPSIBLINGS
parent=group.query(QUERY_HWND_CLIENT)
hwnd=CreateWindowExW(0,"Scintilla","",wstyle,0,0,0,0,parent,0,GetModuleHandleW(Null),Null)
Register GADGET_TEXTAREA,hwnd

_SetParent group
SetShape(x,y,w,h)
SetShow(True)
Sensitize()

SendEditor (SCI_SETMODEVENTMASK , SC_MODEVENTMASKALL)

Return Self

EndMethod')


klepto2(Posted 2009) [#28]
thx will look it later after work :)


klepto2(Posted 2009) [#29]
@SebHoll: thx, I have commited the changes.

I have also disabled the autolist(intellisense) function as well as the single undostep approach. Tested on a XP virtual machine without crashing.

Feedback highly needed :) especially from XP users.


thx in advance


jsp(Posted 2009) [#30]
I just checked out the latest changes and it works quite good (XP SP2).

I can now paste 100.000 lines of code without problems and also the highlight is very fast (2 sec. On my machine).

It didn't crash at all for me during testing. Only one thing I noticed which is may not a bug, but I didn't expect: When you highlight some text and your cursor is above or underneath those lines and you press the right mouse button to get the popup menu, it clears your selection. The selection stays when you right click on the highlighted lines!

And I found some debugstop concerning font handling...

Is it possible to add the Rem – End Rem to the folding?


JoshK(Posted 2009) [#31]
With your latest upload, the sample program no longer crashes when I click on the open/close nodes on the left side. I am testing on WinXP with SP3.


Bremer(Posted 2009) [#32]
This would be very nice for either the official IDE or the CE. I took at look at making a module like this but gave up after a while, glad to see someone staying the distance because scintilla would really improve the current freely available blitzmax IDEs.


xlsior(Posted 2009) [#33]
No kidding...


klepto2(Posted 2009) [#34]
Thx for the feedback and help to find the bug.

Hopefully the bug is fixed :) new Revision up and also a new
download package containing the actual source + dll.

http://scintillabmx.googlecode.com/files/ScintillaRev9.zip

thx again.


EOF(Posted 2009) [#35]
Very nice work so far Klepto!!

Couple of things:

1)
Ctrl + A to select all the code brings up the command box (With the command "SuperStrict" showing)
The box appears very high above the main window (depending how far down in the code you are)

What control do you have over this command box?
Can you, for instance, change things so that the box only appears after 3 chars have been entered?

The reason I ask, I see many instances of the text box flickering as I type stuff in. Try ======== for example

In fact, the popup box is somewhat annoying (sorry)
Try this for example:

Where you have False; in the code example:

> Position the cursor after the ;
> Press backspace to delete the ;
> The popup box appears showing False

Now its not easy to close this box. RETURN and ESCAPE both fail
I have to click away from the line(!)


2)
Switching from INSERT mode to OVERTYPE mode turns the cursor into a tiny underscore which changes size according to the character at the cursor position. Can this change to a thicker version of the standard INSERT mode cursor character instead?

3)
Can Function keys be detected under Scintilla?
For example, pressing F1 over a command to get help(?)


klepto2(Posted 2009) [#36]
1)
The 'command' window is just an experimantal demonstration in the sample. You can handle the appeariance as you wish. eg Filter the keywords, provide field types etc.

2) need to check out this by myself ;)

3) yes, take a look at the filter function. the gadget throws the same events as the standard textarea + one additional where the scintilla messages can be handled.

also keep in mind that this is still work in progress and a lot of things need to be sorted out in the next days/weeks.


EOF(Posted 2009) [#37]
Klepto

How's things looking regarding the font changing?
I tried it with the sample code commenting out the DebugStop but it hangs the demo

Also, how do you control what parts of the code are foldable?
In other words, how do you say to Scintilla, "ok, any lines starting with Function are foldable"

How easy would it be to adapt the code to C++ / Java where {} are foldable for instance?
I see there are tons of options in there. Looks like Scintilla is really flexible

By the way I have adapted the SAMPLE code here so that you can load other Blitz code samples (for testing Scintilla with):
format_codebox('SuperStrict

Framework maxgui.drivers
Import brl.eventqueue
Import "ScintillaCtrl.bmx"


'**************************Sample***************************
Local window:TGadget
Global textarea:TScintillaGadget ' TGadget works as well, but then we need to cast when using scintilla specific stuff

window=CreateWindow("My Window",130,20,800,600,,15|WINDOW_ACCEPTFILES)
Local tabber:TGadget
Local document:TGadget

Local filemenu:TGadget
Local editmenu:TGadget
Local editmenuPOP:TGadget
Local helpmenu:TGadget

Const MENU_NEW:Int=101
Const MENU_OPEN:Int=102
Const MENU_SAVE:Int=103
Const MENU_CLOSE:Int=104
Const MENU_EXIT:Int=105

Const MENU_CUT:Int=106
Const MENU_COPY:Int=107
Const MENU_PASTE:Int = 108
Const MENU_UNDO:Int = 109
Const MENU_REDO:Int = 110
Const MENU_FONT:Int = 111

Const MENU_ABOUT:Int=112


filemenu=CreateMenu("&File",0,WindowMenu(window))
CreateMenu"&New",MENU_NEW,filemenu,KEY_N,MODIFIER_COMMAND
CreateMenu"&Open",MENU_OPEN,filemenu,KEY_O,MODIFIER_COMMAND
CreateMenu"&Close",MENU_CLOSE,filemenu,KEY_W,MODIFIER_COMMAND
CreateMenu"",0,filemenu
CreateMenu"&Save",MENU_SAVE,filemenu,KEY_S,MODIFIER_COMMAND
CreateMenu"",0,filemenu
CreateMenu"E&xit",MENU_EXIT,filemenu,KEY_F4,MODIFIER_COMMAND

editmenu = CreateMenu("&Edit" , 0 , WindowMenu(window) )
CreateMenu "&Undo",MENU_UNDO,editmenu,KEY_U,MODIFIER_COMMAND
CreateMenu "&Redo",MENU_REDO,editmenu,KEY_R,MODIFIER_COMMAND
CreateMenu"",0,editmenu
CreateMenu "Cu&t",MENU_CUT,editmenu,KEY_X,MODIFIER_COMMAND
CreateMenu "&Copy",MENU_COPY,editmenu,KEY_C,MODIFIER_COMMAND
CreateMenu "&Paste" , MENU_PASTE , editmenu , KEY_V , MODIFIER_COMMAND
CreateMenu "Font",MENU_FONT,editmenu

editmenuPop = CreateMenu("&Edit" , 0 , Null)
CreateMenu "&Undo",MENU_UNDO,editmenuPop ,KEY_U,MODIFIER_COMMAND
CreateMenu "&Redo",MENU_REDO,editmenuPop ,KEY_R,MODIFIER_COMMAND
CreateMenu"",0,editmenuPop
CreateMenu "Cu&t",MENU_CUT,editmenuPop ,KEY_X,MODIFIER_COMMAND
CreateMenu "&Copy",MENU_COPY,editmenuPop ,KEY_C,MODIFIER_COMMAND
CreateMenu "&Paste",MENU_PASTE,editmenuPop ,KEY_V,MODIFIER_COMMAND

helpmenu=CreateMenu("&Help",0,WindowMenu(window))
CreateMenu "&About",MENU_ABOUT,helpmenu

UpdateWindowMenu window

' CreateDocument creates a hidden panel that fills entire tabber client area

Function CreateDocument:TGadget(tabber:TGadget)
Local panel:TGadget
panel=CreatePanel(0,0,ClientWidth(tabber),ClientHeight(tabber),tabber)
SetGadgetLayout panel,1,1,1,1
HideGadget panel
Return panel
End Function



tabber=CreateTabber(0,0,ClientWidth(window),ClientHeight(window),window)
SetGadgetLayout tabber,1,1,1,1

document = CreateDocument(tabber)

ShowGadget document

textarea = CreateScintillaArea(,,,,document)
SetGadgetLayout textarea , 1 , 1 , 1 , 1
textarea.SetLineNumbering(0 , False)
textarea.SetMarginType(1, SC_MARGIN_SYMBOL, 20)
textarea.SetMarginSensitive(1 , True)
textarea.SendEditor(SCI_USEPOPUP , 0) 'Deactivate Scintillas own popup

ActivateGadget textarea

LoadFile "ScintillaCtrl.bmx"

Function LoadFile(thisffile$)
If thisffile="" Then Return
Local text:String = LoadText(thisffile)
SetTextAreaText textarea,text
Print thisffile+" Text length: " + textarea.charcount()
End Function


Global keys:String = ""
Global keymap:TMap = New TMap

Local cmds:TStream = ReadStream("commands.txt")

While Not Eof(cmds)
Local L:String = ReadLine(cmds).Trim()
Local Key:String = l[l.FindLast("#") + 1..]
Print Key
If Key.toLower().Contains("extends") Or Key.Contains(":")
Key = Key[..Key.Find(" ")]
End If
keys:+ Key.toLower() + " "
keymap.Insert(Key.toLower(),Key)
Wend


'Highlighting stuff
textarea.SetLexer(SCLEX_BLITZMAX)
textarea.SetLexerKeywords(0 , keys)

For Local I:Int = 0 To 19
textarea.SetLexerStyle(SCI_STYLESETFORE , I , EncodeColor(244,244,244))
textarea.SetLexerStyle(SCI_STYLESETBACK , I , EncodeColor(1 , 88 , 107) )
Next

textarea.SendEditor(SCI_SETCARETFORE,EncodeColor(255,255,255))
textarea.SetLexerStyle(SCI_STYLESETFORE , SCE_B_KEYWORD , EncodeColor(255,255,0))
textarea.SetLexerStyle(SCI_STYLESETBACK , SCE_B_KEYWORD, EncodeColor(1,81,107))
textarea.SetLexerStyle(SCI_STYLESETFORE , SCE_B_MULTILINECOMMENT , EncodeColor(177,231,235))
textarea.SetLexerStyle(SCI_STYLESETFORE , SCE_B_COMMENT , EncodeColor(177 , 231 , 235) )
textarea.SetLexerStyle(SCI_STYLESETFORE , SCE_B_NUMBER , EncodeColor(21 , 255 , 185) )
textarea.SetLexerStyle(SCI_STYLESETFORE , SCE_B_STRING , EncodeColor(0 , 255 , 107) )
textarea.SetLexerStyle(SCI_STYLESETBACK , STYLE_DEFAULT , EncodeColor(1 , 81 , 107) )

textarea.SendEditor(SCI_SETMARGINMASKN , 1 , SC_MASK_FOLDERS) ;

textarea.SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDER, SC_MARK_ARROW);
textarea.SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPEN, SC_MARK_ARROWDOWN);
textarea.SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEREND, SC_MARK_EMPTY);
textarea.SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERMIDTAIL, SC_MARK_EMPTY);
textarea.SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPENMID, SC_MARK_EMPTY);
textarea.SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERSUB, SC_MARK_EMPTY);
textarea.SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERTAIL,SC_MARK_EMPTY );
textarea.SendEditor(SCI_SETFOLDFLAGS , 16 , 0)

textarea.SendEditor(SCI_SETINDENTATIONGUIDES,SC_IV_LOOKBOTH)

textarea.SetProperty("fold","1")
textarea.SetProperty("fold.compact" , "0")

'textarea.DoPrint()

Print textarea.GetLexer()

SelectTextAreaText textarea,0,0,TEXTAREA_LINES

Print "C : " + TextAreaCursor(textarea,TEXTAREA_CHARS)
Print "L : " + TextAreaSelLen(textarea,TEXTAREA_CHARS)


'Print "Text : " +TextAreaText(textarea,TextAreaCursor(textarea,TEXTAREA_CHARS) ,TextAreaSelLen(textarea,TEXTAREA_CHARS) , TextArea_CHARS)

'SetTextAreaText textarea,"Hello World",20,50

SetGadgetFilter(textarea , filter, textarea)

Function filter:Int(event:TEvent,context:Object)
Select event.id
Case EVENT_KEYCHAR
'Lets do a more precise UNDO REDO
'A bit buggy , it adds 2 undos at once, don't know why
'but it should give an idea
Local textarea:TScintillaGadget = TScintillaGadget(context)
If textarea <> Null Then
'Local line:Int = TextAreaCursor(textarea,TEXTAREA_LINES)
'textarea.SendEditor(SCI_ADDUNDOACTION , line)

'Checking AutoList
Local curPosition:Int = TextAreaCursor(textarea)
Local s:Int = textarea.SendEditor(SCI_WORDSTARTPOSITION,curPosition,1)
Local e:Int = textarea.SendEditor(SCI_WORDENDPOSITION,curPosition,1)
Local l:Int = 0
Local token:String
Try
If event.data > 32 And event.data < 126 Then
token = TextAreaText(textarea , s , (e - s) , TEXTAREA_CHARS) + Chr(event.data)
l = token.length -1
Else
token = TextAreaText(textarea , s , (e - s) , TEXTAREA_CHARS)
l=token.length
End If
Catch ex:String
Print "Exception: " + ex
End Try
' Print "Token : " + token + " : " + token.length +";"+ textarea.SendEditor(SCI_AUTOCACTIVE)

Local count:Int = 0
If token.length > 0 And textarea.SendEditor(SCI_AUTOCACTIVE) = 0 Then
Local keylist:String = ""
For Local T:String = EachIn keymap.Values()
'Print token.Trim().toLower() + " : " + token.length
If t.ToLower().StartsWith(token.toLower() ) Then
keylist:+ t + " "
count:+1
End If
Next
' Print "Items: " + count
textarea.SendEditor(SCI_AUTOCSETIGNORECASE , 1)
textarea.SendEditor(SCI_AUTOCSETMAXHEIGHT,10)
textarea.SendEditorString(SCI_AUTOCSHOW , l , keylist)

End If
End If
End Select
Return 1
End Function

Local Font:TGuiFont = Null

While WaitEvent()
'Print CurrentEvent.ToString()+" "+EventSourceHandle()
Select EventID()
Case EVENT_GADGETMENU
PopupWindowMenu(window,editmenuPOP)
Case EVENT_WINDOWCLOSE
End
Case EVENT_APPTERMINATE
End
Case EVENT_GADGETACTION
'Removed Scintilla Eventhandling from main code now everything needs to be handled in the
'maxgui eventsystem
If EventSource() = textarea Then
Local n:TScintillaEventData = TScintillaEventData(EventExtra() )
Select n.Code
Case SCN_MARGINCLICK
Local Line:Int = textarea.SendEditor(SCI_LINEFROMPOSITION , n.position , 0) ;
Local levelClick:Int = textarea.SendEditor(SCI_GETFOLDLEVEL , line) ;
If levelClick & SC_FOLDLEVELHEADERFLAG <> 0 Then
textarea.SendEditor(SCI_TOGGLEFOLD , Line , 0)
End If
Case SCN_MODIFIED
'Print "Char : " + n.ch
End Select

End If

Case EVENT_MENUACTION
Select EventData()
Case MENU_NEW
SetTextAreaText textarea,""
Case MENU_OPEN
Local file$=RequestFile("Choose file","")
LoadFile file
Case MENU_UNDO
textarea.SendEditor(SCI_UNDO)
Case MENU_REDO
textarea.SendEditor(SCI_REDO)
Case MENU_CUT
textarea.SendEditor(SCI_CUT)
Case MENU_COPY
textarea.SendEditor(SCI_COPY)
Case MENU_PASTE
textarea.SendEditor(SCI_PASTE)
Case MENU_FONT
'DebugStop()
font = RequestFont(font)
If font
SetGadgetFont textarea, font
EndIf
Case MENU_EXIT
End
Case MENU_ABOUT
Notify "Scintilla~nBlitzmaxGadget"
End Select
End Select
Wend
')


klepto2(Posted 2009) [#38]
Hi Jim,

thx for the feedback.
Now Step by Step ;)

1. Font Changing works, depends if you use a modified maxgui (the release candidate on the top of this forum with my FontRequest modification). The reason for the hang is simple : I have a forgotten a Debugstop within the SetFont Method ;)

2. Scintilla is flexible thats right, but on some parts it isn't that flexible. Scintilla is based on custom lexers for each language which are normally included directly in the dll. It is also possible to import plugin dlls via runtime and use these.

the Blitzmax lexer for instance is located in the c++ src file: lexbasic.cxx

There you have this function:
format_codebox('
static int CheckBlitzMaxFoldPoint(char const *token, int &level) {
if (!strcmp(token, "function") ||
!strcmp(token, "type") ||
!strcmp(token, "method") ||
!strcmp(token, "for") ||
!strcmp(token, "while") ||
!strcmp(token, "repeat")||
!strcmp(token, "select")){
level |= SC_FOLDLEVELHEADERFLAG;
return 1;
}
if (!strcmp(token, "end function") ||
!strcmp(token, "end type") ||
!strcmp(token, "end method") ||
!strcmp(token, "endfunction") ||
!strcmp(token, "endtype") ||
!strcmp(token, "endmethod") ||
!strcmp(token, "next") ||
!strcmp(token, "end select") ||
!strcmp(token, "endselect") ||
!strcmp(token, "wend") ||
!strcmp(token, "until") ||
!strcmp(token, "forever"))
{
return -1;
}
return 0;
}
')

There you can add the regions you want. But you need to recompile Scintilla with VS or mingw.

There are a lot of other languages already implemented. For details take a look in Scintilla_consts.bmx. For nearly every language there is are also defined constants for eg function or comments etc.

For everything else you need to look at this point: http://www.scintilla.org/ScintillaDoc.html


REDi(Posted 2009) [#39]
Excellent work klepto2, scintilla's working great and so is your lexer!

quick tip, how to use the direct function messaging...
format_code('
Type TScintillaGadget Extends TWindowsGadget

Field SendMessageDirect:Int(directPointer:Int,msg:Int,wp:Int,lp:Int)
Field SCI_DIRECTPOINTER:Int
...

Method Initialize:TScintillaGadget(x:Int, y:Int, w:Int, h:Int, group:TGadget, style:Int)
...

hwnd=CreateWindowExW(0,"Scintilla","",wstyle,0,0,0,0,parent,0,GetModuleHandleW(Null),Null)
SendMessageDirect = Byte Ptr(SendMessageW(hwnd, SCI_GETDIRECTFUNCTION, 0, 0))
SCI_DIRECTPOINTER = SendMessageW(hwnd, SCI_GETDIRECTPOINTER, 0, 0)
...

Method SendEditor:Int(Msg:Int , wParam:Int = 0 , lParam:Int = 0)
Return SendMessageDirect(SCI_DIRECTPOINTER, msg, wparam, lParam)
End Method
')

Just spent a while and got this statically built into a module, if you want the codes klepto :)


klepto2(Posted 2009) [#40]
thx ready. I already know this code (well not exactly the same code). I didn't know this works also with the windows version. Maybe this is one step to have the scintilla multiplattform (Cocoa, GTK and Win).

Currently I'm just using the sendmessage system provided by windows.

I think for a real crossplattform solution it might be the best to add a complete new control instead of having a textarea simulation module to get the full power of scintilla.

What do you guys think about this?

Also currently i'm using the dll, would it be possible to just compile the src code of scintilla directly with bmx and link it? That would make later shipping on multiple plattforms a lot easier.


thx in advance


JoshK(Posted 2009) [#41]
This no longer works with MaxGUI 1.34.


klepto2(Posted 2009) [#42]
thx Leadwerks. I'm already working on this issue. Maybe SebHoll can jump into this and tell me what has changed in maxgui so it breaks my code.


klepto2(Posted 2009) [#43]
Good News :)

Problem with the new maxgui has been solved and i have uploaded a new Version.

The main change in this release is that the control is 'splitted' into 2 parts:
- the control itself
- and a scintilla interface

you get the scintilla interface by eg: textarea.GetScintilla()

I have decided to do this because code may be a bit cleaner and i can have the same names as scintilla has without colliding with maxgui names.

The lib is also prepared to be a module in the future, so you may notice a lot of documentation within the Tscintilla Type.

But now have fun :) and post any bug you find.

http://scintillabmx.googlecode.com/files/ScintillaBMX.zip

PS: This release is a new structured version and not currently not in the SVN.


JoshK(Posted 2009) [#44]
Here's another shot of this excellent code in action. I want to see this incorporated into the BlitzMax IDE!!!




slenkar(Posted 2009) [#45]
looks good man


xlsior(Posted 2009) [#46]
Scintilla in the IDE really would be very nice... Code folding is really the major feature that the IDE is missing in my book.


klepto2(Posted 2009) [#47]
Hi guys.

Just a small progressreport:

- some minor fixes done
- around 50% of the scintilla messages are wrapped and documented
- started a Helper Class with various functions to help using scintilla

and now I have a special surprise:
(big thx to YellowRider)



You can guess yourself what this image means :)

As soon as everything is stable i will recreate the subversion and upload a new Version. No ETA yet but it should not be that far away.


plash(Posted 2009) [#48]
You can guess yourself what this image means :)
It means there is still no Linux version?

I hate FLTK :(


Ked(Posted 2009) [#49]
I got really excited when I saw the Mac screenshot! Now just to settle the Linux problem...


Difference(Posted 2009) [#50]
Looking good! OS X version is much appreciated.


theHand(Posted 2009) [#51]
After you have all of this working well, why not take a look at wxScintilla?
I thought so.


xlsior(Posted 2009) [#52]
After you have all of this working well, why not take a look at wxScintilla?


Brucey already has a wxScintilla mod as part of this wxwidgets framework.

Unfortunately the entire wx-framework is massive though -- I'd greatly prefer a non-wx implementation like Klepto's myself.


outsider(Posted 2009) [#53]
Hi,
can you make MaxIDE CE + Scintilla .exe program? It's looks nice, but I don't have MaxGUI :/.


klepto2(Posted 2009) [#54]
I will do as soon as I have time and have a stable enough version.

currently I don't have much time for coding private things so everything takes longer till it is finished.


outsider(Posted 2009) [#55]
Thank you klepto2 :)


xlsior(Posted 2010) [#56]
Any more progress on this?


ima747(Posted 2010) [#57]
another bump, I would kill for an updated CE edition with depth markers let alone collapsing...


TomToad(Posted 2010) [#58]
I tried compiling the sample.bmx and I am getting an error "Overriding method differs by type " on line 49 of ScintillaCtrl.bmx. Tried Rev9 as well as the SVN versions.


ker2x(Posted 2010) [#59]
Is this project dead ?
I'm still wondering if i should use Brucey's wxMax (it include a scintilla module) or this module with MaxGUI.


TomToad(Posted 2010) [#60]
That's what I'm wondering as well. I tried wxMax version of Scintilla, but I can't seem to get it to work. This looks like it would be a better solution for me, but doesn't seem to want to compile, possibly due to changes in MaxGUI.


klepto2(Posted 2010) [#61]
Sorry for the delay.

I have uploaded a 1.41 compatible Version at googlecode.

http://code.google.com/p/scintillabmx/downloads/list

I hope this helps you.

Unfortunatly the project is nearly dead. I don't have time to maintain it and i have also moved to other languages. But i will try to get it at least to a final and stable version (adding missing methods etc.).


popcade(Posted 2010) [#62]
Hi, klepto

Would you mind release the Console Module source? this mod is really useful but I can't get it work on BMax 1.41....

Last edited show_time('2010-11-12 23:42:36')


TomToad(Posted 2010) [#63]
Klepto,

Thanks a lot. Works great. I did notice a little bug in the sample though. When you type Superstrict on the first line, the autocomplete pops up and the Enter key will not be accepted. You need to either press the space key or click on the autocomplete. Won't be a big problem for me since I don't need the autocomplete anyway.


MOBii(Posted 2014) [#64]
Love you klepto2 I just got the: sample advanced.bmx to work, and start replace the TGadget textarea to Scintilla in my project now!
Only this is a reason why to buy BlitzMax, I am indeed very exited <3


MOBii(Posted 2014) [#65]
I have 2 questions:

Question 1:
How can I turn Character representations OFF?
http://www.scintilla.org/ScintillaDoc.html#CharacterRepresentations

Question 2:
I seen Scintilla as mod:format_code('Import wx.wxScintilla
Import wx.wxFrame')Where can I download wx.wxScintilla?

https://code.google.com/p/scintillabmx/downloads/list

I use the no module .rar
https://code.google.com/p/scintillabmx/downloads/detail?name=Scintilla.rar&can=2&q=
Scintilla bmx 1.41 compatible (Import only / no module)


Derron(Posted 2014) [#66]
wx - like in wxMAX (a wrapper for wxWidgets).


bye
Ron


Dabhand(Posted 2014) [#67]
I built an editor using wxMax... It was monkey at a typewriter setup, but it worked fine... So, just in case you want a reference, you'll find the code here...

http://sourceforge.net/p/bamboobasic/code/ci/master/tree/Editors/Win/Editor/

Dabz


JoshK(Posted 2014) [#68]
I'm using this in Leadwerks now, including the Linux build, and it's really good.