Change in File Link Behavior in NSTextView Under Leopard
Change in File Link Behavior in NSTextView Under Leopard
- Subject: Change in File Link Behavior in NSTextView Under Leopard
- From: Mike Wright <email@hidden>
- Date: Sat, 12 Jan 2008 14:20:18 -0500
I have a Cocoa application ( compiled under XCode 2.5 to work under
both Tiger and Leopard) that lets users create links to files on disk.
Under Tiger, clicking one of these links acts just like double-
clicking the file icon in the Finder--it opens the file in its default
application.
Under Leopard, clicking a file link just shows the file in the Finder.
I thought at first that Leopard might have added a System Preference
item to control this, but haven't found anything.
So, has the behavior of file links been changed in Leopard, or am I
seeing a flaw in my approach that just slipped through in Tiger? The
code involved is pretty simple.
My routine gets an NSURL from from the open panel like this:
NSString *pathName = [[oPanel filenames] objectAtIndex:0];
NSURL *theURL =[NSURL fileURLWithPath:pathName];
The resulting pathName will look something like this:
file://localhost/Users/mikewright/Pictures/fourcards.jpg.
Then, I add theURL to a piece of text in an NSTextView,
freeformTextView:
NSDictionary *attributes = [NSDictionary dictionaryWithObject:theURL
forKey:NSLinkAttributeName];
[[freeformTextView textStorage] addAttributes:(NSDictionary
*)attributes range:(NSRange)selectionRange];
Since I have an NSWindowController that contains freeformTextView, I
decided to implement -textView:clickedOnLink:atIndex: and, within
that, call LSOpenCFURLRef to launch the URL in the link.
That works great under both Tiger and Leopard.
However...I also have an NSTableView that can contain links. In this
case, the link is stored as a plain text as a standard URL, and is
only activated when the cell containing it is clicked.
I have an NSObject, EditorTableController, set as the delegate for the
NSTableView.
In EditorTableController , there is a routine that activates the link
in a clicked cell. There I call:
NSTextView *tableTextView = (NSTextView *)[[editorWindowController
window] firstResponder];
So, in that routine, I decided to add:
[tableTextView setDelegate:self];
I also added -textView:clickedOnLink:atIndex: to
EditorTableController, just as I did for my window controller.
After that, clicking file links caused the files to open just like the
ones in freeformTextView.
Great!
There's just one little glitch--now when I make changes in a cell and
then select a different cell, those changes evaporate.
I've read and re-read the NSTableView documentation, but I haven't
been able to find out how to keep that from happening.
I've also tried saving the tableTextView delegate before the
setDelegate:self call, and then restoring it in -
tableView:shouldEditTableColumn:row: and several other places, but
nothing seems to have any effect on this last problem.
The best solution would be if there were some way to tell Leopard to
behave like Tiger when a file link is clicked.
If that can't be done, is there some solution to the NSTableView
problem that I have missed?
Thanks,
Mike Wright
http://www.idata3.com/
http://www.raccoonbend.com/
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden