Hi,
I have a few questions regarding a Text Editor app which I am creating as a learning experience.
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?
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.
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?
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
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.
Also - when I select text and then press the bold button, the selected text becomes bold.
So, the actual functioning of the buttons all work totally as expected.
The only problems I have are:
The button states do not toggle.
The button’s captions do not recognise Italic or Underline.
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.
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=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.
[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.
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?