Commits

Jens Alfke committed 87ce300

* Fixed deprecation warnings on 10.6.
* Fixed 64-to-32-bit conversion warnings.
* Added some needed #imports.
* Added MYTableView and MYXMLUtils.

Comments (0)

Files changed (11)

 //
 
 #import "DateUtils.h"
+#import "Test.h"
 
 #include <assert.h>
 #include <CoreServices/CoreServices.h>
                                                              NSUserDomainMask, YES)
                          objectAtIndex: 0];
         dir = [dir stringByAppendingPathComponent: [[NSBundle mainBundle] bundleIdentifier]];
+        NSError *error;
         if( ! [[NSFileManager defaultManager] fileExistsAtPath: dir]
-                && ! [[NSFileManager defaultManager] createDirectoryAtPath: dir attributes: nil] )
+               && ! [[NSFileManager defaultManager] createDirectoryAtPath: dir
+                                              withIntermediateDirectories: YES
+                                                               attributes: nil
+                                                                    error: &error] )
             [NSException raise: NSGenericException format: @"Unable to create app support dir %@",dir];
         sPath = [dir copy];
     }

GoogleToolboxSubset/GTMDefines.h

   do {                                                                   \
     if (!(condition)) {                                                  \
       [[NSAssertionHandler currentHandler]                               \
-          handleFailureInFunction:[NSString stringWithCString:__PRETTY_FUNCTION__] \
-                             file:[NSString stringWithCString:__FILE__]  \
+          handleFailureInFunction:[NSString stringWithUTF8String:__PRETTY_FUNCTION__] \
+                             file:[NSString stringWithUTF8String:__FILE__]  \
                        lineNumber:__LINE__                               \
                       description:__VA_ARGS__];                          \
     }                                                                    \
 //
 
 #import "GraphicsUtils.h"
+#import "CollectionUtils.h"
 #import "FileUtils.h"
+#import "Test.h"
 #import <ApplicationServices/ApplicationServices.h>
 
 

ImageAndTextCell.m

         result.size = [image size];
         result.origin = cellFrame.origin;
         result.origin.x += 3;
-        result.origin.y += ceil((cellFrame.size.height - result.size.height) / 2);
+        result.origin.y += ceilf((cellFrame.size.height - result.size.height) / 2.0f);
     } else {
         result = NSZeroRect;
     }
         imageFrame.size = imageSize;
 
         if ([controlView isFlipped])
-            imageFrame.origin.y += ceil((cellFrame.size.height + imageFrame.size.height) / 2);
+            imageFrame.origin.y += ceilf((cellFrame.size.height + imageFrame.size.height) / 2);
         else
-            imageFrame.origin.y += ceil((cellFrame.size.height - imageFrame.size.height) / 2);
+            imageFrame.origin.y += ceilf((cellFrame.size.height - imageFrame.size.height) / 2);
 
         [image compositeToPoint:imageFrame.origin operation:NSCompositeSourceOver];
     }
 
 #import <Foundation/Foundation.h>
 
+/*
+    This is a configurable console-logging facility that lets logging be turned on and off
+    independently for various subsystems or areas of the code. It's used similarly to NSLog:
+        Log(@"the value of foo is %@", foo);
+    You can associate a log message with a particular subsystem or tag by calling LogTo:
+        LogTo(FooVerbose, @"the value of foo is %@", foo);
+ 
+    All logging is off by default.
+
+    To enable logging in general, set the user default 'Log' to 'YES'. You can do this persistently using the 'defaults write' command; but it's very convenient during development to use the Arguments tab in the Xcode Executable Info panel. Just add a new entry to the arguments list, of the form "-Log YES". Now you can check and uncheck that as desired; the change will take effect when relaunching Murky.
+
+    Once logging is enabled, you can turn on and off individual categories of logs. For any category "Something", to enable output from calls of the form LogTo(Something, @"..."), set the user default 'LogSomething' to 'YES', just as above.
+
+    Warn() is a related function that _always_ logs, and prefixes the message with "WARNING***".
+        Warn(@"Reactor coolant system has failed");
+ 
+    Note: Logging is still present in release/nondebug builds. I've found this to be very useful in tracking down problems in the field, since I can tell a user how to turn on logging, and then get detailed logs back.
+*/ 
+
 
 NSString* LOC( NSString *key );     // Localized string lookup
 
     #define IN_SEGMENT_NORETURN(SEG)
 #endif
 
+
 #define Log(FMT,ARGS...) do{if(__builtin_expect(_gShouldLog,0)) {\
                             IN_SEGMENT(Logging){_Log(FMT,##ARGS);}\
                          } }while(0)
                                   } }while(0)
 #define Warn Warn
 
+
 void AlwaysLog( NSString *msg, ... ) __attribute__((format(__NSString__, 1, 2)));
 BOOL EnableLog( BOOL enable );
 #define EnableLogTo( DOMAIN, VALUE )  _EnableLogTo(@""#DOMAIN, VALUE)
+//
+//  MYTableView.h
+//  FeedMe
+//
+//  Created by Jens Alfke on 11/3/09.
+//  Copyright 2009 Jens Alfke. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface NSTableView (MYUtilities)
+
+- (void) my_selectRow: (NSInteger)row;
+
+@end
+//
+//  MYTableView.m
+//  FeedMe
+//
+//  Created by Jens Alfke on 11/3/09.
+//  Copyright 2009 Jens Alfke. All rights reserved.
+//
+
+#import "MYTableView.h"
+
+
+@implementation NSTableView (MYUtilities)
+
+- (void) my_selectRow: (NSInteger)row {
+    NSIndexSet *indexes = [[NSIndexSet alloc] initWithIndex: row];
+    [self selectRowIndexes: indexes byExtendingSelection: NO];
+    [indexes release];
+}
+
+@end
+//
+//  MYXMLUtils.h
+//  FeedMe
+//
+//  Created by Jens Alfke on 11/3/09.
+//  Copyright 2009 Jens Alfke. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+@interface NSXMLElement (MYUtilities)
+
+/*  Follow an XPath, returning the result as a single string.
+    If multiple nodes match, only the text of the first one is returned. */
+- (NSString*) my_stringAtXPath: (NSString*) xpath error: (NSError**)error;
+
+/* Follow an XPath, returning the result as a single URL. */
+- (NSURL*) my_URLAtXPath: (NSString*) xpath error: (NSError**)error;
+
+@end
+//
+//  MYXMLUtils.m
+//  FeedMe
+//
+//  Created by Jens Alfke on 11/3/09.
+//  Copyright 2009 Jens Alfke. All rights reserved.
+//
+
+#import "MYXMLUtils.h"
+
+#import "Logging.h"
+
+
+@implementation NSXMLElement (MYUtilities)
+
+
+/* Follow an XPath, returning the result as a single string */
+- (NSString*) my_stringAtXPath: (NSString*) xpath error: (NSError**)error
+{
+    NSArray *nodes = [self nodesForXPath: xpath error: error];
+    if (!nodes) {
+        // Can't avoid QName errors so don't report them
+        if (!error || [[*error description] rangeOfString: @"can't resolve QName for"].length==0)
+            Warn(@"XPath error for '%@': %@", xpath, (error ?*error :nil));
+        return nil;
+    }
+    if( [nodes count] == 0 ) {
+        if (error) *error = nil;
+        return nil;
+    }
+    if( [nodes count] > 1 )
+        Warn(@"stringAtXPath: Got %u results for '%@'", [nodes count],xpath);
+    return [[nodes objectAtIndex: 0] stringValue];
+}
+
+
+/* Follow an XPath, returning the result as a single URL */
+- (NSURL*) my_URLAtXPath: (NSString*) xpath error: (NSError**)error
+{
+    NSString *str = [self my_stringAtXPath: xpath error: error];
+    if( ! str )
+        return nil;
+    NSURL *url = [NSURL URLWithString: str];
+    if( ! url ) {
+        Warn(@"Invalid URL <%@> for '%@'",str,xpath);
+        if (error) *error = nil;
+    }
+    return url;
+}
+
+
+@end
 //
 
 #import "URLUtils.h"
+#import "CollectionUtils.h"
 
 
 @implementation NSURL (MYUtilities)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.