Skip to content

Commit a3fa021

Browse files
committed
BookMacster 1.16.3
1 parent 9128c3a commit a3fa021

13 files changed

+223
-76
lines changed

.DS_Store

6 KB
Binary file not shown.

SSYBackgroundAwareWindow.h

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#import <Cocoa/Cocoa.h>
2+
3+
/*
4+
@brief A subclass of NSWindow instance methods which behave appropriately
5+
in case a process is launched as or is transformed to a background or
6+
UI element type (currentType != SSYProcessTyperTypeForeground),
7+
8+
This class was added in BookMacster 1.16.1.
9+
*/
10+
@interface SSYBackgroundAwareWindow : NSWindow {
11+
}
12+
13+
/*
14+
@brief Override which returns NO if the the current process is not a
15+
foreground process (currentType != SSYProcessTyperTypeForeground), otherwise
16+
invokes super
17+
*/
18+
- (BOOL)canBecomeMainWindow ;
19+
20+
/*
21+
@brief Override which returns NO if the the current process is not a
22+
foreground process (currentType != SSYProcessTyperTypeForeground), otherwise
23+
invokes super
24+
*/
25+
- (BOOL)canBecomeKeyWindow ;
26+
27+
28+
29+
30+
@end

SSYBackgroundAwareWindow.m

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#import "SSYBackgroundAwareWindow.h"
2+
#import "SSYProcessTyper.h"
3+
4+
@implementation SSYBackgroundAwareWindow
5+
6+
- (BOOL)keepHidden {
7+
return ([SSYProcessTyper currentType] != SSYProcessTyperTypeForeground) ;
8+
}
9+
10+
- (BOOL)canBecomeKeyWindow {
11+
if ([self keepHidden]) {
12+
return NO ;
13+
}
14+
return [super canBecomeKeyWindow] ;
15+
}
16+
17+
- (BOOL)canBecomeMainWindow {
18+
if ([self keepHidden]) {
19+
return NO ;
20+
}
21+
return [super canBecomeMainWindow] ;
22+
}
23+
24+
#if 0
25+
#warning Experimenting with More Windowlessness
26+
// I found it not necessary to override these methods, so I didn't.
27+
// But maybe I didn't find all the corner cases. Someday, I might?
28+
29+
/*
30+
@brief Override which becomes a no-op if the the current process is not a
31+
foreground process (currentType != SSYProcessTyperTypeForeground), otherwise
32+
invokes super
33+
*/
34+
- (void)displayIfNeeded {
35+
if ([self keepHidden]) {
36+
return ;
37+
}
38+
[super displayIfNeeded] ;
39+
}
40+
41+
- (void)display {
42+
if ([self keepHidden]) {
43+
return ;
44+
}
45+
[super display] ;
46+
}
47+
48+
- (void)orderFrontRegardless {
49+
if ([self keepHidden]) {
50+
return ;
51+
}
52+
[super orderFrontRegardless] ;
53+
}
54+
55+
- (void)orderFront:(id)sender {
56+
if ([self keepHidden]) {
57+
return ;
58+
}
59+
[super display] ;
60+
}
61+
62+
- (void)orderBack:(id)sender {
63+
if ([self keepHidden]) {
64+
return ;
65+
}
66+
[super orderFront:sender] ;
67+
}
68+
69+
- (void)makeMainWindow {
70+
if ([self keepHidden]) {
71+
return ;
72+
}
73+
[super makeMainWindow] ;
74+
}
75+
76+
- (void)makeKeyWindow {
77+
if ([self keepHidden]) {
78+
return ;
79+
}
80+
[super makeKeyWindow] ;
81+
}
82+
83+
- (void)makeKeyAndOrderFront:(id)sender {
84+
if ([self keepHidden]) {
85+
return ;
86+
}
87+
[super makeKeyAndOrderFront:sender] ;
88+
}
89+
90+
- (void)orderWindow:(NSWindowOrderingMode)orderingMode relativeTo:(NSInteger)otherWindowNumber {
91+
if ([self keepHidden]) {
92+
return ;
93+
}
94+
[super orderWindow:orderingMode relativeTo:otherWindowNumber] ;
95+
}
96+
97+
#endif
98+
99+
@end

SSYHintableWindow.m

+1-69
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#import "SSYHintableWindow.h"
22
#import "SSYHintArrow.h"
33

4+
45
@implementation SSYHintableWindow
56

67
- (void)sendEvent:(NSEvent *)event {
@@ -9,73 +10,4 @@ - (void)sendEvent:(NSEvent *)event {
910
}
1011

1112

12-
#if 0
13-
#warning Experimenting : Windowless
14-
15-
- (void)displayIfNeeded {
16-
if (WINDOWLESS) {
17-
return ;
18-
}
19-
[super displayIfNeeded] ;
20-
}
21-
22-
23-
- (void)display {
24-
if (WINDOWLESS) {
25-
return ;
26-
}
27-
[super display] ;
28-
}
29-
30-
- (void)orderFrontRegardless {
31-
if (WINDOWLESS) {
32-
return ;
33-
}
34-
[super orderFrontRegardless] ;
35-
}
36-
37-
- (void)orderFront:(id)sender {
38-
if (WINDOWLESS) {
39-
return ;
40-
}
41-
[super display] ;
42-
}
43-
44-
- (void)orderBack:(id)sender {
45-
if (WINDOWLESS) {
46-
return ;
47-
}
48-
[super orderFront:sender] ;
49-
}
50-
51-
- (void)makeMainWindow {
52-
if (WINDOWLESS) {
53-
return ;
54-
}
55-
[super makeMainWindow] ;
56-
}
57-
58-
- (void)makeKeyWindow {
59-
if (WINDOWLESS) {
60-
return ;
61-
}
62-
[super makeKeyWindow] ;
63-
}
64-
65-
- (void)makeKeyAndOrderFront:(id)sender {
66-
if (WINDOWLESS) {
67-
return ;
68-
}
69-
[super makeKeyAndOrderFront:sender] ;
70-
}
71-
72-
- (void)orderWindow:(NSWindowOrderingMode)orderingMode relativeTo:(NSInteger)otherWindowNumber {
73-
if (WINDOWLESS) {
74-
return ;
75-
}
76-
[super orderWindow:orderingMode relativeTo:otherWindowNumber] ;
77-
}
78-
79-
#endif
80-
8113
@end

SSYMojo.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ - (NSManagedObject*)freshObject {
187187

188188
NSManagedObject* object = [NSEntityDescription insertNewObjectForEntityForName:[self entityName]
189189
inManagedObjectContext:moc] ;
190-
// Added in BookMacster 1.15.7 to try and find a rare bug
190+
// Added in BookMacster 1.16 to try and find a rare bug
191191
if (![[NSThread currentThread] isMainThread]) {
192192
NSLog(@"Internal Error 523-0024 %@\n%@",
193193
[self entityName],

SSYPersistentDocumentMultiMigrator.m

+7-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,13 @@ + (BOOL)migrateIfNeededStoreAtUrl:(NSURL*)url
276276
[document setFileURL:url] ;
277277
}
278278
#endif
279-
279+
#if MAC_OS_X_VERSION_MAX_ALLOWED > 1060
280+
if ([document isInViewingMode]) {
281+
[newStoreOptions setObject:[NSNumber numberWithBool:YES]
282+
forKey:NSReadOnlyPersistentStoreOption] ;
283+
}
284+
#endif
285+
280286
// Do the migration, creating a new file at destempUrl.
281287
// Because the Core Data Model Versioning and Data Migration Programming Guide
282288
// indicates that this method reads the whole store into memory, and this

SSYProcessTyper.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
SDK. So I did it the correct way now. For defensive programming,,
88
the three values here match the values of the corresponding
99
kProcessTransformToForegroundApplication and friends.
10+
11+
I don't know what is the difference between the types "Background" and
12+
"UIElement". I never user the former, only the latter. I have not been able
13+
to find any explanation in Apple documemtation.
1014
*/
1115
enum SSYProcessTyperType_enum {
1216
SSYProcessTyperTypeForeground = 1,
@@ -15,14 +19,13 @@ enum SSYProcessTyperType_enum {
1519
} ;
1620
typedef enum SSYProcessTyperType_enum SSYProcessTyperType ;
1721

22+
1823
@interface SSYProcessTyper : NSObject {
1924

2025
}
2126

2227
+ (SSYProcessTyperType)currentType ;
2328

24-
+ (void)transformToType:(SSYProcessTyperType)type ;
25-
2629
+ (void)transformToForeground:(id)sender ;
2730

2831
#if (MAC_OS_X_VERSION_MAX_ALLOWED > 1060)

SSYProcessTyper.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#import "SSYProcessTyper.h"
22

3-
43
@implementation SSYProcessTyper
54

65
/*
@@ -99,7 +98,8 @@ + (void)transformToType:(SSYProcessTyperType)type {
9998
return ;
10099
}
101100
}
102-
101+
102+
// Actual Subtance
103103
ProcessSerialNumber psn = { 0, kCurrentProcess } ;
104104
OSStatus err ;
105105
err = TransformProcessType(&psn, [self appleTypeForType:type]) ;

SSYSearchField.h

+22
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,26 @@ extern NSString* const SSYSearchFieldDidCancelNotification ;
1414
SEL m_cancelButtonAction ;
1515
}
1616

17+
/*!
18+
@brief Prepends a new string to the receiver's recentSearches array,
19+
deleting any earlier copies
20+
21+
@details NSSearchField is supposed to "automatically" add new search strings
22+
to its recentSearches. In my experience, it works about 5% of the time and
23+
I can't figure out why or not. This method works 100% of the time. Invoke
24+
it during the action method ("search:", or whatever) of your search field.
25+
26+
This method was added to fix that unreliable behavior in BookMacster 1.16
27+
28+
@param newString The new string to be prepended. OK if it is nil, or
29+
empty, or if it matches the current first item in the receiver's recentSearches
30+
array. In these cases, this method has no effect. The latter case is now for
31+
efficiency, because does a lot of work whenever anything is done to affect
32+
the little menu inside of an NSSearchField, including the fact that it makes
33+
a copy of its menu from its template. Originally, it was because I was not
34+
aware of this behavior and the more this method had no effect, the less I saw
35+
the effect of a bug which was caused by my lack of awareness.
36+
*/
37+
- (void)appendToRecentSearches:(NSString*)newString ;
38+
1739
@end

SSYSearchField.m

+18
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,22 @@ - (IBAction)cancelAction:(id)sender {
3939
withObject:sender] ;
4040
}
4141

42+
- (void)appendToRecentSearches:(NSString*)newString {
43+
if ([newString length] > 0) {
44+
NSMutableArray* recentSearches = [[self recentSearches] mutableCopy] ;
45+
46+
// In case newString is a re-do of an earlier search,
47+
[recentSearches removeObject:newString] ;
48+
// Now add newString at the top
49+
[recentSearches insertObject:newString
50+
atIndex:0] ;
51+
52+
if (![[self recentSearches] isEqualToArray:recentSearches]) {
53+
[self setRecentSearches:recentSearches] ;
54+
}
55+
56+
[recentSearches release] ;
57+
}
58+
}
59+
4260
@end

SSYTasker.h

+6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ typedef enum SSYTaskerErrorCodes_enum SSYTaskerErrorCodes ;
4444
*/
4545
@interface SSYTasker : NSObject {
4646
NSObject <SSYTaskerProgressDelegate> * __weak m_delegate ;
47+
FILE * restrict m_heartbeatTo ;
4748
}
4849

4950
@property NSObject <SSYTaskerProgressDelegate> * __weak delegate ;
@@ -57,6 +58,10 @@ typedef enum SSYTaskerErrorCodes_enum SSYTaskerErrorCodes ;
5758
@param launchPath The command to run. See -[NSTask setLaunchPath:].
5859
@param arguments The arguments passed to the command. See
5960
-[NSTask setArguments:]. May be nil.
61+
@param heartbeatTo Handle to a file to which the ASCII character "H"
62+
will be written once every few seconds, if no stdout or stderr has been
63+
written in the last few seconds. Typically, you will pass either stdout
64+
or stderr, or NULL if you don't want any heartbeat.
6065
@param stdinData Data to be passed to the command's stdin. May be nil.
6166
6267
@result The exit status from running the command, or if a higher level error
@@ -65,6 +70,7 @@ typedef enum SSYTaskerErrorCodes_enum SSYTaskerErrorCodes ;
6570
*/
6671
- (NSInteger)runCommand:(NSString*)launchPath
6772
arguments:(NSArray*)arguments
73+
heartbeatTo:(FILE* restrict)heartbeatTo
6874
stdinData:(NSData*)stdinData
6975
workingIn:(NSString*)workingDirectory ;
7076

SSYTasker.m

+13-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99

1010
NSInteger SSYTaskerMetaErrorCode = 444000 ;
1111

12+
@interface SSYTasker ()
13+
14+
@property (assign) FILE * restrict heartbeatTo ;
15+
16+
@end
17+
1218
@implementation NSFileHandle (CSFileHandleExtensions)
1319

1420
- (NSData*)availableDataError_p:(NSError**)error_p {
@@ -156,12 +162,16 @@ - (void)taskTerminatedNote:(NSNotification*)note {
156162
}
157163

158164
- (void)kickFromTimer:(NSTimer*)timer {
159-
fprintf(stderr, "t") ;
165+
FILE * restrict heartbeatTo = [self heartbeatTo] ;
166+
if (heartbeatTo != NULL) {
167+
fprintf(heartbeatTo, "H") ;
168+
}
160169
[SSYRunLoopTickler tickle] ;
161170
}
162171

163172
- (NSInteger)runCommand:(NSString*)launchPath
164173
arguments:(NSArray*)arguments
174+
heartbeatTo:(FILE *restrict)heartbeatTo
165175
stdinData:(NSData*)stdinData
166176
workingIn:(NSString*)workingDirectory {
167177
NSInteger errorCode = 0 ;
@@ -171,6 +181,8 @@ - (NSInteger)runCommand:(NSString*)launchPath
171181
[self setStdoutData:nil] ;
172182
[self setStderrData:nil] ;
173183
[self setError:nil] ;
184+
185+
[self setHeartbeatTo:heartbeatTo] ;
174186

175187
// Create task with given parameters
176188
NSTask *task = [[NSTask alloc] init] ;

0 commit comments

Comments
 (0)