-
Notifications
You must be signed in to change notification settings - Fork 0
/
SWSheetController.m
85 lines (63 loc) · 1.98 KB
/
SWSheetController.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
//
// PMDisplaySheet.m
// This file is part of the "SWApplicationSupport" project, and is distributed under the MIT License.
//
// Created by Samuel Williams on 10/07/05.
// Copyright 2005 Samuel Williams. All rights reserved.
//
#import "SWSheetController.h"
@implementation SWSheetController
- (IBAction)showSheet: (id)sender {
NSAssert(self.window != nil, @"Sheet outlet must be set before showing sheet!");
NSAssert(self.parent != nil, @"Parent outlet must be set before showing sheet!");
[self.parent beginSheet:self.window completionHandler:^(NSModalResponse returnCode) {
[self sheetDidEnd:self.window returnCode:returnCode contextInfo:sender];
}];
}
- (IBAction)cancelSheet: (id) sender {
[self.parent endSheet:self.window returnCode:-1];
}
- (IBAction)processSheet: (id) sender {
[self.parent endSheet:self.window returnCode:0];
}
- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(id)contextInfo {
NSAssert(sheet == self.window, @"Inconsistent sheet supplied to controller.");
[self close];
if ([_delegate respondsToSelector:@selector(sheetController:didEndWithResult:)])
[_delegate sheetController:self didEndWithResult:returnCode];
if (contextInfo && [contextInfo conformsToProtocol:@protocol(SWSheetDelegate)])
[contextInfo sheetController:self didEndWithResult:returnCode];
}
- (void) prepareSheet {
}
- (NSString *)nibName {
NSLog(@"Warning: SWSheetController#nibName not implemented!");
return nil;
}
- (NSString *)windowNibName {
return [self nibName];
}
- (void)windowDidLoad
{
[self prepareSheet];
}
- (id)document {
if (self.parent) {
id windowController = (self.parent).windowController;
if (windowController) {
id document = [windowController document];
return document;
}
} else {
NSLog(@"Trying to get document but no parent specified!");
}
return nil;
}
- (id)managedObjectContext {
id document = self.document;
if (document)
return [document managedObjectContext];
else
return nil;
}
@end