Kaynağa Gözat

Moved the API to add user global entries to FLEXManager

Javier Soto 12 yıl önce
ebeveyn
işleme
baf02c7e63

+ 16 - 0
Classes/Explorer Toolbar/FLEXManager+Private.h

@@ -0,0 +1,16 @@
+//
+//  FLEXManager+Private.h
+//  PebbleApp
+//
+//  Created by Javier Soto on 7/26/14.
+//  Copyright (c) 2014 Pebble Technology. All rights reserved.
+//
+
+#import "FLEXManager.h"
+
+@interface FLEXManager ()
+
+/// An array of FLEXGlobalsTableViewControllerEntry objects that have been registered by the user.
+@property (nonatomic, readonly, strong) NSArray *userGlobalEntries;
+
+@end

+ 11 - 0
Classes/Explorer Toolbar/FLEXManager.h

@@ -17,4 +17,15 @@
 - (void)showExplorer;
 - (void)hideExplorer;
 
+#pragma mark - Extensions
+
+/// Adds an entry at the bottom of the list of Global State items. Call this method before this view controller is displayed.
+/// @param entryName The string to be displayed in the cell.
+/// @param objectFutureBlock When you tap on the row, information about the object returned by this block will be displayed.
+/// Passing a block that returns an object allows you to display information about an object whose actual pointer may change at runtime (e.g. +currentUser)
+/// @note This method must be called from the main thread.
+/// The objectFutureBlock will be invoked from the main thread and may return nil.
+/// @note The passed block will be copied and retain for the duration of the application, you may want to use __weak references.
+- (void)registerGlobalEntryWithName:(NSString *)entryName objectFutureBlock:(id(^)(void))objectFutureBlock;
+
 @end

+ 24 - 0
Classes/Explorer Toolbar/FLEXManager.m

@@ -9,12 +9,17 @@
 #import "FLEXManager.h"
 #import "FLEXExplorerViewController.h"
 #import "FLEXWindow.h"
+#import "FLEXGlobalsTableViewControllerEntry.h"
+#import "FLEXObjectExplorerFactory.h"
+#import "FLEXObjectExplorerViewController.h"
 
 @interface FLEXManager () <FLEXWindowEventDelegate, FLEXExplorerViewControllerDelegate>
 
 @property (nonatomic, strong) FLEXWindow *explorerWindow;
 @property (nonatomic, strong) FLEXExplorerViewController *explorerViewController;
 
+@property (nonatomic, readonly, strong) NSMutableArray *userGlobalEntries;
+
 @end
 
 @implementation FLEXManager
@@ -76,4 +81,23 @@
     [self hideExplorer];
 }
 
+
+#pragma mark - Extensions
+
+- (void)registerGlobalEntryWithName:(NSString *)entryName objectFutureBlock:(id (^)(void))objectFutureBlock
+{
+    NSParameterAssert(entryName);
+    NSParameterAssert(objectFutureBlock);
+    NSAssert([NSThread isMainThread], @"This method must be called from the main thread.");
+
+    entryName = entryName.copy;
+    FLEXGlobalsTableViewControllerEntry *entry = [FLEXGlobalsTableViewControllerEntry entryWithNameFuture:^NSString *{
+        return entryName;
+    } viewControllerFuture:^UIViewController *{
+        return [FLEXObjectExplorerFactory explorerViewControllerForObject:objectFutureBlock()];
+    }];
+
+    [self.userGlobalEntries addObject:entry];
+}
+
 @end

+ 0 - 9
Classes/Global State Explorers/FLEXGlobalsTableViewController.h

@@ -18,15 +18,6 @@
 /// We want to display debug state about the application, not about this tool.
 + (void)setApplicationWindow:(UIWindow *)applicationWindow;
 
-/// Adds an entry at the bottom of the list of Global State items. Call this method before this view controller is displayed.
-/// @param entryName The string to be displayed in the cell.
-/// @param objectFutureBlock When you tap on the row, information about the object returned by this block will be displayed.
-/// Passing a block that returns an object allows you to display information about an object whose actual pointer may change at runtime (e.g. +currentUser)
-/// @note This method must be called from the main thread.
-/// The objectFutureBlock will be invoked from the main thread and may return nil.
-/// @note The passed block will be copied and retain for the duration of the application, you may want to use __weak references.
-+ (void)registerGlobalEntryWithName:(NSString *)entryName objectFutureBlock:(id(^)(void))objectFutureBlock;
-
 @end
 
 @protocol FLEXGlobalsTableViewControllerDelegate <NSObject>

+ 2 - 17
Classes/Global State Explorers/FLEXGlobalsTableViewController.m

@@ -15,6 +15,7 @@
 #import "FLEXLiveObjectsTableViewController.h"
 #import "FLEXFileBrowserTableViewController.h"
 #import "FLEXGlobalsTableViewControllerEntry.h"
+#import "FLEXManager+Private.h"
 
 static __weak UIWindow *s_applicationWindow = nil;
 static NSMutableArray *s_globalEntries = nil;
@@ -187,7 +188,7 @@ typedef NS_ENUM(NSUInteger, FLEXGlobalsRow) {
     self = [super initWithStyle:style];
     if (self) {
         self.title = @"🌎  Global State";
-        _entries = [s_globalEntries copy];
+        _entries = [[s_globalEntries copy] arrayByAddingObjectsFromArray:[FLEXManager sharedManager].userGlobalEntries];
     }
     return self;
 }
@@ -199,22 +200,6 @@ typedef NS_ENUM(NSUInteger, FLEXGlobalsRow) {
     s_applicationWindow = applicationWindow;
 }
 
-+ (void)registerGlobalEntryWithName:(NSString *)entryName objectFutureBlock:(id (^)(void))objectFutureBlock
-{
-    NSParameterAssert(entryName);
-    NSParameterAssert(objectFutureBlock);
-    NSAssert([NSThread isMainThread], @"This method must be called from the main thread.");
-
-    entryName = entryName.copy;
-    FLEXGlobalsTableViewControllerEntry *entry = [FLEXGlobalsTableViewControllerEntry entryWithNameFuture:^NSString *{
-        return entryName;
-    } viewControllerFuture:^UIViewController *{
-        return [FLEXObjectExplorerFactory explorerViewControllerForObject:objectFutureBlock()];
-    }];
-
-    [s_globalEntries addObject:entry];
-}
-
 #pragma mark - UIViewController
 
 - (void)viewDidLoad

+ 2 - 0
Example/UICatalog.xcodeproj/project.pbxproj

@@ -251,6 +251,7 @@
 		944F7486197B458C009AB039 /* FLEXHierarchyTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXHierarchyTableViewController.m; sourceTree = "<group>"; };
 		944F7487197B458C009AB039 /* FLEXImagePreviewViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXImagePreviewViewController.h; sourceTree = "<group>"; };
 		944F7488197B458C009AB039 /* FLEXImagePreviewViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXImagePreviewViewController.m; sourceTree = "<group>"; };
+		D03647D51984720F007D2A1B /* FLEXManager+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "FLEXManager+Private.h"; sourceTree = "<group>"; };
 		D03647D719847248007D2A1B /* FLEXGlobalsTableViewControllerEntry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXGlobalsTableViewControllerEntry.h; sourceTree = "<group>"; };
 		D03647D819847248007D2A1B /* FLEXGlobalsTableViewControllerEntry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXGlobalsTableViewControllerEntry.m; sourceTree = "<group>"; };
 /* End PBXFileReference section */
@@ -522,6 +523,7 @@
 				944F746C197B458C009AB039 /* FLEXExplorerViewController.m */,
 				944F746D197B458C009AB039 /* FLEXManager.h */,
 				944F746E197B458C009AB039 /* FLEXManager.m */,
+				D03647D51984720F007D2A1B /* FLEXManager+Private.h */,
 				944F746F197B458C009AB039 /* FLEXToolbarItem.h */,
 				944F7470197B458C009AB039 /* FLEXToolbarItem.m */,
 				944F7471197B458C009AB039 /* FLEXWindow.h */,