Skip to content

Commit aa80ebd

Browse files
committed
Continuation of last Commit. Just trying to get Xcode and Git to cooperate.
1 parent 1c3fffc commit aa80ebd

10 files changed

+157
-41
lines changed

SSYLazyView.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ extern NSString* SSYLazyViewDidLoadPayloadNotification;
4848
4949
@details When the receiver loads its nib as a result of being moved to a
5050
window, the window controller of the window to which it was moved is assigned
51-
as the file's owner of the nib.
51+
as the file's owner of the nib. This will cause it to receive -awakeFromNib,
52+
which has probably happened already. Therefore, such a window controller's
53+
-awakeFromNib method typically needs a lockout to prevent it from running more
54+
than once in an instance.
5255
5356
In the Xcode xib editor, you may have one or more initial placeholder subviews
5457
in your Lazy View. For example, you may place a text field with large

SSYMOCManager.h

+10-4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@
7878
If you do not wish to support multi-hop migration, you may pass nil
7979
and only Core Data's built-in single-hop automatic migration will
8080
be used. For store types other than sqlite, this parameter is ignored.
81+
@param useLegacyRollbackJournaling. See Apple WWDC 2013 Session 207,
82+
"What's New in Core Data and iCloud", 40:00 - 48:00. Ignored if storeType
83+
is not NSSQLiteStoreType.
8184
@param error_p If managed object context could not be created, points to an NSError
8285
on output. This should not occur for NSInMemoryStoreType, only NSSQLiteStoreType.
8386
@result The new or pre-existing managed object context, or nil if one could not be created.
@@ -86,6 +89,7 @@
8689
owner:(id)owner
8790
identifier:(NSString*)identifier
8891
momdName:(NSString*)momdName
92+
useLegacyRollbackJournaling:(BOOL)useLegacyRollbackJournaling
8993
error_p:(NSError**)error_p ;
9094

9195
/*!
@@ -96,10 +100,12 @@
96100
for the managed objects.
97101
98102
This method retains the -document parameter until it receives a corresponding
99-
+destroyManagedObjectContext message, so be careful or you will create retain cycles.
100-
This method will, however, *replace* its record for a particular document if you later
101-
send this message again for the same document with a new or same managedObjectContext.
102-
@param document The document which owns the managed object context
103+
+destroyManagedObjectContext message, so be careful or you will create retain
104+
cycles. This method will, however, *replace* its record for a particular
105+
document if you later send this message again for the same document with a new
106+
or same managedObjectContext.
107+
@param document The document which will own the managed object context
108+
103109
@param managedObjectContext The managed object context to be registered.
104110
*/
105111
+ (void)registerOwnerDocument:(NSPersistentDocument*)document

SSYMOCManager.m

+32-10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#import "BkmxBasis.h"
1313
#import "NSBundle+SSYMotherApp.h"
1414
#import "NSBundle+MainApp.h"
15+
#import "NSDictionary+SimpleMutations.h"
1516

1617

1718
NSString* const constKeyMOC = @"moc" ;
@@ -140,6 +141,7 @@ + (BOOL)sqliteStoreExistsForIdentifier:(NSString*)identifier {
140141
+ (NSPersistentStoreCoordinator*)persistentStoreCoordinatorType:(NSString*)storeType
141142
identifier:(NSString*)identifier
142143
momdName:(NSString*)momdName
144+
options:(NSDictionary*)options
143145
error_p:(NSError**)error_p {
144146
NSPersistentStore* persistentStore = nil ;
145147

@@ -196,26 +198,30 @@ + (NSPersistentStoreCoordinator*)persistentStoreCoordinatorType:(NSString*)store
196198
}
197199

198200
if (ok) {
199-
NSDictionary* options ;
200-
if (momdName) {
201+
if (momdName) {
201202
// Using Multi-Hop Migration
202203
ok = [SSYPersistentDocumentMultiMigrator migrateIfNeededStoreAtUrl:url
203-
storeOptions:nil
204+
storeOptions:options
204205
storeType:NSSQLiteStoreType
205206
momdName:momdName
206207
document:nil
207208
error_p:error_p] ;
208-
options = nil ;
209209
}
210210
else {
211211
// Using Core Data's built-in Single-Hop Migration only
212-
options = [NSDictionary dictionaryWithObjectsAndKeys:
213-
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
214-
nil] ;
212+
NSDictionary* moreOption = [NSDictionary dictionaryWithObjectsAndKeys:
213+
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
214+
nil] ;
215+
if (options) {
216+
options = [options dictionaryByAddingEntriesFromDictionary:moreOption] ;
217+
}
218+
else {
219+
options = moreOption ;
220+
}
215221
}
216222

217223
if (ok) {
218-
// Add persistent store to it
224+
// Add persistent store to it
219225
persistentStore = [newPSC addPersistentStoreWithType:NSSQLiteStoreType
220226
configuration:nil
221227
URL:url
@@ -282,7 +288,7 @@ + (NSPersistentStoreCoordinator*)persistentStoreCoordinatorType:(NSString*)store
282288
persistentStore = [newPSC addPersistentStoreWithType:NSInMemoryStoreType
283289
configuration:nil
284290
URL:nil
285-
options:nil
291+
options:options
286292
error:error_p] ;
287293

288294
if (!persistentStore) {
@@ -304,6 +310,7 @@ - (NSManagedObjectContext*)managedObjectContextType:(NSString*)type
304310
owner:(id)owner_
305311
identifier:(NSString*)identifier
306312
momdName:(NSString*)momdName
313+
options:(NSDictionary*)options
307314
error_p:(NSError**)error_p {
308315
NSManagedObjectContext* managedObjectContext = nil ;
309316
NSMutableDictionary* mocDics = nil ;
@@ -325,6 +332,7 @@ - (NSManagedObjectContext*)managedObjectContextType:(NSString*)type
325332
NSPersistentStoreCoordinator* coordinator = [[self class] persistentStoreCoordinatorType:type
326333
identifier:identifier
327334
momdName:momdName
335+
options:options
328336
error_p:error_p] ;
329337
if (coordinator) {
330338
managedObjectContext = [[NSManagedObjectContext alloc] init] ;
@@ -469,11 +477,25 @@ + (NSManagedObjectContext*)managedObjectContextType:(NSString*)type
469477
owner:(id)owner
470478
identifier:(NSString*)identifier
471479
momdName:(NSString*)momdName
480+
useLegacyRollbackJournaling:(BOOL)useLegacyRollbackJournaling
472481
error_p:(NSError**)error_p {
482+
NSDictionary* options = nil ;
483+
if ([type isEqualToString:NSSQLiteStoreType]) {
484+
if (useLegacyRollbackJournaling) {
485+
NSDictionary* sqlitePragmas = [NSDictionary dictionaryWithObjectsAndKeys:
486+
@"DELETE", @"journal_mode",
487+
nil] ;
488+
options = [NSDictionary dictionaryWithObjectsAndKeys:
489+
sqlitePragmas, NSSQLitePragmasOption,
490+
nil] ;
491+
}
492+
}
493+
473494
NSManagedObjectContext* moc = [[self sharedMOCManager] managedObjectContextType:type
474495
owner:owner
475496
identifier:identifier
476497
momdName:momdName
498+
options:options
477499
error_p:error_p] ;
478500
return moc ;
479501
}
@@ -551,6 +573,6 @@ + (void)logDebugCurrentSqliteMocs {
551573
@end
552574

553575
// Note 1.
554-
// Because our method +persistentStoreCoordinatorType:identifier:momdName:error_p: always creates
576+
// Because our method +persistentStoreCoordinatorType:identifier:momdName:options:error_p: always creates
555577
// a new persistent store coordinator and always adds exactly one persistent
556578
// store to it, we can just grab its first (and only) store.

SSYManagedObject.m

+17-12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#import "NSDocument+SyncModDate.h"
77
#import "NSObject+MoreDescriptions.h"
88
#import "NSBundle+MainApp.h"
9+
#import "NSEntityDescription+SSYMavericksBugFix.h"
910

1011
// Public Notifications
1112
NSString* const constNoteWillUpdateObject = @"willUpdateObject" ;
@@ -125,16 +126,20 @@ + (NSString*)entityNameForClass:(Class)class {
125126
}
126127

127128
+ (NSEntityDescription*)entityDescription {
129+
// This method was rewritten for BookMacster 1.19.2, to work around a
130+
// bug in Mac OS X 10.9. See
131+
// http://stackoverflow.com/questions/19626858/over-optimization-bug-in-10-9-core-data-entity-description-methods
132+
128133
NSArray* bundles = [NSArray arrayWithObject:[NSBundle mainAppBundle]] ;
129134
NSManagedObjectModel* mom = [NSManagedObjectModel mergedModelFromBundles:bundles] ;
130-
NSPersistentStoreCoordinator* psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:mom] ;
131-
NSManagedObjectContext* moc = [[NSManagedObjectContext alloc] init] ;
132-
[moc setPersistentStoreCoordinator:psc] ;
133-
[psc release] ;
134-
NSEntityDescription* entityDescription = [NSEntityDescription entityForName:[self entityNameForClass:self]
135-
inManagedObjectContext:moc] ;
136-
[moc release] ;
137-
135+
NSString* entityName = [self entityNameForClass:self] ;
136+
NSDictionary* entities = [[NSDictionary alloc] initWithDictionary:[mom entitiesByName]] ;
137+
NSEntityDescription* entityDescription = [entities objectForKey:entityName] ;
138+
if (!entityDescription) {
139+
NSLog(@"Internal Error 561-3831 for %@", entityName) ;
140+
}
141+
[entities release] ;
142+
138143
return entityDescription ;
139144
}
140145

@@ -164,8 +169,8 @@ - (BOOL)validateForInsert:(NSError **)error {
164169
}
165170
166171
NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init] ;
167-
[fetchRequest setEntity:[NSEntityDescription entityForName:[[self entity] name]
168-
inManagedObjectContext:managedObjectContext]] ;
172+
[fetchRequest setEntity:[NSEntityDescription SSY_entityForName:[[self entity] name]
173+
inManagedObjectContext:managedObjectContext]] ;
169174
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"(%K == %@) AND (SELF != %@)",
170175
uniqueAttributeKey, uniqueAttributeValue, self]] ;
171176
NSArray* conflictingObjects = [managedObjectContext executeFetchRequest:fetchRequest
@@ -357,8 +362,8 @@ - (void)logChangesForAllManagedObjectsInSameContext {
357362
NSArray* entityNames = [[[[moc persistentStoreCoordinator] managedObjectModel] entities] valueForKey:@"name"] ;
358363
NSUInteger nObjects = 0, nChanged = 0 ;
359364
for (NSString* entityName in entityNames) {
360-
NSEntityDescription* entity = [NSEntityDescription entityForName:entityName
361-
inManagedObjectContext:moc] ;
365+
NSEntityDescription* entity = [NSEntityDescription SSY_entityForName:entityName
366+
inManagedObjectContext:moc] ;
362367
[fetchRequest setEntity:entity] ;
363368
NSArray* objects = [moc executeFetchRequest:fetchRequest
364369
error:&error_] ;

SSYMojo.m

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
#import "SSYAlert.h"
55
#import "NSManagedObjectContext+Cheats.h"
66
#import "NSObject+MoreDescriptions.h"
7+
#import "NSEntityDescription+SSYMavericksBugFix.h"
78

89
// For debugging
910

1011

12+
1113
@implementation SSYMojo
1214

1315
@synthesize managedObjectContext = m_managedObjectContext ;
@@ -68,8 +70,8 @@ - (NSArray*)objectsWithSubpredicates:(NSArray*)subpredicates
6870
NSManagedObjectContext* managedObjectContext = [self managedObjectContext] ;
6971
NSArray* fetches = nil ;
7072
if (managedObjectContext) {
71-
[fetchRequest setEntity:[NSEntityDescription entityForName:[self entityName]
72-
inManagedObjectContext:managedObjectContext]] ;
73+
[fetchRequest setEntity:[NSEntityDescription SSY_entityForName:[self entityName]
74+
inManagedObjectContext:managedObjectContext]] ;
7375
if (compoundPredicate) {
7476
[fetchRequest setPredicate:compoundPredicate] ;
7577
}
@@ -154,8 +156,8 @@ - (NSArray*)allObjectsError_p:(NSError**)error_p {
154156
// when it invoked -[NSArrayController removeSelectionIndexes:[self selectionIndexes]] ;
155157
// [managedObjectContext processPendingChanges] ; // Do not do this
156158

157-
NSEntityDescription* entity = [NSEntityDescription entityForName:[self entityName]
158-
inManagedObjectContext:managedObjectContext] ;
159+
NSEntityDescription* entity = [NSEntityDescription SSY_entityForName:[self entityName]
160+
inManagedObjectContext:managedObjectContext] ;
159161
NSArray* allObjects ;
160162
if (entity) {
161163
[fetchRequest setEntity:entity] ;

SSYShellTasker.h

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ __attribute__((visibility("default"))) @interface SSYShellTasker : NSObject {
88
/*!
99
@brief A wrapper around NSTask to launch a command-line process, with a timeout.
1010
11-
@details Only use this function after you have searched far and wide for a Cocoa, CoreFoundation,
12-
Carbon, or any built-in API to do what you want to do.  That is because this function will spawn
13-
another process which often leads to trouble.  Use it sparingly.  Examine the return value,
11+
@details TODO: This method will fail due to clogged pipe if the stdout
12+
or stderr data is too long. To fix that, incorporate the incremental pipe
13+
emptying as demonstrated in my other class, SSYTasker. Note that this
14+
method does stuff that SSYTasker does not, such as timeout.
15+
16+
Only use this function after you have searched far and wide for a Cocoa, CoreFoundation,
17+
Carbon, or any built-in API to do what you want to do. That is because this function will spawn
18+
another process which often leads to trouble.  Use it sparingly. Examine the return value,
1419
stdout_p and stderr_p and write code to recover from errors.
1520
1621
TIMEOUT Narrated result result *stdoutData_p *stderrData_p *error_p

SSYSizeFixxerSubview.h

+17
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,21 @@
1212
@interface SSYSizeFixxerSubview : NSView {
1313
}
1414

15+
/*
16+
@brief Searches a given array of subviews and extracts (see details), if
17+
any, the size of any SSYSizeFixxerSubview found within it, and returns it,
18+
or if no such SSYSizeFixxerSubview is found, returns a given default size.
19+
20+
@details If any of the elements of the given subviews is an
21+
SSYSizeFixxerSubview, returns the size of the first one. Otherwise, if the
22+
given subviews contains only one element, which responds to -suviews, searches
23+
its subviews and returns the size of the first one. The latter condition is
24+
to support configurations where a view may be the only view embedded in
25+
another view, as will occur with, for example, SSYLazyView.
26+
27+
@param defaultSize This is typically used as a debugging aid, or for
28+
defensive programming.
29+
*/
30+
+ (NSSize)fixedSizeAmongSubviews:(NSArray*)subviews
31+
defaultSize:(NSSize)defaultSize ;
1532
@end

SSYSizeFixxerSubview.m

+45
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,49 @@
33

44
@implementation SSYSizeFixxerSubview
55

6+
7+
+ (BOOL)shallowlyGetFixedSize_p:(NSSize *)size_p
8+
defaultSize:(NSSize)defaultSize
9+
fromSubviews:(NSArray *)subviews {
10+
// Set a large default fixed size for defensive programming
11+
*size_p = defaultSize ;
12+
13+
// Set to the size of the Size Fixxer Subview
14+
BOOL didFindSSYSizeFixxerSubview = NO ;
15+
for (NSView* subview in subviews) {
16+
if ([subview isKindOfClass:[SSYSizeFixxerSubview class]]) {
17+
*size_p = [subview frame].size ;
18+
didFindSSYSizeFixxerSubview = YES ;
19+
break ;
20+
}
21+
}
22+
23+
return didFindSSYSizeFixxerSubview ;
24+
}
25+
26+
+ (NSSize)fixedSizeAmongSubviews:(NSArray *)subviews
27+
defaultSize:(NSSize)defaultSize {
28+
NSSize size;
29+
BOOL didFindSSYSizeFixxerSubview = [self shallowlyGetFixedSize_p:&size
30+
defaultSize:defaultSize
31+
fromSubviews:subviews] ;
32+
33+
if (!didFindSSYSizeFixxerSubview) {
34+
if ([subviews count] == 1) {
35+
// The subview is a thin wrapper around another view.
36+
NSView* innerView = [subviews objectAtIndex:0] ;
37+
NSArray* innerSubviews = [innerView subviews] ;
38+
didFindSSYSizeFixxerSubview = [self shallowlyGetFixedSize_p:&size
39+
defaultSize:defaultSize
40+
fromSubviews:innerSubviews] ;
41+
}
42+
}
43+
44+
if (!didFindSSYSizeFixxerSubview) {
45+
// This will occur for the two spacers, NSToolbarFlexibleSpaceItem
46+
}
47+
48+
return size ;
49+
}
50+
651
@end

SSYTempWindowController.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@
66
instance in the application.
77
88
@details An instance of this object is allocated when required, observes
9-
NSWindowWillCloseNotification, and releases itself when it receives notification
10-
that its window is closing.
9+
NSWindowWillCloseNotification, and releases itself when it receives
10+
notification that its window is closing.
11+
12+
For a cleaner approach to this problem, which does not require subclassing,
13+
see [SSYWindowHangout hungOutWindowControllerOfClass:].
1114
*/
1215
@interface SSYTempWindowController : NSWindowController {
1316
}
1417

1518
/*!
1619
@brief Returns the name of the nib file containing the receiver's window.
1720
18-
@details Subclasses must implement. Simply return an NSString constant. 
19-
Default implementation logs an internal error and returns nil. 
21+
@details Subclasses must implement. Simply return an NSString constant.
22+
Default implementation logs an internal error and returns nil.
2023
2124
In this nib,
2225
* File's Owner should be set to your subclass of this class

SSYTokenFieldCell.m

+11-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,17 @@ - (void)setObjectValue:(id)value {
1212
// Convert to an NSArray, as required by super
1313
value = [value allObjects] ;
1414

15-
// The following line was added in BookMacster 1.12.7, to
16-
// alphabetize tags in Detail View (littleCloud) and Inspector
17-
value = [[(NSCountedSet*)value allObjects] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] ;
15+
/*
16+
The following line was added in BookMacster 1.12.7, to alphabetize
17+
tags in Detail View (littleCloud) and Inspector. However, it also
18+
cast 'value' to an NSCountedSet and re-invoked -allObjects on it.
19+
This *worked* in Mac OS X 10.7 and later, because, strangely, NSArray
20+
*does* respond to -allObjects in these systems, returns a copy of self.
21+
But not in 10.6, where an exception could be raised here
22+
The troublesome cast and -allObjects were removed in
23+
BookMacster 1.19.2.
24+
*/
25+
value = [value sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] ;
1826
}
1927

2028
[super setObjectValue:value] ;

0 commit comments

Comments
 (0)