Edit Control plays IDE

BlitzMax Forums/BlitzMax GUI Programming/Edit Control plays IDE

Hi All,

Been playing with the code of my Edit Control Applet and made it behave like an IDE!

I Still haven't done the cut/paste code, but the scrollbars are in. :)

It's got syntax colors and stuff like that.

This time I've included all the source so you can all nose around and have a play.

Download it here

Looks good so far. Hope you aren't gonna leave in the tab>spaces thing. Hated that in PureBasic (until recently).

Nice work =)

I was playing around with it and added double clicking to select words/lines, if someone wants it.

add some needed fields to TEditControl
	Field DoubleClickTiming:Int = 200
	Field DoubleClickTimer:Int, GotFirstClick:Int

replace the EVENT_MOUSEUP in OnEvent()
				Case EVENT_MOUSEUP
					If event.data = 1 Then						
						If Not GotFirstClick Then
							' start timer
							GotFirstClick = True
							DoubleClickTimer = MilliSecs() + DoubleClickTiming
						Else
							If DoubleClickTimer >= MilliSecs() Then
								' execute actions
								If event.x < 10 Then
									HL(); Action("DBLCLKGT") ' gutter double clicked
								Else
									HL(); Action("DBLCLK") ' editor double clicked
								EndIf
								DoubleClickTimer = 0
								GotFirstClick = False
							Else
								' start timer
								GotFirstClick = True
								DoubleClickTimer = MilliSecs() + DoubleClickTiming
							EndIf
						EndIf
						MB1 = False
					EndIf
					Draw


add these new actions to Action()
			Case "DBLCLK"
				SelectWordAt( Line,Column)
			Case "DBLCLKGT"
				' select line
				HLine = Line
				HColumn = 0
				Column = Dat[Line].Length - 1

and lastly, add this method for selecting words/identifiers
	Method SelectWordAt:Int( ln:Int, col:Int)
		Function IsIdentChar:Int( char:Byte)
			Local chars:String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
			For Local i:Int = 0 Until chars.Length
				If chars[i] = char Then Return True
			Next
			Return False
		EndFunction		
		
		If (ln < 0) Or (ln >= Dat.Length) Then Return False
		Local s:String = Dat[ln]
		Local l:Int,r:Int = s.Length-1
		If s.Length <= 0 Then Return False
		
		' find left edge
		If col >= 1 Then
			For i = col - 1 To 0 Step -1
				If Not IsIdentChar( s[i]) Then 
					l = i
					Exit
				EndIf
			Next
		EndIf
		' find right edge
		If col < s.Length - 2 Then
			For i = col + 1 Until s.LEngth
				If Not IsIdentChar( s[i]) Then 
					r = i
					Exit
				EndIf
			Next
		EndIf
		' select word
		If l < r Then
			HLine = ln
			' make sure the selection is correct
			If (l > 1) Or (Not IsIdentChar(s[l])) Then l :+ 1
			If (r < s.Length-1) Or (Not IsIdentChar(s[r])) Then r :- 1			
			HColumn = l
			Column = r
			Return True
		EndIf
		Return False
	EndMethod


im gonna play with this some more. Again, good work TeraBit =)