Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ozpowell opened this issue Oct 18, 2012 · 1 comment

Comments

@ozpowell
Copy link

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.

@crairdin
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants