From 9297088ae768070bfe59ce0080c0a7cea60d95e9 Mon Sep 17 00:00:00 2001 From: Uli Kusterer Date: Sun, 28 Oct 2018 13:22:09 +0100 Subject: [PATCH] WIP moving from IKImageBrowserViews to NSCollectionViews. --- .../Platforms/Mac/WILDMediaListDataSource.h | 7 +- .../Platforms/Mac/WILDMediaListDataSource.mm | 44 ++++++---- .../Mac/WILDStackCanvasWindowController.mm | 7 +- .../Mac/WILDTemplateProjectPickerController.h | 7 +- .../Mac/WILDTemplateProjectPickerController.m | 64 +++++--------- .../WILDTemplateProjectPickerController.xib | 82 ++++++++++++------ ...ILDTemplateProjectPickerController.xib.zip | Bin 0 -> 2978 bytes 7 files changed, 112 insertions(+), 99 deletions(-) create mode 100644 Stacksmith/Platforms/Mac/WILDTemplateProjectPickerController.xib.zip diff --git a/Stacksmith/Platforms/Mac/WILDMediaListDataSource.h b/Stacksmith/Platforms/Mac/WILDMediaListDataSource.h index ace53ab6..1285438d 100644 --- a/Stacksmith/Platforms/Mac/WILDMediaListDataSource.h +++ b/Stacksmith/Platforms/Mac/WILDMediaListDataSource.h @@ -17,7 +17,6 @@ namespace Carlson }; -@class IKImageBrowserView; @class WILDMediaListDataSource; @@ -29,18 +28,18 @@ namespace Carlson @end -@interface WILDMediaListDataSource : NSObject +@interface WILDMediaListDataSource : NSObject { Carlson::CDocument* mDocument; // This is who we get the icons from. NSMutableArray* mIcons; // Cached lists of icon names/IDs. - IKImageBrowserView* mIconListView; // View in which we show the icons. + NSCollectionView* mIconListView; // View in which we show the icons. NSTextField* mImagePathField; // Field where we show where the icon comes from. id mDelegate; Carlson::TMediaType mMediaType; // Type of media to display, i.e. icons, cursors etc. } @property (assign,nonatomic) Carlson::CDocument* document; -@property (retain,nonatomic) IBOutlet IKImageBrowserView* iconListView; +@property (retain,nonatomic) IBOutlet NSCollectionView* iconListView; @property (retain,nonatomic) IBOutlet NSTextField* imagePathField; @property (assign,nonatomic) id delegate; @property (assign,nonatomic) Carlson::TMediaType mediaType; diff --git a/Stacksmith/Platforms/Mac/WILDMediaListDataSource.mm b/Stacksmith/Platforms/Mac/WILDMediaListDataSource.mm index 5418158c..64c33a2b 100644 --- a/Stacksmith/Platforms/Mac/WILDMediaListDataSource.mm +++ b/Stacksmith/Platforms/Mac/WILDMediaListDataSource.mm @@ -16,7 +16,7 @@ using namespace Carlson; -@interface WILDSimpleImageBrowserItem : NSObject // IKImageBrowserItem +@interface WILDSimpleImageBrowserItem : NSObject { NSString* mName; NSString* mFileName; @@ -142,7 +142,7 @@ -(void) dealloc } --(void) setIconListView: (IKImageBrowserView*)inIconListView +-(void) setIconListView: (NSCollectionView *)inIconListView { if( mIconListView != inIconListView ) { @@ -216,8 +216,7 @@ -(void) setSelectedIconID: (ObjectID)theID { if( sibi.pictureID == theID ) { - [mIconListView setSelectionIndexes: [NSIndexSet indexSetWithIndex: x] byExtendingSelection: NO]; - [mIconListView scrollIndexToVisible: x]; + [mIconListView selectItemsAtIndexPaths: [NSIndexPath indexPathWithIndexes: x] scrollPosition: NSCollectionViewScrollPositionCenteredVertically]; break; } x++; @@ -232,7 +231,7 @@ -(ObjectID) selectedIconID } --(NSUInteger) numberOfItemsInImageBrowser: (IKImageBrowserView *)aBrowser +-(NSInteger) collectionView: (NSCollectionView *)collectionView numberOfItemsInSection: (NSInteger)section { [self ensureIconListExists]; @@ -240,15 +239,25 @@ -(NSUInteger) numberOfItemsInImageBrowser: (IKImageBrowserView *)aBrowser } --(id /*IKImageBrowserItem*/) imageBrowser: (IKImageBrowserView *) aBrowser itemAtIndex: (NSUInteger)idx +- (NSCollectionViewItem *)collectionView:(NSCollectionView *)collectionView itemForRepresentedObjectAtIndexPath:(NSIndexPath *)indexPath { - [self ensureIconListExists]; - - return [mIcons objectAtIndex: idx]; + [mIcons objectAtIndex: [indexPath indexAtPosition: 1]]; +} + + +-(void) collectionView: (NSCollectionView *)collectionView didSelectItemsAtIndexPaths: (NSSet *)indexPaths +{ + [self selectionDidChange]; +} + + +-(void) collectionView: (NSCollectionView *)collectionView didDeselectItemsAtIndexPaths: (NSSet *)indexPaths +{ + [self selectionDidChange]; } --(void) imageBrowserSelectionDidChange: (IKImageBrowserView *)aBrowser +-(void) selectionDidChange { NSInteger selectedIndex = [[mIconListView selectionIndexes] firstIndex]; if( selectedIndex != NSNotFound ) @@ -283,9 +292,8 @@ -(IBAction) paste: (id)sender NSString* imgFileURLStr = [NSString stringWithUTF8String: filePath.c_str()]; NSURL* imgFileURL = [NSURL URLWithString: imgFileURLStr]; - [theImg lockFocus]; - NSBitmapImageRep * bir = [[NSBitmapImageRep alloc] initWithFocusedViewRect: NSMakeRect(0,0,theImg.size.width,theImg.size.height)]; - [theImg unlockFocus]; + CGImageRef imageRef = [theImg CGImageForProposedRect:NULL context:NULL hints:nil]; + NSBitmapImageRep *bir = [[NSBitmapImageRep alloc] initWithCGImage: imageRef]; NSData * pngData = [bir representationUsingType: NSBitmapImageFileTypePNG properties: @{}]; [pngData writeToURL: imgFileURL atomically: YES]; @@ -348,9 +356,8 @@ - (BOOL)performDragOperation: (id )sender NSString* imgFileURLStr = [NSString stringWithUTF8String: filePath.c_str()]; NSURL* imgFileURL = [NSURL URLWithString: imgFileURLStr]; - [theImg lockFocus]; - NSBitmapImageRep * bir = [[NSBitmapImageRep alloc] initWithFocusedViewRect: NSMakeRect(0,0,theImg.size.width,theImg.size.height)]; - [theImg unlockFocus]; + CGImageRef imageRef = [theImg CGImageForProposedRect:NULL context:NULL hints:nil]; + NSBitmapImageRep *bir = [[NSBitmapImageRep alloc] initWithCGImage: imageRef]; NSData * pngData = [bir representationUsingType: NSBitmapImageFileTypePNG properties: @{}]; [pngData writeToURL: imgFileURL atomically: YES]; @@ -376,9 +383,8 @@ - (BOOL)performDragOperation: (id )sender NSString* imgFileURLStr = [NSString stringWithUTF8String: filePath.c_str()]; NSURL* imgFileURL = [NSURL URLWithString: imgFileURLStr]; - [theImg lockFocus]; - NSBitmapImageRep * bir = [[NSBitmapImageRep alloc] initWithFocusedViewRect: NSMakeRect(0,0,theImg.size.width,theImg.size.height)]; - [theImg unlockFocus]; + CGImageRef imageRef = [theImg CGImageForProposedRect:NULL context:NULL hints:nil]; + NSBitmapImageRep *bir = [[NSBitmapImageRep alloc] initWithCGImage: imageRef]; NSData * pngData = [bir representationUsingType: NSBitmapImageFileTypePNG properties: @{}]; [pngData writeToURL: imgFileURL atomically: YES]; diff --git a/Stacksmith/Platforms/Mac/WILDStackCanvasWindowController.mm b/Stacksmith/Platforms/Mac/WILDStackCanvasWindowController.mm index c43be36b..a312743e 100644 --- a/Stacksmith/Platforms/Mac/WILDStackCanvasWindowController.mm +++ b/Stacksmith/Platforms/Mac/WILDStackCanvasWindowController.mm @@ -79,7 +79,7 @@ -(void) windowDidLoad [self reloadData]; - [self.stackCanvasView registerForDraggedTypes: [NSImage.imageTypes arrayByAddingObjectsFromArray: @[ NSFilenamesPboardType ]]]; + [self.stackCanvasView registerForDraggedTypes: [NSImage.imageTypes arrayByAddingObjectsFromArray: @[ (NSString *)kUTTypeFileURL ]]]; } @@ -447,9 +447,8 @@ -(void) addImages: (NSArray*)images NSString* imgFileURLStr = [NSString stringWithUTF8String: filePath.c_str()]; NSURL* imgFileURL = [NSURL URLWithString: imgFileURLStr]; - [theImg lockFocus]; - NSBitmapImageRep * bir = [[[NSBitmapImageRep alloc] initWithFocusedViewRect: NSMakeRect(0,0,theImg.size.width,theImg.size.height)] autorelease]; - [theImg unlockFocus]; + CGImageRef imageRef = [theImg CGImageForProposedRect:NULL context:NULL hints:nil]; + NSBitmapImageRep *bir = [[NSBitmapImageRep alloc] initWithCGImage: imageRef]; NSData * pngData = [bir representationUsingType: NSBitmapImageFileTypePNG properties: @{}]; [pngData writeToURL: imgFileURL atomically: YES]; newIcon.mMediaID = pictureID; diff --git a/Stacksmith/Platforms/Mac/WILDTemplateProjectPickerController.h b/Stacksmith/Platforms/Mac/WILDTemplateProjectPickerController.h index 2039c970..8ee3f63d 100644 --- a/Stacksmith/Platforms/Mac/WILDTemplateProjectPickerController.h +++ b/Stacksmith/Platforms/Mac/WILDTemplateProjectPickerController.h @@ -9,16 +9,13 @@ #import -@class IKImageBrowserView; - - -@interface WILDTemplateProjectPickerController : NSWindowController +@interface WILDTemplateProjectPickerController : NSWindowController { NSMutableArray * groups; NSMutableArray * items; } -@property (assign,nonatomic) IBOutlet IKImageBrowserView* iconListView; +@property (assign,nonatomic) IBOutlet NSCollectionView* iconListView; @property (copy,nonatomic) void (^callbackHandler)( NSString* inPickedFilePath ); -(IBAction) doOK: (id)sender; diff --git a/Stacksmith/Platforms/Mac/WILDTemplateProjectPickerController.m b/Stacksmith/Platforms/Mac/WILDTemplateProjectPickerController.m index 06a05985..f45e7019 100644 --- a/Stacksmith/Platforms/Mac/WILDTemplateProjectPickerController.m +++ b/Stacksmith/Platforms/Mac/WILDTemplateProjectPickerController.m @@ -11,11 +11,7 @@ #import "UKHelperMacros.h" -@interface WILDTemplateProjectPickerController () - -@end - -@interface WILDSimpleTemplateProjectBrowserItem : NSObject // IKImageBrowserItem +@interface WILDSimpleTemplateProjectBrowserItem : NSObject { NSImage* mImage; NSString* mName; @@ -114,32 +110,28 @@ -(void) ensureItemsListExists [[NSApplication sharedApplication] presentError: err]; } - NSInteger groupCount = 0; - NSInteger itemCount = 0; - for( NSString* currSubfolderSubPath in subfolderpaths ) { NSString * currSubfolderPath = [templatesPath stringByAppendingPathComponent: currSubfolderSubPath]; NSArray* subpaths = [[NSFileManager defaultManager] contentsOfDirectoryAtPath: currSubfolderPath error: &err]; - NSUInteger startItemCount = itemCount; + if( !subpaths ) + { + continue; + } + + NSMutableArray *groupContents = [NSMutableArray new]; + + [groups addObject: @{ @"name": currSubfolderSubPath, @"contents": groupContents } ]; + for( NSString* currSubPath in subpaths ) { NSString * currPath = [currSubfolderPath stringByAppendingPathComponent: currSubPath]; WILDSimpleTemplateProjectBrowserItem * tbi = [[[WILDSimpleTemplateProjectBrowserItem alloc] init] autorelease]; tbi.filename = currPath; tbi.name = [[currPath lastPathComponent] stringByDeletingPathExtension]; - [items addObject: tbi]; - - itemCount++; - } - - if( subpaths ) - { - groupCount++; - - [groups addObject: @{ IKImageBrowserGroupRangeKey: [NSValue valueWithRange: (NSRange){ startItemCount, itemCount -startItemCount }], IKImageBrowserGroupTitleKey: currSubfolderSubPath, IKImageBrowserGroupStyleKey: @(IKGroupDisclosureStyle) } ]; + [groupContents addObject: tbi]; } } } @@ -156,45 +148,35 @@ -(void) windowDidLoad } --(NSUInteger) numberOfItemsInImageBrowser: (IKImageBrowserView *)aBrowser +- (NSInteger)collectionView:(NSCollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { [self ensureItemsListExists]; - return [items count]; + NSDictionary *group = groups[ section ]; + return [(NSArray *)group[@"contents"] count]; } --(id /*IKImageBrowserItem*/) imageBrowser: (IKImageBrowserView *) aBrowser itemAtIndex: (NSUInteger)idx +- (NSCollectionViewItem *)collectionView:(NSCollectionView *)collectionView itemForRepresentedObjectAtIndexPath:(NSIndexPath *)indexPath { [self ensureItemsListExists]; - return [items objectAtIndex: idx]; + NSDictionary *group = groups[ [indexPath indexAtPosition:0] ]; + + NSCollectionViewItem *theItem = [collectionView makeItemWithIdentifier: @"StandardItem" forIndexPath: indexPath]; + + theItem.representedObject = group[@"contents"][ [indexPath indexAtPosition: 1] ]; + + return theItem; } -- (NSUInteger) numberOfGroupsInImageBrowser:(IKImageBrowserView *) aBrowser +- (NSInteger)numberOfSectionsInCollectionView:(NSCollectionView *)collectionView { return groups.count; } -/*! - @method imageBrowser:groupAtIndex: - @abstract Returns the group at index 'index' - @discussion A group is defined by a dictionay. Keys for this dictionary are defined below. -*/ -- (NSDictionary *) imageBrowser:(IKImageBrowserView *) aBrowser groupAtIndex:(NSUInteger) index -{ - return groups[index]; -} - - --(void) imageBrowserSelectionDidChange: (IKImageBrowserView *)aBrowser -{ - -} - - -(IBAction) doOK: (id)sender { [self close]; diff --git a/Stacksmith/Platforms/Mac/WILDTemplateProjectPickerController.xib b/Stacksmith/Platforms/Mac/WILDTemplateProjectPickerController.xib index dcf54635..73787593 100644 --- a/Stacksmith/Platforms/Mac/WILDTemplateProjectPickerController.xib +++ b/Stacksmith/Platforms/Mac/WILDTemplateProjectPickerController.xib @@ -1,20 +1,18 @@ - - + + - - - + + - - + @@ -51,33 +49,31 @@ Gw - - - - - + + + + + - - - - - - + + + + + + + - - - + - - - + - - + @@ -87,5 +83,39 @@ Gw + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Stacksmith/Platforms/Mac/WILDTemplateProjectPickerController.xib.zip b/Stacksmith/Platforms/Mac/WILDTemplateProjectPickerController.xib.zip new file mode 100644 index 0000000000000000000000000000000000000000..3875b701660060019d283509985e6ac9f75e62d6 GIT binary patch literal 2978 zcmbW3XH*kd8iqp;O#}q#MPXo&E<`~>RR&T>Gz5^)W2A#50!oo$U=W8Wp*M*d5Rf_q zfk+rYG$JTPAV?=J0YPaJP(fXsJv-y<**#}>?|1Gw_s@6ld*AQ<@gSjm{09KQy_)p( zfCIi;T7dlkS4Y@MXI$uo5Z{Y9BtAR{hrNgl#0KN=cHvwNK5|JWHaa~f21?%k`l9dK=7$sp%Xdz1FN)z znj#BHlJ94FMyn_}43#hvc4G5J!^2TCg_8Q(qT>$;9uM@STKevGwuF9Nzm!tA6<$hm zS0UW}QJAWEP(5%$zewe^;bu?7v75vj_0SiGmtu*oHw^N7*VYN!lU{>0I&`v;w}oC^ z6}n`p;UzJ$k9pGaWD*rciN8Lz)7hww#i;wM&*39D^pk0#vJNkHA1K!+j+K&hKd?3& z9C#&K%1`ENGL$|IwkWzCh|*9#-F1Bo#Ny6LDo{Uo8J~qnMn$CkJbVxDE8rGUoOoC_ z$-lcXz^6yJ;TDg*pJ|QcYm{ziFytyzj2~{T`NO16C}hy@(Q0>2V8Nt=1Bk&|Ry#Xk zFEf$OKL@tZ0QAamdlHC|RuaHwJ;J9hrY-GV-IUitCd^J1Igy@=Y*S(8Jl-g28d z7lyR~FcV!fr;H{~4Qb&kDG$K+l9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