FLEXArgumentInputViewFactory.m 2.7 KB

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