Revision: 7580
http://skim-app.svn.sourceforge.net/skim-app/?rev=7580&view=rev
Author: hofman
Date: 2011-12-16 18:15:22 +0000 (Fri, 16 Dec 2011)
Log Message:
-----------
use formatter for snapshot page cell to convert dictionary value to string value
Modified Paths:
--------------
trunk/SKProgressCell.m
trunk/SKSnapshotPageCell.h
trunk/SKSnapshotPageCell.m
trunk/Skim.xcodeproj/project.pbxproj
Added Paths:
-----------
trunk/SKDictionaryFormatter.h
trunk/SKDictionaryFormatter.m
Added: trunk/SKDictionaryFormatter.h
===================================================================
--- trunk/SKDictionaryFormatter.h (rev 0)
+++ trunk/SKDictionaryFormatter.h 2011-12-16 18:15:22 UTC (rev 7580)
@@ -0,0 +1,46 @@
+//
+// SKDictionaryFormatter.h
+// Skim
+//
+// Created by Christiaan Hofman on 12/16/11.
+/*
+ This software is Copyright (c) 2008-2011
+ Christiaan Hofman. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ - Neither the name of Christiaan Hofman nor the names of any
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface SKDictionaryFormatter : NSFormatter {
+ NSString *key;
+}
+@property (nonatomic, retain) NSString *key;
+@end
Added: trunk/SKDictionaryFormatter.m
===================================================================
--- trunk/SKDictionaryFormatter.m (rev 0)
+++ trunk/SKDictionaryFormatter.m 2011-12-16 18:15:22 UTC (rev 7580)
@@ -0,0 +1,60 @@
+//
+// SKDictionaryFormatter.m
+// Skim
+//
+// Created by Christiaan Hofman on 12/16/11.
+/*
+ This software is Copyright (c) 2008-2011
+ Christiaan Hofman. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ - Neither the name of Christiaan Hofman nor the names of any
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "SKDictionaryFormatter.h"
+
+
+@implementation SKDictionaryFormatter
+
+@synthesize key;
+
+- (void)dealloc {
+ SKDESTROY(key);
+ [super dealloc];
+}
+
+- (NSString *)stringForObjectValue:(id)obj {
+ return [obj respondsToSelector:@selector(objectForKey:)] ? [obj
objectForKey:key ?: @""] : nil;
+}
+
+- (BOOL)getObjectValue:(id *)obj forString:(NSString *)string
errorDescription:(NSString **)error {
+ *obj = [NSDictionary dictionaryWithObjectsAndKeys:[[string copy]
autorelease], key ?: @"", nil];
+ return YES;
+}
+
+@end
Modified: trunk/SKProgressCell.m
===================================================================
--- trunk/SKProgressCell.m 2011-12-16 16:19:11 UTC (rev 7579)
+++ trunk/SKProgressCell.m 2011-12-16 18:15:22 UTC (rev 7580)
@@ -38,28 +38,25 @@
#import "SKProgressCell.h"
#import "SKDownload.h"
+#import "SKDictionaryFormatter.h"
#import "NSString_SKExtensions.h"
#import "NSGeometry_SKExtensions.h"
#define MARGIN_X 8.0
#define MARGIN_Y 2.0
-@interface SKProgressCellFormatter : NSFormatter
-@end
-
-#pragma mark
-
static inline id objectValueForKey(id object, NSString *key) {
return [object respondsToSelector:@selector(objectForKey:)] ? [object
objectForKey:key] : nil;
}
@implementation SKProgressCell
-static SKProgressCellFormatter *progressCellFormatter = nil;
+static SKDictionaryFormatter *progressCellFormatter = nil;
+ (void)initialize {
SKINITIALIZE;
- progressCellFormatter = [[SKProgressCellFormatter alloc] init];
+ progressCellFormatter = [[SKDictionaryFormatter alloc] init];
+ [progressCellFormatter setKey:SKDownloadFileNameKey];
}
@@ -180,18 +177,3 @@
}
@end
-
-#pragma mark -
-
-@implementation SKProgressCellFormatter
-
-- (NSString *)stringForObjectValue:(id)obj {
- return objectValueForKey(obj, SKDownloadFileNameKey);
-}
-
-- (BOOL)getObjectValue:(id *)obj forString:(NSString *)string
errorDescription:(NSString **)error {
- *obj = [NSDictionary dictionaryWithObjectsAndKeys:[[string copy]
autorelease], SKDownloadFileNameKey, nil];
- return YES;
-}
-
-@end
Modified: trunk/SKSnapshotPageCell.h
===================================================================
--- trunk/SKSnapshotPageCell.h 2011-12-16 16:19:11 UTC (rev 7579)
+++ trunk/SKSnapshotPageCell.h 2011-12-16 18:15:22 UTC (rev 7580)
@@ -42,7 +42,5 @@
extern NSString *SKSnapshotPageCellHasWindowKey;
-@interface SKSnapshotPageCell : NSTextFieldCell {
- BOOL hasWindow;
-}
+@interface SKSnapshotPageCell : NSTextFieldCell
@end
Modified: trunk/SKSnapshotPageCell.m
===================================================================
--- trunk/SKSnapshotPageCell.m 2011-12-16 16:19:11 UTC (rev 7579)
+++ trunk/SKSnapshotPageCell.m 2011-12-16 18:15:22 UTC (rev 7580)
@@ -37,6 +37,7 @@
*/
#import "SKSnapshotPageCell.h"
+#import "SKDictionaryFormatter.h"
#import "NSGeometry_SKExtensions.h"
NSString *SKSnapshotPageCellLabelKey = @"label";
@@ -44,36 +45,29 @@
@implementation SKSnapshotPageCell
-- (id)initWithCoder:(NSCoder *)decoder {
- self = [super initWithCoder:decoder];
- if (self) {
- hasWindow = [decoder decodeBoolForKey:@"hasWindow"];
- }
- return self;
-}
+static SKDictionaryFormatter *snapshotPageCellFormatter = nil;
-- (void)encodeWithCoder:(NSCoder *)coder {
- [super encodeWithCoder:coder];
- [coder encodeBool:hasWindow forKey:@"hasWindow"];
++ (void)initialize {
+ SKINITIALIZE;
+ snapshotPageCellFormatter = [[SKDictionaryFormatter alloc] init];
+ [snapshotPageCellFormatter setKey:SKSnapshotPageCellLabelKey];
}
-- (id)copyWithZone:(NSZone *)aZone {
- SKSnapshotPageCell *copy = [super copyWithZone:aZone];
- copy->hasWindow = hasWindow;
- return copy;
-}
-
-- (void)setObjectValue:(id)anObject {
- if ([anObject isKindOfClass:[NSString class]]) {
- [super setObjectValue:anObject];
- } else {
- [super setObjectValue:[anObject
valueForKey:SKSnapshotPageCellLabelKey]];
- hasWindow = [[anObject valueForKey:SKSnapshotPageCellHasWindowKey]
boolValue];
+- (id)initTextCell:(NSString *)aString {
+ self = [super initTextCell:aString];
+ if (self) {
+ [self setFormatter:snapshotPageCellFormatter];
}
+ return self;
}
-- (id)objectValue {
- return [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber
numberWithBool:hasWindow], SKSnapshotPageCellHasWindowKey, [self stringValue],
SKSnapshotPageCellLabelKey, nil];
+- (id)initWithCoder:(NSCoder *)decoder {
+ self = [super initWithCoder:decoder];
+ if (self) {
+ if ([self formatter] == nil)
+ [self setFormatter:snapshotPageCellFormatter];
+ }
+ return self;
}
- (NSSize)cellSizeForBounds:(NSRect)aRect {
@@ -85,7 +79,11 @@
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
NSRect textRect, imageRect;
NSDivideRect(cellFrame, &textRect, &imageRect, 17.0, NSMinYEdge);
+
[super drawInteriorWithFrame:textRect inView:controlView];
+
+ id obj = [self objectValue];
+ BOOL hasWindow = [obj respondsToSelector:@selector(objectForKey:)] ? [[obj
objectForKey:SKSnapshotPageCellHasWindowKey] boolValue] : NO;
if (hasWindow) {
CGFloat radius = 2.0;
NSBezierPath *path = [NSBezierPath bezierPath];
Modified: trunk/Skim.xcodeproj/project.pbxproj
===================================================================
--- trunk/Skim.xcodeproj/project.pbxproj 2011-12-16 16:19:11 UTC (rev
7579)
+++ trunk/Skim.xcodeproj/project.pbxproj 2011-12-16 18:15:22 UTC (rev
7580)
@@ -60,6 +60,7 @@
CE0A3C8E0EBF3AAA00526C74 /* NSResponder_SKExtensions.m in
Sources */ = {isa = PBXBuildFile; fileRef = CE0A3C8D0EBF3AAA00526C74 /*
NSResponder_SKExtensions.m */; };
CE0A9F9C11564AE1004E6BBF /* XDVDocument.icns in Resources */ =
{isa = PBXBuildFile; fileRef = CE0A9F9B11564AE1004E6BBF /* XDVDocument.icns */;
};
CE0AEDC3107A137C000C075E /* SKColorCell.m in Sources */ = {isa
= PBXBuildFile; fileRef = CE0AEDC2107A137C000C075E /* SKColorCell.m */; };
+ CE0DE5BE149BBFC300F4085D /* SKDictionaryFormatter.m in Sources
*/ = {isa = PBXBuildFile; fileRef = CE0DE5BD149BBFC300F4085D /*
SKDictionaryFormatter.m */; };
CE0E83EE114D15E000E37F38 /* SyncPreferences.tiff in Resources
*/ = {isa = PBXBuildFile; fileRef = CE0E83EA114D15E000E37F38 /*
SyncPreferences.tiff */; };
CE0E83EF114D15E000E37F38 /* DisplayPreferences.tiff in
Resources */ = {isa = PBXBuildFile; fileRef = CE0E83EB114D15E000E37F38 /*
DisplayPreferences.tiff */; };
CE0E83F0114D15E000E37F38 /* GeneralPreferences.tiff in
Resources */ = {isa = PBXBuildFile; fileRef = CE0E83EC114D15E000E37F38 /*
GeneralPreferences.tiff */; };
@@ -544,6 +545,8 @@
CE0A9F9B11564AE1004E6BBF /* XDVDocument.icns */ = {isa =
PBXFileReference; lastKnownFileType = image.icns; path = XDVDocument.icns;
sourceTree = "<group>"; };
CE0AEDC1107A137C000C075E /* SKColorCell.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
SKColorCell.h; sourceTree = "<group>"; };
CE0AEDC2107A137C000C075E /* SKColorCell.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= SKColorCell.m; sourceTree = "<group>"; };
+ CE0DE5BC149BBFC300F4085D /* SKDictionaryFormatter.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
SKDictionaryFormatter.h; sourceTree = "<group>"; };
+ CE0DE5BD149BBFC300F4085D /* SKDictionaryFormatter.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= SKDictionaryFormatter.m; sourceTree = "<group>"; };
CE0E83EA114D15E000E37F38 /* SyncPreferences.tiff */ = {isa =
PBXFileReference; lastKnownFileType = image.tiff; path = SyncPreferences.tiff;
sourceTree = "<group>"; };
CE0E83EB114D15E000E37F38 /* DisplayPreferences.tiff */ = {isa =
PBXFileReference; lastKnownFileType = image.tiff; path =
DisplayPreferences.tiff; sourceTree = "<group>"; };
CE0E83EC114D15E000E37F38 /* GeneralPreferences.tiff */ = {isa =
PBXFileReference; lastKnownFileType = image.tiff; path =
GeneralPreferences.tiff; sourceTree = "<group>"; };
@@ -1855,6 +1858,8 @@
CEC0ABED118307F900384CFD /* View Helpers */ = {
isa = PBXGroup;
children = (
+ CE0DE5BC149BBFC300F4085D /*
SKDictionaryFormatter.h */,
+ CE0DE5BD149BBFC300F4085D /*
SKDictionaryFormatter.m */,
CE455392111DA4290060CAC9 /*
SKImageToolTipContext.h */,
CE455393111DA4290060CAC9 /*
SKImageToolTipContext.m */,
CEF60CE1114C01CA0074ACC4 /* SKLocalization.h */,
@@ -2552,6 +2557,7 @@
CEB402C313EDAD6100851D1B /* SKTemporaryData.m
in Sources */,
CE1248C513FEDCF200FFAE20 /* SKTemplateManager.m
in Sources */,
CE139A171450207500E9C069 /*
NSGraphics_SKExtensions.m in Sources */,
+ CE0DE5BE149BBFC300F4085D /*
SKDictionaryFormatter.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Learn Windows Azure Live! Tuesday, Dec 13, 2011
Microsoft is holding a special Learn Windows Azure training event for
developers. It will provide a great way to learn Windows Azure and what it
provides. You can attend the event by watching it streamed LIVE online.
Learn more at http://p.sf.net/sfu/ms-windowsazure
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit