API 0.9.5
AppKit/CPController.j
Go to the documentation of this file.
00001 //
00002 // CPController.j
00003 // AppKit
00004 //
00005 // Created by Ross Boucher 1/15/09
00006 // Copyright 280 North
00007 //
00008 // Adapted from GNUStep
00009 // Copyright (C) 2007 Free Software Foundation, Inc
00010 // Released under the LGPL.
00011 //
00012 
00013 
00014 
00015 var CPControllerDeclaredKeysKey = @"CPControllerDeclaredKeysKey";
00016 
00017 @implementation CPController : CPObject
00018 {
00019     CPArray     _editors;
00020     CPArray     _declaredKeys;
00021 }
00022 
00023 - (id)init
00024 {
00025     self = [super init];
00026 
00027     if (self)
00028     {
00029         _editors = [];
00030         _declaredKeys = [];
00031     }
00032 
00033     return self;
00034 }
00035 
00036 - (void)encodeWithCoder:(CPCoder)aCoder
00037 {
00038     if ([_declaredKeys count] > 0)
00039         [aCoder encodeObject:_declaredKeys forKey:CPControllerDeclaredKeysKey];
00040 }
00041 
00042 - (id)initWithCoder:(CPCoder)aDecoder
00043 {
00044     self = [super init];
00045 
00046     if (self)
00047     {
00048         _editors = [];
00049         _declaredKeys = [aDecoder decodeObjectForKey:CPControllerDeclaredKeysKey] || [];
00050     }
00051 
00052     return self;
00053 }
00054 
00055 - (BOOL)isEditing
00056 {
00057     return [_editors count] > 0;
00058 }
00059 
00060 - (BOOL)commitEditing
00061 {
00062     var index = 0,
00063         count = _editors.length;
00064 
00065     for (; index < count; ++index)
00066         if (![[_editors objectAtIndex:i] commitEditing])
00067             return NO;
00068 
00069     return YES;
00070 }
00071 
00072 - (void)discardEditing
00073 {
00074     [_editors makeObjectsPerformSelector:@selector(discardEditing)];
00075 }
00076 
00077 - (void)objectDidBeginEditing:(id)anEditor
00078 {
00079     [_editors addObject:anEditor];
00080 }
00081 
00082 - (void)objectDidEndEditing:(id)anEditor
00083 {
00084     [_editors removeObject:anEditor];
00085 }
00086 
00087 @end
 All Classes Files Functions Variables Defines