Skip to content

Commit 85cc51b

Browse files
committed
Re-organize + group the globals list into sections
1 parent c3bb4ff commit 85cc51b

File tree

2 files changed

+80
-27
lines changed

2 files changed

+80
-27
lines changed

Classes/GlobalStateExplorers/FLEXGlobalsTableViewController.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
// Copyright (c) 2014 Flipboard. All rights reserved.
77
//
88

9-
#import <UIKit/UIKit.h>
9+
#import "FLEXTableViewController.h"
1010

1111
@protocol FLEXGlobalsTableViewControllerDelegate;
1212

13-
@interface FLEXGlobalsTableViewController : UITableViewController
13+
@interface FLEXGlobalsTableViewController : FLEXTableViewController
1414

1515
@property (nonatomic, weak) id <FLEXGlobalsTableViewControllerDelegate> delegate;
1616

Classes/GlobalStateExplorers/FLEXGlobalsTableViewController.m

Lines changed: 78 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,27 @@
2424

2525
static __weak UIWindow *s_applicationWindow = nil;
2626

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+
2741
typedef NS_ENUM(NSUInteger, FLEXGlobalsRow) {
2842
FLEXGlobalsRowNetworkHistory,
2943
FLEXGlobalsRowSystemLog,
3044
FLEXGlobalsRowLiveObjects,
3145
FLEXGlobalsRowAddressInspector,
3246
FLEXGlobalsRowFileBrowser,
33-
FLEXGlobalsCookies,
47+
FLEXGlobalsRowCookies,
3448
FLEXGlobalsRowSystemLibraries,
3549
FLEXGlobalsRowAppClasses,
3650
FLEXGlobalsRowAppDelegate,
@@ -46,13 +60,31 @@ typedef NS_ENUM(NSUInteger, FLEXGlobalsRow) {
4660

4761
@interface FLEXGlobalsTableViewController ()
4862

49-
@property (nonatomic, readonly) NSArray<FLEXGlobalsTableViewControllerEntry *> *entries;
63+
@property (nonatomic, readonly) NSArray<NSArray<FLEXGlobalsTableViewControllerEntry *> *> *sections;
5064

5165
@end
5266

5367
@implementation FLEXGlobalsTableViewController
5468

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+
{
5688
switch (row) {
5789
case FLEXGlobalsRowAppClasses:
5890
return [FLEXClassesTableViewController flex_concreteGlobalsEntry];
@@ -62,7 +94,7 @@ + (FLEXGlobalsTableViewControllerEntry *)globalsEntryForRow:(FLEXGlobalsRow)row
6294
return [FLEXLibrariesTableViewController flex_concreteGlobalsEntry];
6395
case FLEXGlobalsRowLiveObjects:
6496
return [FLEXLiveObjectsTableViewController flex_concreteGlobalsEntry];
65-
case FLEXGlobalsCookies:
97+
case FLEXGlobalsRowCookies:
6698
return [FLEXCookiesTableViewController flex_concreteGlobalsEntry];
6799
case FLEXGlobalsRowFileBrowser:
68100
return [FLEXFileBrowserTableViewController flex_concreteGlobalsEntry];
@@ -148,24 +180,31 @@ + (FLEXGlobalsTableViewControllerEntry *)globalsEntryForRow:(FLEXGlobalsRow)row
148180
}
149181
}
150182

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
162184
{
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+
];
169208
}
170209

171210
#pragma mark - Public
@@ -180,7 +219,16 @@ + (void)setApplicationWindow:(UIWindow *)applicationWindow
180219
- (void)viewDidLoad
181220
{
182221
[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
184232
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(donePressed:)];
185233
}
186234

@@ -195,7 +243,7 @@ - (void)donePressed:(id)sender
195243

196244
- (FLEXGlobalsTableViewControllerEntry *)globalEntryAtIndexPath:(NSIndexPath *)indexPath
197245
{
198-
return self.entries[indexPath.row];
246+
return self.sections[indexPath.section][indexPath.row];
199247
}
200248

201249
- (NSString *)titleForRowAtIndexPath:(NSIndexPath *)indexPath
@@ -209,12 +257,12 @@ - (NSString *)titleForRowAtIndexPath:(NSIndexPath *)indexPath
209257

210258
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
211259
{
212-
return 1;
260+
return self.sections.count;
213261
}
214262

215263
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
216264
{
217-
return [self.entries count];
265+
return self.sections[section].count;
218266
}
219267

220268
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
@@ -232,6 +280,11 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
232280
return cell;
233281
}
234282

283+
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
284+
{
285+
return [[self class] globalsTitleForSection:section];
286+
}
287+
235288
#pragma mark - Table View Delegate
236289

237290
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

0 commit comments

Comments
 (0)