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.

83 lines
2.5 KiB

  1. //
  2. // FLEXIvarEditorViewController.m
  3. // Flipboard
  4. //
  5. // Created by Ryan Olson on 5/23/14.
  6. // Copyright (c) 2014 Flipboard. All rights reserved.
  7. //
  8. #import "FLEXIvarEditorViewController.h"
  9. #import "FLEXFieldEditorView.h"
  10. #import "FLEXRuntimeUtility.h"
  11. #import "FLEXArgumentInputView.h"
  12. #import "FLEXArgumentInputViewFactory.h"
  13. #import "FLEXArgumentInputSwitchView.h"
  14. @interface FLEXIvarEditorViewController () <FLEXArgumentInputViewDelegate>
  15. @property (nonatomic, assign) Ivar ivar;
  16. @end
  17. @implementation FLEXIvarEditorViewController
  18. - (id)initWithTarget:(id)target ivar:(Ivar)ivar
  19. {
  20. self = [super initWithTarget:target];
  21. if (self) {
  22. self.ivar = ivar;
  23. self.title = @"Instance Variable";
  24. }
  25. return self;
  26. }
  27. - (void)viewDidLoad
  28. {
  29. [super viewDidLoad];
  30. self.fieldEditorView.fieldDescription = [FLEXRuntimeUtility prettyNameForIvar:self.ivar];
  31. FLEXArgumentInputView *inputView = [FLEXArgumentInputViewFactory argumentInputViewForTypeEncoding:ivar_getTypeEncoding(self.ivar)];
  32. inputView.backgroundColor = self.view.backgroundColor;
  33. inputView.inputValue = [FLEXRuntimeUtility valueForIvar:self.ivar onObject:self.target];
  34. inputView.delegate = self;
  35. self.fieldEditorView.argumentInputViews = @[inputView];
  36. // Don't show a "set" button for switches. Set the ivar when the switch toggles.
  37. if ([inputView isKindOfClass:[FLEXArgumentInputSwitchView class]]) {
  38. self.navigationItem.rightBarButtonItem = nil;
  39. }
  40. }
  41. - (void)actionButtonPressed:(id)sender
  42. {
  43. [super actionButtonPressed:sender];
  44. [FLEXRuntimeUtility setValue:self.firstInputView.inputValue forIvar:self.ivar onObject:self.target];
  45. self.firstInputView.inputValue = [FLEXRuntimeUtility valueForIvar:self.ivar onObject:self.target];
  46. // Pop view controller for consistency;
  47. // property setters and method calls also pop on success.
  48. [self.navigationController popViewControllerAnimated:YES];
  49. }
  50. - (void)getterButtonPressed:(id)sender
  51. {
  52. [super getterButtonPressed:sender];
  53. id returnedObject = [FLEXRuntimeUtility valueForIvar:self.ivar onObject:self.target];
  54. [self exploreObjectOrPopViewController:returnedObject];
  55. }
  56. - (void)argumentInputViewValueDidChange:(FLEXArgumentInputView *)argumentInputView
  57. {
  58. if ([argumentInputView isKindOfClass:[FLEXArgumentInputSwitchView class]]) {
  59. [self actionButtonPressed:nil];
  60. }
  61. }
  62. + (BOOL)canEditIvar:(Ivar)ivar currentValue:(id)value
  63. {
  64. return [FLEXArgumentInputViewFactory canEditFieldWithTypeEncoding:ivar_getTypeEncoding(ivar) currentValue:value];
  65. }
  66. @end