Skip to content

Strange behaviour if tabView:shouldAllowTabViewItem:toLeaveTabBar: returns NO #27

Open

Description

@ozpowell

Hi,

I have noticed unusual behaviour when the tabView:shouldAllowTabViewItem:toLeaveTabBar: delegate method return NO. My goal is to allow tabs to be dragged within the current tab bar (to allow them to be re-ordered), but to disallow tear-off or dropping onto other tab bars.

I have modified DemoWindowController.m to include the following delegate method:

- (BOOL) tabView:(NSTabView *)aTabView shouldAllowTabViewItem:(NSTabViewItem *)tabViewItem toLeaveTabBar:(PSMTabBarControl *)tabBarControl
{
    return NO;
}

With the above change, I am able to successfully drag tabs within the tab bar, but if I attempt to drop outside of the tab bar, the ordering of the tabs seems to get out of sync with the actual tab view. Similarly, the highlighting of the tabs doesn't correspond with the currently selected tab view item in the tab view.

I hope this makes sense. Please feel free to contact me if you require any further information.

Activity

  1. crairdin commented on Aug 27, 2013

    @crairdin

    I also saw this erroneous behavior. If you look at the comments in performDragOperation you'll see why it doesn't work: When you try to put the dragged cell back into the original tab bar at the same index you took it from, you will fail to account for the placeholders that are inserted when dragging begins. Rather than duplicating the code that removes the placeholders, I fixed it by modifying draggedImageEndedAt:operation: so that instead of simply putting the dragged cell back at the index from which it was taken, it calls performDragOperation. Here's the modified code:

            // put cell back
            // 8/27/13 - You can't just put this back at the same location because there are 
            // placeholders inserted during dragging. See comments in performDragOperation.
            // AVOID:
            // [[self sourceTabBar] insertCell:[self draggedCell] atIndex:[self draggedCellIndex]];
            [self performDragOperation];
    

    It's possible I'm not accounting for all conditions, but this seems to be working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions