-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMYSTableView.h
188 lines (126 loc) · 6.77 KB
/
MYSTableView.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//
// MYSTableView.h
// Butter
//
// Created by Adam Kirk on 10/30/13.
// Copyright (c) 2013 ButterKit. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import "NSIndexPath+MYSTableView.h"
@protocol MYSTableViewDataSource;
@protocol MYSTableViewDelegate;
@interface MYSTableView : NSTableView
@property (nonatomic, weak) id<MYSTableViewDataSource> MYS_dataSource;
@property (nonatomic, weak) id<MYSTableViewDelegate> MYS_delegate;
/**
* If `tableView:heightForHeaderInSection:` is not implemented, this value is used for the height of section headers.
*/
@property (nonatomic, assign) CGFloat sectionHeaderHeight;
/**
* default is YES. Controls whether rows can be selected when not in editing mode.
*/
@property (nonatomic, assign) BOOL allowsSelection;
/**
* default is the standard separator gray
*/
@property (nonatomic, strong) NSColor *separatorColor;
/**
* Scrolling padding around the table view content.
*/
@property (nonatomic, assign) NSEdgeInsets edgeInsets;
/**
* accessory view for above row content. default is nil. not to be confused with section header.
*/
@property (nonatomic, strong) NSTableHeaderView *tableHeaderView;
@property (nonatomic, assign) BOOL floatingSectionHeaders;
/**
* Converts a row index from the NSTableView into an index path that represents the row.
*
* @param rowIndex The absolute row index of the table (including header rows)..
*
* @return Returns the corresponding index path for the row or `nil` if the rowIndex is a section header.
*/
- (NSIndexPath *)indexPathForRowIndex:(NSInteger)rowIndex;
/**
* Converts an index path into an aboslute NSTableView row index.i
*
* @param indexPath The index path you want to get a row index for.
*
* @return Returns the NSTableView absolute row index. This will never be a section header row because index paths
* cannot represent header rows.
*/
- (NSInteger)rowIndexForIndexPath:(NSIndexPath *)indexPath;
- (NSInteger)numberOfSections;
- (NSInteger)numberOfRowsInSection:(NSInteger)section;
- (CGRect)rectForSection:(NSInteger)section;
- (CGRect)rectForHeaderInSection:(NSInteger)section;
- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point;
- (NSIndexPath *)indexPathForCell:(id)cell;
- (NSArray *)indexPathsForRowsInRect:(CGRect)rect;
- (void)endUpdatesWithCompletion:(void (^)(void))completion;
- (id)cellForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSArray *)visibleCells;
- (NSArray *)indexPathsForVisibleRows;
- (id)headerViewForSection:(NSInteger)section;
- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated;
- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(NSTableViewAnimationOptions)animation;
- (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(NSTableViewAnimationOptions)animation;
- (void)reloadSections:(NSIndexSet *)sections;
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(NSTableViewAnimationOptions)animation;
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(NSTableViewAnimationOptions)animation;
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths;
- (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath;
- (NSIndexPath *)indexPathForSelectedRow;
- (NSArray *)indexPathsForSelectedRows;
- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath;
/**
As opposed to selecting the row, this just highlights it and does not propogate the action of selecting it.
*/
- (void)highlightRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)deselectRowAtIndexPath:(NSIndexPath *)indexPath;
- (id)dequeueReusableCellWithIdentifier:(NSString *)identifier;
- (id)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath;
- (id)dequeueReusableHeaderViewWithIdentifier:(NSString *)identifier;
- (void)registerNib:(NSNib *)nib forCellReuseIdentifier:(NSString *)identifier;
- (void)registerNib:(NSNib *)nib forHeaderViewReuseIdentifier:(NSString *)identifier;
@end
@protocol MYSTableViewDataSource <NSTableViewDataSource>
- (NSInteger)tableView:(MYSTableView *)tableView numberOfRowsInSection:(NSInteger)section;
- (NSView *)tableView:(MYSTableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
@optional
- (NSInteger)numberOfSectionsInTableView:(MYSTableView *)tableView;
- (NSString *)tableView:(MYSTableView *)tableView titleForHeaderInSection:(NSInteger)section;
@end
@protocol MYSTableViewDelegate <NSTableViewDelegate>
@optional
- (void)tableView:(MYSTableView *)tableView willDisplayCell:(NSView *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(MYSTableView *)tableView willDisplayHeaderView:(NSView *)view forSection:(NSInteger)section;
- (CGFloat)tableView:(MYSTableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- (CGFloat)tableView:(MYSTableView *)tableView heightForHeaderInSection:(NSInteger)section;
- (NSView *)tableView:(MYSTableView *)tableView viewForHeaderInSection:(NSInteger)section;
- (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRowAtIndexPath:(NSIndexPath *)indexPath;
- (BOOL)tableView:(MYSTableView *)tableView shouldSelectRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSArray *)tableView:(MYSTableView *)tableView willSelectRowsAtIndexPaths:(NSArray *)indexPaths;
- (NSArray *)tableView:(MYSTableView *)tableView willDeselectRowsAtIndexPaths:(NSArray *)indexPaths;
- (void)tableView:(MYSTableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(MYSTableView *)tableView didSelectRowsAtIndexPaths:(NSArray *)indexPaths;
- (void)tableView:(MYSTableView *)tableView didDeselectRowsAtIndexPaths:(NSArray *)indexPaths;
- (void)tableView:(MYSTableView *)tableView didPressEnterOnRowAtIndexPath:(NSIndexPath *)indexPath withEvent:(NSEvent *)event;
- (void)tableView:(MYSTableView *)tableView didClickRowAtIndexPath:(NSIndexPath *)indexPath withEvent:(NSEvent *)event;
- (void)tableView:(MYSTableView *)tableView didRightClickOnRowAtIndexPath:(NSIndexPath *)indexPath withEvent:(NSEvent *)event;
- (NSMenu *)tableView:(MYSTableView *)tableView menuForRowAtIndexPath:(NSIndexPath *)indexPath withEvent:(NSEvent *)event;
@required
/**
* You must implement this if you want `tableView:viewForHeaderInSection:` to ever be called. Default implementation
* returns NO;
*/
- (BOOL)tableView:(MYSTableView *)tableView hasHeaderInSection:(NSInteger)section;
@end
@interface MYSScrollViewAnimation : NSAnimation
@property (retain) NSScrollView *scrollView;
@property NSPoint originPoint;
@property NSPoint targetPoint;
+ (void)animatedScrollPointToCenter:(NSPoint)targetPoint inScrollView:(NSScrollView *)scrollView duration:(NSTimeInterval)duration;
+ (void)animatedScrollToPoint:(NSPoint)targetPoint inScrollView:(NSScrollView *)scrollView duration:(NSTimeInterval)duration;
@end