Add 10.12 imageViewWithImage to NSImageView, show outline view image to let the user know the item is expandable

This commit is contained in:
Gregory John Casamento 2024-04-21 09:49:37 -04:00
parent 9da7bd4502
commit 5d17658b0e
4 changed files with 21 additions and 3 deletions

View file

@ -64,6 +64,9 @@ APPKIT_EXPORT_CLASS
- (BOOL)allowsCutCopyPaste;
- (void)setAllowsCutCopyPaste:(BOOL)flag;
#endif
#if OS_API_VERSION(MAC_OS_X_VERSION_10_12, GS_API_LATEST)
+ (instancetype) imageViewWithImage: (NSImage *)image;
#endif
@end

View file

@ -3650,7 +3650,6 @@ static NSDictionary *titleTextAttributes[3] = {nil, nil, nil};
NSInteger numberOfColumns = [v numberOfColumns];
CGFloat *columnOrigins = [v _columnOrigins];
NSArray *tableColumns = [v tableColumns];
CGFloat indentationPerLevel = 0.0;
NSInteger numberOfRows = [v numberOfRows];
NSInteger startingColumn;
NSInteger endingColumn;
@ -3677,7 +3676,7 @@ static NSDictionary *titleTextAttributes[3] = {nil, nil, nil};
if ([v isKindOfClass: [NSOutlineView class]])
{
outlineTableColumn = [v outlineTableColumn];
hasMethod = [delegate respondsToSelector: @selector(outlineView:viewForTableColumn:row:)];
hasMethod = [delegate respondsToSelector: @selector(outlineView:viewForTableColumn:item:)];
}
else if ([v isKindOfClass: [NSTableView class]])
{
@ -3722,6 +3721,7 @@ static NSDictionary *titleTextAttributes[3] = {nil, nil, nil};
if ([v isKindOfClass: [NSOutlineView class]])
{
id item = [v itemAtRow: rowIndex];
CGFloat indentationPerLevel = [v indentationPerLevel];
if (tb == outlineTableColumn)
{
@ -3749,6 +3749,7 @@ static NSDictionary *titleTextAttributes[3] = {nil, nil, nil};
level = [v levelForItem: item];
indentationFactor = indentationPerLevel * level;
imageView = [[NSImageView alloc] init];
[imageView setImage: image];
imageRect = [v frameOfOutlineCellAtRow: rowIndex];
/* Do not indent if the delegate set the image to nil. */

View file

@ -69,6 +69,18 @@ static Class imageCellClass;
usedCellClass = factoryId ? factoryId : imageCellClass;
}
+ (instancetype) imageViewWithImage: (NSImage *)image
{
NSImageView *imageView = AUTORELEASE([[NSImageView alloc] init]);
[imageView setImage: image];
return imageView;
}
//
// Instance methods
//
- (id) initWithFrame: (NSRect)aFrame
{

View file

@ -689,7 +689,9 @@ static NSImage *unexpandable = nil;
CHECK_REQUIRED_METHOD(outlineView:child:ofItem:);
CHECK_REQUIRED_METHOD(outlineView:isItemExpandable:);
CHECK_REQUIRED_METHOD(outlineView:numberOfChildrenOfItem:);
CHECK_REQUIRED_METHOD(outlineView:objectValueForTableColumn:byItem:);
// This method is @optional in NSOutlineViewDataSource as of macOS10.0
// CHECK_REQUIRED_METHOD(outlineView:objectValueForTableColumn:byItem:);
// Is the data source editable?
_dataSource_editable = [anObject respondsToSelector: