From: Kent Sutherland Date: Wed, 18 Dec 2002 00:36:56 +0000 (+0000) Subject: Added a new method, moveTab:toIndex: X-Git-Tag: v0.1~80 X-Git-Url: http://git.ithinksw.org/ITKit.git/commitdiff_plain/577abbc3a3ea97ee4db78fd638551956ae4847f7?ds=inline;hp=7b57718f8962695ae287715b8b4cd28a10ed17db Added a new method, moveTab:toIndex: --- diff --git a/ITTabView.h b/ITTabView.h index 4a03809..1c109c8 100755 --- a/ITTabView.h +++ b/ITTabView.h @@ -21,5 +21,12 @@ @interface ITTabView : NSTabView { NSTabViewItem *_draggedTab; + bool _allowsDragging; } + +- (void)setAllowsDragging:(bool)flag; +- (bool)allowsDragging; + +- (void)moveTab:(NSTabViewItem *)tab toIndex:(int)index; + @end diff --git a/ITTabView.m b/ITTabView.m index 9fbfe56..d6940a3 100755 --- a/ITTabView.m +++ b/ITTabView.m @@ -6,43 +6,64 @@ { if ( (self = [super initWithFrame:frame]) ) { _draggedTab = nil; + _allowsDragging = NO; } return self; } +- (void)setAllowsDragging:(bool)flag +{ + _allowsDragging = flag; +} + +- (bool)allowsDragging +{ + return _allowsDragging; +} + +- (void)moveTab:(NSTabViewItem *)tab toIndex:(int)index +{ + if ([self indexOfTabViewItem:tab] != index) + { + [tab retain]; + [self removeTabViewItem:tab]; + [self insertTabViewItem:tab atIndex:index]; + [self selectTabViewItem:tab]; + } +} + - (void)mouseDown:(NSEvent *)event { - NSPoint clickedPoint = [self convertPoint:[event locationInWindow] fromView:[[self window] contentView]]; - NSTabViewItem *clickedTab = [self tabViewItemAtPoint:clickedPoint]; - _draggedTab = clickedTab; + if ([self allowsDragging]) { + NSPoint clickedPoint = [self convertPoint:[event locationInWindow] fromView:[[self window] contentView]]; + NSTabViewItem *clickedTab = [self tabViewItemAtPoint:clickedPoint]; + _draggedTab = clickedTab; + } [super mouseDown:event]; } - (void)mouseUp:(NSEvent *)event { - NSPoint releasedPoint = [self convertPoint:[event locationInWindow] fromView:[[self window] contentView]]; - NSTabViewItem *releasedTab = [self tabViewItemAtPoint:releasedPoint]; - if (releasedTab && ![releasedTab isEqualTo:_draggedTab]) { - int releasedTabIndex = [self indexOfTabViewItem:releasedTab]; - [_draggedTab retain]; - [self removeTabViewItem:_draggedTab]; - [self insertTabViewItem:_draggedTab atIndex:releasedTabIndex]; - [self selectTabViewItem:_draggedTab]; + if ([self allowsDragging]) { + NSPoint releasedPoint = [self convertPoint:[event locationInWindow] fromView:[[self window] contentView]]; + NSTabViewItem *releasedTab = [self tabViewItemAtPoint:releasedPoint]; + if (releasedTab && ![releasedTab isEqualTo:_draggedTab]) { + [self moveTab:_draggedTab toIndex:[self indexOfTabViewItem:releasedTab]]; + } + _draggedTab = nil; } - _draggedTab = nil; [super mouseUp:event]; } - (void)mouseDragged:(NSEvent *)event { - NSPoint currentPoint = [self convertPoint:[event locationInWindow] fromView:[[self window] contentView]]; - NSTabViewItem *curTab = [self tabViewItemAtPoint:currentPoint]; - if (curTab && ![curTab isEqualTo:_draggedTab]) { - int curTabIndex = [self indexOfTabViewItem:curTab]; - [_draggedTab retain]; - [self removeTabViewItem:_draggedTab]; - [self insertTabViewItem:_draggedTab atIndex:curTabIndex]; - [self selectTabViewItem:_draggedTab]; + if ([self allowsDragging]) { + NSPoint currentPoint = [self convertPoint:[event locationInWindow] fromView:[[self window] contentView]]; + NSTabViewItem *curTab = [self tabViewItemAtPoint:currentPoint]; + if (curTab && ![curTab isEqualTo:_draggedTab]) { + [self moveTab:_draggedTab toIndex:[self indexOfTabViewItem:curTab]]; + [self selectTabViewItem:_draggedTab]; + } } [super mouseDragged:event]; }