My favorites | Sign in
Project Home Downloads Wiki Issues Source
Repository:
Checkout   Browse   Changes   Clones  
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */

// Original - Christopher Lloyd <cjwl@objc.net>
#import <AppKit/NSWindowController.h>
#import <AppKit/NSWindow.h>
#import <AppKit/NSNibLoading.h>
#import <AppKit/NSDocument.h>

@implementation NSWindowController

-initWithWindow:(NSWindow *)window {
_window=[window retain];
_nibPath=nil;
_owner=nil;
_document=nil;
_nibPathIsName=NO;
_shouldCloseDocument=YES;
_shouldCascadeWindows=YES;
_windowFrameAutosaveName=nil;
return self;
}

-initWithWindowNibName:(NSString *)nibName {
return [self initWithWindowNibName:nibName owner:self];
}

-initWithWindowNibName:(NSString *)nibName owner:owner {
[self initWithWindow:nil];
_nibPath=[nibName copy];
_nibPathIsName=YES;
_owner=owner;
return self;
}

-initWithWindowNibPath:(NSString *)nibPath owner:owner {
[self initWithWindow:nil];
_nibPath=[nibPath copy];
_nibPathIsName=NO;
_owner=owner;
return self;
}

-(void)dealloc {
[_window release];
[_nibPath release];
[_windowFrameAutosaveName release];
[super dealloc];
}

-(NSWindow *)window {
if(_window==nil && _nibPath!=nil){
[self windowWillLoad];
[_document windowControllerWillLoadNib:self];

[self loadWindow];

[self windowDidLoad];
[_document windowControllerDidLoadNib:self];
}

return _window;
}

-(void)setWindow:(NSWindow *)window {
window=[window retain];
[_window release];
_window=window;
}

-(BOOL)isWindowLoaded {
return (_window!=nil)?YES:NO;
}

-(void)loadWindow {
NSString *path=[self windowNibPath];
NSDictionary *nameTable=[NSDictionary dictionaryWithObject:_owner forKey:@"NSOwner"];

[NSBundle loadNibFile:path externalNameTable:nameTable withZone:NULL];
[self synchronizeWindowTitleWithDocumentName];
}

-(void)windowWillLoad {
// do nothing
}

-(void)windowDidLoad {
// do nothing
}

-(void)showWindow:sender {
[[self window] makeKeyAndOrderFront:sender];
}

-(void)setDocument:(NSDocument *)document {
_document=document;
}

-(id)document {
return _document;
}

-(void)setDocumentEdited:(BOOL)flag {
[_window setDocumentEdited:flag];
}

-(void)close {
[_window close];
}

-(BOOL)shouldCloseDocument {
return _shouldCloseDocument;
}

-(void)setShouldCloseDocument:(BOOL)flag {
_shouldCloseDocument=flag;
}

-owner {
return _owner;
}

-(NSString *)windowNibName {
if(_nibPathIsName)
return _nibPath;
else {
return [[_nibPath lastPathComponent] stringByDeletingPathExtension];
}
}

-(NSString *)windowNibPath {
if(!_nibPathIsName)
return _nibPath;
else {
NSString *name=_nibPath;
NSBundle *bundle=[NSBundle bundleForClass:[_owner class]];
NSString *path=[bundle pathForResource:name ofType:@"nib"];

if(path==nil)
path=[[NSBundle mainBundle] pathForResource:name ofType:@"nib"];

return path;
}
}

-(void)setShouldCascadeWindows:(BOOL)flag {
_shouldCascadeWindows=flag;
}

-(BOOL)shouldCascadeWindows {
return _shouldCascadeWindows;
}

-(void)setWindowFrameAutosaveName:(NSString *)name {
name=[name copy];
[_windowFrameAutosaveName release];
_windowFrameAutosaveName=name;
}

-(NSString *)windowFrameAutosaveName {
return _windowFrameAutosaveName;
}

-(void)synchronizeWindowTitleWithDocumentName {
if(_document!=nil && _window!=nil){
NSString *displayName=[_document displayName];
NSString *title=[self windowTitleForDocumentDisplayName:displayName];
NSString *path=[_document fileName];

if(path==nil)
[_window setTitle:title];
else
[_window setTitle:[NSString stringWithFormat:@"%@ -- %@",displayName,[path stringByDeletingLastPathComponent]]];
}
}

-(NSString *)windowTitleForDocumentDisplayName:(NSString *)displayName {
return displayName;
}

@end

Change log

2470bd80abf4 by cocotron on Jan 1, 2007   Diff
Added templates for many missing classes,
updated copyright for 2007, +[NSValue
valueWithRange:],-[NSObject className]
Go to: 
Project members, sign in to write a code review

Older revisions

e5277a40a7e8 by cocotron on Dec 21, 2006   Diff
Original
All revisions of this file

File info

Size: 4823 bytes, 186 lines
Powered by Google Project Hosting