Using the Pasteboard in GraphPaper
To demonstrate how to use the pasteboard, we’ll first modify the GraphPaper application so that a user can copy a graph to the pasteboard by choosing the Edit → Copy menu command.
When you create a new project in Project Builder and then open the
MainMenu.nib file in Interface Builder, you
are automatically provided with an Edit submenu like the one shown in
Figure 20-1. The top seven menu items listed (all
but the Find and Spelling submenus) come preconnected to the
Responder icon (a proxy icon in IB that represents the current First
Responder object, which changes in response to user events). The
methods invoked by the First Responder object in response to these
menu commands are undo:, redo:, cut:,
copy:, paste:,clear:, and selectAll:,
respectively. Thus, to implement Cut and Copy menu commands for the
graph, all we need to do is add cut:
and copy: methods to
GraphPaper’s Controller class and make Controller
the NSApp (NSApplication object) delegate. (Note that we already made
Controller the NSApp delegate, in Chapter 17.) The
cut: and copy:
messages will automatically be forwarded to
NSApp’s delegate, unless another responder in the
responder chain intercepts them first.
Figure 20-1. Default Edit menu provided for a new Cocoa application in IB
GraphPaper’s implementation of cut, copy, and paste will be able to provide data in two formats: ...
Get Building Cocoa Applications: A Step by Step Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.