FLEXArgumentInputViewFactory.m 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // FLEXArgumentInputViewFactory.m
  3. // FLEXInjected
  4. //
  5. // Created by Ryan Olson on 6/15/14.
  6. //
  7. //
  8. #import "FLEXArgumentInputViewFactory.h"
  9. #import "FLEXArgumentInputView.h"
  10. #import "FLEXArgumentInputJSONObjectView.h"
  11. #import "FLEXArgumentInputNumberView.h"
  12. #import "FLEXArgumentInputSwitchView.h"
  13. #import "FLEXArgumentInputStructView.h"
  14. #import "FLEXArgumentInputNotSupportedView.h"
  15. #import "FLEXArgumentInputStringView.h"
  16. #import "FLEXArgumentInputFontView.h"
  17. #import "FLEXArgumentInputColorView.h"
  18. #import "FLEXArgumentInputDateView.h"
  19. @implementation FLEXArgumentInputViewFactory
  20. + (FLEXArgumentInputView *)argumentInputViewForTypeEncoding:(const char *)typeEncoding
  21. {
  22. return [self argumentInputViewForTypeEncoding:typeEncoding currentValue:nil];
  23. }
  24. + (FLEXArgumentInputView *)argumentInputViewForTypeEncoding:(const char *)typeEncoding currentValue:(id)currentValue
  25. {
  26. Class subclass = [self argumentInputViewSubclassForTypeEncoding:typeEncoding currentValue:currentValue];
  27. if (!subclass) {
  28. // Fall back to a FLEXArgumentInputNotSupportedView if we can't find a subclass that fits the type encoding.
  29. // The unsupported view shows "nil" and does not allow user input.
  30. subclass = [FLEXArgumentInputNotSupportedView class];
  31. }
  32. return [[subclass alloc] initWithArgumentTypeEncoding:typeEncoding];
  33. }
  34. + (Class)argumentInputViewSubclassForTypeEncoding:(const char *)typeEncoding currentValue:(id)currentValue
  35. {
  36. Class argumentInputViewSubclass = nil;
  37. // Note that order is important here since multiple subclasses may support the same type.
  38. // An example is the number subclass and the bool subclass for the type @encode(BOOL).
  39. // Both work, but we'd prefer to use the bool subclass.
  40. if ([FLEXArgumentInputColorView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  41. argumentInputViewSubclass = [FLEXArgumentInputColorView class];
  42. } else if ([FLEXArgumentInputFontView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  43. argumentInputViewSubclass = [FLEXArgumentInputFontView class];
  44. } else if ([FLEXArgumentInputStringView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  45. argumentInputViewSubclass = [FLEXArgumentInputStringView class];
  46. } else if ([FLEXArgumentInputStructView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  47. argumentInputViewSubclass = [FLEXArgumentInputStructView class];
  48. } else if ([FLEXArgumentInputSwitchView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  49. argumentInputViewSubclass = [FLEXArgumentInputSwitchView class];
  50. } else if ([FLEXArgumentInputDateView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  51. argumentInputViewSubclass = [FLEXArgumentInputDateView class];
  52. } else if ([FLEXArgumentInputNumberView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  53. argumentInputViewSubclass = [FLEXArgumentInputNumberView class];
  54. } else if ([FLEXArgumentInputJSONObjectView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  55. argumentInputViewSubclass = [FLEXArgumentInputJSONObjectView class];
  56. }
  57. return argumentInputViewSubclass;
  58. }
  59. + (BOOL)canEditFieldWithTypeEncoding:(const char *)typeEncoding currentValue:(id)currentValue
  60. {
  61. return [self argumentInputViewSubclassForTypeEncoding:typeEncoding currentValue:currentValue] != nil;
  62. }
  63. @end