MaxGui Useful Extra Commands..

Started by Hardcoal, February 04, 2018, 04:47:13

Previous topic - Next topic

Hardcoal

I hope people will Add to this Topic more Extra Commands,  Saving other people precious Time



--Getting TextArea Selected Text--

Function GetTextAreaSelectedText:String(TextArea:TGadget)
Local Length = TextAreaSelLen(TextArea)
Local Start = TextAreaCursor(TextArea)
Return TextAreaText(TextArea, Start, Length)
End Function




Code

degac

Yes it useful.
But I would change (without adding a new 'command') the TextAreaText() that already exists in this way


Function TextAreaText$( textarea:TGadget,pos=0,length=TEXTAREA_ALL,units=TEXTAREA_CHARS )
If pos=-1 And length=-1
pos= TextAreaCursor(TextArea)
length= TextAreaSelLen(TextArea)
End If
Return textarea.AreaText(pos,length,units)
End Function


You should ask to Brucey to add to his GitHub repository all changes/updates you find useful (I did and some fixes/changes are implemented)

https://github.com/bmx-ng/maxgui.mod

If there's a problem, there's at least one solution.
www.blitzmax.org

Hardcoal

#2
I have lots of Stuff To add that really annoyed me Since I only Started Using MaxGui.

I just post Ideas.. People can do as they like with it..
I have extra commands for about everything there is in Blitz..
I like to simplify stuff so I can concentrate on whats really important


Ok here are more



Function ReplaceSelectedTextAreaText(TextArea:TGadget, NewText:String)
Local Start = TextAreaCursor(TextArea)
Local Length = TextAreaSelLen(TextArea)
SetTextAreaText(TextArea, NewText, Start, Length)
SelectTextAreaText(TextArea, Start, 0)
End Function

Function PositionTextAreaCursur(TextArea:TGadget, Pos)
SelectTextAreaText(TextArea, Pos, 0)
End Function



for beginners it really simplify things
Code

Hardcoal

This is something that took me some time to create..
Hope it will help others..
I dont know if Ive missed a command to Read a TextArea Line, but If not, than this is useful


Function ReadTextAreaLine:String(TextArea:TGadget, LineNumber = 1)
Local I, Midd:String, NewLine:String, StartCharNum, AreaLen

StartCharNum = TextAreaChar(TextArea, LineNumber) + 1
AreaLen = TextAreaLen(TextArea)

For I = StartCharNum To AreaLen

Midd = Mid(TextAreaText(TextArea), I, 1)

If Asc(Midd) = 11 Then
Return NewLine
Else
NewLine = NewLine + Midd
End If

Next

Return NewLine
End Function
Code

Derron

Couldn't you just split the area text at all new line chars ("bla".split("~n") - or similar) ?


bye
Ron

Hardcoal

#5
you probably right..
as i said..
I forgot the split command even exists :)
I Didn't deal with Text editing.. almost at all so thats why i said im not sure..

It didn't Recognize the '~n' when i tried to split it with a loop
and I didnt Try split command yet.. but it will probably work :)

Still.. I will see what is best for me.. Tnx


Code

Henri

Hi,

most efficient way to get a single textarea line is:
Code (blitzmax) Select
Function GetTextareaLine:String(textarea:tgadget, line:Int)
If textarea Then Return TextAreaText(textarea, line, 1, TEXTAREA_LINES)
EndFunction


-Henri
- Got 01100011 problems, but the bit ain't 00000001

Hardcoal

About the split command..
the problem with Split is that you can indicate only one separator..
but I need it also to recognize Tabs and not only Spaces..
So I dont think Split will do the trick..
Code

Hardcoal

#8
I needed to read a word From A TextArea..
And I made This..

This Allows you to choose whether to read the word With or Without The Extra Stoppers..


Function ReadWordFromCursor:String(TextArea:TGadget, AlsoStopOn:String = "", IncludeAlsoOnStopChar = False)    'AlsoStopOne List of Chars To Stop. for example , or ( Etc..
Local I, NewWord:String, Midd:String, CursorLoc

CursorLoc = TextAreaCursor(TextArea)

For I = CursorLoc + 1 To TextAreaLen(TextArea)

Midd = Mid(TextAreaText(TextArea), I, 1)

   'Forward
If IsWordEnder(Midd)  Then
If I = CursorLoc + 1 Then
Return
Else
Exit
End If
Else If CharIs(Midd, AlsoStopOn)
If IncludeAlsoOnStopChar Then NewWord = NewWord + Midd
Exit
Else
NewWord = NewWord + Midd
End If

Next

For I = CursorLoc To 0 Step - 1

Midd = Mid(TextAreaText(TextArea), I, 1)

   'Reverse
If IsWordEnder(Midd)
Exit
Else If CharIs(Midd, AlsoStopOn) Then
If IncludeAlsoOnStopChar Then NewWord = Midd + NewWord
Exit
Else
NewWord = Midd + NewWord
End If

Next

Return NewWord
End Function

Function TextAreaCursorChar:String(TextArea:TGadget)
Return
End Function

'--Externals--'

Function IsLineEnder(AChar:String) 'Indicate a LINE END!
Return Asc(AChar) = 13 Or AChar = "~n"
End Function

Function IsWordEnder(AChar:String) 'Indicate a WORD END! and not a line END!
Return AChar = " " Or Asc(AChar) = 9 Or Asc(AChar) = 13 Or AChar = "~n" Or Asc(AChar) = 11
End Function

Function CharIs(Text:String, ChrsList:String)  'Char Is
Local I, J, LenChrs, CurrentChr:String

LenChrs=Len(ChrsList)

For I=1 To LenChrs
CurrentChr=Mid(ChrsList,I,1)
For J=1 To Len(Text)
If Mid(Text,J,1)=CurrentChr Then Return True
Next
Next

End Function
Code