August 06, 2020, 04:17:04 am

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Colorizing Text

Started by tbohon, July 21, 2014, 06:30:00 pm

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

tbohon

I have been trying to modify this piece of code (from Jos from way back when) to colorize the keywords in a richedit box ONLY IF they are the very first word on each line (this routine examines the entire line and colorizes them wherever it finds them).  Only one exception - when a '#' is seen the remainder of the line is colorized.  Keywords found in other than the first location are NOT to be colorized.

Colors:  regular keywords (in first position on the line) are to be BLUE and the #->end of line are to be GREEN.

And yes this is for something I'm trying to do in CB to use with my ftp engine written in <gag> C#.Net .

Going around and around in circles ... I think the change needs to be in the colorize() routine in the process looking through the lines ... but can't come up with the correct solution after multiple hours and I'm slowly going insane here  ;D

Suggestions GREATLY appreciated!!!

TIA.

Tom

Code Select

'This function adjusts the colors of the keywords on the given linenum
SUB colorize(d1,ctl,linenum)
def lineStart, lineLength:int
def i,ctl,linenum,char_start:int
def p, pLine:int

' but how replace (convert) this comand to CB
lineStart = CONTROLCMD (d1, 1,char_start, linenum)
lineLength = CONTROLCMD (d1, 1, @RTGETLINELENGTH,linenum)

'uncolor the whole line, set black color
' CONTROLCMD dlg, ctl, @RTHIDESEL, 0
CONTROLCMD d1, 1, @RTSETSELECTION, lineStart, lineStart + lineLength
CONTROLCMD d1, 1, @RTSETSELCOLOR, RGB(0, 0, 0)

'check the keywords one by one, if they occur on this line
FOR i=0 TO kewordCount-1
p = lineStart+1
DO
'p = RTFINDTEXT(dlg, ctl, keyword[i], p+1, lineStart + lineLength, True, True)
' i change previus line to :
p = CONTROLCMD (d1, 1, @RTFINDTEXT,keyword[i] , p+1,p+LEN(keyword[i]) )

IF p > 0
'the keyword is found at the current line. color it
CONTROLCMD d1, 1, @RTSETSELECTION, p,p+LEN(keyword[i])
CONTROLCMD d1, 1, @RTSETSELCOLOR, RGB(255, 0, 0)
ENDIF

''you can also add making the text uppercase and things like that...
'CONTROLCMD dlg, ctl, @RTREPLACESEL, UCASE$(keyword[i])

UNTIL p < 0
'next two lines solve problem------------------------------------
CONTROLCMD d1, 1, @RTSETSELECTION, p,p-LEN(keyword[i])
CONTROLCMD d1, 1, @RTSETSELCOLOR, RGB(0, 0, 0)
'----------------------------------------------------------------
NEXT i
RETURN
"If you lead your life the right way, the karma will take care of itself ... the dreams will come to you."  -- Randy Pausch, PhD (1961-2008)

LarryMc

I think I can help if you answer a few questions:

How is the richedit loaded? Is it one time whole file type or is it you are continuously adding lines to it?
Once the RE is loaded does the user edit it or simply view it?
What is the max number of lines you ever expect to see in the RE?

LarryMc

Edit: Are all the lines left justified or do some of the lines start off with tabs or spaces?
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Okay
If you don't do any editing then I've got it working.

If you need editing then I need to work on it some more.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

tbohon

The richedit is created once at the beginning of the program but will potentially be changed - it's being used as a script editor component so I would expect people going back to add/delete/modify lines, add comments, etc.

Usual scripts are less than, say, 300 lines long from my experience.

All the lines are left justified so that the interpreter can easily find the first token during processing.

Thanks for the help sir!
"If you lead your life the right way, the karma will take care of itself ... the dreams will come to you."  -- Randy Pausch, PhD (1961-2008)

LarryMc

Attached is a complete editor program
There is a list of keywords,making sure the last element in the list is the "#"
Also, when you add your keywords adjust the
Code Select
if I< 28statement and put the index number for the "#" element.
If a keyword(except for the #) is the first word on the line(regardless of tabs and preceding spaces) the keyword  colored blue,
otherwise it will be ignored.
If the line contains a # the # to the end of the line will be colored green.  This happens even if a keyword has already been colored at the beginning of the line.

Also attached is the test file I used.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

Ahh yes ..i almost forget about that program... ;D
forum for hobby programming:<br />https://aurelsoft.ucoz.com

LarryMc

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

tbohon

Larry it's exactly what I was trying to achieve ... thank you thank you thank you!

I'm going to spend some time this morning (have a very long non-relevant conference call shortly) and study your code so I understand what you did and what I missed.

Again, I greatly appreciate the help on this!!!

Best,

Tom
"If you lead your life the right way, the karma will take care of itself ... the dreams will come to you."  -- Randy Pausch, PhD (1961-2008)