3 @implementation ITTabView
5 - (id)initWithFrame:(NSRect)frame
7 if ( (self = [super initWithFrame:frame]) ) {
14 - (void)setAllowsDragging:(bool)flag
16 _allowsDragging = flag;
19 - (bool)allowsDragging
21 return _allowsDragging;
24 - (void)moveTab:(NSTabViewItem *)tab toIndex:(int)index
26 if ([self indexOfTabViewItem:tab] != index)
29 [self removeTabViewItem:tab];
30 [self insertTabViewItem:tab atIndex:index];
31 [self selectTabViewItem:tab];
35 - (void)mouseDown:(NSEvent *)event
37 if ([self allowsDragging]) {
38 NSPoint clickedPoint = [self convertPoint:[event locationInWindow] fromView:[[self window] contentView]];
39 NSTabViewItem *clickedTab = [self tabViewItemAtPoint:clickedPoint];
40 _draggedTab = clickedTab;
42 [super mouseDown:event];
45 - (void)mouseUp:(NSEvent *)event
47 if ([self allowsDragging]) {
48 NSPoint releasedPoint = [self convertPoint:[event locationInWindow] fromView:[[self window] contentView]];
49 NSTabViewItem *releasedTab = [self tabViewItemAtPoint:releasedPoint];
50 if (releasedTab && ![releasedTab isEqualTo:_draggedTab]) {
51 [self moveTab:_draggedTab toIndex:[self indexOfTabViewItem:releasedTab]];
55 [super mouseUp:event];
58 - (void)mouseDragged:(NSEvent *)event
60 if ([self allowsDragging]) {
61 NSPoint currentPoint = [self convertPoint:[event locationInWindow] fromView:[[self window] contentView]];
62 NSTabViewItem *curTab = [self tabViewItemAtPoint:currentPoint];
63 if (curTab && ![curTab isEqualTo:_draggedTab]) {
64 [self moveTab:_draggedTab toIndex:[self indexOfTabViewItem:curTab]];
65 [self selectTabViewItem:_draggedTab];
68 [super mouseDragged:event];