Skip to content

Commit ded8460

Browse files
committed
MiniSearchWinCon with Text Fields
1 parent ac6cc13 commit ded8460

10 files changed

Lines changed: 287 additions & 42 deletions

SSYDebug.m

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@
4646
free(strs) ;
4747

4848
NSString* answer = [nsString copy] ;
49+
#if NO_ARC
4950
[nsString release] ;
50-
51-
return [answer autorelease] ;
51+
[answer autorelease] ;
52+
#endif
53+
54+
return answer ;
5255
}
5356

5457
void SSYDebugLogBacktrace (void) {
@@ -85,9 +88,12 @@ NSInteger SSYDebugStackDepth(void) {
8588
free(strs) ;
8689

8790
NSString* answer = [nsString copy] ;
91+
#if NO_ARC
8892
[nsString release] ;
93+
[answer autorelease] ;
94+
#endif
8995

90-
return [answer autorelease] ;
96+
return answer ;
9197
}
9298

9399
NSString* SSYDebugCaller(void) {
@@ -108,7 +114,9 @@ NSInteger SSYDebugStackDepth(void) {
108114
range:NSMakeRange(0, [mutant length])] ;
109115
} while ([mutant length] < oldLength) ;
110116
caller = [NSString stringWithString:mutant] ;
117+
#if NO_ARC
111118
[mutant release] ;
119+
#endif
112120
NSArray* comps = [caller componentsSeparatedByString:@" "] ;
113121
caller = [comps objectAtIndex:3] ;
114122
if ([comps count] > 6) {

SSYMojo.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,13 @@ - (NSManagedObject*)freshObject {
187187

188188
NSManagedObject* object = [NSEntityDescription insertNewObjectForEntityForName:[self entityName]
189189
inManagedObjectContext:moc] ;
190-
#if 11
191-
#warning Testing insertions not on main thread
190+
// Added in BookMacster 1.15.7 to try and find a rare bug
192191
if (![[NSThread currentThread] isMainThread]) {
193192
NSLog(@"Internal Error 523-0024 %@\n%@",
194193
[self entityName],
195194
SSYDebugBacktraceDepth(8)) ;
196195
}
197-
#endif
196+
198197
return object ;
199198
}
200199

SSYProcessTyper.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ + (pid_t)inactivateActiveAppAndReturnNewActiveApp {
6969
if (err != noErr) {
7070
NSLog(@"Internal Error 915-9385 %ld", (long)err) ;
7171
}
72-
//NSLog(@"2000 New ActiveApp: %@", [[[NSWorkspace sharedWorkspace] activeApplication] objectForKey:@"NSApplicationName"]) ;
7372
activeAppPid = (pid_t)[[[[NSWorkspace sharedWorkspace] activeApplication] objectForKey:@"NSApplicationProcessIdentifier"] integerValue] ;
7473
return activeAppPid ;
7574
}

SSYResourceForks.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
11
#import <Cocoa/Cocoa.h>
22

33

4-
@interface SSYResourceForks : NSObject {
5-
4+
@interface SSYResourceForks : NSObject <NSXMLParserDelegate> {
5+
NSMutableString* m_xmlString ;
6+
BOOL m_accumulatingUrl ;
67
}
78

9+
/*
10+
@details If a URL cannot be found in the resource fork, looks for XML in the
11+
data fork. Can extract URL from this:
12+
<?xml version="1.0" encoding="UTF-8"?>
13+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
14+
<plist version="1.0">
15+
<dict>
16+
<key>URL</key>
17+
<string>http://ancienthistory.about.com/od/cityofrome/ss/7hillsofRome.htm</string>
18+
</dict>
19+
</plist>
20+
21+
It simply parses whatever is in the last <string>. Of course, we could do a
22+
better job by using some kind of 'state' instance variable and looking for the
23+
<string> element of the <dict> element of the <plist> element, but since
24+
I'm not sure of the exact xml structure anyhow and just reverse-engineered
25+
this from a file I received from a user, this is good enough.
26+
*/
27+
28+
829
+ (NSArray*)weblocFilenamesAndUrlsInPaths:(NSArray*)paths ;
930

1031
@end

SSYResourceForks.m

Lines changed: 93 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,70 @@
11
#import "SSYResourceForks.h"
22

3+
@interface SSYResourceForks ()
4+
5+
@property (retain) NSMutableString* xmlString ;
6+
7+
@end
8+
39

410
@implementation SSYResourceForks
511

6-
+ (NSArray*)weblocFilenamesAndUrlsInPaths:(NSArray*)paths {
12+
@synthesize xmlString = m_xmlString ;
13+
14+
- (void)dealloc {
15+
[m_xmlString release] ;
16+
17+
[super dealloc] ;
18+
}
19+
20+
- (void) parser:(NSXMLParser*)parser
21+
didStartElement:(NSString*)elementName
22+
namespaceURI:(NSString*)namespaceURI
23+
qualifiedName:(NSString*)qualifiedName
24+
attributes:(NSDictionary*)attributeDict {
25+
if ([elementName isEqualToString:@"string"]) {
26+
// The contents are collected in parser:foundCharacters:.
27+
m_accumulatingUrl = YES ;
28+
// The mutable string needs to be reset to empty.
29+
[[self xmlString] setString:@""] ;
30+
}
31+
}
32+
33+
- (void)parser:(NSXMLParser *)parser
34+
didEndElement:(NSString *)elementName
35+
namespaceURI:(NSString *)namespaceURI
36+
qualifiedName:(NSString *)qName {
37+
m_accumulatingUrl = NO ;
38+
}
39+
40+
- (void) parser:(NSXMLParser*)parser
41+
foundCharacters:(NSString*)string {
42+
43+
if (m_accumulatingUrl) {
44+
// If the current element is one whose content we care about, append 'string'
45+
// to the property that holds the content of the current element.
46+
//
47+
[[self xmlString] appendString:string] ;
48+
}
49+
}
50+
51+
#if 0
52+
- (void) parser:(NSXMLParser*)parser
53+
parseErrorOccurred:(NSError*)error {
54+
//NSLog(@"Found error in XML: %@", error) ;
55+
}
56+
#endif
57+
58+
- (NSArray*)weblocFilenamesAndUrlsInPaths:(NSArray*)paths {
759
OSErr err ;
860
FSRef fsRef ;
961
NSInteger fileRef ;
1062
NSMutableArray* filenamesAndURLs = [NSMutableArray array] ;
1163

1264
for (NSString* path in paths) {
13-
err = !noErr ;
65+
NSString* url = nil ;
66+
67+
err = !noErr ;
1468

1569
// Try and open resource fork for path
1670
if( [[NSFileManager defaultManager] fileExistsAtPath:path] )
@@ -23,8 +77,7 @@ + (NSArray*)weblocFilenamesAndUrlsInPaths:(NSArray*)paths {
2377
err = fileRef > 0 ? ResError( ) : !noErr;
2478
}
2579

26-
if (err == noErr)
27-
{
80+
if (err == noErr) {
2881
UseResFile(fileRef) ;
2982
Handle aResHandle = NULL ;
3083
aResHandle = Get1Resource( 'TEXT', 256) ;
@@ -41,7 +94,33 @@ + (NSArray*)weblocFilenamesAndUrlsInPaths:(NSArray*)paths {
4194
CloseResFile(fileRef) ;
4295

4396
// theData is the 'TEXT' resource data
44-
NSString*url = [[NSString alloc] initWithData:theData encoding:kCFStringEncodingMacRoman] ;
97+
url = [[[NSString alloc] initWithData:theData
98+
encoding:NSUTF8StringEncoding] autorelease] ;
99+
}
100+
else {
101+
//NSLog(@"Reading resource fork failed with OSErr %ld", (long)err) ;
102+
NSData* data = [NSData dataWithContentsOfFile:path] ;
103+
if (data) {
104+
NSXMLParser* parser = [[NSXMLParser alloc] initWithData:data] ;
105+
[parser setDelegate:self] ;
106+
NSMutableString* xmlString = [[NSMutableString alloc] init] ;
107+
[self setXmlString:xmlString] ;
108+
[xmlString release] ;
109+
110+
[parser parse] ;
111+
// Note that -parse is synchronous and will not return until the parsing
112+
// is done or aborted.
113+
[parser release] ;
114+
115+
url = [self xmlString] ;
116+
117+
// Not really necessary, but for resource usage efficiency we
118+
// release xmlString here instead of in -dealloc…
119+
[self setXmlString:nil] ;
120+
}
121+
}
122+
123+
if (url) {
45124
NSString* filename = [[path lastPathComponent] stringByDeletingPathExtension] ;
46125

47126
NSDictionary* filenameAndURL = [NSDictionary dictionaryWithObjectsAndKeys:
@@ -50,11 +129,7 @@ + (NSArray*)weblocFilenamesAndUrlsInPaths:(NSArray*)paths {
50129
nil] ;
51130

52131
[filenamesAndURLs addObject:filenameAndURL] ;
53-
54-
[url release] ;
55-
}
56-
else
57-
NSLog(@"Reading resource fork failed with OSErr %ld", (long)err) ;
132+
}
58133
}
59134

60135
if ([filenamesAndURLs count])
@@ -63,4 +138,12 @@ + (NSArray*)weblocFilenamesAndUrlsInPaths:(NSArray*)paths {
63138
return nil ;
64139
}
65140

141+
+ (NSArray*)weblocFilenamesAndUrlsInPaths:(NSArray*)paths {
142+
SSYResourceForks* instance = [[SSYResourceForks alloc] init] ;
143+
NSArray* answer = [instance weblocFilenamesAndUrlsInPaths:paths] ;
144+
[instance release] ;
145+
146+
return answer ;
147+
}
148+
66149
@end

SSYRunLoopTickler.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ + (void)tickle {
1818
NSLog(@"%s failed to send its message.", __PRETTY_FUNCTION__) ;
1919
}
2020

21+
#if NO_ARC
2122
[message release] ;
22-
23+
#endif
24+
2325
// If I remove the port now, the desired "tickle" causing a
2426
// blocked -[NSRunLoop runMode:beforeDate:] to return will
2527
// not occur. But if I do so with a delay of 0.0, it works.

SSYSearchyMenu.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#import <Cocoa/Cocoa.h>
2+
3+
@interface SSYSearchyMenu : NSPanel
4+
5+
@property (assign) NSSize size ;
6+
7+
- (void)popUpMenu:(NSMenu*)menu ;
8+
9+
@end
10+

SSYSearchyMenu.m

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#import "SSYSearchyMenu.h"
2+
3+
NSString* SSYSearchyMenuWillProcessEventNotification = @"SSYSearchyMenuWillProcessEventNotification" ;
4+
5+
@implementation SSYSearchyMenu
6+
7+
@synthesize size = m_size ;
8+
9+
/*
10+
@details NSWindow will refuse to become the main window unless it has a title
11+
bar. This override lets us become main even though we don't have a title bar.
12+
*/
13+
- (BOOL)canBecomeMainWindow {
14+
return YES ;
15+
}
16+
17+
/*
18+
@details Much like above method.
19+
*/
20+
- (BOOL) canBecomeKeyWindow {
21+
return YES ;
22+
}
23+
24+
- (BOOL)isExcludedFromWindowsMenu {
25+
return YES ;
26+
}
27+
28+
- (void)goAway {
29+
[self orderOut:self] ;
30+
// [[NSNotificationCenter defaultCenter] removeObserver:self] ;
31+
}
32+
33+
#define SSY_SEARCHY_MENU_WIDTH 100.0
34+
#define SSY_SEARCHY_MENU_HEIGHT 50.0
35+
36+
- (id)initWithTitle:(NSString*)title
37+
atLocation:(NSPoint)location
38+
delegate:(NSObject*)delegate {
39+
// Create dummy initial contentRect for window.
40+
NSRect frame = NSMakeRect(
41+
location.x,
42+
location.y - SSY_SEARCHY_MENU_HEIGHT,
43+
SSY_SEARCHY_MENU_WIDTH,
44+
SSY_SEARCHY_MENU_HEIGHT
45+
) ;
46+
NSRect contentFrame = NSMakeRect(
47+
0.0,
48+
0.0,
49+
SSY_SEARCHY_MENU_WIDTH,
50+
SSY_SEARCHY_MENU_HEIGHT
51+
) ;
52+
if ((self = [super initWithContentRect:contentFrame
53+
styleMask:(NSBorderlessWindowMask + NSTitledWindowMask)
54+
backing:NSBackingStoreBuffered
55+
defer:NO])) {
56+
57+
[[NSNotificationCenter defaultCenter] addObserver:self
58+
selector:@selector(didReceiveEvent:)
59+
name:SSYSearchyMenuWillProcessEventNotification
60+
object:nil] ;
61+
62+
// Configure window
63+
if (title) {
64+
[self setTitle:title] ;
65+
}
66+
[self setMovableByWindowBackground:NO] ;
67+
[self setExcludedFromWindowsMenu:YES] ;
68+
[self setAlphaValue:1.0] ;
69+
[self setOpaque:NO] ; // was NO
70+
[self setHasShadow:YES] ;
71+
[self useOptimizedDrawing:YES] ;
72+
73+
[[self contentView] setFrame:contentFrame] ;
74+
[self setFrame:frame
75+
display:YES] ;
76+
77+
[self setLevel:NSDockWindowLevel] ;
78+
[self setHidesOnDeactivate:NO] ;
79+
[self makeKeyAndOrderFront:self] ;
80+
}
81+
82+
return self ;
83+
}
84+
85+
- (void)popUpMenu:(NSMenu*)menu {
86+
[menu popUpMenuPositioningItem:[[menu itemArray] objectAtIndex:0]
87+
atLocation:[self frame].origin
88+
inView:nil] ;
89+
}
90+
91+
@end

SSYTasker.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ extern NSInteger SSYTaskerMetaErrorCode ;
1313

1414
typedef enum SSYTaskerErrorCodes_enum SSYTaskerErrorCodes ;
1515

16+
@protocol SSYTaskerProgressDelegate
17+
18+
- (void)gotBytesCount:(NSInteger)bytesCount
19+
pipeName:(NSString*)pipeName ;
20+
21+
@end
22+
23+
24+
1625
/*!
1726
@brief A wrapper around NSTask which runs a task synchronously, as in
1827
-[NSTask waitUntilExit], but is more robust.
@@ -33,7 +42,11 @@ typedef enum SSYTaskerErrorCodes_enum SSYTaskerErrorCodes ;
3342
3443
This class assumes Objective-C Automatic Reference Counting (ARC).
3544
*/
36-
@interface SSYTasker : NSObject
45+
@interface SSYTasker : NSObject {
46+
NSObject <SSYTaskerProgressDelegate> * __weak m_delegate ;
47+
}
48+
49+
@property NSObject <SSYTaskerProgressDelegate> * __weak delegate ;
3750

3851
/*!
3952
@brief Runs a shell task synchronously and robustly

0 commit comments

Comments
 (0)