From 514f65bcb583a6770c4e8dae1138fe538e03ee51 Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Mon, 11 Mar 2013 17:24:41 +0100 Subject: [PATCH] Improve window sizing when toggling file browser MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The first time the browser is toggled, we’ll save the current frame so that we can restore it if the user toggles again (the calculated frame won’t match when window is moved or width is “truncated”). Additionally when file browser is on the left side, we reframe the window so that the text view remains in the same place on the screen. Closes #827. --- .../DocumentWindow/src/DocumentController.mm | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/Frameworks/DocumentWindow/src/DocumentController.mm b/Frameworks/DocumentWindow/src/DocumentController.mm index 3bcc6a94..61a042b4 100644 --- a/Frameworks/DocumentWindow/src/DocumentController.mm +++ b/Frameworks/DocumentWindow/src/DocumentController.mm @@ -59,6 +59,8 @@ static BOOL IsInShouldTerminateEventLoop = NO; @property (nonatomic) OakFileBrowser* fileBrowser; @property (nonatomic) BOOL disableFileBrowserWindowResize; +@property (nonatomic) NSRect oldWindowFrame; +@property (nonatomic) NSRect newWindowFrame; @property (nonatomic) HTMLOutputWindowController* htmlOutputWindowController; @property (nonatomic) OakHTMLOutputView* htmlOutputView; @@ -1543,17 +1545,42 @@ namespace if(!self.disableFileBrowserWindowResize && ([self.window styleMask] & NSFullScreenWindowMask) != NSFullScreenWindowMask) { NSRect windowFrame = self.window.frame; - if(makeVisibleFlag) + + if(NSEqualRects(windowFrame, self.newWindowFrame)) + { + windowFrame = self.oldWindowFrame; + } + else if(makeVisibleFlag) { NSRect screenFrame = [[self.window screen] visibleFrame]; - windowFrame.size.width = MIN(NSWidth(windowFrame) + self.fileBrowserWidth, NSWidth(screenFrame)); - windowFrame.origin.x = MIN(NSMinX(windowFrame), NSMaxX(screenFrame) - NSWidth(windowFrame)); + CGFloat minX = NSMinX(windowFrame); + CGFloat maxX = NSMaxX(windowFrame); + + if(self.layoutView.fileBrowserOnRight) + maxX += self.fileBrowserWidth + 1; + else minX -= self.fileBrowserWidth + 1; + + if(minX < NSMinX(screenFrame)) + maxX += NSMinX(screenFrame) - minX; + if(maxX > NSMaxX(screenFrame)) + minX -= maxX - NSMaxX(screenFrame); + + minX = MAX(minX, NSMinX(screenFrame)); + maxX = MIN(maxX, NSMaxX(screenFrame)); + + windowFrame.origin.x = minX; + windowFrame.size.width = maxX - minX; } else { - windowFrame.size.width -= self.fileBrowserWidth; + windowFrame.size.width -= self.fileBrowserWidth + 1; + if(!self.layoutView.fileBrowserOnRight) + windowFrame.origin.x += self.fileBrowserWidth + 1; } + + self.oldWindowFrame = self.window.frame; [self.window setFrame:windowFrame display:YES]; + self.newWindowFrame = self.window.frame; } } [[self class] scheduleSessionBackup:self];