FLEXClassShortcuts.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // FLEXClassShortcuts.m
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 11/22/19.
  6. // Copyright © 2019 Flipboard. All rights reserved.
  7. //
  8. #import "FLEXClassShortcuts.h"
  9. #import "FLEXObjectExplorerFactory.h"
  10. #import "FLEXShortcut.h"
  11. #import "FLEXInstancesViewController.h"
  12. /// Pretty much only necessary because I want to provide
  13. /// a useful subtitle for the bundles of classes
  14. @interface FLEXBundleShortcut : NSObject <FLEXShortcut>
  15. @end
  16. #pragma mark -
  17. @implementation FLEXBundleShortcut
  18. - (NSString *)titleWith:(id)object {
  19. return @"Bundle";
  20. }
  21. - (NSString *)subtitleWith:(id)object {
  22. return [self shortNameForBundlePath:[NSBundle bundleForClass:object].executablePath];
  23. }
  24. - (UIViewController *)viewerWith:(id)object {
  25. NSBundle *bundle = [NSBundle bundleForClass:object];
  26. return [FLEXObjectExplorerFactory explorerViewControllerForObject:bundle];
  27. }
  28. - (NSString *)shortNameForBundlePath:(NSString *)imageName {
  29. NSArray<NSString *> *components = [imageName componentsSeparatedByString:@"/"];
  30. if (components.count >= 2) {
  31. return [NSString stringWithFormat:@"%@/%@",
  32. components[components.count - 2],
  33. components[components.count - 1]
  34. ];
  35. }
  36. return imageName.lastPathComponent;
  37. }
  38. - (UITableViewCellAccessoryType)accessoryTypeWith:(id)object {
  39. NSParameterAssert(object != nil);
  40. return UITableViewCellAccessoryDisclosureIndicator;
  41. }
  42. - (NSString *)customReuseIdentifierWith:(id)object {
  43. return nil;
  44. }
  45. - (void (^)(UIViewController *))didSelectActionWith:(id)object {
  46. return nil;
  47. }
  48. @end
  49. #pragma mark -
  50. @interface FLEXClassShortcuts ()
  51. @property (nonatomic, readonly) Class cls;
  52. @end
  53. @implementation FLEXClassShortcuts
  54. #pragma mark Internal
  55. - (Class)cls {
  56. return self.object;
  57. }
  58. #pragma mark Overrides
  59. + (instancetype)forObject:(Class)cls {
  60. // These additional rows will appear at the beginning of the shortcuts section.
  61. // The methods below are written in such a way that they will not interfere
  62. // with properties/etc being registered alongside these
  63. return [self forObject:cls additionalRows:@[[FLEXBundleShortcut new], @"Live Instances"]];
  64. }
  65. - (UIViewController *)viewControllerToPushForRow:(NSInteger)row {
  66. if (row == 1) {
  67. return [FLEXInstancesViewController
  68. instancesTableViewControllerForClassName:NSStringFromClass(self.cls)
  69. ];
  70. }
  71. return [super viewControllerToPushForRow:row];
  72. }
  73. - (UITableViewCellAccessoryType)accessoryTypeForRow:(NSInteger)row {
  74. return row == 1 ? UITableViewCellAccessoryDisclosureIndicator : [super accessoryTypeForRow:row];
  75. }
  76. @end