The dissolve, cut and slides all work properly now, I hope :D
[ITKit.git] / ITTabView.m
index d6940a3..66f0bcc 100755 (executable)
@@ -1,5 +1,15 @@
 #import "ITTabView.h"
 
+/*************************************************************************/
+#pragma mark -
+#pragma mark EVIL HACKERY
+/*************************************************************************/
+
+@interface NSTabViewItem (HACKHACKHACKHACK)
+- (NSRect)_tabRect;
+@end
+
+
 @implementation ITTabView
 
 - (id)initWithFrame:(NSRect)frame
@@ -7,6 +17,7 @@
     if ( (self = [super initWithFrame:frame]) ) {
         _draggedTab = nil;
         _allowsDragging = NO;
+        _requiredModifiers = NSCommandKeyMask;
     }
     return self;
 }
@@ -14,6 +25,7 @@
 - (void)setAllowsDragging:(bool)flag
 {
     _allowsDragging = flag;
+    _requiredModifiers = NSCommandKeyMask;
 }
 
 - (bool)allowsDragging
     return _allowsDragging;
 }
 
+- (void)setRequiredModifiers:(unsigned int)modifiers
+{
+    _requiredModifiers = modifiers;
+}
+
+- (unsigned int)requiredModifiers
+{
+    return _requiredModifiers;
+}
+
 - (void)moveTab:(NSTabViewItem *)tab toIndex:(int)index
 {
     if ([self indexOfTabViewItem:tab] != index)
@@ -34,8 +56,9 @@
 
 - (void)mouseDown:(NSEvent *)event
 {
-    if ([self allowsDragging]) {
-        NSPoint clickedPoint = [self convertPoint:[event locationInWindow] fromView:[[self window] contentView]];
+    if ((_requiredModifiers == 0 || ([[NSApp currentEvent] modifierFlags] & _requiredModifiers)) && [self allowsDragging]) {
+        NSPoint clickedPoint;
+        clickedPoint = [self convertPoint:[event locationInWindow] fromView:[[self window] contentView]];
         NSTabViewItem *clickedTab = [self tabViewItemAtPoint:clickedPoint];
         _draggedTab = clickedTab;
     }
@@ -44,7 +67,7 @@
 
 - (void)mouseUp:(NSEvent *)event
 {
-    if ([self allowsDragging]) {
+    if (_draggedTab && [self allowsDragging]) {
         NSPoint releasedPoint = [self convertPoint:[event locationInWindow] fromView:[[self window] contentView]];
         NSTabViewItem *releasedTab = [self tabViewItemAtPoint:releasedPoint];
         if (releasedTab && ![releasedTab isEqualTo:_draggedTab]) {
@@ -57,7 +80,7 @@
 
 - (void)mouseDragged:(NSEvent *)event
 {
-    if ([self allowsDragging]) {
+    if (_draggedTab && [self allowsDragging]) {
         NSPoint currentPoint = [self convertPoint:[event locationInWindow] fromView:[[self window] contentView]];
         NSTabViewItem *curTab = [self tabViewItemAtPoint:currentPoint];
         if (curTab && ![curTab isEqualTo:_draggedTab]) {
@@ -68,4 +91,5 @@
     [super mouseDragged:event];
 }
 
+
 @end