Skip to content
This repository was archived by the owner on Nov 19, 2019. It is now read-only.

Commit 94f8f83

Browse files
author
Michael Ehrmann
committed
[FIX] make sure window reappears after dropping tab on old window.
1 parent c8d0ce5 commit 94f8f83

File tree

2 files changed

+90
-65
lines changed

2 files changed

+90
-65
lines changed

Source/PSMTabBarControl.m

Lines changed: 81 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,100 +1688,116 @@ - (void)draggedImage:(NSImage *)image movedTo:(NSPoint)screenPoint {
16881688

16891689
// NSDraggingDestination
16901690
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
1691-
if([[[sender draggingPasteboard] types] indexOfObject:@"PSMTabBarControlItemPBType"] != NSNotFound) {
1692-
if([self delegate] && [[self delegate] respondsToSelector:@selector(tabView:shouldDropTabViewItem:inTabBar:)] &&
1693-
![[self delegate] tabView:[[sender draggingSource] tabView] shouldDropTabViewItem:[[[PSMTabDragAssistant sharedDragAssistant] draggedCell] representedObject] inTabBar:self]) {
1694-
return NSDragOperationNone;
1695-
}
1691+
if (self.window.alphaValue > 0.0) {
1692+
if([[[sender draggingPasteboard] types] indexOfObject:@"PSMTabBarControlItemPBType"] != NSNotFound) {
1693+
if([self delegate] && [[self delegate] respondsToSelector:@selector(tabView:shouldDropTabViewItem:inTabBar:)] &&
1694+
![[self delegate] tabView:[[sender draggingSource] tabView] shouldDropTabViewItem:[[[PSMTabDragAssistant sharedDragAssistant] draggedCell] representedObject] inTabBar:self]) {
1695+
return NSDragOperationNone;
1696+
}
16961697

1697-
[[PSMTabDragAssistant sharedDragAssistant] draggingEnteredTabBarControl:self atPoint:[self convertPoint:[sender draggingLocation] fromView:nil]];
1698-
return NSDragOperationMove;
1698+
[[PSMTabDragAssistant sharedDragAssistant] draggingEnteredTabBarControl:self atPoint:[self convertPoint:[sender draggingLocation] fromView:nil]];
1699+
return NSDragOperationMove;
1700+
}
16991701
}
1700-
17011702
return NSDragOperationNone;
17021703
}
17031704

17041705
- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender {
1705-
PSMTabBarCell *cell = [self cellForPoint:[self convertPoint:[sender draggingLocation] fromView:nil] cellFrame:nil];
1706+
if (self.window.alphaValue > 0.0) {
1707+
PSMTabBarCell *cell = [self cellForPoint:[self convertPoint:[sender draggingLocation] fromView:nil] cellFrame:nil];
17061708

1707-
if([[[sender draggingPasteboard] types] indexOfObject:@"PSMTabBarControlItemPBType"] != NSNotFound) {
1708-
if([self delegate] && [[self delegate] respondsToSelector:@selector(tabView:shouldDropTabViewItem:inTabBar:)] &&
1709-
![[self delegate] tabView:[[sender draggingSource] tabView] shouldDropTabViewItem:[[[PSMTabDragAssistant sharedDragAssistant] draggedCell] representedObject] inTabBar:self]) {
1710-
return NSDragOperationNone;
1711-
}
1709+
if([[[sender draggingPasteboard] types] indexOfObject:@"PSMTabBarControlItemPBType"] != NSNotFound) {
1710+
if([self delegate] && [[self delegate] respondsToSelector:@selector(tabView:shouldDropTabViewItem:inTabBar:)] &&
1711+
![[self delegate] tabView:[[sender draggingSource] tabView] shouldDropTabViewItem:[[[PSMTabDragAssistant sharedDragAssistant] draggedCell] representedObject] inTabBar:self]) {
1712+
return NSDragOperationNone;
1713+
}
17121714

1713-
[[PSMTabDragAssistant sharedDragAssistant] draggingUpdatedInTabBarControl:self atPoint:[self convertPoint:[sender draggingLocation] fromView:nil]];
1714-
return NSDragOperationMove;
1715-
} else if(cell) {
1716-
//something that was accepted by the delegate was dragged on
1717-
1718-
//Test for the space bar (the skip-the-delay key).
1719-
/*enum { virtualKeycodeForSpace = 49 }; //Source: IM:Tx (Fig. C-2)
1720-
union {
1721-
KeyMap keymap;
1722-
char bits[16];
1723-
} keymap;
1724-
GetKeys(keymap.keymap);
1725-
if ((GetCurrentEventKeyModifiers() == 0) && bit_test(keymap.bits, virtualKeycodeForSpace)) {
1726-
//The user pressed the space bar. This skips the delay; the user wants to pop the spring on this tab *now*.
1727-
1728-
//For some reason, it crashes if I call -fire here. I don't know why. It doesn't crash if I simply set the fire date to now.
1729-
[_springTimer setFireDate:[NSDate date]];
1730-
} else {*/
1731-
//Wind the spring for a spring-loaded drop.
1732-
//The delay time comes from Finder's defaults, which specifies it in milliseconds.
1733-
//If the delegate can't handle our spring-loaded drop, we'll abort it when the timer fires. See fireSpring:. This is simpler than constantly (checking for spring-loaded awareness and tearing down/rebuilding the timer) at every delegate change.
1734-
1735-
//If the user has dragged to a different tab, reset the timer.
1736-
if(_tabViewItemWithSpring != [cell representedObject]) {
1737-
[_springTimer invalidate];
1738-
[_springTimer release]; _springTimer = nil;
1739-
_tabViewItemWithSpring = [cell representedObject];
1740-
}
1741-
if(!_springTimer) {
1742-
//Finder's default delay time, as of Tiger, is 668 ms. If the user has never changed it, there's no setting in its defaults, so we default to that amount.
1743-
NSNumber *delayNumber = NSMakeCollectable([(NSNumber *)CFPreferencesCopyAppValue((CFStringRef)@"SpringingDelayMilliseconds", (CFStringRef)@"com.apple.finder") autorelease]);
1744-
NSTimeInterval delaySeconds = delayNumber ?[delayNumber doubleValue] / 1000.0 : 0.668;
1745-
_springTimer = [[NSTimer scheduledTimerWithTimeInterval:delaySeconds
1746-
target:self
1747-
selector:@selector(fireSpring:)
1748-
userInfo:sender
1749-
repeats:NO] retain];
1715+
[[PSMTabDragAssistant sharedDragAssistant] draggingUpdatedInTabBarControl:self atPoint:[self convertPoint:[sender draggingLocation] fromView:nil]];
1716+
return NSDragOperationMove;
1717+
} else if(cell) {
1718+
//something that was accepted by the delegate was dragged on
1719+
1720+
//Test for the space bar (the skip-the-delay key).
1721+
/*enum { virtualKeycodeForSpace = 49 }; //Source: IM:Tx (Fig. C-2)
1722+
union {
1723+
KeyMap keymap;
1724+
char bits[16];
1725+
} keymap;
1726+
GetKeys(keymap.keymap);
1727+
if ((GetCurrentEventKeyModifiers() == 0) && bit_test(keymap.bits, virtualKeycodeForSpace)) {
1728+
//The user pressed the space bar. This skips the delay; the user wants to pop the spring on this tab *now*.
1729+
1730+
//For some reason, it crashes if I call -fire here. I don't know why. It doesn't crash if I simply set the fire date to now.
1731+
[_springTimer setFireDate:[NSDate date]];
1732+
} else {*/
1733+
//Wind the spring for a spring-loaded drop.
1734+
//The delay time comes from Finder's defaults, which specifies it in milliseconds.
1735+
//If the delegate can't handle our spring-loaded drop, we'll abort it when the timer fires. See fireSpring:. This is simpler than constantly (checking for spring-loaded awareness and tearing down/rebuilding the timer) at every delegate change.
1736+
1737+
//If the user has dragged to a different tab, reset the timer.
1738+
if(_tabViewItemWithSpring != [cell representedObject]) {
1739+
[_springTimer invalidate];
1740+
[_springTimer release]; _springTimer = nil;
1741+
_tabViewItemWithSpring = [cell representedObject];
1742+
}
1743+
if(!_springTimer) {
1744+
//Finder's default delay time, as of Tiger, is 668 ms. If the user has never changed it, there's no setting in its defaults, so we default to that amount.
1745+
NSNumber *delayNumber = NSMakeCollectable([(NSNumber *)CFPreferencesCopyAppValue((CFStringRef)@"SpringingDelayMilliseconds", (CFStringRef)@"com.apple.finder") autorelease]);
1746+
NSTimeInterval delaySeconds = delayNumber ?[delayNumber doubleValue] / 1000.0 : 0.668;
1747+
_springTimer = [[NSTimer scheduledTimerWithTimeInterval:delaySeconds
1748+
target:self
1749+
selector:@selector(fireSpring:)
1750+
userInfo:sender
1751+
repeats:NO] retain];
1752+
}
1753+
return NSDragOperationCopy;
17501754
}
1751-
return NSDragOperationCopy;
17521755
}
17531756

17541757
return NSDragOperationNone;
17551758
}
17561759

17571760
- (void)draggingExited:(id <NSDraggingInfo>)sender {
1758-
[_springTimer invalidate];
1759-
[_springTimer release]; _springTimer = nil;
1761+
if (self.window.alphaValue > 0.0) {
1762+
[_springTimer invalidate];
1763+
[_springTimer release]; _springTimer = nil;
17601764

1761-
[[PSMTabDragAssistant sharedDragAssistant] draggingExitedTabBarControl:self];
1765+
[[PSMTabDragAssistant sharedDragAssistant] draggingExitedTabBarControl:self];
1766+
}
17621767
}
17631768

17641769
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender {
1765-
//validate the drag operation only if there's a valid tab bar to drop into
1766-
return [[[sender draggingPasteboard] types] indexOfObject:@"PSMTabBarControlItemPBType"] == NSNotFound ||
1767-
[[PSMTabDragAssistant sharedDragAssistant] destinationTabBar] != nil;
1770+
if (self.window.alphaValue > 0.0) {
1771+
//validate the drag operation only if there's a valid tab bar to drop into
1772+
return [[[sender draggingPasteboard] types] indexOfObject:@"PSMTabBarControlItemPBType"] == NSNotFound ||
1773+
[[PSMTabDragAssistant sharedDragAssistant] destinationTabBar] != nil;
1774+
}
1775+
return NO;
17681776
}
17691777

17701778
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
1771-
if([[[sender draggingPasteboard] types] indexOfObject:@"PSMTabBarControlItemPBType"] != NSNotFound) {
1772-
[[PSMTabDragAssistant sharedDragAssistant] performDragOperation];
1773-
} else if([self delegate] && [[self delegate] respondsToSelector:@selector(tabView:acceptedDraggingInfo:onTabViewItem:)]) {
1774-
//forward the drop to the delegate
1775-
[[self delegate] tabView:tabView acceptedDraggingInfo:sender onTabViewItem:[[self cellForPoint:[self convertPoint:[sender draggingLocation] fromView:nil] cellFrame:nil] representedObject]];
1779+
if (self.window.alphaValue > 0.0) {
1780+
if([[[sender draggingPasteboard] types] indexOfObject:@"PSMTabBarControlItemPBType"] != NSNotFound) {
1781+
[[PSMTabDragAssistant sharedDragAssistant] performDragOperation];
1782+
} else if([self delegate] && [[self delegate] respondsToSelector:@selector(tabView:acceptedDraggingInfo:onTabViewItem:)]) {
1783+
//forward the drop to the delegate
1784+
[[self delegate] tabView:tabView acceptedDraggingInfo:sender onTabViewItem:[[self cellForPoint:[self convertPoint:[sender draggingLocation] fromView:nil] cellFrame:nil] representedObject]];
1785+
}
1786+
return YES;
17761787
}
1777-
return YES;
1788+
return NO;
1789+
}
1790+
1791+
- (BOOL)wantsPeriodicDraggingUpdates {
1792+
return NO;
17781793
}
17791794

17801795
- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation {
1781-
[[PSMTabDragAssistant sharedDragAssistant] draggedImageEndedAt:aPoint operation:operation];
1796+
[[PSMTabDragAssistant sharedDragAssistant] draggedImageEndedAt:aPoint operation:operation];
17821797
}
17831798

17841799
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender {
1800+
self.window.alphaValue = 1.0;
17851801
}
17861802

17871803
#pragma mark -

Source/PSMTabDragAssistant.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,15 @@ - (void)performDragOperation {
377377
[tabView selectTabViewItem:item];
378378
}
379379
[tabView setDelegate:tempDelegate];
380+
381+
// make sure window of tab view is visible again.
382+
[tabView.window setAlphaValue:1.0];
383+
if(_currentTearOffStyle == PSMTabBarTearOffAlphaWindow) {
384+
[[tabView window] makeKeyAndOrderFront:nil];
385+
} else {
386+
//center the window over where we ended dragging
387+
[self _expandWindow:[tabView window] atPoint:[NSEvent mouseLocation]];
388+
}
380389
}
381390

382391
if(([[[self sourceTabBar] cells] indexOfObject:[self draggedCell]] != _draggedCellIndex) && [[[self sourceTabBar] delegate] respondsToSelector:@selector(tabView:didDropTabViewItem:inTabBar:)]) {

0 commit comments

Comments
 (0)