You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.1 KiB

  1. //
  2. // FLEXGlobalsEntry.m
  3. // FLEX
  4. //
  5. // Created by Javier Soto on 7/26/14.
  6. // Copyright (c) 2014 f. All rights reserved.
  7. //
  8. #import "FLEXGlobalsEntry.h"
  9. @implementation FLEXGlobalsEntry
  10. + (instancetype)entryWithEntry:(Class<FLEXGlobalsEntry>)cls row:(FLEXGlobalsRow)row
  11. {
  12. NSParameterAssert(cls);
  13. NSParameterAssert(
  14. [cls respondsToSelector:@selector(globalsEntryViewController:)] ||
  15. [cls respondsToSelector:@selector(globalsEntryRowAction:)]
  16. );
  17. FLEXGlobalsEntry *entry = [self new];
  18. entry->_entryNameFuture = ^{ return [cls globalsEntryTitle:row]; };
  19. if ([cls respondsToSelector:@selector(globalsEntryViewController:)]) {
  20. entry->_viewControllerFuture = ^{ return [cls globalsEntryViewController:row]; };
  21. } else {
  22. entry->_rowAction = [cls globalsEntryRowAction:row];
  23. }
  24. return entry;
  25. }
  26. + (instancetype)entryWithNameFuture:(FLEXGlobalsEntryNameFuture)nameFuture
  27. viewControllerFuture:(FLEXGlobalsTableViewControllerViewControllerFuture)viewControllerFuture
  28. {
  29. NSParameterAssert(nameFuture);
  30. NSParameterAssert(viewControllerFuture);
  31. FLEXGlobalsEntry *entry = [self new];
  32. entry->_entryNameFuture = [nameFuture copy];
  33. entry->_viewControllerFuture = [viewControllerFuture copy];
  34. return entry;
  35. }
  36. + (instancetype)entryWithNameFuture:(FLEXGlobalsEntryNameFuture)nameFuture
  37. action:(FLEXGlobalsTableViewControllerRowAction)rowSelectedAction
  38. {
  39. NSParameterAssert(nameFuture);
  40. NSParameterAssert(rowSelectedAction);
  41. FLEXGlobalsEntry *entry = [self new];
  42. entry->_entryNameFuture = [nameFuture copy];
  43. entry->_rowAction = [rowSelectedAction copy];
  44. return entry;
  45. }
  46. #pragma mark FLEXPatternMatching
  47. - (BOOL)matches:(NSString *)query
  48. {
  49. return [self.entryNameFuture() localizedCaseInsensitiveContainsString:query];
  50. }
  51. @end
  52. #pragma mark - flex_concreteGlobalsEntry
  53. @implementation NSObject (FLEXGlobalsEntry)
  54. + (FLEXGlobalsEntry *)flex_concreteGlobalsEntry:(FLEXGlobalsRow)row {
  55. if ([self conformsToProtocol:@protocol(FLEXGlobalsEntry)]) {
  56. return [FLEXGlobalsEntry entryWithEntry:self row:row];
  57. }
  58. return nil;
  59. }
  60. @end