-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathMyDocument.m
176 lines (130 loc) · 4.77 KB
/
MyDocument.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
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
//
// MyDocument.m
// GCDrawKit
//
// Created by graham on 5/12/09.
// Copyright 2009-2011 Apptree.net. All rights reserved.
//
#import "MyDocument.h"
#import "GCUndoManager.h"
#import "GCUndoTestView.h"
@implementation MyDocument
- (id)init
{
self = [super init];
if (self) {
// Add your subclass-specific initialization here.
// If an error occurs here, send a [self release] message and return nil.
GCUndoManager* um = [[GCUndoManager alloc] init];
[um enableUndoTaskCoalescing];
[um setLevelsOfUndo:16];
[self setUndoManager:(id)um];
[um release];
[self setHasUndoManager:YES];
}
return self;
}
- (NSString *)windowNibName
{
// Override returning the nib file name of the document
// If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
return @"MyDocument";
}
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
(void)typeName;
// Insert code here to write your document to data of the specified type. If the given outError != NULL, ensure that you set *outError when returning nil.
// You can also choose to override -fileWrapperOfType:error:, -writeToURL:ofType:error:, or -writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead.
// For applications targeted for Panther or earlier systems, you should use the deprecated API -dataRepresentationOfType:. In this case you can also choose to override -fileWrapperRepresentationOfType: or -writeToFile:ofType: instead.
if ( outError != NULL ) {
*outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
}
return nil;
}
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
{
(void)data;
(void)typeName;
// Insert code here to read your document from the given data of the specified type. If the given outError != NULL, ensure that you set *outError when returning NO.
// You can also choose to override -readFromFileWrapper:ofType:error: or -readFromURL:ofType:error: instead.
// For applications targeted for Panther or earlier systems, you should use the deprecated API -loadDataRepresentation:ofType. In this case you can also choose to override -readFromFile:ofType: or -loadFileWrapperRepresentation:ofType: instead.
if ( outError != NULL ) {
*outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
}
return YES;
}
- (IBAction) enableUndoAction:(id) sender
{
NSCellStateValue state = [(NSButton*)sender state];
if(state == NSOnState )
[[self undoManager] enableUndoRegistration];
else
[[self undoManager] disableUndoRegistration];
}
- (IBAction) enableCoalescingAction:(id) sender
{
NSCellStateValue state = [(NSButton*)sender state];
if(state == NSOnState )
[(GCUndoManager*)[self undoManager] enableUndoTaskCoalescing];
else
[(GCUndoManager*)[self undoManager] disableUndoTaskCoalescing];
}
- (IBAction) enableEventGroupingAction:(id) sender
{
NSCellStateValue state = [(NSButton*)sender state];
[[self undoManager] setGroupsByEvent:(state == NSOnState)];
}
- (IBAction) removeAllActionsAction:(id) sender
{
(void)sender;
[[self undoManager] removeAllActions];
}
- (IBAction) colourAction:(id) sender
{
[mMainView setDraggedBoxColour:[sender color]];
}
- (IBAction) umTypeAction:(id) sender
{
NSInteger tag = [[sender selectedCell] tag];
id um;
if( tag == 0 )
{
um = [[NSUndoManager alloc] init];
[mEnableCoalescingCheckbox setEnabled:NO];
}
else
{
um = [[GCUndoManager alloc] init];
[mEnableCoalescingCheckbox setEnabled:YES];
if([mEnableCoalescingCheckbox state] == NSOnState)
[um enableUndoTaskCoalescing];
}
[um setLevelsOfUndo:16];
[self setUndoManager:um];
[um release];
}
- (IBAction) logUMDescription:(id) sender
{
(void)sender;
NSLog(@"%@", [[self undoManager] description]);
}
- (IBAction) explodeUndoAction:(id) sender
{
(void)sender;
if([[self undoManager] respondsToSelector:@selector(explodeTopUndoAction)])
[(GCUndoManager*)[self undoManager] explodeTopUndoAction];
}
- (void) windowControllerDidLoadNib:(NSWindowController *) aController
{
[super windowControllerDidLoadNib:aController];
[mEnableUndoCheckbox setState:[[self undoManager] isUndoRegistrationEnabled]];
[mEnableCoalescingCheckbox setState:[(GCUndoManager*)[self undoManager] isUndoTaskCoalescingEnabled]];
[mEnableGroupByEventCheckbox setState:[[self undoManager] groupsByEvent]];
[mColourPropertyWell setColor:[mMainView draggedBoxColour]];
id um = [self undoManager];
if([um isKindOfClass:[GCUndoManager class]])
[mUndoTypeRadioButtons selectCellWithTag:1];
else
[mUndoTypeRadioButtons selectCellWithTag:0];
}
@end