-
Notifications
You must be signed in to change notification settings - Fork 4
/
InspectorPaneContainer.m
150 lines (112 loc) · 4.29 KB
/
InspectorPaneContainer.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//
// InspectorContainer.m
// InspectorPane
//
// Created by Steven on 3/8/09.
// Copyright 2009 Thoughtful Tree Software. All rights reserved.
//
#import "InspectorPaneContainer.h"
#import "InspectorPane.h"
#import "NSWindow+Geometry.h"
@interface InspectorPaneContainer ( Private )
- (void) adjustActualWindowToFitContainer;
- (void) repositionViewsIgnoringView:(NSView*)viewToIgnore;
// get rid of these 2
- (void) setHeight:(float)newHeight forPane:(NSView*)view;
- (void) togglePane:(InspectorPane*)pane collapsed:(BOOL)collapsed;
@end
@implementation InspectorPaneContainer
@synthesize autosaveName;
- (id)initWithFrame:(NSRect)frame {
if (self = [super initWithFrame:frame]) {
autosaveName = [@"Some_Inspector" retain];
}
return self;
}
- (id)initWithCoder:(NSCoder*)coder {
if (self = [super initWithCoder:coder]) {
autosaveName = [[coder decodeObjectForKey:@"SDAutosaveName"] retain];
NSArray *subviews = [coder decodeObjectForKey:@"SDSubviews"];
[self setSubviews:subviews];
}
return self;
}
- (void) encodeWithCoder:(NSCoder*)coder {
[super encodeWithCoder:coder];
[coder encodeObject:autosaveName forKey:@"SDAutosaveName"];
[coder encodeObject:[self subviews] forKey:@"SDSubviews"];
}
- (void) dealloc {
for (NSView *subview in [self subviews]) {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:NSViewFrameDidChangeNotification
object:subview];
}
[autosaveName release];
[super dealloc];
}
- (void) awakeFromNib {
topMargin = NSHeight([[self superview] frame]) - NSMaxY([self frame]);
if (SDIsInIB == NO) {
[self adjustActualWindowToFitContainer];
[[self window] setShowsResizeIndicator:NO];
[[self window] setMovableByWindowBackground:YES];
//[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resetWindowSize:) name:NSApplicationWillTerminateNotification object:NSApp];
for (NSView *subview in [self subviews]) {
if ([subview isHidden])
continue;
[subview setPostsFrameChangedNotifications:YES];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(adjustSubviewFrames:)
name:NSViewFrameDidChangeNotification
object:subview];
}
[self repositionViewsIgnoringView:nil];
}
}
- (void) adjustSubviewFrames:(NSNotification*)notification {
[self repositionViewsIgnoringView:[notification object]];
}
- (void) adjustActualWindowToFitContainer {
float distanceFromTop = NSHeight([[self superview] frame]) - NSMaxY([self frame]);
NSRect selfFrame = [self frame];
selfFrame.size.height -= 20.0;
NSSize newContentViewSize = selfFrame.size;
newContentViewSize.height += distanceFromTop;
[[self window] setContentViewSize:newContentViewSize display:YES animate:NO];
selfFrame.origin.x = 0;
selfFrame.origin.y = 0;
[self setFrame:selfFrame];
}
// these 2 methods are apparently only here for persistence.. thus they're horribly named :/
- (void) togglePane:(InspectorPane*)pane collapsed:(BOOL)collapsed {
//int index = [[self subviews] indexOfObject:view];
//[collapsedSubviewIndexes replaceObjectAtIndex:index withObject:[NSNumber numberWithBool:collapsed]];
}
- (void) setHeight:(float)newHeight forPane:(NSView*)view {
// int index = [[self subviews] indexOfObject:view];
// [subviewHeights replaceObjectAtIndex:index withObject:[NSNumber numberWithFloat:newHeight]];
}
- (void) repositionViewsIgnoringView:(NSView*)viewToIgnore {
float top = 0.0;
for (NSView *view in [[self subviews] objectEnumerator]) {
NSRect newFrame = [view frame];
newFrame.origin.y = [self frame].size.height - (newFrame.size.height + top);
if (view == viewToIgnore)
[view setPostsFrameChangedNotifications:NO];
[view setFrame:newFrame];
if (view == viewToIgnore)
[view setPostsFrameChangedNotifications:YES];
top += newFrame.size.height;
}
NSView *contentView = [self superview];
NSRect newMainFrame = [self bounds];
newMainFrame.origin.y = [contentView frame].size.height - newMainFrame.size.height - topMargin;
newMainFrame.size.height = top;
[self setFrame:newMainFrame];
NSSize contentViewSize = newMainFrame.size;
contentViewSize.height += topMargin;
NSRect newWindowFrame = [[self window] windowFrameForNewContentViewSize:contentViewSize];
[[self window] setFrame:newWindowFrame display:YES];
}
@end