Revision: 12585
http://bibdesk.svn.sourceforge.net/bibdesk/?rev=12585&view=rev
Author: amaxwell
Date: 2008-01-19 11:02:10 -0800 (Sat, 19 Jan 2008)
Log Message:
-----------
Block assertions in release builds, so NSAssert can be used freely.
Add a framework assertions as a convenience to enforce API usage.
Fix incorrect label range in comment.
Modified Paths:
--------------
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderLabel.h
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderLabel.m
trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.h
trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.m
trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.xcodeproj/project.pbxproj
trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView_Prefix.pch
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderLabel.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderLabel.h 2008-01-19
18:52:39 UTC (rev 12584)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderLabel.h 2008-01-19
19:02:10 UTC (rev 12585)
@@ -48,6 +48,9 @@
+ (NSString *)localizedNameForLabel:(NSInteger)label;
+ (NSUInteger)finderLabelForURL:(NSURL *)aURL;
+
+// valid range is 0--7 (pass 0 to clear the label)
+// non-file: URL and non-existent files are silently ignored
+ (void)setFinderLabel:(NSUInteger)label forURL:(NSURL *)aURL;
@end
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderLabel.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderLabel.m 2008-01-19
18:52:39 UTC (rev 12584)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFinderLabel.m 2008-01-19
19:02:10 UTC (rev 12585)
@@ -165,6 +165,7 @@
+ (NSString *)localizedNameForLabel:(NSInteger)label
{
+ FVAPIAssert1(label <= 7, @"Invalid Finder label %d (must be in the range
0--7)", label);
NSArray *labelNames = nil;
if (nil == labelNames) {
NSBundle *bundle = [NSBundle bundleForClass:[FVFinderLabel self]];
@@ -272,6 +273,7 @@
+ (void)drawFinderLabel:(NSUInteger)label inRect:(CGRect)rect
ofContext:(CGContextRef)context flipped:(BOOL)isFlipped roundEnds:(BOOL)flag;
{
+ FVAPIAssert1(label <= 7, @"Invalid Finder label %d (must be in the range
0--7)", label);
CGContextSaveGState(context);
if (isFlipped) {
CGContextTranslateCTM(context, 0, CGRectGetMaxY(rect));
@@ -323,10 +325,8 @@
{
FSRef fileRef;
- NSParameterAssert(label <= 7);
-
- if (label > 7) label = 0;
-
+ FVAPIAssert1(label <= 7, @"Invalid Finder label %d (must be in the range
0--7)", label);
+
if ([aURL isFileURL] && CFURLGetFSRef((CFURLRef)aURL, &fileRef)) {
FSCatalogInfo catalogInfo;
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.h 2008-01-19
18:52:39 UTC (rev 12584)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.h 2008-01-19
19:02:10 UTC (rev 12585)
@@ -126,7 +126,7 @@
- (IBAction)selectNextIcon:(id)sender;
- (IBAction)delete:(id)sender;
-// sender must implement -tag to return a valid Finder label integer (0-6);
non-file URLs are ignored
+// sender must implement -tag to return a valid Finder label integer (0-7);
non-file URLs are ignored
- (IBAction)changeFinderLabel:(id)sender;
- (IBAction)openSelectedURLs:(id)sender;
- (IBAction)trashSelectedURLs:(id)sender;
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.m 2008-01-19
18:52:39 UTC (rev 12584)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.m 2008-01-19
19:02:10 UTC (rev 12585)
@@ -294,7 +294,7 @@
- (void)setIconScale:(CGFloat)scale;
{
- NSParameterAssert(scale > 0);
+ FVAPIAssert(scale > 0, @"scale must be greater than zero");
_iconSize.width = DEFAULT_ICON_SIZE.width * scale;
_iconSize.height = DEFAULT_ICON_SIZE.height * scale;
_padding = [self _paddingForScale:scale];
@@ -322,10 +322,18 @@
- (void)_registerForDraggedTypes
{
if (_isEditable && _dataSource) {
- NSParameterAssert([_dataSource
respondsToSelector:@selector(fileView:insertURLs:atIndexes:)]);
- NSParameterAssert([_dataSource
respondsToSelector:@selector(fileView:replaceURLsAtIndexes:withURLs:)]);
- NSParameterAssert([_dataSource
respondsToSelector:@selector(fileView:moveURLsAtIndexes:toIndex:)]);
- NSParameterAssert([_dataSource
respondsToSelector:@selector(fileView:deleteURLsAtIndexes:)]);
+ const SEL selectors[] =
+ {
+ @selector(fileView:insertURLs:atIndexes:),
+ @selector(fileView:insertURLs:atIndexes:),
+ @selector(fileView:replaceURLsAtIndexes:withURLs:),
+ @selector(fileView:moveURLsAtIndexes:toIndex:),
+ @selector(fileView:deleteURLsAtIndexes:)
+ };
+ NSUInteger i, iMax = sizeof(selectors) / sizeof(SEL);
+ for (i = 0; i < iMax; i++)
+ FVAPIAssert1([_dataSource respondsToSelector:selectors[i]],
@"datasource must implement %@", NSStringFromSelector(selectors[i]));
+
[self registerForDraggedTypes:[NSArray
arrayWithObjects:NSFilenamesPboardType, NSURLPboardType,
FVWeblocFilePboardType, (NSString *)kUTTypeURL, (NSString
*)kUTTypeUTF8PlainText, NSStringPboardType, nil]];
} else {
[self registerForDraggedTypes:nil];
@@ -343,8 +351,8 @@
- (void)setDataSource:(id)obj;
{
if (obj) {
- NSParameterAssert([obj
respondsToSelector:@selector(numberOfIconsInFileView:)]);
- NSParameterAssert([obj
respondsToSelector:@selector(fileView:URLAtIndex:)]);
+ FVAPIAssert1([obj
respondsToSelector:@selector(numberOfIconsInFileView:)], @"datasource must
implement %@", NSStringFromSelector(@selector(numberOfIconsInFileView:)));
+ FVAPIAssert1([obj respondsToSelector:@selector(fileView:URLAtIndex:)],
@"datasource must implement %@",
NSStringFromSelector(@selector(fileView:URLAtIndex:)));
}
_dataSource = obj;
// convenient time to do this, although the timer would also handle it
@@ -578,7 +586,7 @@
- (void)setSelectionIndexes:(NSIndexSet *)indexSet;
{
- NSParameterAssert(nil != indexSet);
+ FVAPIAssert(nil != indexSet, @"index set must not be nil");
[_selectedIndexes autorelease];
_selectedIndexes = [indexSet mutableCopy];
}
@@ -2318,7 +2326,7 @@
{
// Sender is an NSMenuItem, and tag corresponds to the Finder label integer
NSInteger label = [sender tag];
- NSParameterAssert(label >= 0 && label <= 7);
+ FVAPIAssert1(label >=0 && label <= 7, @"invalid label %d (must be between
0 and 7)", label);
NSArray *selectedURLs = [self _selectedURLs];
NSUInteger i, iMax = [selectedURLs count];
Modified:
trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.xcodeproj/project.pbxproj
===================================================================
---
trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.xcodeproj/project.pbxproj
2008-01-19 18:52:39 UTC (rev 12584)
+++
trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView.xcodeproj/project.pbxproj
2008-01-19 19:02:10 UTC (rev 12585)
@@ -118,7 +118,7 @@
isa = PBXContainerItemProxy;
containerPortal = 0867D690FE84028FC02AAC07 /* Project
object */;
proxyType = 1;
- remoteGlobalIDString = F9F04CE10CE260EB00F28ED2 /*
Framework + Plugin */;
+ remoteGlobalIDString = F9F04CE10CE260EB00F28ED2;
remoteInfo = "Framework + Plugin";
};
F9F04CDA0CE260AC00F28ED2 /* PBXContainerItemProxy */ = {
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView_Prefix.pch
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView_Prefix.pch
2008-01-19 18:52:39 UTC (rev 12584)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FileView_Prefix.pch
2008-01-19 19:02:10 UTC (rev 12585)
@@ -30,6 +30,27 @@
#define NSAppKitVersionNumber10_4 824
#endif
+#ifndef DEBUG
+#if !defined(NS_BLOCK_ASSERTIONS)
+#define NS_BLOCK_ASSERTIONS 1
+#endif /* NS_BLOCK_ASSERTIONS */
+#endif /* DEBUG */
+
+#if !defined(_FVAPIAssertBody)
+#define _FVAPIAssertBody(condition, desc, arg1, arg2) \
+do { if(!(condition)) { [NSException raise:NSInvalidArgumentException
format:(desc), (arg1), (arg2)]; } } while(0)
+#endif /* _FVAPIAssertBody */
+
+// use NSAssert internally for debugging; these asserts are to enforce public
API usage for framework clients
+#define FVAPIAssert(condition, desc) \
+_FVAPIAssertBody((condition), desc, 0, 0)
+
+#define FVAPIAssert1(condition, desc, arg1) \
+_FVAPIAssertBody((condition), (desc), (arg1), 0)
+
+#define FVAPIAssert2(condition, desc, arg1, arg2) \
+_FVAPIAssertBody((condition), (desc), (arg1), (arg2))
+
// copied from AppKit
#if defined(__MACH__)
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit