Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > How to realize syntax highlighting in Cocoa?

How to realize syntax highlighting in Cocoa?
Thread Tools
Vax
Junior Member
Join Date: Oct 2001
Location: Osnabrueck, North Germany
Status: Offline
Reply With Quote
Mar 11, 2002, 01:23 PM
 
Hi,

i try to program some nice text editor. But how to realize syntax highlighting with a normal text field? Should i have to subclass it?
In which function should i do the highlighting?

Greetings
Vax
--:: Insanity is also a state of mind ::--
     
amonitzer
Forum Regular
Join Date: Aug 2001
Location: Vienna, Austria
Status: Offline
Reply With Quote
Mar 16, 2002, 07:03 AM
 
I guess you're German, since you misused the word "realize"

Well, get the TeXShop-source, this app does exactly what you want.
     
LordJavac
Forum Regular
Join Date: Oct 2000
Location: Portland, OR USA
Status: Offline
Reply With Quote
Mar 18, 2002, 07:22 PM
 
Originally posted by amonitzer:
<STRONG>I guess you're German, since you misused the word "realize"

Well, get the TeXShop-source, this app does exactly what you want.</STRONG>
That's not a misuse of realize, just not a common use (in the US, at least).

I have been curious about this as well, but more importantly, I've been wondering about spell checking in code. How do you get it to spell check code and comments differently, and how do you get it to spell check code properly?
     
exrae
Junior Member
Join Date: Sep 2000
Location: Calgary, Alberta, Canada
Status: Offline
Reply With Quote
Mar 18, 2002, 09:50 PM
 
You will have to subclass NSTextField (or whichever view you choose) to achieve this, then implement your parsing/highlighting techniques in that subclass.
"The pool on the roof must have a leak"
     
Wixar
Junior Member
Join Date: Mar 2001
Status: Offline
Reply With Quote
Mar 19, 2002, 02:03 PM
 
I do not think it's possible to display more than one style in an NSTextField (e.g. the text has to be all blue, or all red; it can't be blue in some parts and red in the rest). You'll want to use an NSTextView.

-Peter
     
Rickster
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Mar 20, 2002, 12:58 AM
 
If you want to do syntax highlighting in an NSTextView (i.e. the large scrollable text widget that's like a TextEdit document window), you'll want to subclass NSTextView and/or NSTextStorage.

I don't think the original poster meant to ask about NSTextField (the little fields you can tab between, most often found in preferences dialogs and such), but I'll answer for that, too: That's probably much easier -- NSFormatter's attributedStringForObjectValue:defaultAttributes: method should help you there.
Rick Roe
icons.cx | weblog
     
Vax  (op)
Junior Member
Join Date: Oct 2001
Location: Osnabrueck, North Germany
Status: Offline
Reply With Quote
Mar 23, 2002, 01:25 PM
 
Hi,

for people curious about syntax highlighting in NSTextViews, visit http://www.cocoadev.com . Nice site with a lot of program examples and such things.

Greetings

Vax
--:: Insanity is also a state of mind ::--
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 07:41 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,