Revision: 7581
          http://skim-app.svn.sourceforge.net/skim-app/?rev=7581&view=rev
Author:   hofman
Date:     2011-12-16 21:34:28 +0000 (Fri, 16 Dec 2011)
Log Message:
-----------
use generic dictionary formatter for text+icon cell

Modified Paths:
--------------
    trunk/BookmarksWindow.xib
    trunk/SKTextWithIconCell.h
    trunk/SKTextWithIconCell.m

Modified: trunk/BookmarksWindow.xib
===================================================================
--- trunk/BookmarksWindow.xib   2011-12-16 18:15:22 UTC (rev 7580)
+++ trunk/BookmarksWindow.xib   2011-12-16 21:34:28 UTC (rev 7581)
@@ -45,7 +45,7 @@
                                <string 
key="NSWindowContentMaxSize">{1.79769e+308, 1.79769e+308}</string>
                                <string key="NSWindowContentMinSize">{300, 
100}</string>
                                <object class="NSView" key="NSWindowView" 
id="598959779">
-                                       <reference key="NSNextResponder"/>
+                                       <nil key="NSNextResponder"/>
                                        <int key="NSvFlags">256</int>
                                        <object class="NSMutableArray" 
key="NSSubviews">
                                                <bool 
key="EncodedWithXMLCoder">YES</bool>
@@ -54,7 +54,6 @@
                                                        <int 
key="NSvFlags">290</int>
                                                        <string 
key="NSFrameSize">{400, 22}</string>
                                                        <reference 
key="NSSuperview" ref="598959779"/>
-                                                       <reference 
key="NSWindow"/>
                                                        <string 
key="NSClassName">SKStatusBar</string>
                                                        <string 
key="NSExtension">NSControl</string>
                                                </object>
@@ -73,14 +72,12 @@
                                                                                
        <int key="NSvFlags">256</int>
                                                                                
        <string key="NSFrameSize">{400, 212}</string>
                                                                                
        <reference key="NSSuperview" ref="1011170753"/>
-                                                                               
        <reference key="NSWindow"/>
                                                                                
        <bool key="NSEnabled">YES</bool>
                                                                                
        <object class="NSTableHeaderView" key="NSHeaderView" id="304023328">
                                                                                
                <reference key="NSNextResponder" ref="940762177"/>
                                                                                
                <int key="NSvFlags">256</int>
                                                                                
                <string key="NSFrameSize">{400, 17}</string>
                                                                                
                <reference key="NSSuperview" ref="940762177"/>
-                                                                               
                <reference key="NSWindow"/>
                                                                                
                <reference key="NSTableView" ref="9273418"/>
                                                                                
        </object>
                                                                                
        <object class="_NSCornerView" key="NSCornerView" id="806461566">
@@ -88,7 +85,6 @@
                                                                                
                <int key="NSvFlags">-2147483392</int>
                                                                                
                <string key="NSFrame">{{-26, 0}, {16, 17}}</string>
                                                                                
                <reference key="NSSuperview" ref="793888819"/>
-                                                                               
                <reference key="NSWindow"/>
                                                                                
        </object>
                                                                                
        <object class="NSMutableArray" key="NSTableColumns">
                                                                                
                <bool key="EncodedWithXMLCoder">YES</bool>
@@ -309,7 +305,6 @@
                                                                        
</object>
                                                                        <string 
key="NSFrame">{{0, 17}, {400, 212}}</string>
                                                                        
<reference key="NSSuperview" ref="793888819"/>
-                                                                       
<reference key="NSWindow"/>
                                                                        
<reference key="NSNextKeyView" ref="9273418"/>
                                                                        
<reference key="NSDocView" ref="9273418"/>
                                                                        
<reference key="NSBGColor" ref="211017390"/>
@@ -320,7 +315,6 @@
                                                                        <int 
key="NSvFlags">-2147483392</int>
                                                                        <string 
key="NSFrame">{{-30, 17}, {15, 213}}</string>
                                                                        
<reference key="NSSuperview" ref="793888819"/>
-                                                                       
<reference key="NSWindow"/>
                                                                        
<reference key="NSTarget" ref="793888819"/>
                                                                        <string 
key="NSAction">_doScroller:</string>
                                                                        <double 
key="NSPercent">0.80075189999999996</double>
@@ -330,7 +324,6 @@
                                                                        <int 
key="NSvFlags">-2147483392</int>
                                                                        <string 
key="NSFrame">{{1, -30}, {385, 15}}</string>
                                                                        
<reference key="NSSuperview" ref="793888819"/>
-                                                                       
<reference key="NSWindow"/>
                                                                        <int 
key="NSsFlags">1</int>
                                                                        
<reference key="NSTarget" ref="793888819"/>
                                                                        <string 
key="NSAction">_doScroller:</string>
@@ -345,7 +338,6 @@
                                                                        
</object>
                                                                        <string 
key="NSFrameSize">{400, 17}</string>
                                                                        
<reference key="NSSuperview" ref="793888819"/>
-                                                                       
<reference key="NSWindow"/>
                                                                        
<reference key="NSNextKeyView" ref="304023328"/>
                                                                        
<reference key="NSDocView" ref="304023328"/>
                                                                        
<reference key="NSBGColor" ref="211017390"/>
@@ -355,7 +347,6 @@
                                                        </object>
                                                        <string 
key="NSFrame">{{0, 22}, {400, 229}}</string>
                                                        <reference 
key="NSSuperview" ref="598959779"/>
-                                                       <reference 
key="NSWindow"/>
                                                        <reference 
key="NSNextKeyView" ref="1011170753"/>
                                                        <int 
key="NSsFlags">560</int>
                                                        <reference 
key="NSVScroller" ref="1017415117"/>
@@ -367,16 +358,11 @@
                                                </object>
                                        </object>
                                        <string key="NSFrameSize">{400, 
250}</string>
-                                       <reference key="NSSuperview"/>
-                                       <reference key="NSWindow"/>
                                </object>
                                <string key="NSScreenRect">{{0, 0}, {1440, 
938}}</string>
                                <string key="NSMinSize">{300, 122}</string>
                                <string key="NSMaxSize">{1.79769e+308, 
1.79769e+308}</string>
                        </object>
-                       <object class="NSCustomObject" id="1025403429">
-                               <string 
key="NSClassName">SKTextWithIconFormatter</string>
-                       </object>
                </object>
                <object class="IBObjectContainer" key="IBDocument.Objects">
                        <object class="NSMutableArray" key="connectionRecords">
@@ -437,14 +423,6 @@
                                        </object>
                                        <int key="connectionID">90</int>
                                </object>
-                               <object class="IBConnectionRecord">
-                                       <object class="IBOutletConnection" 
key="connection">
-                                               <string 
key="label">formatter</string>
-                                               <reference key="source" 
ref="6516295"/>
-                                               <reference key="destination" 
ref="1025403429"/>
-                                       </object>
-                                       <int key="connectionID">103</int>
-                               </object>
                        </object>
                        <object class="IBMutableOrderedSet" key="objectRecords">
                                <object class="NSArray" key="orderedObjects">
@@ -587,11 +565,6 @@
                                                <reference key="object" 
ref="579474317"/>
                                                <reference key="parent" 
ref="744363902"/>
                                        </object>
-                                       <object class="IBObjectRecord">
-                                               <int key="objectID">102</int>
-                                               <reference key="object" 
ref="1025403429"/>
-                                               <reference key="parent" 
ref="0"/>
-                                       </object>
                                </object>
                        </object>
                        <object class="NSMutableDictionary" 
key="flattenedProperties">
@@ -605,7 +578,6 @@
                                        
<string>101.IBNumberFormatterBehaviorMetadataKey</string>
                                        
<string>101.IBNumberFormatterLocalizesFormatMetadataKey</string>
                                        <string>101.IBPluginDependency</string>
-                                       <string>102.IBPluginDependency</string>
                                        <string>37.IBPluginDependency</string>
                                        <string>37.ImportedFromIB2</string>
                                        
<string>5.IBEditorWindowLastContentRect</string>
@@ -649,7 +621,6 @@
                                        <boolean value="YES"/>
                                        
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
-                                       
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <boolean value="YES"/>
                                        <string>{{42, 549}, {400, 250}}</string>
                                        
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -1312,7 +1283,7 @@
                                <object class="IBPartialClassDescription">
                                        <string 
key="className">SKTextWithIconCell</string>
                                        <string 
key="superclassName">NSTextFieldCell</string>
-                                       <object 
class="IBClassDescriptionSource" key="sourceIdentifier" id="916925389">
+                                       <object 
class="IBClassDescriptionSource" key="sourceIdentifier">
                                                <string 
key="majorKey">IBProjectSource</string>
                                                <string 
key="minorKey">SKTextWithIconCell.h</string>
                                        </object>
@@ -1326,11 +1297,6 @@
                                        </object>
                                </object>
                                <object class="IBPartialClassDescription">
-                                       <string 
key="className">SKTextWithIconFormatter</string>
-                                       <string 
key="superclassName">NSFormatter</string>
-                                       <reference key="sourceIdentifier" 
ref="916925389"/>
-                               </object>
-                               <object class="IBPartialClassDescription">
                                        <string 
key="className">SKWindowController</string>
                                        <string 
key="superclassName">NSWindowController</string>
                                        <object 
class="IBClassDescriptionSource" key="sourceIdentifier">

Modified: trunk/SKTextWithIconCell.h
===================================================================
--- trunk/SKTextWithIconCell.h  2011-12-16 18:15:22 UTC (rev 7580)
+++ trunk/SKTextWithIconCell.h  2011-12-16 21:34:28 UTC (rev 7581)
@@ -51,9 +51,3 @@
 - (NSRect)iconRectForBounds:(NSRect)aRect;
 
 @end
-
-#pragma mark -
-
-@interface SKTextWithIconFormatter : NSFormatter
-- (NSImage *)imageForObjectValue:(id)obj;
-@end

Modified: trunk/SKTextWithIconCell.m
===================================================================
--- trunk/SKTextWithIconCell.m  2011-12-16 18:15:22 UTC (rev 7580)
+++ trunk/SKTextWithIconCell.m  2011-12-16 21:34:28 UTC (rev 7581)
@@ -37,6 +37,7 @@
  */
 
 #import "SKTextWithIconCell.h"
+#import "SKDictionaryFormatter.h"
 #import "NSImage_SKExtensions.h"
 #import "NSGeometry_SKExtensions.h"
 #import "NSEvent_SKExtensions.h"
@@ -50,11 +51,27 @@
 
 @implementation SKTextWithIconCell
 
+static SKDictionaryFormatter *textWithIconCellFormatter = nil;
+
++ (void)initialize {
+    SKINITIALIZE;
+    textWithIconCellFormatter = [[SKDictionaryFormatter alloc] init];
+    [textWithIconCellFormatter setKey:SKTextWithIconStringKey];
+}
+
+- (void)commonInit {
+    if (imageCell == nil) {
+        imageCell = [[NSImageCell alloc] init];
+        [imageCell setImageScaling:NSImageScaleProportionallyUpOrDown];
+    }
+    if ([self formatter] == nil)
+        [self setFormatter:textWithIconCellFormatter];
+}
+
 - (id)initTextCell:(NSString *)aString {
     self = [super initTextCell:aString];
     if (self) {
-        imageCell = [[NSImageCell alloc] init];
-        [imageCell setImageScaling:NSImageScaleProportionallyUpOrDown];
+        [self commonInit];
     }
     return self;
 }
@@ -63,10 +80,7 @@
     self = [super initWithCoder:decoder];
     if (self) {
         imageCell = [[decoder decodeObjectForKey:@"imageCell"] retain];
-        if (imageCell == nil) {
-            imageCell = [[NSImageCell alloc] init];
-            [imageCell setImageScaling:NSImageScaleProportionallyUpOrDown];
-        }
+        [self commonInit];
     }
     return self;
 }
@@ -135,8 +149,8 @@
 
 - (void)setObjectValue:(id <NSCopying>)obj {
     [super setObjectValue:obj];
-    if ([[self formatter] respondsToSelector:@selector(imageForObjectValue:)])
-        [imageCell setImage:[[self formatter] imageForObjectValue:obj]];
+    if ([(id)obj respondsToSelector:@selector(objectForKey:)])
+        [imageCell setImage:[(id)obj objectForKey:SKTextWithIconImageKey]];
 }
 
 - (NSImage *)icon {
@@ -144,24 +158,3 @@
 }
 
 @end
-
-#pragma mark -
-
-@implementation SKTextWithIconFormatter
-
-- (NSImage *)imageForObjectValue:(id)obj {
-    return [obj isKindOfClass:[NSString class]] ? nil : [obj 
valueForKey:SKTextWithIconImageKey];
-}
-
-- (NSString *)stringForObjectValue:(id)obj {
-    return [obj isKindOfClass:[NSString class]] ? obj : [obj 
valueForKey:SKTextWithIconStringKey];
-}
-
-- (BOOL)getObjectValue:(id *)obj forString:(NSString *)string 
errorDescription:(NSString **)error {
-    // even though 'string' is reported as immutable, it's actually changed 
after this method returns and before it's returned by the control!
-    string = [[string copy] autorelease];
-    *obj = [NSDictionary dictionaryWithObjectsAndKeys:string, 
SKTextWithIconStringKey, nil];
-    return YES;
-}
-
-@end

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
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to