Text formatting

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Philhold
Posts: 64
Joined: Thu Mar 05, 2009 3:39 pm

Text formatting

Post by Philhold » Wed Aug 12, 2009 5:34 pm

Hi,

I'm trying to make a simple application that needs to apply basic text formatting to chunks within text in a field. I want to be able to select a word and then click a button to make that text go bold for example.

The button that has a script like this.

Code: Select all

on mouseDown pMouseBtnNo
set the textStyle the selectedChunk of field "mText" to "bold"
end mouseDown
It doesn't work but I'm at a loss to see why.

Any pointers would be much appreciated.

Thanks

Phil

PS If you recognise the name it is because I got started with RR some time ago and then my priorities got changed for me. I'm back again having slid down the snake to square one.

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Wed Aug 12, 2009 5:56 pm

Hi Phil,

did you check "the selectedchunk" in the Rev Dictionary?
Obviously not, but that is ALWAYS a good idea :)

"the selectedchunk" MUST not have a descriptor (...of whatever) like in your script, since it returns something like "char x to y OF FIELD Z".

So just write:
...
set the textStyle the selectedChunk to "bold"
...
and you are done :)


Best

Klaus


P.S.
Most of the beginners questions here in the forum would be answered by a quick look into the docs...

Philhold
Posts: 64
Joined: Thu Mar 05, 2009 3:39 pm

Post by Philhold » Wed Aug 12, 2009 9:28 pm

Thanks Klaus,

In fact your line throws an error should be:

Code: Select all

set the textstyle of selectedchunk to "bold"     
I always search the docs first but you have to know what you are looking for. Then as a last resort ask here.

Cheers

Phil

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Thu Aug 13, 2009 8:38 am

Hi Phil,

sorry, but MY line does not throw an error, YOUR line does :D
Add THE -> "of THE selectedchunk" and you're done!


Best

Klaus

Philhold
Posts: 64
Joined: Thu Mar 05, 2009 3:39 pm

Post by Philhold » Thu Aug 13, 2009 8:59 am

Hi Klaus,

set the textStyle of selectedChunk to "bold"

definitely works here but what you said
So just write:
...
set the textStyle the selectedChunk to "bold"
...
and you are done Smile
throws an error. textStyle of the selectedChunk works as well. I only mentioned it as this forum is for newbies and these tiny specifics of grammar are often what catches us out. I didn't mean to sound ungrateful as I am very grateful for your advice.

Many thanks

Phil

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Thu Aug 13, 2009 10:03 am

Hi Phil,

oh damn, you are right, of course, my fault, please excuse me!
Will be more careful in the future.


Best

Klaus

P.S.
But at least I did not forget the "THE" :D

But:
set the textStyle of selectedChunk to "bold"
threw an error here...?!

Philhold
Posts: 64
Joined: Thu Mar 05, 2009 3:39 pm

Post by Philhold » Thu Aug 13, 2009 10:45 am

Hi Klaus,

Are you using a different version to me? I'm running 3.5.0-gm-1 and it does not seem to need "the".

I'm really struggling to get simple text format toggling to work and may just throw in the towel and use rrpHTMLToolbar.

How hard can it be to check the current status of the selectedchunk and then if it is say bold make it normal or the other way around? Also the lack of built in toggle buttons doesn't help.

Cheers

Phil

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Thu Aug 13, 2009 11:10 am

Hi Phil,

well, I am using just another IDE: MetaCard, but the underlying engine is the SAME,
so differences should not appear at all?!?

Anyway, in my current project I have a text format palette and use checkboxes (with custom icons!)
to represent the state of "bold" and/or "italic" and manage this with something like this:

Code: Select all

on selectionchanged
   put the effective textfont of the selectedchunk into tCh
   set the hiltite of btn "bold" to tCh caontains "bold"
   set the hilite of btn "italic" to tCh contains "italic"
end selectionchanged
You get the picture :)


Best

Klaus

Philhold
Posts: 64
Joined: Thu Mar 05, 2009 3:39 pm

Post by Philhold » Thu Aug 13, 2009 11:16 am

Hi Klaus,

Many thanks for that. Also for anyone else having problems with this Sarah's blog here http://sarahrev.blogspot.com/ is interesting.

Thanks again

Phil

Post Reply