October 26, 2020, 01:52:46 AM

Author Topic: MaxGui Useful Extra Commands..  (Read 2185 times)

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 472
MaxGui Useful Extra Commands..
« on: February 04, 2018, 04:47:13 AM »
I hope people will Add to this Topic more Extra Commands,  Saving other people precious Time

Code: [Select]

--Getting TextArea Selected Text--

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



Go with the Flow

Offline degac

  • Full Member
  • ***
  • Posts: 159
    • graphio.net
Re: MaxGui Useful Extra Commands..
« Reply #1 on: February 04, 2018, 08:58:16 AM »
Yes it useful.
But I would change (without adding a new 'command') the TextAreaText() that already exists in this way

Code: [Select]
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

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 472
Re: MaxGui Useful Extra Commands..
« Reply #2 on: February 04, 2018, 09:39:06 AM »
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

Code: [Select]

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
Go with the Flow

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 472
Re: MaxGui Useful Extra Commands..
« Reply #3 on: February 10, 2018, 08:59:09 PM »
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

Code: [Select]
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
Go with the Flow

Offline Derron

  • Hero Member
  • *****
  • Posts: 3234
Re: MaxGui Useful Extra Commands..
« Reply #4 on: February 10, 2018, 09:13:33 PM »
Couldn't you just split the area text at all new line chars ("bla".split("~n") - or similar) ?


bye
Ron

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 472
Re: MaxGui Useful Extra Commands..
« Reply #5 on: February 10, 2018, 09:39:09 PM »
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


Go with the Flow

Offline Henri

  • Sr. Member
  • ****
  • Posts: 263
Re: MaxGui Useful Extra Commands..
« Reply #6 on: February 11, 2018, 11:19:57 AM »
Hi,

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

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

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 472
Re: MaxGui Useful Extra Commands..
« Reply #7 on: February 11, 2018, 03:44:38 PM »
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..
Go with the Flow

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 472
Re: MaxGui Useful Extra Commands..
« Reply #8 on: February 11, 2018, 04:20:57 PM »
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..

Code: [Select]
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
Go with the Flow

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal