-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNSSplitView+GitX.m
47 lines (37 loc) · 1.54 KB
/
NSSplitView+GitX.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//
// NSSplitView+GitX.m
// GitX
//
// Created by Kent Sutherland on 4/25/17.
//
//
#import "NSSplitView+GitX.h"
@implementation NSSplitView (GitX)
// Taken from http://stackoverflow.com/questions/16587058/nssplitview-auto-saving-divider-positions-doesnt-work-with-auto-layout-enable
// Without this split views don't automatically restore for windows that aren't reopened by state restoration
- (void)pb_restoreAutosavedPositions
{
NSString *key = [NSString stringWithFormat:@"NSSplitView Subview Frames %@", self.autosaveName];
NSArray<NSString *> *subviewFrames = [[NSUserDefaults standardUserDefaults] objectForKey:key];
// the last frame is skipped because I have one less divider than I have frames
for (NSInteger i = 0; i < subviewFrames.count; i++) {
if (i < self.subviews.count) { // safety-check (in case number of views have been removed while dev)
// this is the saved frame data - it's an NSString
NSString *frameString = subviewFrames[i];
NSArray<NSString *> *components = [frameString componentsSeparatedByString:@", "];
// Manage the 'hidden state' per view
BOOL hidden = [components[4] boolValue];
NSView *subview = [self subviews][i];
[subview setHidden:hidden];
// Set height (horizontal) or width (vertical)
if (![self isVertical]) {
CGFloat height = [components[3] floatValue];
[subview setFrameSize:NSMakeSize(subview.frame.size.width, height)];
} else {
CGFloat width = [components[2] floatValue];
[subview setFrameSize:NSMakeSize(width, subview.frame.size.height)];
}
}
}
}
@end