24
24
25
25
static __weak UIWindow *s_applicationWindow = nil ;
26
26
27
+ typedef NS_ENUM (NSUInteger , FLEXGlobalsSection) {
28
+ // / NSProcessInfo, Network history, system log,
29
+ // / heap, address explorer, libraries, app classes
30
+ FLEXGlobalsSectionProcessAndEvents,
31
+ // / Browse container, browse bundle, NSBundle.main,
32
+ // / NSUserDefaults.standard, UIApplication,
33
+ // / app delegate, key window, root VC, cookies
34
+ FLEXGlobalsSectionAppShortcuts,
35
+ // / UIPasteBoard.general, UIScreen, UIDevice
36
+ FLEXGlobalsSectionMisc,
37
+ FLEXGlobalsSectionCustom,
38
+ FLEXGlobalsSectionCount
39
+ };
40
+
27
41
typedef NS_ENUM (NSUInteger , FLEXGlobalsRow) {
28
42
FLEXGlobalsRowNetworkHistory,
29
43
FLEXGlobalsRowSystemLog,
30
44
FLEXGlobalsRowLiveObjects,
31
45
FLEXGlobalsRowAddressInspector,
32
46
FLEXGlobalsRowFileBrowser,
33
- FLEXGlobalsCookies,
47
+ FLEXGlobalsRowCookies,
34
48
FLEXGlobalsRowSystemLibraries,
35
49
FLEXGlobalsRowAppClasses,
36
50
FLEXGlobalsRowAppDelegate,
@@ -46,13 +60,31 @@ typedef NS_ENUM(NSUInteger, FLEXGlobalsRow) {
46
60
47
61
@interface FLEXGlobalsTableViewController ()
48
62
49
- @property (nonatomic , readonly ) NSArray <FLEXGlobalsTableViewControllerEntry *> *entries ;
63
+ @property (nonatomic , readonly ) NSArray <NSArray< FLEXGlobalsTableViewControllerEntry *> *> *sections ;
50
64
51
65
@end
52
66
53
67
@implementation FLEXGlobalsTableViewController
54
68
55
- + (FLEXGlobalsTableViewControllerEntry *)globalsEntryForRow : (FLEXGlobalsRow)row {
69
+ + (NSString *)globalsTitleForSection : (FLEXGlobalsSection)section
70
+ {
71
+ switch (section) {
72
+ case FLEXGlobalsSectionProcessAndEvents:
73
+ return @" Process and Events" ;
74
+ case FLEXGlobalsSectionAppShortcuts:
75
+ return @" App Shortcuts" ;
76
+ case FLEXGlobalsSectionMisc:
77
+ return @" Miscellaneous" ;
78
+ case FLEXGlobalsSectionCustom:
79
+ return @" Custom Additions" ;
80
+
81
+ default :
82
+ @throw NSInternalInconsistencyException ;
83
+ }
84
+ }
85
+
86
+ + (FLEXGlobalsTableViewControllerEntry *)globalsEntryForRow : (FLEXGlobalsRow)row
87
+ {
56
88
switch (row) {
57
89
case FLEXGlobalsRowAppClasses:
58
90
return [FLEXClassesTableViewController flex_concreteGlobalsEntry ];
@@ -62,7 +94,7 @@ + (FLEXGlobalsTableViewControllerEntry *)globalsEntryForRow:(FLEXGlobalsRow)row
62
94
return [FLEXLibrariesTableViewController flex_concreteGlobalsEntry ];
63
95
case FLEXGlobalsRowLiveObjects:
64
96
return [FLEXLiveObjectsTableViewController flex_concreteGlobalsEntry ];
65
- case FLEXGlobalsCookies :
97
+ case FLEXGlobalsRowCookies :
66
98
return [FLEXCookiesTableViewController flex_concreteGlobalsEntry ];
67
99
case FLEXGlobalsRowFileBrowser:
68
100
return [FLEXFileBrowserTableViewController flex_concreteGlobalsEntry ];
@@ -148,24 +180,31 @@ + (FLEXGlobalsTableViewControllerEntry *)globalsEntryForRow:(FLEXGlobalsRow)row
148
180
}
149
181
}
150
182
151
- + (NSArray <FLEXGlobalsTableViewControllerEntry *> *)defaultGlobalEntries
152
- {
153
- NSMutableArray <FLEXGlobalsTableViewControllerEntry *> *defaultGlobalEntries = [NSMutableArray array ];
154
- for (FLEXGlobalsRow defaultRowIndex = 0 ; defaultRowIndex < FLEXGlobalsRowCount; defaultRowIndex++) {
155
- [defaultGlobalEntries addObject: [self globalsEntryForRow: defaultRowIndex]];
156
- }
157
-
158
- return defaultGlobalEntries;
159
- }
160
-
161
- - (id )initWithStyle : (UITableViewStyle)style
183
+ + (NSArray <NSArray<FLEXGlobalsTableViewControllerEntry *> *> *)defaultGlobalSections
162
184
{
163
- self = [super initWithStyle: style];
164
- if (self) {
165
- self.title = @" 💪 FLEX" ;
166
- _entries = [[[self class ] defaultGlobalEntries ] arrayByAddingObjectsFromArray: [FLEXManager sharedManager ].userGlobalEntries];
167
- }
168
- return self;
185
+ return @[
186
+ @[ // FLEXGlobalsSectionProcess
187
+ [self globalsEntryForRow: FLEXGlobalsRowNetworkHistory],
188
+ [self globalsEntryForRow: FLEXGlobalsRowSystemLog],
189
+ [self globalsEntryForRow: FLEXGlobalsRowLiveObjects],
190
+ [self globalsEntryForRow: FLEXGlobalsRowAddressInspector],
191
+ [self globalsEntryForRow: FLEXGlobalsRowSystemLibraries],
192
+ [self globalsEntryForRow: FLEXGlobalsRowAppClasses],
193
+ ],
194
+ @[ // FLEXGlobalsSectionAppShortcuts
195
+ [self globalsEntryForRow: FLEXGlobalsRowMainBundle],
196
+ [self globalsEntryForRow: FLEXGlobalsRowUserDefaults],
197
+ [self globalsEntryForRow: FLEXGlobalsRowApplication],
198
+ [self globalsEntryForRow: FLEXGlobalsRowAppDelegate],
199
+ [self globalsEntryForRow: FLEXGlobalsRowKeyWindow],
200
+ [self globalsEntryForRow: FLEXGlobalsRowRootViewController],
201
+ [self globalsEntryForRow: FLEXGlobalsRowCookies],
202
+ ],
203
+ @[ // FLEXGlobalsSectionMisc
204
+ [self globalsEntryForRow: FLEXGlobalsRowMainScreen],
205
+ [self globalsEntryForRow: FLEXGlobalsRowCurrentDevice],
206
+ ]
207
+ ];
169
208
}
170
209
171
210
#pragma mark - Public
@@ -180,7 +219,16 @@ + (void)setApplicationWindow:(UIWindow *)applicationWindow
180
219
- (void )viewDidLoad
181
220
{
182
221
[super viewDidLoad ];
183
-
222
+
223
+ self.title = @" 💪 FLEX" ;
224
+
225
+ // Table view data
226
+ _sections = [[self class ] defaultGlobalSections ];
227
+ if ([FLEXManager sharedManager ].userGlobalEntries .count ) {
228
+ _sections = [_sections arrayByAddingObject: [FLEXManager sharedManager ].userGlobalEntries];
229
+ }
230
+
231
+ // Done button
184
232
self.navigationItem .rightBarButtonItem = [[UIBarButtonItem alloc ] initWithBarButtonSystemItem: UIBarButtonSystemItemDone target: self action: @selector (donePressed: )];
185
233
}
186
234
@@ -195,7 +243,7 @@ - (void)donePressed:(id)sender
195
243
196
244
- (FLEXGlobalsTableViewControllerEntry *)globalEntryAtIndexPath : (NSIndexPath *)indexPath
197
245
{
198
- return self.entries [indexPath.row];
246
+ return self.sections [indexPath.section] [indexPath.row];
199
247
}
200
248
201
249
- (NSString *)titleForRowAtIndexPath : (NSIndexPath *)indexPath
@@ -209,12 +257,12 @@ - (NSString *)titleForRowAtIndexPath:(NSIndexPath *)indexPath
209
257
210
258
- (NSInteger )numberOfSectionsInTableView : (UITableView *)tableView
211
259
{
212
- return 1 ;
260
+ return self. sections . count ;
213
261
}
214
262
215
263
- (NSInteger )tableView : (UITableView *)tableView numberOfRowsInSection : (NSInteger )section
216
264
{
217
- return [ self .entries count ] ;
265
+ return self.sections [section]. count ;
218
266
}
219
267
220
268
- (UITableViewCell *)tableView : (UITableView *)tableView cellForRowAtIndexPath : (NSIndexPath *)indexPath
@@ -232,6 +280,11 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
232
280
return cell;
233
281
}
234
282
283
+ - (NSString *)tableView : (UITableView *)tableView titleForHeaderInSection : (NSInteger )section
284
+ {
285
+ return [[self class ] globalsTitleForSection: section];
286
+ }
287
+
235
288
#pragma mark - Table View Delegate
236
289
237
290
- (void )tableView : (UITableView *)tableView didSelectRowAtIndexPath : (NSIndexPath *)indexPath
0 commit comments