| 191 | | [[self window] makeFirstResponder:[[_activeViewController view] nextKeyView]]; |
|---|
| 192 | | return [[(JVChatTabItem *)tabViewItem chatViewController] menu]; |
|---|
| | 217 | if( [[(JVChatTabItem *)tabViewItem chatViewController] respondsToSelector:@selector( menu )] ) { |
|---|
| | 218 | [[self window] makeFirstResponder:[[_activeViewController view] nextKeyView]]; |
|---|
| | 219 | return [[(JVChatTabItem *)tabViewItem chatViewController] menu]; |
|---|
| | 220 | } |
|---|
| | 221 | |
|---|
| | 222 | return nil; |
|---|
| | 223 | } |
|---|
| | 224 | |
|---|
| | 225 | - (NSString *) customTabView:(AICustomTabsView *) view toolTipForTabViewItem:(NSTabViewItem *) tabViewItem { |
|---|
| | 226 | if( [[(JVChatTabItem *)tabViewItem chatViewController] respondsToSelector:@selector( toolTip )] ) |
|---|
| | 227 | return [[(JVChatTabItem *)tabViewItem chatViewController] toolTip]; |
|---|
| | 228 | return nil; |
|---|
| | 261 | |
|---|
| | 262 | #pragma mark - |
|---|
| | 263 | #pragma mark Tab Bar Visibility toggle |
|---|
| | 264 | |
|---|
| | 265 | // Toggles whether we should hide or show the tab bar |
|---|
| | 266 | - (IBAction) toggleTabBarVisible:(id) sender { |
|---|
| | 267 | if( _forceTabBarVisible < 0 ) { |
|---|
| | 268 | if( _tabIsShowing ) _forceTabBarVisible = 0; |
|---|
| | 269 | else _forceTabBarVisible = 1; |
|---|
| | 270 | } else if( ! _forceTabBarVisible ) _forceTabBarVisible = 1; |
|---|
| | 271 | else if( _forceTabBarVisible > 0 ) _forceTabBarVisible = 0; |
|---|
| | 272 | |
|---|
| | 273 | [self updateTabBarVisibilityAndAnimate:YES]; |
|---|
| | 274 | } |
|---|
| | 275 | |
|---|
| | 276 | // Update the visibility of our tab bar (tab bar is visible if there are 2 or more tabs present) |
|---|
| | 277 | - (void) updateTabBarVisibilityAndAnimate:(BOOL) animate { |
|---|
| | 278 | if( tabView ) { // Ignore if our tabs haven't loaded yet |
|---|
| | 279 | BOOL shouldShowTabs = ( _supressHiding || ! _autoHideTabBar || ( [tabView numberOfTabViewItems] > 1 ) ); |
|---|
| | 280 | |
|---|
| | 281 | if( _forceTabBarVisible != -1 ) shouldShowTabs = ( _forceTabBarVisible || _supressHiding ); |
|---|
| | 282 | |
|---|
| | 283 | if( shouldShowTabs != _tabIsShowing ) { |
|---|
| | 284 | _tabIsShowing = shouldShowTabs; |
|---|
| | 285 | if( animate ) [self _resizeTabBarTimer:nil]; |
|---|
| | 286 | else [self _resizeTabBarAbsolute:YES]; |
|---|
| | 287 | } |
|---|
| | 288 | } |
|---|
| | 289 | } |
|---|
| | 290 | |
|---|
| | 291 | // Drag entered, enable suppression |
|---|
| | 292 | - (NSDragOperation) draggingEntered:(id <NSDraggingInfo>) sender { |
|---|
| | 293 | NSString *type = [[sender draggingPasteboard] availableTypeFromArray:[NSArray arrayWithObjects:TAB_CELL_IDENTIFIER, nil]]; |
|---|
| | 294 | NSDragOperation operation = NSDragOperationNone; |
|---|
| | 295 | |
|---|
| | 296 | if( ! sender || type ) { |
|---|
| | 297 | [self _supressTabBarHiding:YES]; // show the tab bar |
|---|
| | 298 | if( ! [[self window] isKeyWindow] ) [[self window] makeKeyAndOrderFront:nil]; // bring our window to the front |
|---|
| | 299 | operation = NSDragOperationPrivate; |
|---|
| | 300 | } |
|---|
| | 301 | |
|---|
| | 302 | return operation; |
|---|
| | 303 | } |
|---|
| | 304 | |
|---|
| | 305 | // Drag exited, disable suppression |
|---|
| | 306 | - (void) draggingExited:(id <NSDraggingInfo>) sender { |
|---|
| | 307 | NSString *type = [[sender draggingPasteboard] availableTypeFromArray:[NSArray arrayWithObjects:TAB_CELL_IDENTIFIER, nil]]; |
|---|
| | 308 | if( ! sender || type ) [self _supressTabBarHiding:NO]; // hide the tab bar |
|---|
| | 309 | } |
|---|
| | 315 | - (void) _supressTabBarHiding:(BOOL) supress { |
|---|
| | 316 | _supressHiding = supress; // temporarily suppress bar hiding |
|---|
| | 317 | [self updateTabBarVisibilityAndAnimate:YES]; |
|---|
| | 318 | } |
|---|
| | 319 | |
|---|
| | 320 | // Smoothly resize the tab bar (calls itself with a timer until the tabbar is correctly positioned) |
|---|
| | 321 | - (void) _resizeTabBarTimer:(NSTimer *) inTimer { |
|---|
| | 322 | // If the tab bar isn't at the right height, we set ourself to adjust it again |
|---|
| | 323 | if( inTimer == nil || ! [self _resizeTabBarAbsolute:NO] ) { //Do nothing when called from outside a timer. This prevents the tabs from jumping when set from show to hide, and back rapidly. |
|---|
| | 324 | [NSTimer scheduledTimerWithTimeInterval:( 1. / 30. ) target:self selector:@selector( _resizeTabBarTimer: ) userInfo:nil repeats:NO]; |
|---|
| | 325 | } |
|---|
| | 326 | } |
|---|
| | 327 | |
|---|
| | 328 | // Resize the tab bar towards it's desired height |
|---|
| | 329 | - (BOOL) _resizeTabBarAbsolute:(BOOL) absolute { |
|---|
| | 330 | NSSize tabSize = [customTabsView frame].size; |
|---|
| | 331 | double destHeight = 0.; |
|---|
| | 332 | NSRect newFrame = NSZeroRect; |
|---|
| | 333 | |
|---|
| | 334 | // determine the desired height |
|---|
| | 335 | destHeight = ( _tabIsShowing ? _tabHeight : 0. ); |
|---|
| | 336 | |
|---|
| | 337 | // move the tab view's height towards this desired height |
|---|
| | 338 | int distance = ( destHeight - tabSize.height ) * 0.8; |
|---|
| | 339 | if( absolute || ( distance > -1 && distance < 1 ) ) distance = destHeight - tabSize.height; |
|---|
| | 340 | |
|---|
| | 341 | tabSize.height += distance; |
|---|
| | 342 | [customTabsView setFrameSize:tabSize]; |
|---|
| | 343 | [customTabsView setNeedsDisplay:YES]; |
|---|
| | 344 | |
|---|
| | 345 | // adjust other views |
|---|
| | 346 | newFrame = [tabView frame]; |
|---|
| | 347 | newFrame.size.height -= distance; |
|---|
| | 348 | newFrame.origin.y += distance; |
|---|
| | 349 | [tabView setFrame:newFrame]; |
|---|
| | 350 | [tabView setNeedsDisplay:YES]; |
|---|
| | 351 | |
|---|
| | 352 | [[self window] displayIfNeeded]; |
|---|
| | 353 | |
|---|
| | 354 | // return YES when the desired height is reached |
|---|
| | 355 | return ( tabSize.height == destHeight ); |
|---|
| | 356 | } |
|---|
| | 357 | |
|---|