Changeset 10371


Ignore:
Timestamp:
Mar 14, 2010, 2:53:22 AM (12 years ago)
Author:
livings124
Message:

move the code for remembering resize information for the info views into the individual views

Location:
trunk/macosx
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/InfoFileViewController.h

    r10368 r10371  
    4242- (void) updateInfo;
    4343
     44- (void) saveViewSize;
     45
    4446- (void) setFileFilterText: (id) sender;
    4547
  • trunk/macosx/InfoFileViewController.m

    r10335 r10371  
    4747- (void) awakeFromNib
    4848{
     49    const CGFloat height = [[NSUserDefaults standardUserDefaults] floatForKey: @"InspectorContentHeightFiles"];
     50    if (height != 0.0)
     51    {
     52        NSRect viewRect = [[self view] frame];
     53        viewRect.size.height = height;
     54        [[self view] setFrame: viewRect];
     55    }
     56   
    4957    [[fFileFilterField cell] setPlaceholderString: NSLocalizedString(@"Filter", "inspector -> file filter")];
    5058}
     
    7583    if ([fTorrents count] == 1)
    7684        [fFileController reloadData];
     85}
     86
     87- (void) saveViewSize
     88{
     89    [[NSUserDefaults standardUserDefaults] setFloat: NSHeight([[self view] frame]) forKey: @"InspectorContentHeightFiles"];
    7790}
    7891
  • trunk/macosx/InfoPeersViewController.h

    r10369 r10371  
    4545- (void) updateInfo;
    4646
     47- (void) saveViewSize;
    4748- (void) clearView;
    4849- (void) stopWebSeedAnimation;
  • trunk/macosx/InfoPeersViewController.m

    r10369 r10371  
    4848- (void) awakeFromNib
    4949{
     50    const CGFloat height = [[NSUserDefaults standardUserDefaults] floatForKey: @"InspectorContentHeightPeers"];
     51    if (height != 0.0)
     52    {
     53        NSRect viewRect = [[self view] frame];
     54        viewRect.size.height = height;
     55        [[self view] setFrame: viewRect];
     56    }
     57   
    5058    //set table header text
    5159    [[[fPeerTable tableColumnWithIdentifier: @"IP"] headerCell] setStringValue: NSLocalizedString(@"IP Address",
     
    222230}
    223231
     232- (void) saveViewSize
     233{
     234    [[NSUserDefaults standardUserDefaults] setFloat: NSHeight([[self view] frame]) forKey: @"InspectorContentHeightPeers"];
     235}
     236
    224237- (void) clearView
    225238{
  • trunk/macosx/InfoTrackersViewController.h

    r10369 r10371  
    4747- (void) updateInfo;
    4848
     49
     50- (void) saveViewSize;
    4951- (void) clearView;
    5052
  • trunk/macosx/InfoTrackersViewController.m

    r10369 r10371  
    3535#define TRACKER_REMOVE_TAG 1
    3636
     37
    3738@interface InfoTrackersViewController (Private)
    3839
     
    5455   
    5556    return self;
     57}
     58
     59- (void) awakeFromNib
     60{
     61    const CGFloat height = [[NSUserDefaults standardUserDefaults] floatForKey: @"InspectorContentHeightTracker"];
     62    if (height != 0.0)
     63    {
     64        NSRect viewRect = [[self view] frame];
     65        viewRect.size.height = height;
     66        [[self view] setFrame: viewRect];
     67    }
    5668}
    5769
     
    121133        }
    122134    }
     135}
     136
     137- (void) saveViewSize
     138{
     139    [[NSUserDefaults standardUserDefaults] setFloat: NSHeight([[self view] frame]) forKey: @"InspectorContentHeightTracker"];
    123140}
    124141
  • trunk/macosx/InfoViewController.h

    r10369 r10371  
    3333@optional
    3434- (void) clearView;
     35- (void) saveViewSize;
    3536
    3637@end
  • trunk/macosx/InfoWindowController.m

    r10370 r10371  
    142142- (void) dealloc
    143143{
    144     //save resizeable view height
    145     NSString * resizeSaveKey = nil;
    146     switch (fCurrentTabTag)
    147     {
    148         case TAB_TRACKERS_TAG:
    149             resizeSaveKey = @"InspectorContentHeightTracker";
    150             break;
    151         case TAB_PEERS_TAG:
    152             resizeSaveKey = @"InspectorContentHeightPeers";
    153             break;
    154         case TAB_FILE_TAG:
    155             resizeSaveKey = @"InspectorContentHeightFiles";
    156             break;
    157     }
    158     if (resizeSaveKey)
    159         [[NSUserDefaults standardUserDefaults] setFloat: [[fViewController view] frame].size.height forKey: resizeSaveKey];
    160    
    161144    [[NSNotificationCenter defaultCenter] removeObserver: self];
     145   
     146    if ([fViewController respondsToSelector: @selector(saveViewSize)])
     147        [fViewController saveViewSize];
    162148   
    163149    [fGeneralViewController dealloc];
     
    215201    //take care of old view
    216202    CGFloat oldHeight = 0;
    217     NSString * oldResizeSaveKey = nil;
    218203    if (oldTabTag != INVALID)
    219204    {
     
    221206        [(InfoTabButtonCell *)[fTabMatrix cellWithTag: oldTabTag] setSelectedTab: NO];
    222207       
     208        if ([fViewController respondsToSelector: @selector(saveViewSize)])
     209            [fViewController saveViewSize];
     210       
    223211        if ([fViewController respondsToSelector: @selector(clearView)])
    224212            [fViewController clearView];
    225213       
    226         switch (oldTabTag)
    227         {
    228             case TAB_TRACKERS_TAG:
    229                 oldResizeSaveKey = @"InspectorContentHeightTracker";
    230                 break;
    231             case TAB_PEERS_TAG:
    232                 oldResizeSaveKey = @"InspectorContentHeightPeers";
    233                 break;
    234             case TAB_FILE_TAG:
    235                 oldResizeSaveKey = @"InspectorContentHeightFiles";
    236                 break;
    237         }
    238        
    239214        NSView * oldView = [fViewController view];
    240215        oldHeight = NSHeight([oldView frame]);
    241         if (oldResizeSaveKey)
    242             [[NSUserDefaults standardUserDefaults] setFloat: oldHeight forKey: oldResizeSaveKey];
    243216       
    244217        //remove old view
     
    249222    //set new tab item
    250223    #warning get titles from view controller?
    251     NSString * resizeSaveKey = nil;
    252224    NSString * identifier, * title;
    253225    switch (fCurrentTabTag)
     
    285257            identifier = TAB_TRACKER_IDENT;
    286258            title = NSLocalizedString(@"Trackers", "Inspector -> title");
    287             resizeSaveKey = @"InspectorContentHeightTracker";
    288259            break;
    289260        case TAB_PEERS_TAG:
     
    297268            identifier = TAB_PEERS_IDENT;
    298269            title = NSLocalizedString(@"Peers", "Inspector -> title");
    299             resizeSaveKey = @"InspectorContentHeightPeers";
    300270            break;
    301271        case TAB_FILE_TAG:
     
    309279            identifier = TAB_FILES_IDENT;
    310280            title = NSLocalizedString(@"Files", "Inspector -> title");
    311             resizeSaveKey = @"InspectorContentHeightFiles";
    312281            break;
    313282        case TAB_OPTIONS_TAG:
     
    342311    NSRect windowRect = [window frame], viewRect = [view frame];
    343312   
    344     if (resizeSaveKey)
    345     {
    346         CGFloat height = [[NSUserDefaults standardUserDefaults] floatForKey: resizeSaveKey];
    347         if (height != 0.0)
    348             viewRect.size.height = MAX(height, TAB_MIN_HEIGHT);
    349     }
    350    
    351     CGFloat difference = (viewRect.size.height - oldHeight) * [window userSpaceScaleFactor];
     313    CGFloat difference = (NSHeight(viewRect) - oldHeight) * [window userSpaceScaleFactor];
    352314    windowRect.origin.y -= difference;
    353315    windowRect.size.height += difference;
    354316   
    355     if (resizeSaveKey)
    356     {
    357         if (!oldResizeSaveKey)
    358         {
    359             [window setMinSize: NSMakeSize([window minSize].width, windowRect.size.height - viewRect.size.height + TAB_MIN_HEIGHT)];
    360             [window setMaxSize: NSMakeSize(FLT_MAX, FLT_MAX)];
    361         }
     317    if ([fViewController respondsToSelector: @selector(saveViewSize)]) //a little bit hacky, but avoids an extra required method
     318    {
     319        [window setMinSize: NSMakeSize([window minSize].width, NSHeight(windowRect) - NSHeight(viewRect) + TAB_MIN_HEIGHT)];
     320        [window setMaxSize: NSMakeSize(FLT_MAX, FLT_MAX)];
    362321    }
    363322    else
    364323    {
    365         [window setMinSize: NSMakeSize([window minSize].width, windowRect.size.height)];
    366         [window setMaxSize: NSMakeSize(FLT_MAX, windowRect.size.height)];
     324        [window setMinSize: NSMakeSize([window minSize].width, NSHeight(windowRect))];
     325        [window setMaxSize: NSMakeSize(FLT_MAX, NSHeight(windowRect))];
    367326    }
    368327   
Note: See TracChangeset for help on using the changeset viewer.