About | Buy Stuff | Industry Watch | Learning Curve | Products | Search | Twitter
Home » Learning Curve

NCE - The OS X No Code Editor 1

All legacy text apps for all versions of MacOS are outdated. Here's why.

For these exercises you will need:
  • the ADC developers tools; and
  • ambition, patience, and perseverance.

To call the NeXTSTEP text engine in OS X 'sophisticated' would be a gross understatement. The underbody in Cocoa that deals with text is so extensive and yet so malleable; in the old days before OS X it might have made sense to develop one's own text system, but today it's like a horse and cart trying to outrun a Formula One Ferrari.

Also factored in is the remarkable development environment spearheaded by Interface Builder - the same development tool that brings you the 'no code web browser'. And while it will take a bit of code for you to both read and write text files, you should be able to accomplish all of this without having the foggiest what you're doing - it's that easy.

Start by getting the ADC developers tools - they're free for the download or you can have them shipped to you for the S&H of US$20. Then read on.

Project Builder/Xcode

We have to start by creating an application 'project'. We do this through either Project Builder or the newer Xcode. What's important at this stage is that you choose the right type of project - a 'Cocoa Document-based Application'.

Goto 'File-New Project' or whatever it is on your menu and choose 'Cocoa Document-based Application' and click through - the 'assistant' merely wants to know where you want to put the project and what name you want to give it. Choose the name 'NCE' for 'No Code Editor'.

You can run this application already: click the 'run' toolbar button to build and run it. All you'll get is an empty window, but what the heck: all you did was click a mouse button a few times and type in three characters off the keyboard, so that's not bad at all.

It's time to turn this guy into a text editor - so roll up yer sleeves and let's get to it.

Interface Builder

Interface Builder is the tool that separates OS X from the rest of the pack - the wannabes on other platforms. This thing is still light years ahead of anything anywhere else. We're going to try it now.

Find a 'folder' in your Project Builder/Xcode display called 'Resources' and in there find 'MyDocument.nib' and double-click it.

This is Interface Builder - you should see a panel in the lower left like this:

And then another panel off somewhere on the right like this:

And then of course your document window.

First order of business is to get 'Your document contents here' off the document window: just click on it to select it and then hit 'delete'.

And all that remains for this first exercise is to place a 'text view' on the document window and voíla we'll have our text editor.

So click the toolbar buttons in the panel off to the right until you see the same thing as below, then click and drag the image in the upper right to your document window. (The tooltip on the image should say 'NSTextView'.)

Then drag the edges of the text view so it fills the entire window. Your window should now look like the following.

Hit ⌘R to test run the window. You'll already be able to type text into it. Hit ⌘Q to quit the test run. While you're still running, type in some text, select it, and hit ⌘T to bring up the OS X font panel. Change the font around.

While you're still running, ctrl-click on the text view and toggle 'Check Spelling As You Type' to turn on OS X's automatic spell checking, then munge a few words to see how the spell checker reacts. Also try 'Spelling...' on the same 'Spelling' menu to bring up the OS X spelling panel.

And all this is all built in: you didn't have to hot-wire anything. Presenting (just a bit of) the NeXTSTEP text engine!

Now all you have to do before you save is make sure your text view follows along with your document window.

Click on your text view and hit ⌘3. You should see something like the following.

What you have to do is click inside that inner box to get those springs in there. What those springs mean is the text view will expand and contract to fit the size of the window.

[And don't worry that it says 'NSScrollView' at the top - your text view actually resides inside a scroll view - let's not get too technical here.]

When you've done this - when your 'inspector' panel looks like the above, save your project, quit Interface Builder, then run your program in Project Builder again. Try out all the features you know you have: typing in text, selecting text, cutting, copying, and pasting text, changing fonts, dragging text (and from one window to another), using the spell checker, etc.

[Don't forget to try the application's menu to open new windows (⌘N) and try dragging text between them. Also notice that 'Close' (⌘W) already works too. And hey - even your 'about box' is already in place!]

Next time we'll look at how you can open and save files with this application. (It will take 'a little bit' of code but it won't be that difficult at all - 'promise'.)

About | ACP | Buy | Forum | Industry Watch | Learning Curve | Search | Twitter | Xnews
Copyright © Rixstep. All rights reserved.