Skip to content

Commit 7a85cd5

Browse files
committedOct 8, 2013
Shipped BookMacster 1.19
1 parent 7876e28 commit 7a85cd5

11 files changed

+153
-86
lines changed
 

‎SSYAlert.h

+17-13
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,23 @@ extern NSString* const SSYAlert_ErrorSupportEmailKey ;
6161
*/
6262
extern NSString* const SSYAlertDidProcessErrorNotification ;
6363

64+
/*!
65+
@brief The subclass of NSWindow created by SSYAlert. The interface
66+
is exposed so that you can get the checkbox state after an SSYAlert is closed,
67+
without setting shouldStickAround to YES
68+
69+
@details Typically, in a -didEndSheet:returnCode:contextInfo: callback
70+
on a sheet whose window controller is an SSYAlert alert, the SSYAlert may
71+
already be gone and [sheet windowController] will return nil. So you can't
72+
get control values from the window controller. This class allows you to get
73+
control states from the window directly.
74+
*/
75+
@interface SSYAlertWindow : NSWindow
76+
77+
- (NSInteger)checkboxState ;
78+
79+
@end
80+
6481
/*!
6582
@brief The SSYErrorRecoveryAttempting informal protocol is a
6683
replacement for Cocoa's NSErrorRecoveryAttempting informal protocol
@@ -921,19 +938,6 @@ extern NSObject <SSYAlertErrorHideManager> * gSSYAlertErrorHideManager ;
921938
- (void)addOtherSubview:(NSView*)subview
922939
atIndex:(NSInteger)index ;
923940

924-
/*!
925-
@brief Removes the "other subview" with a given index
926-
from the receiver.
927-
928-
@details The index must exist or an exception will be raised.
929-
@param index The index of the "other subview" to be removed.
930-
*/
931-
- (void)removeOtherSubviewAtIndex:(NSInteger)index ;
932-
933-
/*!
934-
@brief Removes all of the <i>other subviews</i> from the receiver.
935-
*/
936-
- (void)removeAllOtherSubviews ;
937941

938942
/*!
939943
@brief Returns a text view which looks like the receiver's

‎SSYAlert.m

+62-47
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,6 @@ @interface SSYAlert ()
185185
@end
186186

187187

188-
@interface SSYAlertWindow : NSWindow
189-
190-
@end
191-
192188
@implementation SSYAlertWindow
193189

194190
/*!
@@ -243,7 +239,26 @@ - (void)setFrameOrigin:(NSPoint)frameOrigin {
243239
}
244240
}
245241

246-
#pragma mark *
242+
- (NSInteger)checkboxState {
243+
NSInteger state = NSMixedState ; // default answer in case we can't find checkbox
244+
BOOL didFindCheckbox = NO ;
245+
for (NSView* view in [[self contentView] subviews]) {
246+
if ([view isKindOfClass:[SSYWrappingCheckbox class]]) {
247+
SSYWrappingCheckbox* checkbox = (SSYWrappingCheckbox*)view ;
248+
state = [checkbox state] ;
249+
didFindCheckbox = YES ;
250+
break ;
251+
}
252+
}
253+
254+
if (!didFindCheckbox) {
255+
NSLog(@"Internal Error 624-9382 %@ %@", [self title], [[self contentView] subviews]) ;
256+
}
257+
258+
return state ;
259+
}
260+
261+
#pragma mark *
247262

248263
// At one time, I thought that NSWindow's keyboard loop was
249264
// broken in a programmatically-created window.
@@ -841,48 +856,6 @@ - (void)setSupportEmail {
841856
}
842857
}
843858

844-
//#define DEFAULT_MIN_TEXT_FIELD_WIDTH 250.0
845-
- (void)cleanSlate {
846-
[self setWindowTitle:nil] ; // Defaults to mainBundle's CFBundleName (which should be the localized name of the app)
847-
[self setShowsProgressBar:NO] ;
848-
[self setTitleText:nil] ;
849-
[self setSmallText:nil] ;
850-
[self setIconStyle:SSYAlertIconNoIcon] ;
851-
[self setButton1Title:nil] ;
852-
[self setButton2Title:nil] ;
853-
[self setButton3Title:nil] ;
854-
[self setHelpAnchor:nil] ;
855-
[self setCheckboxTitle:nil] ;
856-
[self setWhyDisabled:nil] ;
857-
[self removeAllOtherSubviews] ;
858-
859-
// The following is a holdover from when SSYAlert support a
860-
// configuration stack, and may no longer be needed...
861-
// Now, there may still be some subviews left in the view...
862-
// The -removeAllOtherSubviews only removed those which are in
863-
// the current self.otherSubviews array. But if the configuration has
864-
// been pushed, self.otherSubviews will be a new, empty array.
865-
// Therefore, we now ask the -contentView if it has any more subviews
866-
// left and if so remove them...
867-
NSView* contentView = [[self window] contentView] ;
868-
// We use a regular C loop since -removeFromSuperviewWithoutNeedingDisplay
869-
// mutates the [contentView subviews] and therefore we cannot
870-
// use an enumeration
871-
NSArray* subviews = [contentView subviews] ;
872-
NSInteger i ;
873-
for (i=[subviews count]-1; i>=0; i--) {
874-
NSView* subview = [subviews objectAtIndex:i] ;
875-
[subview removeFromSuperviewWithoutNeedingDisplay] ;
876-
}
877-
878-
self.allowsShrinking = YES ;
879-
[self setIsEnabled:YES] ;
880-
self.isVisible = YES ;
881-
self.progressBarShouldAnimate = NO ;
882-
[self setRightColumnMinimumWidth:0.0] ;
883-
[self setRightColumnMaximumWidth:CGFLOAT_MAX] ;
884-
}
885-
886859
- (void)setWindowTitle:(NSString*)title {
887860
if (!title) {
888861
title = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"] ; // CFBundleName may be localized
@@ -1200,6 +1173,48 @@ - (void)setCheckboxState:(NSCellStateValue)state {
12001173
[[self checkbox] setState:state] ;
12011174
}
12021175

1176+
//#define DEFAULT_MIN_TEXT_FIELD_WIDTH 250.0
1177+
- (void)cleanSlate {
1178+
[self setWindowTitle:nil] ; // Defaults to mainBundle's CFBundleName (which should be the localized name of the app)
1179+
[self setShowsProgressBar:NO] ;
1180+
[self setTitleText:nil] ;
1181+
[self setSmallText:nil] ;
1182+
[self setIconStyle:SSYAlertIconNoIcon] ;
1183+
[self setButton1Title:nil] ;
1184+
[self setButton2Title:nil] ;
1185+
[self setButton3Title:nil] ;
1186+
[self setHelpAnchor:nil] ;
1187+
[self setCheckboxTitle:nil] ;
1188+
[self setWhyDisabled:nil] ;
1189+
[self removeAllOtherSubviews] ;
1190+
1191+
// The following is a holdover from when SSYAlert support a
1192+
// configuration stack, and may no longer be needed...
1193+
// Now, there may still be some subviews left in the view...
1194+
// The -removeAllOtherSubviews only removed those which are in
1195+
// the current self.otherSubviews array. But if the configuration has
1196+
// been pushed, self.otherSubviews will be a new, empty array.
1197+
// Therefore, we now ask the -contentView if it has any more subviews
1198+
// left and if so remove them...
1199+
NSView* contentView = [[self window] contentView] ;
1200+
// We use a regular C loop since -removeFromSuperviewWithoutNeedingDisplay
1201+
// mutates the [contentView subviews] and therefore we cannot
1202+
// use an enumeration
1203+
NSArray* subviews = [contentView subviews] ;
1204+
NSInteger i ;
1205+
for (i=[subviews count]-1; i>=0; i--) {
1206+
NSView* subview = [subviews objectAtIndex:i] ;
1207+
[subview removeFromSuperviewWithoutNeedingDisplay] ;
1208+
}
1209+
1210+
self.allowsShrinking = YES ;
1211+
[self setIsEnabled:YES] ;
1212+
self.isVisible = YES ;
1213+
self.progressBarShouldAnimate = NO ;
1214+
[self setRightColumnMinimumWidth:0.0] ;
1215+
[self setRightColumnMaximumWidth:CGFLOAT_MAX] ;
1216+
}
1217+
12031218
#pragma mark * Public Methods for Displaying and Running
12041219

12051220
- (void)errorSheetDidEnd:(NSWindow *)sheet

‎SSYDebug.m

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#import "SSYDebug.h"
21
#import <execinfo.h>
32
#import <mach-o/dyld.h>
43

‎SSYInterappServer.m

+5-3
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ - (id)initWithPortName:(NSString*)portName
144144
SSYInterappServerCallBackCreateData,
145145
&context,
146146
NULL) ;
147+
147148
if (m_port) {
148149
[self setDelegate:delegate] ;
149150
CFRunLoopSourceRef source = CFMessagePortCreateRunLoopSource(
@@ -177,7 +178,7 @@ - (id)initWithPortName:(NSString*)portName
177178
*error_p = [NSError errorWithDomain:SSYInterappServerErrorDomain
178179
code:errorCode
179180
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
180-
@"Could not initialize server", NSLocalizedDescriptionKey,
181+
@"Mac OS X failed to create a local message port.", NSLocalizedDescriptionKey,
181182
portName, @"Port Name",
182183
nil]] ;
183184
}
@@ -221,8 +222,9 @@ + (SSYInterappServer*)leaseServerWithPortName:(NSString*)portName
221222
}
222223
else {
223224
// When testing, I got a crash of BookMacster-Worker here because
224-
// server was nil. Maybe the port was already in use?
225-
NSLog(@"Internal Error 713-0192 %@ %@ %@ del=%@", portName, static_serversInUse, error, delegate) ;
225+
// server was nil. Until BookMacster 1.19, I logged
226+
// Internal Error 713-0192 here, but it was not providing any
227+
// useful information not already in the error.
226228
}
227229
[server release] ;
228230
}

‎SSYLabelledTextField.h

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
NSWindowController* windowController ; // Documentation explains why this kludge is necessary
1919
id validationObject ;
2020
NSString* errorMessage ;
21+
NSInteger m_tag ;
2122
}
2223

2324
@property (retain) NSTextField* keyField ;
@@ -26,6 +27,7 @@
2627
@property (retain) id windowController ;
2728
@property (retain) id validationObject ;
2829
@property (retain) NSString* errorMessage ;
30+
@property (assign) NSInteger tag ;
2931

3032
/*!
3133
@brief Convenience method for getting an autoreleased instance of this class.
@@ -83,6 +85,7 @@
8385
displayedKey:(NSString*)displayedKey
8486
displayedValue:(NSString*)displayedValue
8587
editable:(BOOL)editable
88+
tag:(NSInteger)tag
8689
errorMessage:(NSString*)errorMessage ;
8790

8891
/*!

‎SSYLabelledTextField.m

+16-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
NSString* const constKeyValidationObject = @"ValidationObject" ;
1010
NSString* const constKeyWindowController = @"WindowController" ;
1111
NSString* const constKeyErrorMessage = @"ErrorMessage" ;
12+
NSString* const constKeyTextFieldTag = @"tag" ;
1213

1314

1415
@interface NSWindowController (Disableable)
@@ -26,6 +27,7 @@ @implementation SSYLabelledTextField
2627
@synthesize validationObject ;
2728
@synthesize windowController ;
2829
@synthesize errorMessage ;
30+
@synthesize tag = m_tag ;
2931

3032
- (void)setStringValue:(NSString*)stringValue {
3133
[[self valueField] setStringValue:stringValue] ;
@@ -70,6 +72,7 @@ - (id)initAsSecure:(BOOL)secure
7072
displayedKey:(NSString*)displayedKey
7173
displayedValue:(NSString*)displayedValue
7274
editable:(BOOL)editable_
75+
tag:(NSInteger)tag
7376
errorMessage:(NSString*)errorMessage_ {
7477
self = [super initWithFrame:NSZeroRect];
7578
if (self != nil) {
@@ -129,6 +132,7 @@ - (id)initAsSecure:(BOOL)secure
129132
}
130133
[[self valueField] setEditable:editable_] ;
131134
[self setErrorMessage:errorMessage_] ;
135+
[self setTag:tag] ;
132136

133137
// The following is needed in the usual case where, upon initialization,
134138
// the initial value of @"" is invalid.&nbsp; We need to send validation
@@ -145,13 +149,16 @@ + (SSYLabelledTextField*)labelledTextFieldSecure:(BOOL)secure
145149
displayedKey:(NSString*)displayedKey
146150
displayedValue:(NSString*)displayedValue
147151
editable:(BOOL)editable
152+
tag:(NSInteger)tag
148153
errorMessage:(NSString*)errorMessage {
149154
SSYLabelledTextField* instance = [[SSYLabelledTextField alloc] initAsSecure:secure
150155
validationSelector:validationSelector
151156
validationObject:validationObject
152157
windowController:windowController
153158
displayedKey:displayedKey
154-
displayedValue:displayedValue editable:editable
159+
displayedValue:displayedValue
160+
editable:editable
161+
tag:tag
155162
errorMessage:errorMessage] ;
156163
return [instance autorelease] ;
157164
}
@@ -178,7 +185,12 @@ - (NSString*)description {
178185
NSMutableDictionary* dic = [NSMutableDictionary dictionaryWithDictionary:dictionary] ;
179186
[dic setValue:NSStringFromSelector([self validationSelector])
180187
forKey:@"validationSelector"] ;
181-
return [dic description] ;
188+
[dic setValue:[NSNumber numberWithInteger:[self tag]]
189+
forKey:@"tag"] ;
190+
return [NSString stringWithFormat:
191+
@"%@ %@",
192+
[super description],
193+
[dic description]] ;
182194
}
183195

184196
- (void)sizeHeightToFitAllowShrinking:(BOOL)allowShrinking {
@@ -246,6 +258,7 @@ - (void)encodeWithCoder:(NSCoder *)coder {
246258
[coder encodeObject:validationObject forKey:constKeyValidationObject] ;
247259
[coder encodeObject:windowController forKey:constKeyWindowController] ;
248260
[coder encodeObject:errorMessage forKey:constKeyErrorMessage] ;
261+
[coder encodeInteger:m_tag forKey:constKeyTextFieldTag] ;
249262
}
250263

251264
- (id)initWithCoder:(NSCoder *)coder {
@@ -257,6 +270,7 @@ - (id)initWithCoder:(NSCoder *)coder {
257270
validationObject = [[coder decodeObjectForKey:constKeyValidationObject] retain] ;
258271
windowController = [[coder decodeObjectForKey:constKeyWindowController] retain] ;
259272
errorMessage = [[coder decodeObjectForKey:constKeyErrorMessage] retain] ;
273+
m_tag = [coder decodeIntegerForKey:constKeyTextFieldTag] ;
260274

261275
return self ;
262276
}

‎SSYMOCManager.h

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
which the owner is desired turns out to not be one of this class's creations.
1414
This class itself is instantiated as an app-wide
1515
singleton and no public instance methods are available.
16+
17+
When using this class, [NSApp delegate] must conform to protocol
18+
SSYAppSupporter.
1619
*/
1720
@interface SSYMOCManager : NSObject {
1821
NSMutableDictionary* inMemoryMOCDics ;

0 commit comments

Comments
 (0)
Please sign in to comment.