Skip to content

Commit 42bb6fb

Browse files
committedJun 5, 2019
In SSYDooDoUndoManager, removed the kludgey methods to 'couple' to document and managed object context, because now thanks to BSManagedDocument commit aa76e79, this can be done without kludging, and it seems to have fixed some edge case hangs.
1 parent 23fac6a commit 42bb6fb

File tree

2 files changed

+0
-89
lines changed

2 files changed

+0
-89
lines changed
 

‎SSYDooDooUndoManager.h

-51
Original file line numberDiff line numberDiff line change
@@ -99,45 +99,6 @@ extern NSString* const SSYUndoManagerDocumentWillSaveNotification ;
9999
NSManagedObjectContext* m_managedObjectContext ;
100100
}
101101

102-
/*!
103-
@brief Gets a newSSYDooDooUndoManager instance and assigns it
104-
to a given document and its managed object context.
105-
106-
@details The document is required for three reasons:
107-
* The returned SSYDooDooUndoManager instance is set as its undo manager.
108-
* The returned SSYDooDooUndoManager instance is set as its
109-
managed object context's undo manager.
110-
* The returned SSYDooDooUndoManager begins observing it for
111-
SSYUndoManagerDocumentWillSaveNotification.
112-
* A weak reference to the document's undo manager is kept
113-
in order to -processPendingChanges before ending an undo group.
114-
115-
Although the document could possibly be obtained by iterating
116-
through the shared NSDocumentController's documents, that will fail
117-
if you invoke this method during document initialization, before it
118-
has been added to NSDocumentController, which you usually do.
119-
120-
Note that NSDocument creates an NSUndoManager and assigns it during
121-
its initialization. Thus, the document you pass will probably already
122-
have an undo manager. That's OK, though. We just set our own
123-
instead, and the original NSUndoManager instance is discarded.
124-
125-
We access the managed object context of the given document by
126-
sending -managedObjectContext to it. If the document has never
127-
has never before had its managed object context accessed in this
128-
way, this will cause one to be created. Thus, if your document
129-
did not have a managed object context prior to being passed to
130-
this method, it will have one after this method executes.
131-
It needs one sooner or later anyhow.
132-
133-
@param document The document to be associated with the new
134-
SSYDooDooUndoManager instance.
135-
@result The new SSYDooDooUndoManager instance. Typically, you
136-
don't need this. You can always get it later by sending -undoManager
137-
to your document.
138-
*/
139-
+ (SSYDooDooUndoManager*)makeUndoManagerForDocument:(NSDocument*)document ;
140-
141102
/*!
142103
@brief Begins an undo grouping which is highly resistant to
143104
being screwed up by Core Data and closes itself automatically.
@@ -189,18 +150,6 @@ extern NSString* const SSYUndoManagerDocumentWillSaveNotification ;
189150
*/
190151
- (void)endUndoGrouping ;
191152

192-
/*!
193-
@brief Performs operations necessary to make the receiver act as the undo
194-
manager for a given document
195-
@details You typically send this after initializing the receiver, if the
196-
receiver is to be the undo manager for a document. This method does not
197-
associate a document's managed object context, if any. For Core Data documents,
198-
you must also -coupleToManagedObjectContext:.
199-
*/
200-
- (void)coupleToDocument:(NSDocument*)document ;
201-
202-
- (void)coupleToManagedObjectContext:(NSManagedObjectContext*)managedObjectContext ;
203-
204153
@end
205154

206155

‎SSYDooDooUndoManager.m

-38
Original file line numberDiff line numberDiff line change
@@ -35,50 +35,12 @@ - (NSInteger)nLivingManualGroups {
3535

3636
@synthesize managedObjectContext = m_managedObjectContext ;
3737

38-
- (void)coupleToManagedObjectContext:(NSManagedObjectContext*)managedObjectContext {
39-
[managedObjectContext setUndoManager:(id)self] ;
40-
[self setManagedObjectContext:managedObjectContext] ;
41-
}
42-
43-
44-
- (void)coupleToDocument:(NSDocument*)document {
45-
// [self setGroupsByEvent:NO] ; // Causes all hell to break loose with Core Data.
46-
47-
/* The following line has no effect if document defines its
48-
-setUndoManager method to be a noop. Check with your document class :)
49-
50-
We cast to an id since the compiler expects these to methods
51-
to get something which inherits from NSUndoManager, which
52-
GCUndoManager does not. */
53-
[document setUndoManager:(id)self] ; // Causes moc to be created, which causes persisten store to be created ??
54-
55-
[[NSNotificationCenter defaultCenter] addObserver:self
56-
selector:@selector(endAnyUndoGroupings:)
57-
name:SSYUndoManagerDocumentWillSaveNotification
58-
object:document] ;
59-
[[NSNotificationCenter defaultCenter] addObserver:self
60-
selector:@selector(endAnyUndoGroupings:)
61-
name:SSYUndoManagerDocumentWillCloseNotification
62-
object:document] ;
63-
}
64-
6538
- (void)dealloc {
6639
[[NSNotificationCenter defaultCenter] removeObserver:self] ;
6740

6841
[super dealloc] ;
6942
}
7043

71-
+ (SSYDooDooUndoManager*)makeUndoManagerForDocument:(BSManagedDocument*)document {
72-
SSYDooDooUndoManager* undoManager = [[SSYDooDooUndoManager alloc] init] ;
73-
/* The following line has no effect if document defines its
74-
-setUndoManager method to be a noop. Check with your document class :)
75-
. */
76-
[undoManager coupleToDocument:document] ;
77-
[undoManager coupleToManagedObjectContext:[document managedObjectContext]] ;
78-
[undoManager autorelease] ;
79-
return undoManager ;
80-
}
81-
8244
- (void)beginManualUndoGrouping {
8345
if ([self isUndoRegistrationEnabled]) {
8446
nLivingManualGroups++ ;

0 commit comments

Comments
 (0)
Please sign in to comment.