API  1.0.0
CPController.j
Go to the documentation of this file.
1 //
2 // CPController.j
3 // AppKit
4 //
5 // Created by Ross Boucher 1/15/09
6 // Copyright 280 North
7 //
8 // Adapted from GNUStep
9 // Copyright (C) 2007 Free Software Foundation, Inc
10 // Released under the LGPL.
11 //
12 
13 
14 
15 var CPControllerDeclaredKeysKey = @"CPControllerDeclaredKeysKey";
16 
17 @implementation CPController : CPObject
18 {
19  CPArray _editors;
20  CPArray _declaredKeys;
21 }
22 
23 - (id)init
24 {
25  self = [super init];
26 
27  if (self)
28  {
29  _editors = [];
30  _declaredKeys = [];
31  }
32 
33  return self;
34 }
35 
36 - (void)encodeWithCoder:(CPCoder)aCoder
37 {
38  if ([_declaredKeys count] > 0)
39  [aCoder encodeObject:_declaredKeys forKey:CPControllerDeclaredKeysKey];
40 }
41 
42 - (id)initWithCoder:(CPCoder)aDecoder
43 {
44  self = [super init];
45 
46  if (self)
47  {
48  _editors = [];
49  _declaredKeys = [aDecoder decodeObjectForKey:CPControllerDeclaredKeysKey] || [];
50  }
51 
52  return self;
53 }
54 
55 - (BOOL)isEditing
56 {
57  return [_editors count] > 0;
58 }
59 
60 - (BOOL)commitEditing
61 {
62  var index = 0,
63  count = _editors.length;
64 
65  for (; index < count; ++index)
66  if (![[_editors objectAtIndex:index] commitEditing])
67  return NO;
68 
69  return YES;
70 }
71 
72 - (void)discardEditing
73 {
74  [_editors makeObjectsPerformSelector:@selector(discardEditing)];
75 }
76 
77 - (void)objectDidBeginEditing:(id)anEditor
78 {
79  [_editors addObject:anEditor];
80 }
81 
82 - (void)objectDidEndEditing:(id)anEditor
83 {
84  [_editors removeObject:anEditor];
85 }
86 
87 @end
id init()
Definition: CALayer.j:126
var CPControllerDeclaredKeysKey
Definition: CPController.j:15
Defines methods for use when archiving & restoring (enc/decoding).
Definition: CPCoder.h:2
id init()
Definition: CPObject.j:145