Hello to all AppleScript Studio mailing list subscribers,
I found a somewhat simple solution to the problem that an Outline
View does not call the "selection changed" handler. The workaround
involves creating a subclass of NSOutlineView, registering itself to
receive the NSOutlineViewSelectionDidChange notification and posting
a NSTableViewSelectionDidChange notification.
I'm going to demonstrate this by modifying the example project
"Outline" with you. So let's go.
2. Click the disclosure triangle next to the "Resources" folder in
the Xcode "Groups & File" list.
3. Double click the "MainMenu.nib" file to open it in Interface Builder.
4. In Interface Builder: Select the "Show Inspector" command from the
"Tools" menu in the main menu bar.
5. Select "AppleScript" from the first popup button in the Inspector
Window.
6. Click the Outline View in the "Outline" window until the title of
the Inspector Window changes to "NSOutlineView Inspector".
7. Click the disclosure triangle next to "Data View" in the "Event
Handlers" list of the Inspector Window.
8. Click the checkbox for "selection changed".
9. Make sure the checkbox next to "Application.applescript" in the
"Script" list of the Inspector Window is checked.
9. Click the "Edit" button at the bottom of the Inspector Window.
10. In Xcode: Replace the line "(*Add your script here.*) in the
"selection changed" handler with the command:
log "Selection Changed"
-- Where are we? --------------------------------
--
-- We opened the "Outline" example project, opened the MainMenu.nib
file
-- and set the Outline View in the "Outline" window to call the
"selection changed"
-- handler. We also modifed the "selection changed" handler to log a
message to
-- the run log to inform us that the script is actually performing
this handler. If we
-- would build and run this project now, changing the selection of
the outline view
-- would do nothing. Let's go on and create a subclass of
NSOutlineView to fix this problem.
-------------------------------------------------------
11. Go back to Interface Builder.
12. Click on the "Classes" tab in the "MainMenu.nib (English)" window
to bring up the Class Browser.
13. Click on the Outline View in the "Outline" window until the right
most browser column of the Class Browser reads "NSOutlineView".
14. Select the command "Subclass NSOutlineView" from the "Classes"
menu in the main menu bar.
15. A new browser column has been added reading "MyOutlineView".
16. Change the name of "MyOutlineView" to "ASKOutlineViewWorkaround"
and press the return key to confirm.
17. Select the command "Create Files for ASKOutlineViewWorkaround"
from the "Classes" menu in the main menu bar.
18. Accept the default settings in the sheet that appears by pressing
the "Choose" button.
19. Click the Outline View in the "Outline" window until the title of
the Inspector Window changes to "NSOutlineView Inspector".
20. Select "Custom Class" from the first popup button in the
Inspector Window.
21. In the "Class" list of the Inspector Window select
"ASKOutlineViewWorkaround" instead of "NSOutlineView"
-- Where are we? --------------------------------
--
-- We created a subclass of NSOutlineView, created the files and set
the
-- Outline View in the "Outline" window to be of class
"ASKOutlineViewWorkaround".
-------------------------------------------------------
22. Go back to Xcode.
23. Click the disclosure triangle next to the "Other Sources" folder
in the Xcode "Groups & File" list.
24. Double-click the "ASKOutlineViewWorkaround.h" file to edit the
header file for our custom outline view.
25. Replace the contents of this file with:
26. Go back to the "Groups & File" list and double-click the
"ASKOutlineViewWorkaround.m" file to edit the implementation file for
our custom outline view.
27. Replace the contents of this file with: