Re: Making NSTableView Cells Selectable, But Not Editable
Re: Making NSTableView Cells Selectable, But Not Editable
- Subject: Re: Making NSTableView Cells Selectable, But Not Editable
- From: Matt Neuburg <email@hidden>
- Date: Tue, 27 Jun 2006 10:27:20 -0700
- Thread-topic: Making NSTableView Cells Selectable, But Not Editable
On Tue, 27 Jun 2006 10:22:32 -0500, Mike Wright <email@hidden>
said:
>(I thought I'd try this again on a weekday.)
>
>I have a window containing an NSTableView. I have a controller object
>set as delegate for the table view, but have not subclassed the table
>view.
>
>The following applies to the IBAction method that is called whenever
>the table is clicked.
>
>I look at a BOOL to decide whether to keep the user from editing cells
>in the table view. However, the cell content needs to remain
>selectable for copying or for dragging to other windows.
>
>I can't use -tableView:shouldEditTableColumn:row:, because returning
>NO to that apparently prevents cell selection as well as editing.
>NSTableColumn -setEditable: causes the same problem.
>
>As this is only called after the table view field editor has become
>the first responder, I use the following line to get the current
>cell text:
>
> NSTextView *textView = (NSTextView *)[[editorWindowController
>window] firstResponder];
>
>Then, if required by my BOOL, I say:
>
> [textView setEditable:NO];
>
>This works just fine if the user single-clicks in a cell. The cell
>becomes active, but the text is not automatically selected. The text
>is selectable, so it can be copied or dragged, but is not editable,
>so it can't be changed.
>
>The problem arises when the user double-clicks in a cell. The cell
>content is selected automatically and is editable. (This is not
>disastrous, because the document associated with the table view
>cannot be saved, but it's still misleading and potentially confusing
>to the user.)
>
>Just hacking around, I've also tried adding the following lines,
>which don't seem to have any effect, either:
>
> [tableView setIgnoresMultiClick:YES];
> [tableView setDoubleAction:nil];
>
>In this same action method, I also set a link attribute if the cell
>contains a URL. This works as expected when I single-click; the URL
>text becomes blue and underlined. When I double-click a cell that
>contains a URL, however, I can see the text going blue and underlined
>while the background remains white, but then the text goes plain
>again and becomes selected. So, it appears that the double-click is
>causing something to happen following my action method, which is
>undoing my attempts to make the cell uneditable--and redrawing the
>cell in the process.
>
>How do I prevent this? Do I have to subclass my NSTableView? If so,
>in which method would I do it? -doubleAction: is called "when the
>user double-clicks a column header or an uneditable cell", and my
>cells are not technically "uneditable"--or are they? I think I'm
>beginning to get confused...
>
>What have I missed in all this mess?
Why don't you just implement control:textShouldBeginEditing: and return the
value of your boolean?
m.
PS. It also happens that in your app (iData 2) single-clicking a row
automatically makes that cell editable (and you can't cancel out of this
situation by hitting Return). I've lost a lot of data because I clicked on
row and then happened to start typing, accidentally wiping out what was in
the cell. In my view, a cell should not become editable unless the user does
something explicit (e.g. double-clicks). Fixing this might be better both
for the user and for the programmer. :)
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden