Revision: 26695
          http://sourceforge.net/p/bibdesk/svn/26695
Author:   hofman
Date:     2021-08-20 09:45:40 +0000 (Fri, 20 Aug 2021)
Log Message:
-----------
Hide column type enum in private for main table class. No need for custom 
dataCell in columns as we don't use it. Get width for special columns from a 
temporary view instead. Check type of column by checking the connections of the 
table cell view.

Modified Paths:
--------------
    trunk/bibdesk/BDSKMainTableView.h
    trunk/bibdesk/BDSKMainTableView.m
    trunk/bibdesk/BibDocument_DataSource.m

Modified: trunk/bibdesk/BDSKMainTableView.h
===================================================================
--- trunk/bibdesk/BDSKMainTableView.h   2021-08-20 06:31:00 UTC (rev 26694)
+++ trunk/bibdesk/BDSKMainTableView.h   2021-08-20 09:45:40 UTC (rev 26695)
@@ -52,11 +52,6 @@
 @end
 
 
-/*!
-    @class BDSKMainTableView
-    @abstract Drag n' Droppable Tableview
-    @discussion Subclass of NSTableview that allows drag n' drop.
-*/
 @interface BDSKMainTableView : BDSKTableView
 {
     NSArray *alternatingRowBackgroundColors;
@@ -76,6 +71,8 @@
 - (void)removeTableColumnWithIdentifier:(NSString *)identifier;
 - (void)updateTableColumnTypes;
 
+- (NSString *)identifierForTableColumn:(NSTableColumn *)tableColumn;
+
 @property (nonatomic, readonly) NSArray *tableColumnIdentifiers;
 - (void)scrollRowToCenter:(NSUInteger)row;
 
@@ -93,24 +90,6 @@
 @end
 
 
-typedef NS_ENUM(NSInteger, BDSKColumnType) {
-    BDSKColumnTypeText,
-    BDSKColumnTypeURL,
-    BDSKColumnTypeLinkedFile,
-    BDSKColumnTypeRating,
-    BDSKColumnTypeBoolean,
-    BDSKColumnTypeTriState,
-    BDSKColumnTypeCrossref,
-    BDSKColumnTypeImportOrder,
-    BDSKColumnTypeRelevance,
-    BDSKColumnTypeColor
-};
-
-@interface NSTableColumn (BDSKMainTableView)
-@property (nonatomic, readonly) BDSKColumnType columnType;
-@end
-
-
 @interface BDSKColorView : NSControl
 @end
 

Modified: trunk/bibdesk/BDSKMainTableView.m
===================================================================
--- trunk/bibdesk/BDSKMainTableView.m   2021-08-20 06:31:00 UTC (rev 26694)
+++ trunk/bibdesk/BDSKMainTableView.m   2021-08-20 09:45:40 UTC (rev 26695)
@@ -42,12 +42,9 @@
 #import "NSString_BDSKExtensions.h"
 #import "BDSKFieldSheetController.h"
 #import "BDSKTypeManager.h"
-#import "BDSKRatingButton.h"
-#import "BDSKRatingButtonCell.h"
 #import "NSBezierPath_BDSKExtensions.h"
 #import "BDSKLevelIndicatorCell.h"
 #import <QuartzCore/QuartzCore.h>
-#import "BDSKTextWithIconCell.h"
 #import "NSImage_BDSKExtensions.h"
 #import "NSParagraphStyle_BDSKExtensions.h"
 #import "NSMenu_BDSKExtensions.h"
@@ -56,6 +53,19 @@
 #import "NSGeometry_BDSKExtensions.h"
 
 
+typedef NS_ENUM(NSInteger, BDSKColumnType) {
+    BDSKColumnTypeText,
+    BDSKColumnTypeURL,
+    BDSKColumnTypeLinkedFile,
+    BDSKColumnTypeRating,
+    BDSKColumnTypeBoolean,
+    BDSKColumnTypeTriState,
+    BDSKColumnTypeCrossref,
+    BDSKColumnTypeImportOrder,
+    BDSKColumnTypeRelevance,
+    BDSKColumnTypeColor
+};
+
 @interface BDSKTableColumn : NSTableColumn {
     BDSKColumnType columnType;
 }
@@ -224,91 +234,34 @@
     return type;
 }
 
-- (NSCell *)newDataCellForColumnType:(NSInteger)columnType {
-    id cell = nil;
-    
-    switch(columnType) {
-        case BDSKColumnTypeURL:
-            cell = [[NSImageCell alloc] init];
-            [cell setImageScaling:NSImageScaleProportionallyUpOrDown];
-            break;
-        case BDSKColumnTypeLinkedFile:
-            cell = [[BDSKTextWithIconCell alloc] init];
-            [cell setLineBreakMode:NSLineBreakByClipping];
-            break;
-        case BDSKColumnTypeRating:
-            cell = [[BDSKRatingButtonCell alloc] initWithMaxRating:5];
-            [cell setBordered:NO];
-            [cell setAlignment:NSCenterTextAlignment];
-            [cell setEnabled:NO];
-            break;
-        case BDSKColumnTypeBoolean:
-            cell = [[NSButtonCell alloc] initTextCell:@""];
-            [cell setButtonType:NSSwitchButton];
-            [cell setImagePosition:NSImageOnly];
-            [cell setControlSize:NSSmallControlSize];
-            [cell setAllowsMixedState:NO];
-            [cell setEnabled:NO];
-            break;
-        case BDSKColumnTypeTriState:
-            cell = [[NSButtonCell alloc] initTextCell:@""];
-            [cell setButtonType:NSSwitchButton];
-            [cell setImagePosition:NSImageOnly];
-            [cell setControlSize:NSSmallControlSize];
-            [cell setAllowsMixedState:YES];
-            [cell setEnabled:NO];
-            break;
-        case BDSKColumnTypeCrossref: 
-            cell = [[NSButtonCell alloc] initTextCell:@""];
-            [cell setButtonType:NSMomentaryChangeButton];
-            [cell setBordered:NO];
-            [cell setImagePosition:NSImageOnly];
-            [cell setImageScaling:NSImageScaleProportionallyDown];
-            [cell setControlSize:NSSmallControlSize];
-            [cell setImage:[NSImage 
imageNamed:NSImageNameFollowLinkFreestandingTemplate]];
-            break;
-        case BDSKColumnTypeImportOrder:
-            cell = [[NSButtonCell alloc] 
initTextCell:NSLocalizedString(@"Import", @"button title")];
-            [cell setButtonType:NSMomentaryPushInButton];
-            [cell setBezelStyle:NSRoundRectBezelStyle];
-            [cell setImagePosition:NSNoImage];
-            [cell setControlSize:NSSmallControlSize];
-            break;
-        case BDSKColumnTypeRelevance: 
-            cell = [[BDSKLevelIndicatorCell alloc] 
initWithLevelIndicatorStyle:NSRelevancyLevelIndicatorStyle];
-            [cell setMaxValue:1.0];
-            [cell setEnabled:NO];
-            break;
-        case BDSKColumnTypeColor: 
-            cell = [[BDSKColorCell alloc] initImageCell:nil];
-            break;
-        case BDSKColumnTypeText:
-        default:
-            cell = [[NSTextFieldCell alloc] initTextCell:@""];
-            [cell setBordered:NO];
-            [cell setLineBreakMode:NSLineBreakByTruncatingTail];
-            break;
-    }
-    
-    if ([self fontNamePreferenceKey] && [self fontSizePreferenceKey] && [self 
font])
-        [cell setFont:[self font]];
-    
-    return cell;
+- (NSString *)identifierForTableColumn:(NSTableColumn *)tableColumn {
+    // these correspond to the identifiers of the table cell views in the NIB
+    static NSString *columnTypeIdentifiers[] = {
+        @"text",
+        @"url",
+        @"linkedFile",
+        @"rating",
+        @"boolean",
+        @"triState",
+        @"crossref",
+        @"importOrder",
+        @"relevance",
+        @"color"
+    };
+    BDSKColumnType columnType = [tableColumn 
respondsToSelector:@selector(columnType)] ? [(BDSKTableColumn *)tableColumn 
columnType] : BDSKColumnTypeText;
+    return columnTypeIdentifiers[columnType];
 }
 
 - (NSTableColumn *)newConfiguredTableColumnForField:(NSString *)identifier {
     BDSKTableColumn *tc = [[BDSKTableColumn alloc] 
initWithIdentifier:identifier];
     BDSKColumnType columnType = [self columnTypeForField:identifier];
-    NSCell *dataCell = [self newDataCellForColumnType:columnType];
     
     [tc setResizingMask:(NSTableColumnAutoresizingMask | 
NSTableColumnUserResizingMask)];
     [tc setEditable:NO];
     [tc setMinWidth:16.0];
     [tc setMaxWidth:1000.0];
-    [tc setDataCell:dataCell];
     [tc setColumnType:columnType];
-    [dataCell release];
-
+    
     NSTableHeaderCell *headerCell = [tc headerCell];
     NSImage *image;
     NSString *title;
@@ -320,9 +273,11 @@
     else
         [headerCell setStringValue:[[NSBundle mainBundle] 
localizedStringForKey:identifier value:@"" table:@"BibTeXKeys"]];
     
-    if (columnType != BDSKColumnTypeText && columnType != 
BDSKColumnTypeLinkedFile && columnType != BDSKColumnTypeRelevance)
-        [tc setWidth:fmax([dataCell cellSize].width, [headerCell 
cellSize].width)];
-    
+    if (columnType != BDSKColumnTypeText && columnType != 
BDSKColumnTypeLinkedFile && columnType != BDSKColumnTypeRelevance) {
+        NSView *view = [self makeViewWithIdentifier:[self 
identifierForTableColumn:tc] owner:nil];
+        [tc setWidth:fmax([view fittingSize].width, [headerCell 
cellSize].width)];
+    }
+
     return tc;
 }
 
@@ -355,10 +310,7 @@
     for (BDSKTableColumn *tc in [self tableColumns]) {
         BDSKColumnType columnType = [self columnTypeForField:[tc identifier]];
         if ([tc columnType] != columnType) {
-            NSCell *dataCell = [self newDataCellForColumnType:columnType];
-            [tc setDataCell:dataCell];
             [tc setColumnType:columnType];
-            [dataCell release];
             [columnIndexes addIndex:column];
         }
         column++;
@@ -714,12 +666,6 @@
 
 #pragma mark -
 
-@implementation NSTableColumn (BDSKMainTableView)
-
-- (BDSKColumnType)columnType { return BDSKColumnTypeText; }
-
-@end
-
 @implementation BDSKTableColumn
 
 @synthesize columnType;

Modified: trunk/bibdesk/BibDocument_DataSource.m
===================================================================
--- trunk/bibdesk/BibDocument_DataSource.m      2021-08-20 06:31:00 UTC (rev 
26694)
+++ trunk/bibdesk/BibDocument_DataSource.m      2021-08-20 09:45:40 UTC (rev 
26695)
@@ -109,49 +109,18 @@
 
 #pragma mark TableView delegate
 
-// these correspond to the identifiers of the table cell views in the NIB
-static NSString *columnTypeIdentifiers[] = {
-    @"text",
-    @"url",
-    @"linkedFile",
-    @"rating",
-    @"boolean",
-    @"triState",
-    @"crossref",
-    @"importOrder",
-    @"relevance",
-    @"color"
-};
-
 - (NSView *)tableView:(NSTableView *)tv viewForTableColumn:(NSTableColumn 
*)tableColumn row:(NSInteger)row {
     NSString *tcID = [tableColumn identifier];
     if (tv == tableView) {
-        BDSKColumnType columnType = [tableColumn columnType];
-        id view = [tableView 
makeViewWithIdentifier:columnTypeIdentifiers[columnType] owner:self];
+        NSString *identifier = [tableView 
identifierForTableColumn:tableColumn];
+        NSTableCellView *view = [tableView makeViewWithIdentifier:identifier 
owner:self];
         BibItem *pub = [[self shownPublications] objectAtIndex:row];
         id value = [pub displayValueOfField:tcID];
-        if (columnType == BDSKColumnTypeText) {
-            NSTextField *textField = [view textField];
-            // possibly reset red color from invalid cite key, can be reused 
for any text field
-            if ([tcID isEqualToString:BDSKCiteKeyString] && [pub 
isValidCiteKey:[pub citeKey]] == NO)
-                [textField setTextColor:[NSColor systemRedColor]];
-            else
-                [textField setTextColor:[NSColor controlTextColor]];
-            [textField setObjectValue:value];
-        } else if (columnType == BDSKColumnTypeURL) {
-            NSImageView *imageView = [view imageView];
-            NSURL *url = [pub URLForField:tcID];
-            [imageView setToolTip:[url isFileURL] ? [[url path] 
stringByAbbreviatingWithTildeInPath] : [url absoluteString]];
-            [imageView setObjectValue:value];
-        } else if (columnType == BDSKColumnTypeLinkedFile) {
-            if ([tcID isEqualToString:BDSKLocalFileString])
-                [view setToolTip:[[pub existingLocalFiles] 
valueForKeyPath:@"path.stringByAbbreviatingWithTildeInPath.@componentsJoinedByComma"]];
-            else if ([tcID isEqualToString:BDSKRemoteURLString])
-                [view setToolTip:[[pub remoteURLs] 
valueForKeyPath:@"URL.absoluteString.@componentsJoinedByComma"]];
-            [[view textField] setObjectValue:[value valueForKey:@"string"]];
-            [[view imageView] setObjectValue:[value valueForKey:@"image"]];
-        } else {
-            NSControl *control = [view control];
+        NSTextField *textField = [view textField];
+        NSImageView *imageView = [view imageView];
+        if (textField == nil && imageView == nil) {
+            // special field types displayed using a button or level indicator
+            NSControl *control = [(BDSKControlTableCellView *)view control];
             if ([tcID isEqualToString:BDSKImportOrderString]) {
                 if ([pub isImported]) {
                     [control setEnabled:NO];
@@ -172,6 +141,27 @@
                 [control setEnabled:[self 
hasGroupTypeSelected:BDSKExternalGroupType] == NO];
             }
             [control setObjectValue:value];
+        } else if (imageView == nil) {
+            // generic text field
+            // possibly reset red color from invalid cite key, can be reused 
for any text field
+            if ([tcID isEqualToString:BDSKCiteKeyString] && [pub 
isValidCiteKey:[pub citeKey]] == NO)
+                [textField setTextColor:[NSColor systemRedColor]];
+            else
+                [textField setTextColor:[NSColor controlTextColor]];
+            [textField setObjectValue:value];
+        } else if (textField == nil) {
+            // URL field
+            NSURL *url = [pub URLForField:tcID];
+            [imageView setToolTip:[url isFileURL] ? [[url path] 
stringByAbbreviatingWithTildeInPath] : [url absoluteString]];
+            [imageView setObjectValue:value];
+        } else {
+            // linked files and URLs
+            if ([tcID isEqualToString:BDSKLocalFileString])
+                [view setToolTip:[[pub existingLocalFiles] 
valueForKeyPath:@"path.stringByAbbreviatingWithTildeInPath.@componentsJoinedByComma"]];
+            else if ([tcID isEqualToString:BDSKRemoteURLString])
+                [view setToolTip:[[pub remoteURLs] 
valueForKeyPath:@"URL.absoluteString.@componentsJoinedByComma"]];
+            [textField setObjectValue:[value valueForKey:@"string"]];
+            [imageView setObjectValue:[value valueForKey:@"image"]];
         }
         return view;
     } else {

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
Bibdesk-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to