I have a question about implementing a few specific behaviors in NSTableViews/NSOutlineViews.
WHAT I’M TRYING TO ACHIEVE:
I’m trying to create an NSOutlineView that mimics the behavior of Photoshop’s layers panel (except the “Layers” column is hierarchical). My outlineview is a 3-column table, with a “Layer” column, “Visbility” column, and a “Lock” column. I’ve implemented the “visibility” and “lock” columns as NSImageCells, and the “layer” column as a custom text and image cell.
Specifically, here’s the behavior I’m struggling to implement:
-
Just like Photoshop, the user should be able to click on a visibility (eyeball) icon and drag up or down to different rows to turn the other row visibilities “on” or “off” depending on the visibility of the first row clicked…exactly how Photoshop does hiding and showing of layers. Note that autoscroll should be supported for cases when there are many rows in the table.
-
Just like Photoshop, when one or more rows in the “Layer” column is selected, the visibility/lock columns should NOT have the highlight bar behind them (that is, the row highlight should not pass through their columns).
-
Clicking and/or dragging in the “visibility” or “lock” columns should not change the selection of the table…only their states as described above.
I’ve been banging my head against the wall for a week trying to get this to work. I’ve read the Controls & Cells Programming Guide, Table View Programming Guide, Class references for NSCell, NSActionCell, NSTableView, NSControl, NSOutlineView, and the Protocol references for NSOutlineViewDelegate and NSOutlineViewDataSource…and have been trying different approaches all week…and I’m just not figuring this one out.
Can someone steer me in the right direction? Thanks in advance for the help!
Through some additional web searching and experimentation, I can answer most of my own questions:
HIGHLIGHTING ONLY THE FIRST COLUMN IN THE NSOUTLINEVIEW
I was able to have the selection highlight appear only over the selected rows of the first column by subclassing NSOutlineView and implementing
It’s important to note that I had to override my custom NSCell subclass’s drawInteriorWithFrame:inView: method to keep it from drawing the standard highlight, like this:
So there’s a solution for part of the question. If this isn’t the “correct” way, please let me know :).
CLICKING/DRAGGING IN VIS/LOCK COLUMNS SHOULD NOT CHANGE THE SELECTION
I’ve determined now that I should be doing this in the
method. If I’m in the middle of a drag that originated in the visibility or lock columns, I just return the current selectedRows to keep the selection the same. I haven’t implemented this yet, but it should be easy once I get my final problem solved (see below).
DRAGGING UP OR DOWN IN VISIBILITY/LOCKED COLUMNS TO CHANGE THEIR STATE
I’m getting really close with this one. In my custom NSCell, I’ve overridden the following three methods:
I’m down to my last problem, and here it is: I need to know when I’m inside the dragging operation and when the dragging operation finishes. There’s two ways I can do this:
If I do not override
in my NSCell subclass (so it returns the default NO value), then I receive a stopTracking:at:inView:mouseIsUp: message every time I leave a cell and go to the next one during a dragging operation…which means I can’t use that method to determine when the dragging operation is done.
If instead I do override
and return YES, I get a stopTracking:… call only on mouse up, which is great…but the problem is that the table doesn’t seem to update the UI for the cell on mouseDown or while I’m dragging inside the cell. For instance, in the startTracking:… method, if I set the cell’s objectValue to nil (so that its image is no longer displayed), I don’t see the update until the mouse button goes back up or the cursor leaves the cell. (When prefersTrackingUntilMouseUp returned NO, it updated immediately).
So I need to both be able to update the cell’s UI immediately (on mouseDown) but also have a way to know when the dragging operation completes. This is the final piece of the puzzle. Can anyone help?