FLEXArgumentInputViewFactory.m 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. @implementation FLEXArgumentInputViewFactory
  19. + (FLEXArgumentInputView *)argumentInputViewForTypeEncoding:(const char *)typeEncoding
  20. {
  21. Class subclass = [self argumentInputViewSubclassForTypeEncoding:typeEncoding currentValue:nil];
  22. if (!subclass) {
  23. // Fall back to a FLEXArgumentInputNotSupportedView if we can't find a subclass that fits the type encoding.
  24. // The unsupported view shows "nil" and does not allow user input.
  25. subclass = [FLEXArgumentInputNotSupportedView class];
  26. }
  27. return [[subclass alloc] initWithArgumentTypeEncoding:typeEncoding];
  28. }
  29. + (Class)argumentInputViewSubclassForTypeEncoding:(const char *)typeEncoding currentValue:(id)currentValue
  30. {
  31. Class argumentInputViewSubclass = nil;
  32. // Note that order is important here since multiple subclasses may support the same type.
  33. // An example is the number subclass and the bool subclass for the type @encode(BOOL).
  34. // Both work, but we'd prefer to use the bool subclass.
  35. if ([FLEXArgumentInputColorView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  36. argumentInputViewSubclass = [FLEXArgumentInputColorView class];
  37. } else if ([FLEXArgumentInputFontView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  38. argumentInputViewSubclass = [FLEXArgumentInputFontView class];
  39. } else if ([FLEXArgumentInputStringView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  40. argumentInputViewSubclass = [FLEXArgumentInputStringView class];
  41. } else if ([FLEXArgumentInputStructView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  42. argumentInputViewSubclass = [FLEXArgumentInputStructView class];
  43. } else if ([FLEXArgumentInputSwitchView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  44. argumentInputViewSubclass = [FLEXArgumentInputSwitchView class];
  45. } else if ([FLEXArgumentInputNumberView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  46. argumentInputViewSubclass = [FLEXArgumentInputNumberView class];
  47. } else if ([FLEXArgumentInputJSONObjectView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  48. argumentInputViewSubclass = [FLEXArgumentInputJSONObjectView class];
  49. }
  50. return argumentInputViewSubclass;
  51. }
  52. + (BOOL)canEditFieldWithTypeEncoding:(const char *)typeEncoding currentValue:(id)currentValue
  53. {
  54. return [self argumentInputViewSubclassForTypeEncoding:typeEncoding currentValue:currentValue] != nil;
  55. }
  56. @end