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.

86 lines
2.7 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) 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. // TODO: check mutability and use mutableCopy if necessary;
  45. // this currently could and would assign NSArray to NSMutableArray
  46. [FLEXRuntimeUtility setValue:self.firstInputView.inputValue forIvar:self.ivar onObject:self.target];
  47. self.firstInputView.inputValue = [FLEXRuntimeUtility valueForIvar:self.ivar onObject:self.target];
  48. // Pop view controller for consistency;
  49. // property setters and method calls also pop on success.
  50. [self.navigationController popViewControllerAnimated:YES];
  51. }
  52. - (void)getterButtonPressed:(id)sender
  53. {
  54. [super getterButtonPressed:sender];
  55. id returnedObject = [FLEXRuntimeUtility valueForIvar:self.ivar onObject:self.target];
  56. [self exploreObjectOrPopViewController:returnedObject];
  57. }
  58. - (void)argumentInputViewValueDidChange:(FLEXArgumentInputView *)argumentInputView
  59. {
  60. if ([argumentInputView isKindOfClass:[FLEXArgumentInputSwitchView class]]) {
  61. [self actionButtonPressed:nil];
  62. }
  63. }
  64. + (BOOL)canEditIvar:(Ivar)ivar currentValue:(id)value
  65. {
  66. return [FLEXArgumentInputViewFactory canEditFieldWithTypeEncoding:ivar_getTypeEncoding(ivar) currentValue:value];
  67. }
  68. @end