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.

69 lines
2.8 KiB

  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. NSArray<Class> *inputViewClasses = @[[FLEXArgumentInputColorView class],
  38. [FLEXArgumentInputFontView class],
  39. [FLEXArgumentInputStringView class],
  40. [FLEXArgumentInputStructView class],
  41. [FLEXArgumentInputSwitchView class],
  42. [FLEXArgumentInputDateView class],
  43. [FLEXArgumentInputNumberView class],
  44. [FLEXArgumentInputJSONObjectView class]];
  45. // Note that order is important here since multiple subclasses may support the same type.
  46. // An example is the number subclass and the bool subclass for the type @encode(BOOL).
  47. // Both work, but we'd prefer to use the bool subclass.
  48. for (Class inputView in inputViewClasses) {
  49. if ([inputView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  50. argumentInputViewSubclass = inputView;
  51. break;
  52. }
  53. }
  54. return argumentInputViewSubclass;
  55. }
  56. + (BOOL)canEditFieldWithTypeEncoding:(const char *)typeEncoding currentValue:(id)currentValue
  57. {
  58. return [self argumentInputViewSubclassForTypeEncoding:typeEncoding currentValue:currentValue] != nil;
  59. }
  60. @end