Permalink
Browse files

Migrated changes in from another project.

  • Loading branch information...
joshaber committed Jan 5, 2011
1 parent 99faf0f commit 52322a72e0045dedb1a3080f61999bc06f014ac1
Showing with 140 additions and 90 deletions.
  1. +2 −10 JAListView.h
  2. +14 −64 JAListView.m
  3. +8 −5 JAObjectListView.h
  4. +80 −11 JAObjectListView.m
  5. +17 −0 JAObjectListViewItem.h
  6. +19 −0 JAObjectListViewItem.m
View
@@ -85,6 +85,8 @@ extern NSString * const JAListViewDraggingPasteboardType;
- (NSInteger)indexForView:(JAListViewItem *)view;
- (BOOL)isViewVisible:(JAListViewItem *)view;
+- (BOOL)containsViewItem:(JAListViewItem *)viewItem;
+
- (JAListViewItem *)viewAtPoint:(NSPoint)point;
/*
@@ -97,16 +99,6 @@ extern NSString * const JAListViewDraggingPasteboardType;
*/
- (CGFloat)heightForView:(JAListViewItem *)view proposedHeight:(CGFloat)proposedHeight;
-- (void)setView:(JAListViewItem *)view forKey:(id)key;
-- (id)viewForKey:(id)key;
-- (void)removeViewForKey:(id)key;
-- (id)keyForView:(JAListViewItem *)view;
-
-- (void)setView:(JAListViewItem *)view forObject:(id)object;
-- (id)viewForObject:(id)object;
-- (void)removeViewForObject:(id)object;
-- (void)removeAllStoredViews;
-
- (CGFloat)cachedYLocationForView:(JAListViewItem *)view;
/**
View
@@ -26,7 +26,6 @@ - (void)showVisibleViewsAnimated:(BOOL)animated;
- (void)updateCachedVisibleViews;
- (void)clearCachedLocations;
- (void)seriouslyShowVisibleViewsWithAnimation;
-- (id)keyForObject:(id)object;
- (void)getSelectionMinimumIndex:(NSUInteger *)minIndex maximumIndex:(NSUInteger *)maxIndex;
- (JAListViewItem *)nextSelectableView;
- (JAListViewItem *)nextSelectableViewFromIndex:(NSUInteger)startingIndex;
@@ -40,7 +39,6 @@ - (void)standardLayoutAnimated:(BOOL)animated removeViews:(NSArray *)viewsToRemo
@property (nonatomic, retain) NSArray *cachedVisibleViews;
@property (nonatomic, assign) __weak JAListViewItem *viewBeingSelected;
@property (nonatomic, retain) NSArray *viewsCurrentlyBeingDragged;
-@property (nonatomic, retain) NSMutableDictionary *viewStorage;
@property (nonatomic, retain) NSMutableArray *currentlySelectedViews;
@property (nonatomic, retain) NSTrackingArea *currentTrackingArea;
@property (nonatomic, copy) void (^currentAnimationBlock)(NSView *newSuperview, NSArray *viewsToAdd, NSArray *viewsToRemove, NSArray *viewsToMove);
@@ -67,7 +65,6 @@ - (void)dealloc {
self.viewBeingUsedForInertialScroll = nil;
self.backgroundColor = nil;
self.cachedVisibleViews = nil;
- self.viewStorage = nil;
self.currentlySelectedViews = nil;
self.currentTrackingArea = nil;
self.currentAnimationBlock = nil;
@@ -194,13 +191,13 @@ - (void)mouseUp:(NSEvent *)event {
self.viewBeingSelected.highlighted = NO;
self.viewBeingSelected = nil;
} else {
- for(JAListViewItem *selectedView in [[self.currentlySelectedViews copy] autorelease]) {
- [[selectedView retain] autorelease];
- selectedView.selected = NO;
- [self.currentlySelectedViews removeObject:selectedView];
+ for(JAListViewItem *itemView in [[self.currentlySelectedViews copy] autorelease]) {
+ [[itemView retain] autorelease];
+ itemView.selected = NO;
+ [self.currentlySelectedViews removeObject:itemView];
if(respondsToUnSelect) {
- [self.delegate listView:self didDeselectView:selectedView];
+ [self.delegate listView:self didDeselectView:itemView];
}
}
}
@@ -278,13 +275,13 @@ - (void)mouseUp:(NSEvent *)event {
[self.delegate listView:self didSelectView:view];
}
} else {
- for(JAListViewItem *selectedView in [[self.currentlySelectedViews copy] autorelease]) {
- [[selectedView retain] autorelease];
- selectedView.selected = NO;
- [self.currentlySelectedViews removeObject:selectedView];
+ for(JAListViewItem *itemView in [[self.currentlySelectedViews copy] autorelease]) {
+ [[itemView retain] autorelease];
+ itemView.selected = NO;
+ [self.currentlySelectedViews removeObject:itemView];
if(respondsToUnSelect) {
- [self.delegate listView:self didDeselectView:selectedView];
+ [self.delegate listView:self didDeselectView:itemView];
}
}
@@ -513,7 +510,6 @@ - (void)setup {
margin = NSZeroPoint;
self.backgroundColor = [NSColor darkGrayColor];
[self registerForDraggedTypes:[NSArray arrayWithObject:JAListViewDraggingPasteboardType]];
- self.viewStorage = [NSMutableDictionary dictionary];
self.currentlySelectedViews = [NSMutableArray array];
}
@@ -801,6 +797,10 @@ - (BOOL)isViewVisible:(JAListViewItem *)view {
return [self.visibleViews containsObject:view];
}
+- (BOOL)containsViewItem:(JAListViewItem *)viewItem {
+ return [self.cachedViews containsObject:viewItem];
+}
+
- (NSArray *)visibleViews {
return self.cachedVisibleViews;
}
@@ -820,55 +820,6 @@ - (void)updateCachedVisibleViews {
self.cachedVisibleViews = newVisibleViews;
}
-- (void)setView:(JAListViewItem *)view forKey:(id)key {
- [self.viewStorage setObject:view forKey:key];
-}
-
-- (id)viewForKey:(id)key {
- return [self.viewStorage objectForKey:key];
-}
-
-- (void)removeViewForKey:(id)key {
- [self.viewStorage removeObjectForKey:key];
-}
-
-- (id)keyForView:(JAListViewItem *)view {
- for(id key in self.viewStorage) {
- if([[self.viewStorage objectForKey:key] isEqualTo:view]) {
- return key;
- }
- }
-
- return nil;
-}
-
-- (void)setView:(JAListViewItem *)view forObject:(id)object {
- [self setView:view forKey:[self keyForObject:object]];
-}
-
-- (id)viewForObject:(id)object {
- return [self viewForKey:[self keyForObject:object]];
-}
-
-- (void)removeViewForObject:(id)object {
- [self removeViewForKey:[self keyForObject:object]];
-}
-
-- (void)removeAllStoredViews {
- [self.viewStorage removeAllObjects];
-}
-
-- (id)keyForObject:(id)object {
- // keys are copied when put into a dictionary, so if they object isn't copyable then we need to just use its pointer address as the key
- if([object conformsToProtocol:@protocol(NSCopying)]) {
- return object;
- } else if([object respondsToSelector:@selector(hash)]) {
- return [NSNumber numberWithUnsignedInteger:[object hash]];
- } else {
- return [NSString stringWithFormat:@"%p", object];
- }
-}
-
- (NSScrollView *)scrollView {
return [self enclosingScrollView];
}
@@ -1037,7 +988,6 @@ - (void)deselectAllViews {
@synthesize backgroundColor;
@synthesize heightForAllContent;
@synthesize conditionallyUseLayerBacking;
-@synthesize viewStorage;
@synthesize currentlySelectedViews;
@synthesize currentTrackingArea;
@synthesize currentAnimationBlock;
View
@@ -9,21 +9,24 @@
#import <Cocoa/Cocoa.h>
#import "JASectionedListView.h"
-@class JAListViewItem;
+@class JAObjectListViewItem;
@interface JAObjectListView : JASectionedListView <JASectionedListViewDataSource> {}
-- (void)addListViewItem:(JAListViewItem *)view inSection:(NSUInteger)section atIndex:(NSUInteger)index;
-- (void)addListViewItem:(JAListViewItem *)view inSection:(NSUInteger)section;
+- (void)addListViewItem:(JAObjectListViewItem *)view inSection:(NSUInteger)section atIndex:(NSUInteger)index;
+- (void)addListViewItem:(JAObjectListViewItem *)view inSection:(NSUInteger)section;
- (void)removeListViewItemInSection:(NSUInteger)section atIndex:(NSUInteger)index;
-- (void)addListViewItem:(JAListViewItem *)view forHeaderForSection:(NSUInteger)section;
+- (void)addListViewItem:(JAObjectListViewItem *)view forHeaderForSection:(NSUInteger)section;
- (void)removeListViewItemForHeaderForSection:(NSUInteger)section;
-- (void)removeListViewItem:(JAListViewItem *)view;
+- (void)removeListViewItem:(JAObjectListViewItem *)view;
- (void)removeAllListViewItems;
- (NSArray *)viewsInSection:(NSUInteger)section;
- (NSUInteger)numberOfSections;
+- (JAObjectListViewItem *)viewItemForObject:(id)object;
+- (NSIndexPath *)indexPathForObject:(id)object;
+
@end
View
@@ -7,9 +7,14 @@
//
#import "JAObjectListView.h"
+#import "JAObjectListViewItem.h"
+
+@interface JAListView (Private)
+- (NSArray *)cachedViews;
+@end
@interface JAObjectListView ()
-- (void)reallyAddListViewItem:(JAListViewItem *)view inSection:(NSUInteger)section atIndex:(NSUInteger)index;
+- (void)reallyAddListViewItem:(JAObjectListViewItem *)view inSection:(NSUInteger)section atIndex:(NSUInteger)index;
@property (nonatomic, retain) NSMutableArray *sectionRowViews;
@end
@@ -66,60 +71,89 @@ - (JAListViewItem *)listView:(JAListView *)listView viewForSection:(NSUInteger)s
@synthesize sectionRowViews;
-- (void)addListViewItem:(JAListViewItem *)view inSection:(NSUInteger)section atIndex:(NSUInteger)index {
+- (void)addListViewItem:(JAObjectListViewItem *)view inSection:(NSUInteger)section atIndex:(NSUInteger)index {
[self reallyAddListViewItem:view inSection:section atIndex:index + 1];
}
-- (void)reallyAddListViewItem:(JAListViewItem *)view inSection:(NSUInteger)section atIndex:(NSUInteger)index {
+- (void)reallyAddListViewItem:(JAObjectListViewItem *)view inSection:(NSUInteger)section atIndex:(NSUInteger)index {
NSMutableArray *sectionViews = nil;
if(section < self.sectionRowViews.count) {
sectionViews = [self.sectionRowViews objectAtIndex:section];
} else if(section != NSNotFound) { // added NSNotFound check
sectionViews = [NSMutableArray array];
[self.sectionRowViews insertObject:sectionViews atIndex:section]; //!!! boom - bounds
+ } else {
+ NSAssert1(NO, @"Tried to insert view into a non-existent section: %@", view);
}
if(index < sectionViews.count) {
[sectionViews replaceObjectAtIndex:index withObject:view];
} else if(index != NSNotFound) { // added NSNotFound check
[sectionViews insertObject:view atIndex:index]; //!!! boom - bounds
+ } else {
+ NSAssert1(NO, @"Tried to insert view into a non-existent row: %@", view);
}
}
-- (void)addListViewItem:(JAListViewItem *)view inSection:(NSUInteger)section {
+- (void)addListViewItem:(JAObjectListViewItem *)view inSection:(NSUInteger)section {
[self addListViewItem:view inSection:section atIndex:[self viewsInSection:section].count];
}
- (void)removeListViewItemInSection:(NSUInteger)section atIndex:(NSUInteger)index {
NSMutableArray *sectionViews = [self.sectionRowViews objectAtIndex:section];
- [sectionViews removeObjectAtIndex:index + 1];
+
+ NSUInteger trueIndex = index + 1;
+ JAObjectListViewItem *view = [sectionViews objectAtIndex:trueIndex];
+ if(self.viewBeingUsedForInertialScroll == view) {
+ self.viewBeingUsedForInertialScroll = nil;
+ }
+
+ [self deselectView:view];
+
+ [sectionViews removeObjectAtIndex:trueIndex];
}
-- (void)addListViewItem:(JAListViewItem *)view forHeaderForSection:(NSUInteger)section {
+- (void)addListViewItem:(JAObjectListViewItem *)view forHeaderForSection:(NSUInteger)section {
NSMutableArray *sectionViews = [NSMutableArray array];
[self.sectionRowViews insertObject:sectionViews atIndex:section];
[sectionViews insertObject:view atIndex:0];
}
- (void)removeListViewItemForHeaderForSection:(NSUInteger)section {
+ NSArray *views = [self.sectionRowViews objectAtIndex:section];
+ for(JAObjectListViewItem *item in views) {
+ if(self.viewBeingUsedForInertialScroll == item) {
+ self.viewBeingUsedForInertialScroll = nil;
+ }
+
+ [self deselectView:item];
+ }
+
[self.sectionRowViews removeObjectAtIndex:section];
}
-- (void)removeListViewItem:(JAListViewItem *)view {
+- (void)removeListViewItem:(JAObjectListViewItem *)view {
+ if(self.viewBeingUsedForInertialScroll == view) {
+ self.viewBeingUsedForInertialScroll = nil;
+ }
+
[self deselectView:view];
for(NSUInteger sectionIndex = 0; sectionIndex < self.sectionRowViews.count; sectionIndex++) {
NSMutableArray *sectionViews = [self.sectionRowViews objectAtIndex:sectionIndex];
NSUInteger index = [sectionViews indexOfObject:view];
- if(index == 0) {
- [self.sectionRowViews removeObjectAtIndex:sectionIndex];
- } else if(index != NSNotFound) {
- [sectionViews removeObjectAtIndex:index];
+ if(index != NSNotFound) {
+ if(index == 0) {
+ [self.sectionRowViews removeObjectAtIndex:sectionIndex];
+ } else {
+ [sectionViews removeObjectAtIndex:index];
+ }
}
}
}
- (void)removeAllListViewItems {
+ self.viewBeingUsedForInertialScroll = nil;
[self deselectAllViews];
[self.sectionRowViews removeAllObjects];
}
@@ -138,4 +172,39 @@ - (NSUInteger)numberOfSections {
return self.sectionRowViews.count;
}
+- (JAObjectListViewItem *)viewItemForObject:(id)object {
+ for(NSArray *views in self.sectionRowViews) {
+ for(JAObjectListViewItem *item in views) {
+ if([item.object isEqual:object]) {
+ return item;
+ }
+ }
+ }
+
+ return nil;
+}
+
+- (NSIndexPath *)indexPathForObject:(id)object {
+ NSUInteger section = 0;
+ for(NSArray *views in self.sectionRowViews) {
+
+ NSUInteger index = 0;
+ for(JAObjectListViewItem *item in views) {
+ if([item.object isEqual:object]) {
+ if(index == 0) {
+ return [NSIndexPath indexPathForIndex:JASectionedListViewHeaderIndex inSection:section];
+ } else {
+ return [NSIndexPath indexPathForIndex:index - 1 inSection:section];
+ }
+ }
+
+ index++;
+ }
+
+ section++;
+ }
+
+ return nil;
+}
+
@end
View
@@ -0,0 +1,17 @@
+//
+// JAObjectListViewItem.h
+// GitHub
+//
+// Created by Josh Abernathy on 12/29/10.
+// Copyright 2010 GitHub. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+#import "JAListViewItem.h"
+
+
+@interface JAObjectListViewItem : JAListViewItem {}
+
+@property (nonatomic, retain) id object;
+
+@end
View
@@ -0,0 +1,19 @@
+//
+// JAObjectListViewItem.m
+// GitHub
+//
+// Created by Josh Abernathy on 12/29/10.
+// Copyright 2010 GitHub. All rights reserved.
+//
+
+#import "JAObjectListViewItem.h"
+
+
+@implementation JAObjectListViewItem
+
+
+#pragma mark API
+
+@synthesize object;
+
+@end

0 comments on commit 52322a7

Please sign in to comment.