Changeset 4956

Show
Ignore:
Timestamp:
10/16/07 17:29:56 (9 months ago)
Author:
morris
Message:

Fix problems with saving only window frame origin

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • WiredAdditions/trunk/WIWindowController.m

    r4707 r4956  
    3030#import <WiredAdditions/WIWindowController.h> 
    3131 
    32 static NSMutableDictionary                      *_WIWindowController_frames; 
    33 static NSMutableArray                           *_WIWindowController_windows; 
     32#define WIWindowControllerCascadeOffsetX        20.0 
     33#define WIWindowControllerCascadeOffsetY        20.0 
     34 
     35 
     36static NSMutableDictionary                                      *_WIWindowController_frames; 
     37static NSMutableArray                                           *_WIWindowController_windows; 
     38 
    3439 
    3540@interface WIWindowController(Private) 
     
    96101- (void)_loadWindowFrame { 
    97102        NSScreen        *screen; 
    98         NSString        *key, *frame, *previousFrame; 
    99         NSRect          rect, previousRect; 
    100         NSSize          size; 
     103        NSString        *key, *savedFrameString, *cascadedFrameString; 
     104        NSRect          frame, previousFrame, cascadedFrame, savedFrame; 
    101105         
    102106        if([_WI_windowFrameAutosaveName length] > 0) { 
    103107                key = [NSSWF:@"WIWindowController %@ Frame", _WI_windowFrameAutosaveName]; 
    104                 frame = [[NSUserDefaults standardUserDefaults] objectForKey:key]; 
    105                 size = [[self window] frame].size
    106                  
    107                 if([frame length] > 0) 
    108                         rect = NSRectFromString(frame); 
     108                savedFrameString = [[NSUserDefaults standardUserDefaults] objectForKey:key]; 
     109                previousFrame = [[self window] frame]
     110                 
     111                if([savedFrameString length] > 0) 
     112                        savedFrame = NSRectFromString(savedFrameString); 
    109113                else 
    110                         rect = [[self window] frame]; 
     114                        savedFrame = previousFrame; 
     115                 
     116                if([self shouldSaveWindowFrameOriginOnly]) { 
     117                        frame.origin.x = savedFrame.origin.x; 
     118                        frame.origin.y = savedFrame.origin.y + savedFrame.size.height - previousFrame.size.height; 
     119                        frame.size = previousFrame.size; 
     120                } else { 
     121                        frame = savedFrame; 
     122                } 
    111123                         
    112124                if(_WI_shouldCascadeWindows) { 
    113                         previousFrame = [_WIWindowController_frames objectForKey:key]; 
    114                          
    115                         if([previousFrame length] > 0) { 
    116                                 previousRect = NSRectFromString(previousFrame); 
    117                                 rect.origin = previousRect.origin; 
     125                        cascadedFrameString = [_WIWindowController_frames objectForKey:key]; 
     126                         
     127                        if([cascadedFrameString length] > 0) { 
     128                                cascadedFrame = NSRectFromString(cascadedFrameString); 
     129                                 
     130                                if([self shouldSaveWindowFrameOriginOnly]) { 
     131                                        frame.origin.x = cascadedFrame.origin.x; 
     132                                        frame.origin.y = cascadedFrame.origin.y + cascadedFrame.size.height - previousFrame.size.height; 
     133                                } else { 
     134                                        frame.origin = cascadedFrame.origin; 
     135                                } 
    118136                        } 
    119137                         
    120                         rect.origin.x += 20.0
    121                         rect.origin.y -= 20.0
    122                          
    123                         if(rect.origin.x < 0.0 || rect.origin.y < 0.0) { 
     138                        frame.origin.x += WIWindowControllerCascadeOffsetX
     139                        frame.origin.y -= WIWindowControllerCascadeOffsetY
     140                         
     141                        if(frame.origin.x < 0.0 || frame.origin.y < 0.0) { 
    124142                                screen = [[self window] screen]; 
    125143                                 
    126                                 rect.origin.x = 20.0
    127                                 rect.origin.y = [screen frame].size.height - 20.0
     144                                frame.origin.x = WIWindowControllerCascadeOffsetX
     145                                frame.origin.y = [screen frame].size.height - WIWindowControllerCascadeOffsetY
    128146                        } 
    129147                } 
    130148                 
    131                 if([self shouldSaveWindowFrameOriginOnly]) 
    132                         rect.size = size; 
    133                  
    134                 [[self window] setFrame:rect display:NO]; 
     149                [[self window] setFrame:frame display:NO]; 
    135150                 
    136151                [_WIWindowController_windows addObject:[self window]]; 
    137                 [_WIWindowController_frames setObject:NSStringFromRect(rect) forKey:key]; 
     152                [_WIWindowController_frames setObject:NSStringFromRect(frame) forKey:key]; 
    138153        } 
    139154} 
     
    143158- (void)_saveWindowFrame { 
    144159        NSString        *key, *value; 
    145         NSRect          rect
    146          
    147         if([_WI_windowFrameAutosaveName length] > 0) { 
    148                 rect = [[self window] frame]; 
     160        NSRect          frame
     161         
     162        if([_WI_windowFrameAutosaveName length] > 0) { 
     163                frame = [[self window] frame]; 
    149164                 
    150165                if(_WI_shouldCascadeWindows) { 
    151                         rect.origin.x -= 20; 
    152                         rect.origin.y += 20; 
    153                 } 
    154                  
    155                  
     166                        frame.origin.x -= WIWindowControllerCascadeOffsetY; 
     167                        frame.origin.y += WIWindowControllerCascadeOffsetX; 
     168                } 
    156169                 
    157170                key = [NSSWF:@"WIWindowController %@ Frame", _WI_windowFrameAutosaveName]; 
    158                 value = NSStringFromRect(rect); 
     171                value = NSStringFromRect(frame); 
    159172 
    160173                [[NSUserDefaults standardUserDefaults] setObject:value forKey:key];