Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxHighlighting #399

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexP

- (UIContextMenuConfiguration *)tableView:(UITableView *)tableView contextMenuConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath point:(CGPoint)point __IOS_AVAILABLE(13.0) {
FLEXTableViewSection *section = self.filterDelegate.sections[indexPath.section];
NSString *title = [section menuTitleForRow:indexPath.row];
NSString *title = [section menuTitleForRow:indexPath.row].string;
NSArray<UIMenuElement *> *menuItems = [section menuItemsForRow:indexPath.row sender:self];

if (menuItems.count) {
Expand Down
14 changes: 7 additions & 7 deletions Classes/Core/FLEXSingleRowSection.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ @interface FLEXSingleRowSection ()
@property (nonatomic, readonly) NSString *reuseIdentifier;
@property (nonatomic, readonly) void (^cellConfiguration)(__kindof UITableViewCell *cell);

@property (nonatomic) NSString *lastTitle;
@property (nonatomic) NSString *lastSubitle;
@property (nonatomic) NSAttributedString *lastTitle;
@property (nonatomic) NSAttributedString *lastSubtitle;
@end

@implementation FLEXSingleRowSection
Expand Down Expand Up @@ -72,16 +72,16 @@ - (void)configureCell:(__kindof UITableViewCell *)cell forRow:(NSInteger)row {
cell.accessoryType = UITableViewCellAccessoryNone;

self.cellConfiguration(cell);
self.lastTitle = cell.textLabel.text;
self.lastSubitle = cell.detailTextLabel.text;
self.lastTitle = cell.textLabel.attributedText;
self.lastSubtitle = cell.detailTextLabel.attributedText;
}

- (NSString *)titleForRow:(NSInteger)row {
- (NSAttributedString *)titleForRow:(NSInteger)row {
return self.lastTitle;
}

- (NSString *)subtitleForRow:(NSInteger)row {
return self.lastSubitle;
- (NSAttributedString *)subtitleForRow:(NSInteger)row {
return self.lastSubtitle;
}

@end
8 changes: 4 additions & 4 deletions Classes/Core/FLEXTableViewSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ NS_ASSUME_NONNULL_BEGIN

/// By default, this is the title of the row.
/// @return The title of the context menu, if any.
- (nullable NSString *)menuTitleForRow:(NSInteger)row API_AVAILABLE(ios(13.0));
- (nullable NSAttributedString *)menuTitleForRow:(NSInteger)row API_AVAILABLE(ios(13.0));
/// Protected, not intended for public use. \c menuTitleForRow:
/// already includes the value returned from this method.
///
/// By default, this returns \c @"". Subclasses may override to
/// provide a detailed description of the target of the context menu.
- (NSString *)menuSubtitleForRow:(NSInteger)row API_AVAILABLE(ios(13.0));
- (NSAttributedString *)menuSubtitleForRow:(NSInteger)row API_AVAILABLE(ios(13.0));
/// The context menu items, if any. Subclasses may override.
/// By default, only inludes items for \c copyMenuItemsForRow:.
- (nullable NSArray<UIMenuElement *> *)menuItemsForRow:(NSInteger)row sender:(UIViewController *)sender API_AVAILABLE(ios(13.0));
Expand Down Expand Up @@ -124,10 +124,10 @@ NS_ASSUME_NONNULL_BEGIN

/// For use by whatever view controller uses your section. Not required.
/// @return An optional title.
- (nullable NSString *)titleForRow:(NSInteger)row;
- (nullable NSAttributedString *)titleForRow:(NSInteger)row;
/// For use by whatever view controller uses your section. Not required.
/// @return An optional subtitle.
- (nullable NSString *)subtitleForRow:(NSInteger)row;
- (nullable NSAttributedString *)subtitleForRow:(NSInteger)row;

@end

Expand Down
17 changes: 9 additions & 8 deletions Classes/Core/FLEXTableViewSection.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "FLEXTableView.h"
#import "FLEXUtility.h"
#import "UIMenu+FLEX.h"
#import "NSString+SyntaxHighlighting.h"

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wincomplete-implementation"
Expand Down Expand Up @@ -53,19 +54,19 @@ - (NSString *)reuseIdentifierForRow:(NSInteger)row {

#if FLEX_AT_LEAST_IOS13_SDK

- (NSString *)menuTitleForRow:(NSInteger)row {
NSString *title = [self titleForRow:row];
NSString *subtitle = [self menuSubtitleForRow:row];
- (NSAttributedString *)menuTitleForRow:(NSInteger)row {
NSAttributedString *title = [self titleForRow:row];
NSAttributedString *subtitle = [self menuSubtitleForRow:row];

if (subtitle.length) {
return [NSString stringWithFormat:@"%@\n\n%@", title, subtitle];
return [NSString stringWithFormat:@"%@\n\n%@", title, subtitle].attributedString;
}

return title;
}

- (NSString *)menuSubtitleForRow:(NSInteger)row {
return @"";
- (NSAttributedString *)menuSubtitleForRow:(NSInteger)row {
return @"".attributedString;
}

- (NSArray<UIMenuElement *> *)menuItemsForRow:(NSInteger)row sender:(UIViewController *)sender API_AVAILABLE(ios(13)) {
Expand Down Expand Up @@ -120,8 +121,8 @@ - (NSString *)menuSubtitleForRow:(NSInteger)row {
return nil;
}

- (NSString *)titleForRow:(NSInteger)row { return nil; }
- (NSString *)subtitleForRow:(NSInteger)row { return nil; }
- (NSAttributedString *)titleForRow:(NSInteger)row { return nil; }
- (NSAttributedString *)subtitleForRow:(NSInteger)row { return nil; }

@end

Expand Down
3 changes: 2 additions & 1 deletion Classes/Editing/FLEXDefaultEditorViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "FLEXRuntimeUtility.h"
#import "FLEXArgumentInputView.h"
#import "FLEXArgumentInputViewFactory.h"
#import "NSString+SyntaxHighlighting.h"

@interface FLEXDefaultEditorViewController ()

Expand All @@ -37,7 +38,7 @@ - (NSUserDefaults *)defaults {
- (void)viewDidLoad {
[super viewDidLoad];

self.fieldEditorView.fieldDescription = self.key;
self.fieldEditorView.fieldDescription = self.key.attributedString;

id currentValue = [self.defaults objectForKey:self.key];
FLEXArgumentInputView *inputView = [FLEXArgumentInputViewFactory
Expand Down
2 changes: 1 addition & 1 deletion Classes/Editing/FLEXFieldEditorView.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@interface FLEXFieldEditorView : UIView

@property (nonatomic, copy) NSString *targetDescription;
@property (nonatomic, copy) NSString *fieldDescription;
@property (nonatomic, copy) NSAttributedString *fieldDescription;

@property (nonatomic, copy) NSArray<FLEXArgumentInputView *> *argumentInputViews;

Expand Down
4 changes: 2 additions & 2 deletions Classes/Editing/FLEXFieldEditorView.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ - (void)setTargetDescription:(NSString *)targetDescription {
}
}

- (void)setFieldDescription:(NSString *)fieldDescription {
- (void)setFieldDescription:(NSAttributedString *)fieldDescription {
if (![_fieldDescription isEqual:fieldDescription]) {
_fieldDescription = fieldDescription;
self.fieldDescriptionLabel.text = fieldDescription;
self.fieldDescriptionLabel.attributedText = fieldDescription;
[self setNeedsLayout];
}
}
Expand Down
11 changes: 6 additions & 5 deletions Classes/Editing/FLEXFieldEditorViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#import "FLEXUtility.h"
#import "FLEXColor.h"
#import "UIBarButtonItem+FLEX.h"
#import "NSString+SyntaxHighlighting.h"

@interface FLEXFieldEditorViewController () <FLEXArgumentInputViewDelegate>

Expand All @@ -22,7 +23,7 @@ @interface FLEXFieldEditorViewController () <FLEXArgumentInputViewDelegate>

@property (nonatomic, readonly) id currentValue;
@property (nonatomic, readonly) const FLEXTypeEncoding *typeEncoding;
@property (nonatomic, readonly) NSString *fieldDescription;
@property (nonatomic, readonly) NSAttributedString *fieldDescription;

@end

Expand All @@ -37,14 +38,14 @@ + (instancetype)target:(id)target property:(FLEXProperty *)property {
}

FLEXFieldEditorViewController *editor = [self target:target];
editor.title = [@"Property: " stringByAppendingString:property.name];
editor.title = [@"Property: " stringByAppendingString:property.name.string];
editor.property = property;
return editor;
}

+ (instancetype)target:(id)target ivar:(nonnull FLEXIvar *)ivar {
FLEXFieldEditorViewController *editor = [self target:target];
editor.title = [@"Ivar: " stringByAppendingString:ivar.name];
editor.title = [@"Ivar: " stringByAppendingString:ivar.name.string];
editor.ivar = ivar;
return editor;
}
Expand Down Expand Up @@ -142,11 +143,11 @@ - (const FLEXTypeEncoding *)typeEncoding {
}
}

- (NSString *)fieldDescription {
- (NSAttributedString *)fieldDescription {
if (self.property) {
return self.property.fullDescription;
} else {
return self.ivar.description;
return self.ivar.description.attributedString;
}
}

Expand Down
7 changes: 3 additions & 4 deletions Classes/Editing/FLEXMethodCallingViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#import "FLEXArgumentInputView.h"
#import "FLEXArgumentInputViewFactory.h"
#import "FLEXUtility.h"
#import "NSAttributedString+FLEX.h"
#import "NSString+SyntaxHighlighting.h"

@interface FLEXMethodCallingViewController ()
@property (nonatomic) FLEXMethod *method;
Expand Down Expand Up @@ -45,10 +47,7 @@ - (void)viewDidLoad {

// Configure field editor view
self.fieldEditorView.argumentInputViews = [self argumentInputViews];
self.fieldEditorView.fieldDescription = [NSString stringWithFormat:
@"Signature:\n%@\n\nReturn Type:\n%s",
self.method.description, (char *)self.method.returnType
];
self.fieldEditorView.fieldDescription = [NSAttributedString stringWithFormat:@"Signature:\n%@\n\nReturn Type:\n%@", self.method.description, [NSString stringWithFormat:@"%s", (char *)self.method.returnType].attributedString];
}

- (NSArray<FLEXArgumentInputView *> *)argumentInputViews {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ - (UITableViewCell *)tableView:(FLEXTableView *)tableView cellForRowAtIndexPath:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kFLEXDetailCell forIndexPath:indexPath];

id object = self.bookmarks[indexPath.row];
cell.textLabel.text = [FLEXRuntimeUtility safeDescriptionForObject:object];
cell.textLabel.attributedText = [FLEXRuntimeUtility safeDescriptionForObject:object];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ — %p", [object class], object];

return cell;
Expand Down
2 changes: 2 additions & 0 deletions Classes/FLEX-Categories.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@
#import <FLEX/NSUserDefaults+FLEX.h>
#import <FLEX/NSMapTable+FLEX_Subscripting.h>
#import <FLEX/NSTimer+Blocks.h>
#import <FLEX/NSAttributedString+FLEX.h>
#import <FLEX/NSMutableAttributedString+FLEX.h>
4 changes: 2 additions & 2 deletions Classes/GlobalStateExplorers/FLEXObjectListViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ - (FLEXMutableListSection *)makeSection:(NSArray *)rows title:(NSString *)title
FLEXMutableListSection *section = [FLEXMutableListSection list:rows
cellConfiguration:^(FLEXTableViewCell *cell, FLEXObjectRef *ref, NSInteger row) {
cell.textLabel.text = ref.reference;
cell.detailTextLabel.text = ref.summary;
cell.detailTextLabel.attributedText = ref.summary;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
} filterMatcher:^BOOL(NSString *filterText, FLEXObjectRef *ref) {
if (ref.summary && [ref.summary localizedCaseInsensitiveContainsString:filterText]) {
if (ref.summary && [ref.summary.string localizedCaseInsensitiveContainsString:filterText]) {
return YES;
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/GlobalStateExplorers/FLEXObjectRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@property (nonatomic, readonly) NSString *reference;
/// For instances, this is the result of -[FLEXRuntimeUtility summaryForObject:]
/// For classes, there is no summary.
@property (nonatomic, readonly) NSString *summary;
@property (nonatomic, readonly) NSAttributedString *summary;
@property (nonatomic, readonly) id object;

@end
2 changes: 1 addition & 1 deletion Classes/GlobalStateExplorers/FLEXObjectRef.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ - (id)initWithObject:(id)object ivarName:(NSString *)ivar showSummary:(BOOL)show
return self;
}

- (NSString *)summary {
- (NSAttributedString *)summary {
if (self.wantsSummary) {
if (!_summary) {
_summary = [FLEXRuntimeUtility summaryForObject:self.object];
Expand Down
2 changes: 1 addition & 1 deletion Classes/ObjectExplorers/FLEXObjectExplorer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@property (nonatomic, readonly) id object;
/// Subclasses can override to provide a more useful description
@property (nonatomic, readonly) NSString *objectDescription;
@property (nonatomic, readonly) NSAttributedString *objectDescription;

/// @return \c YES if \c object is an instance of a class,
/// or \c NO if \c object is a class itself.
Expand Down
21 changes: 11 additions & 10 deletions Classes/ObjectExplorers/FLEXObjectExplorer.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#import "NSObject+Reflection.h"
#import "FLEXMetadataSection.h"
#import "NSUserDefaults+FLEX.h"
#import "NSAttributedString+FLEX.h"

@interface FLEXObjectExplorer () {
NSMutableArray<NSArray<FLEXProperty *> *> *_allProperties;
Expand All @@ -26,7 +27,7 @@ @interface FLEXObjectExplorer () {
NSMutableArray<NSArray<FLEXProtocol *> *> *_allConformedProtocols;
NSMutableArray<FLEXStaticMetadata *> *_allInstanceSizes;
NSMutableArray<FLEXStaticMetadata *> *_allImageNames;
NSString *_objectDescription;
NSAttributedString *_objectDescription;
}
@end

Expand Down Expand Up @@ -55,29 +56,29 @@ - (id)initWithObject:(id)objectOrClass {

#pragma mark - Public

- (NSString *)objectDescription {
- (NSAttributedString *)objectDescription {
if (!_objectDescription) {
// Hard-code UIColor description
if ([self.object isKindOfClass:[UIColor class]]) {
CGFloat h, s, l, r, g, b, a;
[self.object getRed:&r green:&g blue:&b alpha:&a];
[self.object getHue:&h saturation:&s brightness:&l alpha:nil];

return [NSString stringWithFormat:
@"HSL: (%.3f, %.3f, %.3f)\nRGB: (%.3f, %.3f, %.3f)\nAlpha: %.3f",
h, s, l, r, g, b, a
];
NSAttributedString *rString = [NSAttributedString stringWithAttributes:@{ NSForegroundColorAttributeName: UIColor.redColor } format:@"%.3f", r];
NSAttributedString *gString = [NSAttributedString stringWithAttributes:@{ NSForegroundColorAttributeName: UIColor.greenColor } format:@"%.3f", g];
NSAttributedString *bString = [NSAttributedString stringWithAttributes:@{ NSForegroundColorAttributeName: UIColor.blueColor } format:@"%.3f", b];
return [NSAttributedString stringWithFormat:@"HSL: (%.3f, %.3f, %.3f)\nRGB: (%@, %@, %@)\nAlpha: %.3f", h, s, l, rString, gString, bString, a];
}

NSString *description = [FLEXRuntimeUtility safeDescriptionForObject:self.object];
NSAttributedString *description = [FLEXRuntimeUtility safeDescriptionForObject:self.object];

if (!description.length) {
NSString *address = [FLEXUtility addressOfObject:self.object];
return [NSString stringWithFormat:@"Object at %@ returned empty description", address];
NSAttributedString *address = [FLEXUtility addressOfObject:self.object];
return [NSAttributedString stringWithFormat:@"Object at %@ returned empty description", address];
}

if (description.length > 10000) {
description = [description substringToIndex:10000];
description = [description attributedSubstringFromRange:NSMakeRange(0, 10000)];
}

_objectDescription = description;
Expand Down
16 changes: 7 additions & 9 deletions Classes/ObjectExplorers/FLEXObjectExplorerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ - (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView {
_descriptionSection = [FLEXSingleRowSection
title:@"Description" reuse:kFLEXMultilineCell cell:^(FLEXTableViewCell *cell) {
cell.titleLabel.font = UIFont.flex_defaultTableCellFont;
cell.titleLabel.text = explorer.objectDescription;
cell.titleLabel.attributedText = explorer.objectDescription;
}
];
self.descriptionSection.filterMatcher = ^BOOL(NSString *filterText) {
return [explorer.objectDescription localizedCaseInsensitiveContainsString:filterText];
return [explorer.objectDescription.string localizedCaseInsensitiveContainsString:filterText];
};
}

Expand Down Expand Up @@ -227,10 +227,10 @@ - (void)shareButtonPressed {
[FLEXBookmarkManager.bookmarks addObject:self.object];
});
make.button(@"Copy Description").handler(^(NSArray<NSString *> *strings) {
UIPasteboard.generalPasteboard.string = self.explorer.objectDescription;
UIPasteboard.generalPasteboard.string = self.explorer.objectDescription.string;
});
make.button(@"Copy Address").handler(^(NSArray<NSString *> *strings) {
UIPasteboard.generalPasteboard.string = [FLEXUtility addressOfObject:self.object];
UIPasteboard.generalPasteboard.string = [FLEXUtility addressOfObject:self.object].string;
});
make.button(@"Cancel").cancelStyle();
} showFrom:self];
Expand Down Expand Up @@ -345,10 +345,8 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
FLEXTableViewSection *section = self.filterDelegate.sections[indexPath.section];

if (section == self.descriptionSection) {
NSAttributedString *attributedText = [[NSAttributedString alloc]
initWithString:self.explorer.objectDescription
attributes:@{ NSFontAttributeName : UIFont.flex_defaultTableCellFont }
];
NSMutableAttributedString *attributedText = self.explorer.objectDescription.mutableCopy;
[attributedText addAttribute:NSFontAttributeName value:UIFont.flex_defaultTableCellFont range:NSMakeRange(0, attributedText.length)];

return [FLEXMultilineTableViewCell
preferredHeightWithAttributedText:attributedText
Expand Down Expand Up @@ -376,7 +374,7 @@ - (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAt

- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
if (action == @selector(copy:)) {
UIPasteboard.generalPasteboard.string = self.explorer.objectDescription;
UIPasteboard.generalPasteboard.string = self.explorer.objectDescription.string;
}
}

Expand Down
Loading