NSEditor and NSEditorRegistration

31 views
Skip to first unread message

Andy Balholm

unread,
Jul 3, 2009, 10:52:28 AM7/3/09
to cocotr...@googlegroups.com
This patch adds the NSEditor and NSEditorRegistration protocols, and implementations of NSEditor (for NSControl and NSController) and of NSEditorRegistration (for NSController).

I put the declarations of the protocols in NSObject+BindingSupport.h . I'm not sure if that's really the best place to put them. Apple declares them in NSKeyValueBinding.h.

Is my implementation of -[NSControl commitEditing] correct?

NSEditor.diff

Supreme Cocotron Committee

unread,
Jul 3, 2009, 11:21:17 AM7/3/09
to Cocotron Developers
Hi Andy,

I don't think the group system allows attachments, if there was one it
got removed.

All patches should be submitted at http://code.google.com/p/cocotron/issues/list
this allows us to track the status more easily than group messages.
Issue updates are then relayed to the group.


Thanks!

Chris

Andy Balholm

unread,
Jul 3, 2009, 12:24:05 PM7/3/09
to cocotr...@googlegroups.com
Hi Chris,

I have e-mail but I don't have web access. So I don't know how I can
put my patches in the bug-tracking system. Do you have any suggestions?

Here is what was in my attachment. The attachment came through fine,
since I get the group messages by e-mail. But maybe it doesn't show up
if you access the group messages on the web site.

diff --git a/AppKit/NSControl.m b/AppKit/NSControl.m
index 2af7f82..0302d44 100755
--- a/AppKit/NSControl.m
+++ b/AppKit/NSControl.m
@@ -15,6 +15,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY
OF ANY KIND, EXPRESS OR IMPLI
#import <AppKit/NSClipView.h>
#import <Foundation/NSKeyedArchiver.h>
#import <AppKit/NSRaise.h>
+#import <AppKit/NSObject+BindingSupport.h>

NSString
*NSControlTextDidBeginEditingNotification
=@"NSControlTextDidBeginEditingNotification";
NSString
*NSControlTextDidChangeNotification
=@"NSControlTextDidChangeNotification";
@@ -366,6 +367,15 @@ static NSMutableDictionary *cellClassDictionary =
nil;

[[NSNotificationCenter defaultCenter]
postNotificationName:NSControlTextDidBeginEditingNotification
object:self userInfo:[NSDictionary dictionaryWithObject:[note
object] forKey:@"NSFieldEditor"]];
+
+ // If this control's value is bound to an object that conforms to
NSEditorRegistration, register as an editor.
+ NSDictionary * bindingInfo = [self infoForBinding:@"value"];
+ if (bindingInfo)
+ {
+ id observedObject = [bindingInfo
objectForKey:NSObservedObjectKey];
+ if ([observedObject
respondsToSelector:@selector(objectDidBeginEditing:)])
+ [observedObject objectDidBeginEditing:self];
+ }
}

-(void)textDidChange:(NSNotification *)note {
@@ -390,6 +400,15 @@ static NSMutableDictionary *cellClassDictionary =
nil;
[[NSNotificationCenter defaultCenter]
postNotificationName:NSControlTextDidEndEditingNotification
object:self userInfo:[NSDictionary dictionaryWithObject:[note
object] forKey:@"NSFieldEditor"]];

+ // If this control's value is bound to an object that conforms to
NSEditorRegistration, unregister as an editor.
+ NSDictionary * bindingInfo = [self infoForBinding:@"value"];
+ if (bindingInfo)
+ {
+ id observedObject = [bindingInfo
objectForKey:NSObservedObjectKey];
+ if ([observedObject
respondsToSelector:@selector(objectDidEndEditing:)])
+ [observedObject objectDidEndEditing:self];
+ }
+
[self setNeedsDisplay:YES];
}

@@ -438,4 +457,15 @@ static NSMutableDictionary *cellClassDictionary =
nil;
}
}

+// NSEditor methods
+
+-(BOOL)commitEditing {
+ [self validateEditing];
+ return YES;
+}
+
+- (void)discardEditing {
+ [self abortEditing];
+}
+
@end
diff --git a/AppKit/NSController/NSController.h b/AppKit/NSController/
NSController.h
index 0dab4e0..f155edf 100644
--- a/AppKit/NSController/NSController.h
+++ b/AppKit/NSController/NSController.h
@@ -6,6 +6,7 @@ The above copyright notice and this permission notice
shall be included in all c

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSObject.h>
+#import <Foundation/NSMutableArray.h>
#import <AppKit/AppKitExport.h>

APPKIT_EXPORT NSString *NSNoSelectionMarker;
@@ -15,7 +16,7 @@ APPKIT_EXPORT NSString *NSNotApplicableMarker;
APPKIT_EXPORT BOOL NSIsControllerMarker(id object);

@interface NSController : NSObject <NSCoding> {
-
+ NSMutableArray *_editors;
}

-(BOOL)commitEditing;
diff --git a/AppKit/NSController/NSController.m b/AppKit/NSController/
NSController.m
index 8cd637a..c2aecd0 100644
--- a/AppKit/NSController/NSController.m
+++ b/AppKit/NSController/NSController.m
@@ -32,6 +32,20 @@ BOOL NSIsControllerMarker(id object)
}
}

+-init {
+ self = [super init];
+ if (self)
+ {
+ _editors = [[NSMutableArray alloc] init];
+ }
+ return self;
+}
+
+-(void)dealloc {
+ [_editors release];
+ [super dealloc];
+}
+
-initWithCoder:(NSCoder *)coder {
NSUnimplementedMethod();
return self;
@@ -42,25 +56,35 @@ BOOL NSIsControllerMarker(id object)
}

-(BOOL)commitEditing {
- NSUnimplementedMethod();
- return NO;
+ if ([_editors count] == 0)
+ return YES;
+
+ NSEnumerator * e = [_editors objectEnumerator];
+ id editor;
+ while ((editor = [e nextObject]))
+ if ([editor commitEditing] == NO)
+ return NO;
+
+ return YES;
}

-(void)discardEditing {
- NSUnimplementedMethod();
+ NSEnumerator * e = [_editors objectEnumerator];
+ id editor;
+ while ((editor = [e nextObject]))
+ [editor discardEditing];
}

-(BOOL)isEditing {
- NSUnimplementedMethod();
- return NO;
+ return [_editors count] > 0;
}

-(void)objectDidBeginEditing:editor {
- NSUnimplementedMethod();
+ [_editors addObject:editor];
}

-(void)objectDidEndEditing:editor {
- NSUnimplementedMethod();
+ [_editors removeObject:editor];
}

@end
diff --git a/AppKit/NSKeyValueBinding/NSObject+BindingSupport.h b/
AppKit/NSKeyValueBinding/NSObject+BindingSupport.h
index 13af090..908ac96 100644
--- a/AppKit/NSKeyValueBinding/NSObject+BindingSupport.h
+++ b/AppKit/NSKeyValueBinding/NSObject+BindingSupport.h
@@ -47,6 +47,16 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY
OF ANY KIND, EXPRESS OR IMPLI
-(id)_setCurrentValueIsPlaceholder:(BOOL)isPlaceholder;
@end

+@interface NSObject (NSEditor)
+-(BOOL)commitEditing;
+-(void)discardEditing;
+@end
+
+@interface NSObject (NSEditorRegistration)
+-(void)objectDidBeginEditing:editor;
+-(void)objectDidEndEditing:editor;
+@end
+
APPKIT_EXPORT NSString* NSObservedObjectKey;
APPKIT_EXPORT NSString* NSObservedKeyPathKey;
APPKIT_EXPORT NSString* NSOptionsKey;


Andy Balholm
(509) 276-9718
an...@balholm.com

Supreme Cocotron Committee

unread,
Jul 3, 2009, 1:45:58 PM7/3/09
to Cocotron Developers
Hi Andy,

Ah, okay, yea, I do get the emails and the patches are there, so just
send them as an attachment always not as email content as they get
mangled. I'll put them in issues. If/when you get web access you can
just put them in issues directly.

Chris

Supreme Cocotron Committee

unread,
Jul 19, 2009, 12:08:09 PM7/19/09
to Cocotron Developers
This was committed in r538.
Reply all
Reply to author
Forward
0 new messages