Text Editor Question.

Hi,
I have a few questions regarding a Text Editor app which I am creating as a learning experience.

  1. Can anyone point me to a resource (project file / video etc.) which explains in a novice understandable way - how to create toggle buttons for bold, italic and underline, (and possibly left, centre, and right alignment) buttons?

  2. If I set my computer (OS X) to open all text files with my Text Editor app, - what would I need to do inside my app to allow this?
    I am presuming that I need to add code which will enter the text of a txt file which is double clicked, into my TextArea - but I have no idea how?

Thank you all in advance for any help you can give.

in the ACTION event of you buttons for BOLD/ITALIC etc

textarea1.selbold=not textarea1.selbold

same for SELITALIC, SELUNDERLINE (for somefonts), SELALIGNMENT

Read up on the OPENDOCUMENT event of the APP object

Thanks Dave - I will look into that.

My buttons now function correctly, however, the buttons do not toggle, so I can’t tell which state they are currently set to.
I have looked in the language reference, but can see no properties for toggling buttons?

I have also notice that the caption for the bold button displays as bold, but the button captions for Italic and Underline refuse to display in Italic or underlined.

Does this have anything to do with the fact that my app is Cocoa?

Thanks.

Remember BOLD/ITALIC etc… is confined to the SELECTED text… SELBOLD will return true if ALL the selected text if bold (false if not, or mixed bold/not bold), same with the other flags

Sorry Dave, but I’m a bit confused.

I have the bold button at the top of my window.
When I press it and then start to type - any text I now type is bold. When I press it again - any text I start to type is normal. :slight_smile:
Also - when I select text and then press the bold button, the selected text becomes bold. :slight_smile:

So, the actual functioning of the buttons all work totally as expected.
The only problems I have are:

  1. The button states do not toggle.
  2. The button’s captions do not recognise Italic or Underline.

I have even typed:

Me.Italic = True

In the open event of the button - to no avail.

What kind of button are you using? The BevelButton control has a toggle mode: it stays pressed until you click it again.

You’ll also need to add code to your textarea’s SelChanged event to update the status of the buttons. (That way when you move your cursor into text that us bold, the bold button will be pressed down to indicate a bold state, and vice versa.)

I’m not sure what you mean but bullet point #2 – the code foe the different buttons is ore pretty much identical, except you change the style property you’re setting.

Thanks Marc.
Regarding number 2:

I have a button, and have set its caption to U (for underline). However, the letter U is itself not underlined.
The same applies for the Italic button - the actual caption text refuses to become Italicised.

I have also just tested a Bevel Button, and it does not toggle upon pressing?
I guess it must have something to do with Cocoa??

[quote=84252:@Richard Summers]I have also just tested a Bevel Button, and it does not toggle upon pressing?
I guess it must have something to do with Cocoa??[/quote]

When you select the button and go to the Inspector panel, under “ButtonType” have you set it to the “Toggles” type? You need to do that for toggling to work.

Thanks Marc.
That worked as expected, although the CAPTION still refuses to become italicised.

So is it not possible to have a push button toggle?
The Bevel button is ugly when it is toggled - it just has a 1980’s grey look to it :frowning:

[quote=84250:@Richard Summers]Thanks Marc.
Regarding number 2:

I have a button, and have set its caption to U (for underline). However, the letter U is itself not underlined. The same applies for the Italic button - the actual caption text refuses to become Italicised.[/quote]

The way you’d usually do that is by creating pictures (icons) of the bold/unbold state and apply them to the BevelButton. When it’s pushed, use the bold version of the icon, etc. There are tons of free basic icon sets on the 'net if you do don’t feel like creating your own icons for this kind of thing.

[quote=84271:@Richard Summers]So is it not possible to have a push button toggle?
The Bevel button is ugly when it is toggled - it just has a 1980’s grey look to it :([/quote]

No, a regular pushButton can’t toggle.

If you use an icon, you can customize the BevelButton look. (And if you don’t like that, you could roll your own button as a canvas subclass just using your pictures to indicate pressed and unpressed, though that’s getting way off topic of this thread. :slight_smile:

Thanks Marc - I will try a bevel button with a different icon for each state.

Off to find me some icons for the bold, italic, underline - (another 3 hours work) :slight_smile:

Ok - I am now almost there.

In my Underline button’s action event, I have the following code:

TextArea1.selunderline=not TextArea1.SelUnderline

This works perfectly.
All I need to do now is change the colour of the button’s caption, when it is toggled on, and then change the caption colour back to it’s original colour, when it is toggled off.

I am now going crazy, as I can’t find a way of doing this.
Do I need to set a Boolean value, and then in the action event, check if true or false, and then change the colour appropriately - OR - is that not the way to do it, due to there being a more standard solution?

Thank you all in advance.

Wouldn’t something like

if TextArea1.SelUnderline then myButton.textColor = &cFF0000 else myButton.textColor = &c000000 end if

work?

I tried that and it didn’t work?

I think my copy of Xojo may be corrupted, as yesterday, my menubar kept disappearing for no reason?
I will re-download Xojo and then try it again.

Thanks.