Przeglądaj źródła

Add "Get" to readwrite editor screens, fix #235

Previously you could only "Set" mutable ivars or properties. This commit adds a "Get" button to the same screen to allow you to view the current value instead. Also works in the user defaults explorer.

It may be worth considering other approaches to this entirely, such as an alert that asks you if you want to get or set the ivar/property before a new screen is even pushed, or maybe a "Get" button as an accessory view on the rows of mutable ivars/properties.
Tanner Bennett 7 lat temu
rodzic
commit
b64cd37ec6

+ 2 - 2
Classes/Editing/FLEXDefaultEditorViewController.h

@@ -6,9 +6,9 @@
 //  Copyright (c) 2014 Flipboard. All rights reserved.
 //
 
-#import "FLEXFieldEditorViewController.h"
+#import "FLEXMutableFieldEditorViewController.h"
 
-@interface FLEXDefaultEditorViewController : FLEXFieldEditorViewController
+@interface FLEXDefaultEditorViewController : FLEXMutableFieldEditorViewController
 
 - (id)initWithDefaults:(NSUserDefaults *)defaults key:(NSString *)key;
 

+ 7 - 0
Classes/Editing/FLEXDefaultEditorViewController.m

@@ -64,6 +64,13 @@
     self.firstInputView.inputValue = [self.defaults objectForKey:self.key];
 }
 
+- (void)getterButtonPressed:(id)sender
+{
+    [super getterButtonPressed:sender];
+    id returnedObject = [self.defaults objectForKey:self.key];
+    [self exploreObjectOrPopViewController:returnedObject];
+}
+
 + (BOOL)canEditDefaultWithValue:(id)currentValue
 {
     return [FLEXArgumentInputViewFactory canEditFieldWithTypeEncoding:@encode(id) currentValue:currentValue];

+ 4 - 0
Classes/Editing/FLEXFieldEditorViewController.h

@@ -22,7 +22,11 @@
 @property (nonatomic, strong, readonly) id target;
 @property (nonatomic, strong, readonly) FLEXFieldEditorView *fieldEditorView;
 @property (nonatomic, strong, readonly) UIBarButtonItem *setterButton;
+
 - (void)actionButtonPressed:(id)sender;
 - (NSString *)titleForActionButton;
+/// Pushes an explorer view controller for the given object
+/// or pops the current view controller.
+- (void)exploreObjectOrPopViewController:(id)objectOrNil;
 
 @end

+ 14 - 0
Classes/Editing/FLEXFieldEditorViewController.m

@@ -10,8 +10,10 @@
 #import "FLEXFieldEditorView.h"
 #import "FLEXRuntimeUtility.h"
 #import "FLEXUtility.h"
+#import "FLEXObjectExplorerFactory.h"
 #import "FLEXArgumentInputView.h"
 #import "FLEXArgumentInputViewFactory.h"
+#import "FLEXObjectExplorerViewController.h"
 
 @interface FLEXFieldEditorViewController () <UIScrollViewDelegate>
 
@@ -114,4 +116,16 @@
     return @"Set";
 }
 
+- (void)exploreObjectOrPopViewController:(id)objectOrNil {
+    if (objectOrNil) {
+        // For non-nil (or void) return types, push an explorer view controller to display the object
+        FLEXObjectExplorerViewController *explorerViewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:objectOrNil];
+        [self.navigationController pushViewController:explorerViewController animated:YES];
+    } else {
+        // If we didn't get a returned object but the method call succeeded,
+        // pop this view controller off the stack to indicate that the call went through.
+        [self.navigationController popViewControllerAnimated:YES];
+    }
+}
+
 @end

+ 2 - 2
Classes/Editing/FLEXIvarEditorViewController.h

@@ -6,10 +6,10 @@
 //  Copyright (c) 2014 Flipboard. All rights reserved.
 //
 
-#import "FLEXFieldEditorViewController.h"
+#import "FLEXMutableFieldEditorViewController.h"
 #import <objc/runtime.h>
 
-@interface FLEXIvarEditorViewController : FLEXFieldEditorViewController
+@interface FLEXIvarEditorViewController : FLEXMutableFieldEditorViewController
 
 - (id)initWithTarget:(id)target ivar:(Ivar)ivar;
 

+ 11 - 0
Classes/Editing/FLEXIvarEditorViewController.m

@@ -55,6 +55,17 @@
     
     [FLEXRuntimeUtility setValue:self.firstInputView.inputValue forIvar:self.ivar onObject:self.target];
     self.firstInputView.inputValue = [FLEXRuntimeUtility valueForIvar:self.ivar onObject:self.target];
+    
+    // Pop view controller for consistency;
+    // property setters and method calls also pop on success.
+    [self.navigationController popViewControllerAnimated:YES];
+}
+
+- (void)getterButtonPressed:(id)sender
+{
+    [super getterButtonPressed:sender];
+    id returnedObject = [FLEXRuntimeUtility valueForIvar:self.ivar onObject:self.target];
+    [self exploreObjectOrPopViewController:returnedObject];
 }
 
 - (void)argumentInputViewValueDidChange:(FLEXArgumentInputView *)argumentInputView

+ 1 - 9
Classes/Editing/FLEXMethodCallingViewController.m

@@ -9,8 +9,6 @@
 #import "FLEXMethodCallingViewController.h"
 #import "FLEXRuntimeUtility.h"
 #import "FLEXFieldEditorView.h"
-#import "FLEXObjectExplorerFactory.h"
-#import "FLEXObjectExplorerViewController.h"
 #import "FLEXArgumentInputView.h"
 #import "FLEXArgumentInputViewFactory.h"
 
@@ -86,14 +84,8 @@
         NSString *message = [error localizedDescription];
         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
         [alert show];
-    } else if (returnedObject) {
-        // For non-nil (or void) return types, push an explorer view controller to display the returned object
-        FLEXObjectExplorerViewController *explorerViewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:returnedObject];
-        [self.navigationController pushViewController:explorerViewController animated:YES];
     } else {
-        // If we didn't get a returned object but the method call succeeded,
-        // pop this view controller off the stack to indicate that the call went through.
-        [self.navigationController popViewControllerAnimated:YES];
+        [self exploreObjectOrPopViewController:returnedObject];
     }
 }
 

+ 18 - 0
Classes/Editing/FLEXMutableFieldEditorViewController.h

@@ -0,0 +1,18 @@
+//
+//  FLEXMutableFieldEditorViewController.h
+//  FLEX
+//
+//  Created by Tanner on 11/22/18.
+//  Copyright © 2018 Flipboard. All rights reserved.
+//
+
+#import "FLEXFieldEditorViewController.h"
+
+@interface FLEXMutableFieldEditorViewController : FLEXFieldEditorViewController
+
+@property (nonatomic, strong, readonly) UIBarButtonItem *getterButton;
+
+- (void)getterButtonPressed:(id)sender;
+- (NSString *)titleForGetterButton;
+
+@end

+ 36 - 0
Classes/Editing/FLEXMutableFieldEditorViewController.m

@@ -0,0 +1,36 @@
+//
+//  FLEXMutableFieldEditorViewController.m
+//  FLEX
+//
+//  Created by Tanner on 11/22/18.
+//  Copyright © 2018 Flipboard. All rights reserved.
+//
+
+#import "FLEXMutableFieldEditorViewController.h"
+#import "FLEXFieldEditorView.h"
+
+@interface FLEXMutableFieldEditorViewController ()
+
+@property (nonatomic, strong, readwrite) UIBarButtonItem *getterButton;
+
+@end
+
+@implementation FLEXMutableFieldEditorViewController
+
+- (void)viewDidLoad {
+    [super viewDidLoad];
+    
+    self.getterButton = [[UIBarButtonItem alloc] initWithTitle:[self titleForGetterButton] style:UIBarButtonItemStyleDone target:self action:@selector(getterButtonPressed:)];
+    self.navigationItem.rightBarButtonItems = @[self.setterButton, self.getterButton];
+}
+
+- (void)getterButtonPressed:(id)sender {
+    // Subclasses can override
+    [self.fieldEditorView endEditing:YES];
+}
+
+- (NSString *)titleForGetterButton {
+    return @"Get";
+}
+
+@end

+ 2 - 2
Classes/Editing/FLEXPropertyEditorViewController.h

@@ -6,10 +6,10 @@
 //  Copyright (c) 2014 Flipboard. All rights reserved.
 //
 
-#import "FLEXFieldEditorViewController.h"
+#import "FLEXMutableFieldEditorViewController.h"
 #import <objc/runtime.h>
 
-@interface FLEXPropertyEditorViewController : FLEXFieldEditorViewController
+@interface FLEXPropertyEditorViewController : FLEXMutableFieldEditorViewController
 
 - (id)initWithTarget:(id)target property:(objc_property_t)property;
 

+ 7 - 0
Classes/Editing/FLEXPropertyEditorViewController.m

@@ -76,6 +76,13 @@
     }
 }
 
+- (void)getterButtonPressed:(id)sender
+{
+    [super getterButtonPressed:sender];
+    id returnedObject = [FLEXRuntimeUtility valueForProperty:self.property onObject:self.target];
+    [self exploreObjectOrPopViewController:returnedObject];
+}
+
 - (void)argumentInputViewValueDidChange:(FLEXArgumentInputView *)argumentInputView
 {
     if ([argumentInputView isKindOfClass:[FLEXArgumentInputSwitchView class]]) {

+ 10 - 2
FLEX.xcodeproj/project.pbxproj

@@ -168,6 +168,8 @@
 		94AAF03A1BAF2F0300DE8760 /* FLEXKeyboardShortcutManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 942DCD821BAE0AD300DB5DC2 /* FLEXKeyboardShortcutManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		C395D6D921789BD800BEAD4D /* FLEXColorExplorerViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = C395D6D721789BD800BEAD4D /* FLEXColorExplorerViewController.h */; };
 		C395D6DA21789BD800BEAD4D /* FLEXColorExplorerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C395D6D821789BD800BEAD4D /* FLEXColorExplorerViewController.m */; };
+		C3DA55FE21A76406005DDA60 /* FLEXMutableFieldEditorViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = C3DA55FC21A76406005DDA60 /* FLEXMutableFieldEditorViewController.h */; };
+		C3DA55FF21A76406005DDA60 /* FLEXMutableFieldEditorViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C3DA55FD21A76406005DDA60 /* FLEXMutableFieldEditorViewController.m */; };
 		C3DB9F642107FC9600B46809 /* FLEXObjectRef.h in Headers */ = {isa = PBXBuildFile; fileRef = C3DB9F622107FC9600B46809 /* FLEXObjectRef.h */; };
 		C3DB9F652107FC9600B46809 /* FLEXObjectRef.m in Sources */ = {isa = PBXBuildFile; fileRef = C3DB9F632107FC9600B46809 /* FLEXObjectRef.m */; };
 /* End PBXBuildFile section */
@@ -348,6 +350,8 @@
 		94AAF0371BAF2E1F00DE8760 /* FLEXKeyboardHelpViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXKeyboardHelpViewController.m; sourceTree = "<group>"; };
 		C395D6D721789BD800BEAD4D /* FLEXColorExplorerViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FLEXColorExplorerViewController.h; sourceTree = "<group>"; };
 		C395D6D821789BD800BEAD4D /* FLEXColorExplorerViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FLEXColorExplorerViewController.m; sourceTree = "<group>"; };
+		C3DA55FC21A76406005DDA60 /* FLEXMutableFieldEditorViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FLEXMutableFieldEditorViewController.h; sourceTree = "<group>"; };
+		C3DA55FD21A76406005DDA60 /* FLEXMutableFieldEditorViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FLEXMutableFieldEditorViewController.m; sourceTree = "<group>"; };
 		C3DB9F622107FC9600B46809 /* FLEXObjectRef.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FLEXObjectRef.h; sourceTree = "<group>"; };
 		C3DB9F632107FC9600B46809 /* FLEXObjectRef.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FLEXObjectRef.m; sourceTree = "<group>"; };
 /* End PBXFileReference section */
@@ -500,12 +504,14 @@
 			isa = PBXGroup;
 			children = (
 				3A4C94671B5B21410088C3F2 /* ArgumentInputViews */,
-				3A4C94821B5B21410088C3F2 /* FLEXDefaultEditorViewController.h */,
-				3A4C94831B5B21410088C3F2 /* FLEXDefaultEditorViewController.m */,
 				3A4C94841B5B21410088C3F2 /* FLEXFieldEditorView.h */,
 				3A4C94851B5B21410088C3F2 /* FLEXFieldEditorView.m */,
 				3A4C94861B5B21410088C3F2 /* FLEXFieldEditorViewController.h */,
 				3A4C94871B5B21410088C3F2 /* FLEXFieldEditorViewController.m */,
+				C3DA55FC21A76406005DDA60 /* FLEXMutableFieldEditorViewController.h */,
+				C3DA55FD21A76406005DDA60 /* FLEXMutableFieldEditorViewController.m */,
+				3A4C94821B5B21410088C3F2 /* FLEXDefaultEditorViewController.h */,
+				3A4C94831B5B21410088C3F2 /* FLEXDefaultEditorViewController.m */,
 				3A4C94881B5B21410088C3F2 /* FLEXIvarEditorViewController.h */,
 				3A4C94891B5B21410088C3F2 /* FLEXIvarEditorViewController.m */,
 				3A4C948A1B5B21410088C3F2 /* FLEXMethodCallingViewController.h */,
@@ -701,6 +707,7 @@
 				779B1EDA1C0C4D7C001F5E49 /* FLEXTableListViewController.h in Headers */,
 				3A4C94ED1B5B21410088C3F2 /* FLEXArgumentInputColorView.h in Headers */,
 				3A4C94EB1B5B21410088C3F2 /* FLEXImagePreviewViewController.h in Headers */,
+				C3DA55FE21A76406005DDA60 /* FLEXMutableFieldEditorViewController.h in Headers */,
 				3A4C95381B5B21410088C3F2 /* FLEXNetworkRecorder.h in Headers */,
 				3A4C94251B5B20570088C3F2 /* FLEX.h in Headers */,
 				3A4C95051B5B21410088C3F2 /* FLEXArgumentInputViewFactory.h in Headers */,
@@ -902,6 +909,7 @@
 				94AAF0391BAF2E1F00DE8760 /* FLEXKeyboardHelpViewController.m in Sources */,
 				3A4C951F1B5B21410088C3F2 /* FLEXClassesTableViewController.m in Sources */,
 				3A4C94C61B5B21410088C3F2 /* FLEXArrayExplorerViewController.m in Sources */,
+				C3DA55FF21A76406005DDA60 /* FLEXMutableFieldEditorViewController.m in Sources */,
 				3A4C95081B5B21410088C3F2 /* FLEXDefaultEditorViewController.m in Sources */,
 				779B1ED11C0C4D7C001F5E49 /* FLEXMultiColumnTableView.m in Sources */,
 				3A4C94EE1B5B21410088C3F2 /* FLEXArgumentInputColorView.m in Sources */,