Skip to content

Commit a556ece

Browse files
committed
Tidy up database browser
1 parent 35ce037 commit a556ece

22 files changed

+537
-501
lines changed

Classes/Editing/FLEXMethodCallingViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ - (void)actionButtonPressed:(id)sender {
7878
NSMutableArray *arguments = [NSMutableArray array];
7979
for (FLEXArgumentInputView *inputView in self.fieldEditorView.argumentInputViews) {
8080
// Use NSNull as a nil placeholder; it will be interpreted as nil
81-
[arguments addObject:inputView.inputValue ?: [NSNull null]];
81+
[arguments addObject:inputView.inputValue ?: NSNull.null];
8282
}
8383

8484
// Call method
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// FLEXDBQueryRowCell.h
3+
// FLEX
4+
//
5+
// Created by Peng Tao on 15/11/24.
6+
// Copyright © 2015年 f. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
extern NSString * const kFLEXDBQueryRowCellReuse;
12+
13+
14+
@interface FLEXDBQueryRowCell : UITableViewCell
15+
16+
/// An array of NSString, NSNumber, or NSData objects
17+
@property (nonatomic) NSArray *data;
18+
19+
@end
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//
2+
// FLEXDBQueryRowCell.m
3+
// FLEX
4+
//
5+
// Created by Peng Tao on 15/11/24.
6+
// Copyright © 2015年 f. All rights reserved.
7+
//
8+
9+
#import "FLEXDBQueryRowCell.h"
10+
#import "FLEXMultiColumnTableView.h"
11+
#import "NSArray+Functional.h"
12+
#import "UIFont+FLEX.h"
13+
#import "FLEXColor.h"
14+
15+
NSString * const kFLEXDBQueryRowCellReuse = @"kFLEXDBQueryRowCellReuse";
16+
17+
@interface FLEXDBQueryRowCell ()
18+
@property (nonatomic) NSInteger columnCount;
19+
@property (nonatomic) NSArray<UILabel *> *labels;
20+
@end
21+
22+
@implementation FLEXDBQueryRowCell
23+
24+
- (void)setData:(NSArray *)data {
25+
_data = data;
26+
self.columnCount = data.count;
27+
28+
[self.labels flex_forEach:^(UILabel *label, NSUInteger idx) {
29+
id content = self.data[idx];
30+
31+
if ([content isKindOfClass:[NSString class]]) {
32+
label.text = content;
33+
} else if (content == NSNull.null) {
34+
label.text = @"<null>";
35+
label.textColor = FLEXColor.deemphasizedTextColor;
36+
} else {
37+
label.text = [content description];
38+
}
39+
}];
40+
}
41+
42+
- (void)setColumnCount:(NSInteger)columnCount {
43+
if (columnCount != _columnCount) {
44+
_columnCount = columnCount;
45+
46+
// Remove existing labels
47+
for (UILabel *l in self.labels) {
48+
[l removeFromSuperview];
49+
}
50+
51+
// Create new labels
52+
self.labels = [NSArray flex_forEachUpTo:columnCount map:^id(NSUInteger i) {
53+
UILabel *label = [UILabel new];
54+
label.font = UIFont.flex_defaultTableCellFont;
55+
label.textAlignment = NSTextAlignmentLeft;
56+
[self.contentView addSubview:label];
57+
58+
return label;
59+
}];
60+
}
61+
}
62+
63+
- (void)layoutSubviews {
64+
[super layoutSubviews];
65+
66+
CGFloat width = self.contentView.frame.size.width / self.labels.count;
67+
CGFloat height = self.contentView.frame.size.height;
68+
69+
[self.labels flex_forEach:^(UILabel *label, NSUInteger i) {
70+
label.frame = CGRectMake(width * i + 5, 0, (width - 10), height);
71+
}];
72+
}
73+
74+
@end

Classes/GlobalStateExplorers/DatabaseBrowser/FLEXDatabaseManager.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
@protocol FLEXDatabaseManager <NSObject>
1717

1818
@required
19-
- (instancetype)initWithPath:(NSString*)path;
19+
+ (instancetype)managerForDatabase:(NSString *)path;
2020

2121
- (BOOL)open;
22-
- (NSArray<NSDictionary<NSString *, id> *> *)queryAllTables;
22+
/// @return a list of all table names
23+
- (NSArray<NSString *> *)queryAllTables;
2324
- (NSArray<NSString *> *)queryAllColumnsWithTableName:(NSString *)tableName;
24-
- (NSArray<NSDictionary<NSString *, id> *> *)queryAllDataWithTableName:(NSString *)tableName;
25+
- (NSArray<NSArray *> *)queryAllDataWithTableName:(NSString *)tableName;
2526

2627
@end

Classes/GlobalStateExplorers/DatabaseBrowser/FLEXMultiColumnTableView.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
@protocol FLEXMultiColumnTableViewDelegate <NSObject>
1515

1616
@required
17-
- (void)multiColumnTableView:(FLEXMultiColumnTableView *)tableView didTapLabelWithText:(NSString *)text;
18-
- (void)multiColumnTableView:(FLEXMultiColumnTableView *)tableView didTapHeaderWithText:(NSString *)text sortType:(FLEXTableColumnHeaderSortType)sortType;
17+
- (void)multiColumnTableView:(FLEXMultiColumnTableView *)tableView didSelectRow:(NSInteger)row;
18+
- (void)multiColumnTableView:(FLEXMultiColumnTableView *)tableView didSelectHeaderForColumn:(NSInteger)column sortType:(FLEXTableColumnHeaderSortType)sortType;
1919

2020
@end
2121

@@ -25,10 +25,9 @@
2525

2626
- (NSInteger)numberOfColumnsInTableView:(FLEXMultiColumnTableView *)tableView;
2727
- (NSInteger)numberOfRowsInTableView:(FLEXMultiColumnTableView *)tableView;
28-
- (NSString *)columnNameInColumn:(NSInteger)column;
29-
- (NSString *)rowNameInRow:(NSInteger)row;
30-
- (NSString *)contentAtColumn:(NSInteger)column row:(NSInteger)row;
31-
- (NSArray *)contentAtRow:(NSInteger)row;
28+
- (NSString *)columnTitle:(NSInteger)column;
29+
- (NSString *)rowTitle:(NSInteger)row;
30+
- (NSArray<NSString *> *)contentForRow:(NSInteger)row;
3231

3332
- (CGFloat)multiColumnTableView:(FLEXMultiColumnTableView *)tableView widthForContentCellInColumn:(NSInteger)column;
3433
- (CGFloat)multiColumnTableView:(FLEXMultiColumnTableView *)tableView heightForContentCellInRow:(NSInteger)row;
@@ -40,8 +39,8 @@
4039

4140
@interface FLEXMultiColumnTableView : UIView
4241

43-
@property (nonatomic, weak) id<FLEXMultiColumnTableViewDataSource>dataSource;
44-
@property (nonatomic, weak) id<FLEXMultiColumnTableViewDelegate>delegate;
42+
@property (nonatomic, weak) id<FLEXMultiColumnTableViewDataSource> dataSource;
43+
@property (nonatomic, weak) id<FLEXMultiColumnTableViewDelegate> delegate;
4544

4645
- (void)reloadData;
4746

0 commit comments

Comments
 (0)