Changeset 1444

Show
Ignore:
Timestamp:
06/12/04 10:19:41 (4 years ago)
Author:
nonex
Message:

Tab bar auto hides if there is only one panel active. Expands when a new one is attached.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/JVChatController.m

    r1436 r1444  
    9494        else windowController = [[[JVChatWindowController alloc] init] autorelease]; 
    9595        [self _addWindowController:windowController]; 
     96        [windowController showWindow:nil]; 
    9697        return [[windowController retain] autorelease]; 
    9798} 
  • trunk/JVChatWindowController.m

    r1436 r1444  
    5454                _views = [[NSMutableArray array] retain]; 
    5555                _usesSmallIcons = [[NSUserDefaults standardUserDefaults] boolForKey:@"JVChatWindowUseSmallDrawerIcons"]; 
    56  
    57                 [[self window] makeKeyAndOrderFront:nil]; 
    5856        } 
    5957        return self; 
  • trunk/JVTabbedChatWindowController.h

    r1436 r1444  
    88        IBOutlet NSTabView *tabView; 
    99        NSMutableArray *_tabItems; 
     10    BOOL _supressHiding; 
     11    BOOL _tabIsShowing; 
     12    BOOL _autoHideTabBar; 
     13        int _forceTabBarVisible; // -1 = Doesn't matter, 0 = NO, 1 = YES; 
     14    float _tabHeight; 
    1015} 
    11  
     16- (IBAction) toggleTabBarVisible:(id) sender; 
     17- (void) updateTabBarVisibilityAndAnimate:(BOOL) animate; 
    1218@end 
  • trunk/JVTabbedChatWindowController.m

    r1441 r1444  
    1414#pragma mark - 
    1515 
     16@interface JVTabbedChatWindowController (JVTabbedChatWindowControllerPrivate) 
     17- (void) _supressTabBarHiding:(BOOL) supress; 
     18- (void) _resizeTabBarTimer:(NSTimer *) inTimer; 
     19- (BOOL) _resizeTabBarAbsolute:(BOOL) absolute; 
     20@end 
     21 
     22#pragma mark - 
     23 
    1624@interface AICustomTabsView (AICustomTabsViewPrivate) 
    1725- (void) smoothlyArrangeTabs; 
     
    2836        if( ( self = [super initWithWindowNibName:windowNibName] ) ) { 
    2937                _tabItems = [[NSMutableArray array] retain]; 
     38                _tabIsShowing = YES; 
     39                _supressHiding = NO; 
     40                _autoHideTabBar = YES; 
     41                _forceTabBarVisible = -1; 
    3042        } 
    3143        return self; 
     
    3345 
    3446- (void) windowDidLoad { 
     47        _tabHeight = NSHeight( [customTabsView frame] ); 
     48 
    3549        [super windowDidLoad]; 
    36  
    37         [chatViewsOutlineView setRefusesFirstResponder:NO]; 
    38         [chatViewsOutlineView setAllowsEmptySelection:YES]; 
    3950 
    4051    // Remove any tabs from our tab view, it needs to start out empty 
    4152    while( [tabView numberOfTabViewItems] > 0 ) 
    4253        [tabView removeTabViewItem:[tabView tabViewItemAtIndex:0]]; 
     54 
     55        [chatViewsOutlineView setRefusesFirstResponder:NO]; 
     56        [chatViewsOutlineView setAllowsEmptySelection:YES]; 
     57 
     58        [[self window] registerForDraggedTypes:[NSArray arrayWithObjects:TAB_CELL_IDENTIFIER, nil]]; 
     59 
     60        [self updateTabBarVisibilityAndAnimate:NO]; 
     61 
     62        [[self window] useOptimizedDrawing:YES]; 
    4363} 
    4464 
     
    152172} 
    153173 
     174- (void) customTabViewDidChangeNumberOfTabViewItems:(AICustomTabsView *) view { 
     175        [self updateTabBarVisibilityAndAnimate:( [[tabView window] isVisible] )]; 
     176} 
     177 
    154178- (void) customTabViewDidChangeOrderOfTabViewItems:(AICustomTabsView *) view { 
    155179        [_views removeAllObjects]; 
     
    186210                [chatController release]; 
    187211        } 
     212 
     213        [self _supressTabBarHiding:NO]; 
    188214} 
    189215 
    190216- (NSMenu *) customTabView:(AICustomTabsView *) view menuForTabViewItem:(NSTabViewItem *) tabViewItem { 
    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; 
    193229} 
    194230 
     
    223259        return 18; 
    224260} 
     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} 
    225310@end 
    226311 
     
    228313 
    229314@implementation JVTabbedChatWindowController (JVTabbedChatWindowControllerPrivate) 
     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 
    230358- (void) _refreshList { 
    231359        [super _refreshList]; 
  • trunk/Languages/English.lproj/Colloquy.nib/classes.nib

    r1106 r1444  
    1515                showInspector = id;  
    1616                toggleSmallDrawerIcons = id;  
     17                toggleTabBarVisible = id;  
    1718                toggleViewsDrawer = id;  
    1819            };  
  • trunk/Languages/English.lproj/Colloquy.nib/info.nib

    r1387 r1444  
    44<dict> 
    55        <key>IBDocumentLocation</key> 
    6         <string>81 42 356 240 0 0 1440 878 </string> 
     6        <string>69 78 356 240 0 0 1280 832 </string> 
    77        <key>IBEditorPositions</key> 
    88        <dict> 
    99                <key>29</key> 
    10                 <string>105 627 366 44 0 0 1440 878 </string> 
     10                <string>89 592 366 44 0 0 1280 832 </string> 
    1111        </dict> 
    1212        <key>IBFramework Version</key>