Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make command-A select all the NSTextView text in rows in an NSTableView?

So if I have an NSView based tableview and inside the views are NSTextViews which are non-editable but selectable...

how can I get that nice functionality of command-A selects all the text? I don't mean row selection. I have row selection disabled for the tableview. I mean highlighting the text in blue so you can copy it to your clipboard. But not just 1 NSTextView's text from one row, all of them from all the rows.

And in addition to command-A click and drag should do this too. But out of the box it seems I can only select one row's text. Here is video showing problem:

https://dl.dropboxusercontent.com/u/2510380/table.mov (i keep clicking and dragging but can't highlight text on the next row)

here are two mac apps (skype and gabble) that do this:

https://dl.dropboxusercontent.com/u/2510380/skype.mov

and

https://dl.dropboxusercontent.com/u/2510380/gabble.mov

Assuming they are NOT using WebViews with just HTML inside, how do you get this control over the clipboard? i.e. in Skype you select the text and only the conversation is highlighted, not the timestamp of each message. Also the text copied to the clipboard is formatted very nicely. Can you point me in the right direction to reverse engineer skype?

like image 825
Andrew Arrow Avatar asked Oct 20 '22 21:10

Andrew Arrow


1 Answers

Unfortunately there's no way to do this easily. This is because only ONE control can be the first responder at a time. This means that, though you can have selection in multiple text views, there are several problems:

  1. Only one text view's text will actually be highlighted with the "live" highlight color; the others will have the gray highlight of non-focused controls.

  2. Copy commands will only apply to the first responder text view.

  3. Drag session starts will be initiated from the control the mouse was actually pointing at (irrespective of first responder) and will only drag that control's text.

  4. In a view-based table view, the controls may not even "exist" for a row not currently displayed, so it'll never get the message unless you forcibly create each row, which could be costly for a large table.

Knowing all this, you might be able to "fake it" by having your controller be complicit in a text view and table view subclass's special handling of a select-all message when it's first responder. On receiving this message, the text view subclass can call super then notify the controller (to get its default behavior AND to let you know it happened), at which point the controller can turn around and send the command to all (existing) text views. Highlighting can be spoofed by overriding the text view's drawing and a drag initiation could defer to a delegate (the controller), which would handle writing ALL the strings from your model to the pasteboard (not even touching the text views in possibly-nonexistent row views). The table view subclass would simply pass the same select-all message to the controller without calling super (and even forcibly making sure nothing is selected before returning for good measure).

I hope this helps. If I've forgotten any of your requirements, let me know.

like image 116
Joshua Nozzi Avatar answered Oct 24 '22 11:10

Joshua Nozzi