Commits

Anonymous committed 98abd7f

BWTabViewController should support encoding

Comments (0)

Files changed (2)

BWTabViewController.h

 #endif
 
 
-@interface BWTabViewController : NSViewController <NSTabViewDelegate>
+@interface BWTabViewController : NSViewController <NSTabViewDelegate, NSCoding>
 {
   @private
     NSString        *_identifier;

BWTabViewController.m

     return [self initWithTabViewType:NSTopTabsBezelBorder];
 }
 
-- (id)initWithCoder:(NSCoder *)decoder
-{
-    if (self = [super initWithCoder:decoder])
-    {
-        [self didInit];
-    }
-    return self;
-}
-
 - (void)dealloc
 {
     [self setTabView:nil];  // releases view and tears down binding/delegation
     return result;
 }
 
+#pragma mark NSCoding
+
+- (id)initWithCoder:(NSCoder *)decoder
+{
+    if (self = [super initWithCoder:decoder])
+    {
+        [self didInit];
+    }
+    return self;
+}
+
+- (void)encodeWithCoder:(NSCoder *)aCoder
+{
+    [super encodeWithCoder:aCoder];
+    
+    [aCoder encodeObject:[self identifier] forKey:@"identifier"];
+    
+    
+    // Super should take care of encoding view if it deems necessary. A decoded View Controller should be quite able to create the views it needs, but in case a view is explicitly archived too, want to reference the specific Tab View within it.
+    if ([self isTabViewLoaded]) 
+    {
+        [aCoder encodeConditionalObject:[self tabView] forKey:@"tabView"];
+    }
+    
+    
+    // Should selection also be encoded?
+    [aCoder encodeObject:[self viewControllers] forKey:@"viewControllers"];
+}
+
+
 @end