FLEXViewControllerShortcuts.m 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // FLEXViewControllerShortcuts.m
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 12/12/19.
  6. // Copyright © 2020 FLEX Team. All rights reserved.
  7. //
  8. #import "FLEXViewControllerShortcuts.h"
  9. #import "FLEXObjectExplorerFactory.h"
  10. #import "FLEXRuntimeUtility.h"
  11. #import "FLEXShortcut.h"
  12. #import "FLEXAlert.h"
  13. @interface FLEXViewControllerShortcuts ()
  14. @end
  15. @implementation FLEXViewControllerShortcuts
  16. #pragma mark - Overrides
  17. + (instancetype)forObject:(UIViewController *)viewController {
  18. BOOL (^vcIsInuse)(UIViewController *) = ^BOOL(UIViewController *controller) {
  19. if (controller.viewIfLoaded.window) {
  20. return YES;
  21. }
  22. return controller.navigationController != nil;
  23. };
  24. return [self forObject:viewController additionalRows:@[
  25. [FLEXActionShortcut title:@"Push View Controller"
  26. subtitle:^NSString *(UIViewController *controller) {
  27. return vcIsInuse(controller) ? @"In use, cannot push" : nil;
  28. }
  29. selectionHandler:^void(UIViewController *host, UIViewController *controller) {
  30. if (!vcIsInuse(controller)) {
  31. [host.navigationController pushViewController:controller animated:YES];
  32. } else {
  33. [FLEXAlert
  34. showAlert:@"Cannot Push View Controller"
  35. message:@"This view controller's view is currently in use."
  36. from:host
  37. ];
  38. }
  39. }
  40. accessoryType:^UITableViewCellAccessoryType(UIViewController *controller) {
  41. if (!vcIsInuse(controller)) {
  42. return UITableViewCellAccessoryDisclosureIndicator;
  43. } else {
  44. return UITableViewCellAccessoryNone;
  45. }
  46. }
  47. ]
  48. ]];
  49. }
  50. @end