Procházet zdrojové kódy

Push editor for readonly properties that actually have setters

There's a weird case with frame and bounds on UIView where the properties are marked as readonly but setters exist. If we can call the setter, it more useful to push an editor for properties like these.
Ryan Olson (IG) před 7 roky
rodič
revize
e07bfa8d5f

+ 1 - 1
Classes/Editing/FLEXPropertyEditorViewController.h

@@ -13,6 +13,6 @@
 
 
 - (id)initWithTarget:(id)target property:(objc_property_t)property;
 - (id)initWithTarget:(id)target property:(objc_property_t)property;
 
 
-+ (BOOL)canEditProperty:(objc_property_t)property currentValue:(id)value;
++ (BOOL)canEditProperty:(objc_property_t)property onObject:(id)object currentValue:(id)value;
 
 
 @end
 @end

+ 4 - 3
Classes/Editing/FLEXPropertyEditorViewController.m

@@ -37,7 +37,7 @@
     
     
     self.fieldEditorView.fieldDescription = [FLEXRuntimeUtility fullDescriptionForProperty:self.property];
     self.fieldEditorView.fieldDescription = [FLEXRuntimeUtility fullDescriptionForProperty:self.property];
     id currentValue = [FLEXRuntimeUtility valueForProperty:self.property onObject:self.target];
     id currentValue = [FLEXRuntimeUtility valueForProperty:self.property onObject:self.target];
-    self.setterButton.enabled = [[self class] canEditProperty:self.property currentValue:currentValue];
+    self.setterButton.enabled = [[self class] canEditProperty:self.property onObject:self.target currentValue:currentValue];
     
     
     const char *typeEncoding = [[FLEXRuntimeUtility typeEncodingForProperty:self.property] UTF8String];
     const char *typeEncoding = [[FLEXRuntimeUtility typeEncodingForProperty:self.property] UTF8String];
     FLEXArgumentInputView *inputView = [FLEXArgumentInputViewFactory argumentInputViewForTypeEncoding:typeEncoding];
     FLEXArgumentInputView *inputView = [FLEXArgumentInputViewFactory argumentInputViewForTypeEncoding:typeEncoding];
@@ -90,11 +90,12 @@
     }
     }
 }
 }
 
 
-+ (BOOL)canEditProperty:(objc_property_t)property currentValue:(id)value
++ (BOOL)canEditProperty:(objc_property_t)property onObject:(id)object currentValue:(id)value
 {
 {
     const char *typeEncoding = [[FLEXRuntimeUtility typeEncodingForProperty:property] UTF8String];
     const char *typeEncoding = [[FLEXRuntimeUtility typeEncodingForProperty:property] UTF8String];
     BOOL canEditType = [FLEXArgumentInputViewFactory canEditFieldWithTypeEncoding:typeEncoding currentValue:value];
     BOOL canEditType = [FLEXArgumentInputViewFactory canEditFieldWithTypeEncoding:typeEncoding currentValue:value];
-    BOOL isReadonly = [FLEXRuntimeUtility isReadonlyProperty:property];
+    SEL setterSelector = [FLEXRuntimeUtility setterSelectorForProperty:property];
+    BOOL isReadonly = [FLEXRuntimeUtility isReadonlyProperty:property] && (!setterSelector || ![object respondsToSelector:setterSelector]);
     return canEditType && !isReadonly;
     return canEditType && !isReadonly;
 }
 }
 
 

+ 2 - 2
Classes/ObjectExplorers/Controllers/FLEXObjectExplorerViewController.m

@@ -789,7 +789,7 @@ typedef NS_ENUM(NSUInteger, FLEXMetadataKind) {
                 FLEXPropertyBox *propertyBox = self.filteredProperties[row];
                 FLEXPropertyBox *propertyBox = self.filteredProperties[row];
                 objc_property_t property = propertyBox.property;
                 objc_property_t property = propertyBox.property;
                 id currentValue = [self valueForPropertyAtIndex:row];
                 id currentValue = [self valueForPropertyAtIndex:row];
-                BOOL canEdit = [FLEXPropertyEditorViewController canEditProperty:property currentValue:currentValue];
+                BOOL canEdit = [FLEXPropertyEditorViewController canEditProperty:property onObject:self.object currentValue:currentValue];
                 BOOL canExplore = currentValue != nil;
                 BOOL canExplore = currentValue != nil;
                 canDrillIn = canEdit || canExplore;
                 canDrillIn = canEdit || canExplore;
             }
             }
@@ -888,7 +888,7 @@ typedef NS_ENUM(NSUInteger, FLEXMetadataKind) {
             FLEXPropertyBox *propertyBox = self.filteredProperties[row];
             FLEXPropertyBox *propertyBox = self.filteredProperties[row];
             objc_property_t property = propertyBox.property;
             objc_property_t property = propertyBox.property;
             id currentValue = [self valueForPropertyAtIndex:row];
             id currentValue = [self valueForPropertyAtIndex:row];
-            if ([FLEXPropertyEditorViewController canEditProperty:property currentValue:currentValue]) {
+            if ([FLEXPropertyEditorViewController canEditProperty:property onObject:self.object currentValue:currentValue]) {
                 viewController = [[FLEXPropertyEditorViewController alloc] initWithTarget:self.object property:property];
                 viewController = [[FLEXPropertyEditorViewController alloc] initWithTarget:self.object property:property];
             } else if (currentValue) {
             } else if (currentValue) {
                 viewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:currentValue];
                 viewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:currentValue];

+ 1 - 1
Classes/ObjectExplorers/Controllers/FLEXViewExplorerViewController.m

@@ -161,7 +161,7 @@ typedef NS_ENUM(NSUInteger, FLEXViewExplorerRow) {
         objc_property_t property = [self viewPropertyForName:rowCookie];
         objc_property_t property = [self viewPropertyForName:rowCookie];
         if (property) {
         if (property) {
             id currentValue = [FLEXRuntimeUtility valueForProperty:property onObject:self.viewToExplore];
             id currentValue = [FLEXRuntimeUtility valueForProperty:property onObject:self.viewToExplore];
-            if ([FLEXPropertyEditorViewController canEditProperty:property currentValue:currentValue]) {
+            if ([FLEXPropertyEditorViewController canEditProperty:property onObject:self.viewToExplore currentValue:currentValue]) {
                 drillInViewController = [[FLEXPropertyEditorViewController alloc] initWithTarget:self.object property:property];
                 drillInViewController = [[FLEXPropertyEditorViewController alloc] initWithTarget:self.object property:property];
             } else {
             } else {
                 drillInViewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:currentValue];
                 drillInViewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:currentValue];