FLEXArgumentInputViewFactory.m 2.3 KB

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