Improve window sizing when toggling file browser

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.
This commit is contained in:
Allan Odgaard
2013-03-11 17:24:41 +01:00
parent 00d381ec5f
commit 514f65bcb5

View File

@@ -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];