FLEXClassShortcuts.m 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 "FLEXInstancesTableViewController.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. @implementation FLEXBundleShortcut
  17. - (NSString *)titleWith:(id)object {
  18. return @"Bundle";
  19. }
  20. - (NSString *)subtitleWith:(id)object {
  21. return [self shortNameForBundlePath:[NSBundle bundleForClass:object].executablePath];
  22. }
  23. - (UIViewController *)viewerWith:(id)object {
  24. NSBundle *bundle = [NSBundle bundleForClass:object];
  25. return [FLEXObjectExplorerFactory explorerViewControllerForObject:bundle];
  26. }
  27. - (NSString *)shortNameForBundlePath:(NSString *)imageName {
  28. NSArray<NSString *> *components = [imageName componentsSeparatedByString:@"/"];
  29. if (components.count >= 2) {
  30. return [NSString stringWithFormat:@"%@/%@",
  31. components[components.count - 2],
  32. components[components.count - 1]
  33. ];
  34. }
  35. return imageName.lastPathComponent;
  36. }
  37. - (UITableViewCellAccessoryType)accessoryTypeWith:(id)object {
  38. NSParameterAssert(object != nil);
  39. return UITableViewCellAccessoryDisclosureIndicator;
  40. }
  41. - (NSString *)customReuseIdentifierWith:(id)object {
  42. return nil;
  43. }
  44. @end
  45. @interface FLEXClassShortcuts ()
  46. @property (nonatomic, readonly) Class cls;
  47. @end
  48. @implementation FLEXClassShortcuts
  49. #pragma mark - Internal
  50. - (Class)cls {
  51. return self.object;
  52. }
  53. #pragma mark - Overrides
  54. + (instancetype)forObject:(Class)cls {
  55. // These additional rows will appear at the beginning of the shortcuts section.
  56. // The methods below are written in such a way that they will not interfere
  57. // with properties/etc being registered alongside these
  58. return [self forObject:cls additionalRows:@[[FLEXBundleShortcut new], @"Live Instances"]];
  59. }
  60. - (UIViewController *)viewControllerToPushForRow:(NSInteger)row {
  61. if (row == 1) {
  62. return [FLEXInstancesTableViewController
  63. instancesTableViewControllerForClassName:NSStringFromClass(self.cls)
  64. ];
  65. }
  66. return [super viewControllerToPushForRow:row];
  67. }
  68. - (UITableViewCellAccessoryType)accessoryTypeForRow:(NSInteger)row {
  69. return row == 1 ? UITableViewCellAccessoryDisclosureIndicator : [super accessoryTypeForRow:row];
  70. }
  71. @end