Просмотр исходного кода

Add string argument input view so that properties with explicit NSString typing don’t require quotes.

Ryan Olson лет назад: 12
Родитель
Сommit
d4ffec2678

+ 13 - 0
Classes/Editing/Argument Input Views/FLEXArgumentInputStringView.h

@@ -0,0 +1,13 @@
+//
+//  FLEXArgumentInputStringView.h
+//  Flipboard
+//
+//  Created by Ryan Olson on 6/28/14.
+//  Copyright (c) 2014 Flipboard. All rights reserved.
+//
+
+#import "FLEXArgumentInputTextView.h"
+
+@interface FLEXArgumentInputStringView : FLEXArgumentInputTextView
+
+@end

+ 44 - 0
Classes/Editing/Argument Input Views/FLEXArgumentInputStringView.m

@@ -0,0 +1,44 @@
+//
+//  FLEXArgumentInputStringView.m
+//  Flipboard
+//
+//  Created by Ryan Olson on 6/28/14.
+//  Copyright (c) 2014 Flipboard. All rights reserved.
+//
+
+#import "FLEXArgumentInputStringView.h"
+
+@implementation FLEXArgumentInputStringView
+
+- (instancetype)initWithArgumentTypeEncoding:(const char *)typeEncoding
+{
+    self = [super initWithArgumentTypeEncoding:typeEncoding];
+    if (self) {
+        self.targetSize = FLEXArgumentInputViewSizeLarge;
+    }
+    return self;
+}
+
+- (void)setInputValue:(id)inputValue
+{
+    self.inputTextView.text = inputValue;
+}
+
+- (id)inputValue
+{
+    // Interpret empty string as nil. We loose the ablitiy to set empty string as a string value,
+    // but we accept that tradeoff in exchange for not having to type quotes for every string.
+    return [self.inputTextView.text length] > 0 ? [self.inputTextView.text copy] : nil;
+}
+
+
+#pragma mark -
+
++ (BOOL)supportsObjCType:(const char *)type withCurrentValue:(id)value
+{
+    BOOL supported = strcmp(type, "@\"NSString\"") == 0;
+    supported = supported || (value && [value isKindOfClass:[NSString class]]);
+    return supported;
+}
+
+@end

+ 4 - 1
Classes/Editing/Argument Input Views/FLEXArgumentInputViewFactory.m

@@ -13,6 +13,7 @@
 #import "FLEXArgumentInputSwitchView.h"
 #import "FLEXArgumentInputStructView.h"
 #import "FLEXArgumentInputNotSupportedView.h"
+#import "FLEXArgumentInputStringView.h"
 
 @implementation FLEXArgumentInputViewFactory
 
@@ -34,7 +35,9 @@
     // Note that order is important here since multiple subclasses may support the same type.
     // An example is the number subclass and the bool subclass for the type @encode(BOOL).
     // Both work, but we'd prefer to use the bool subclass.
-    if ([FLEXArgumentInputStructView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
+    if ([FLEXArgumentInputStringView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
+        argumentInputViewSubclass = [FLEXArgumentInputStringView class];
+    } else if ([FLEXArgumentInputStructView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
         argumentInputViewSubclass = [FLEXArgumentInputStructView class];
     } else if ([FLEXArgumentInputSwitchView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
         argumentInputViewSubclass = [FLEXArgumentInputSwitchView class];