/** EOModelerEditor.m
Compound editors subclass this to send an EOMSelectionChangeNotification and manage the selection arrays.
*/ - (void)setSelectionPath:(NSArray *)newSelection { unsigned int indexOfLast = [newSelection indexOfObject:[newSelection lastObject]]; NSRange allButLastElement; /* int i,j; printf("%@\n",NSStringFromSelector(_cmd)); for (i = 0; i < [newSelection count]; i++) { id foo = [newSelection objectAtIndex:i]; if ([foo isKindOfClass:[NSArray class]]) { printf("\t"); for (j = 0; j < [foo count]; j++) printf("%@", [[foo objectAtIndex:j] class]); printf("\n"); } else printf("%@\n", [[newSelection objectAtIndex:i] class]); } */ if (indexOfLast != NSNotFound || indexOfLast != 1) { allButLastElement.location = 0; allButLastElement.length = indexOfLast; ASSIGN(_viewedObjectPath, [newSelection subarrayWithRange:allButLastElement]); ASSIGN(_selectionWithinViewedObject, [newSelection lastObject]); } else { [[NSException exceptionWithName:@"foo" reason:@"bar" userInfo:nil] raise]; ASSIGN(_viewedObjectPath, [NSArray array]); ASSIGN(_selectionWithinViewedObject, [NSArray array]); } [self selectionDidChange]; } /**Compound editors subclass this to send an EOMSelectionChangeNotification and manage the selection arrays.
*/ - (void) setSelectionWithinViewedObject:(NSArray *) newSelection { /* int i,j; printf("%@\n",NSStringFromSelector(_cmd)); for (i = 0; i < [newSelection count]; i++) { id foo = [newSelection objectAtIndex:i]; if ([foo isKindOfClass:[NSArray class]]) { printf("\t"); for (j = 0; j < [foo count]; j++) printf("%@", [[foo objectAtIndex:j] class]); printf("\n"); } else printf("%@\n", [[newSelection objectAtIndex:i] class]); } */ ASSIGN(_selectionWithinViewedObject, newSelection); [self selectionDidChange]; } /**Compound editors subclass this to send an EOMSelectionChangeNotification and manage the selection arrays.
*/ - (void) setViewedObjectPath:(NSArray *)newPath { /* int i,j; printf("%@\n",NSStringFromSelector(_cmd)); for (i = 0; i < [newPath count]; i++) { id foo = [newPath objectAtIndex:i]; if ([foo isKindOfClass:[NSArray class]]) { printf("\t"); for (j = 0; j < [foo count]; j++) printf("%@", [[foo objectAtIndex:j] class]); printf("\n"); } else printf("%@\n", [[newPath objectAtIndex:i] class]); } */ ASSIGN(_viewedObjectPath, newPath); [self selectionDidChange]; } - (void)setStoredProceduresSelected:(BOOL)selected { _storedProceduresSelected = selected; } - (BOOL)storedProceduresSelected { if ([[_viewedObjectPath lastObject] isKindOfClass: NSClassFromString(@"EOModel")]) { return _storedProceduresSelected; } return NO; } /* viewing the selection */ - (void)viewSelectedObject { if (![_selectionWithinViewedObject count]) return; { id object = [_selectionWithinViewedObject objectAtIndex:0]; [self setSelectionPath: [[_viewedObjectPath arrayByAddingObject: object] arrayByAddingObject:[NSArray array]]]; } } - (void) activate { [EOMApp setCurrentEditor:self]; } @end @implementation EOModelerEmbedibleEditor - (void) dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; [super dealloc]; } - (id) initWithParentEditor:(EOModelerCompoundEditor *)parentEditor { if ((self = [super initWithDocument: [parentEditor document]])) { _parentEditor = parentEditor; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectionDidChange:) name:EOMSelectionChangedNotification object:[self document]]; } return self; } - (EOModelerCompoundEditor *)parentEditor { return _parentEditor; } - (void)selectionDidChange:(NSNotification *)notification { if (self == [_parentEditor activeEditor]) { [self activate]; } } /** subclasses should return YES if they can edit the current selection (should return NO if there is no selection */ - (BOOL)canSupportCurrentSelection { return NO; } /* subclasses should implement */ - (NSArray *)friendEditorClasses { return nil; } /* subclasses should implement */ - (NSView *)mainView { return nil; } - (NSString *)pathViewPreferenceHint { [self subclassResponsibility: _cmd]; return nil; } - (void)print { [self subclassResponsibility: _cmd]; } /** Returns the selection path from the parent editor */ - (NSArray *)selectionPath { return [[self parentEditor] selectionPath]; } /** Returns the viewed object path from the parent editor */ - (NSArray *) viewedObjectPath { return [[self parentEditor] viewedObjectPath]; } /** Returns the selection within the viewed object from the parent editor */ - (NSArray *)selectionWithinViewedObject { return [[self parentEditor] selectionWithinViewedObject]; } /** Forwarded to the parent editor. * This method is not called by the parent editor. * to update the selection when its changed in the parent editor, * register for EOMSelectionDidChangeNotification. */ - (void)setSelectionPath:(NSArray *)newSelection { [[self parentEditor] setSelectionPath: newSelection]; } /** Forwarded to the parent editor. * This method is not called by the parent editor. * to update the selection when its changed in the parent editor, * register for EOMSelectionDidChangeNotification. */ - (void) setSelectionWithinViewedObject:(NSArray *) newSelection { [[self parentEditor] setSelectionWithinViewedObject: newSelection]; } /** Forwarded to the parent editor. * This method is not called by the parent editor. * to update the selection when its changed in the parent editor, * register for EOMSelectionDidChangeNotification. */ - (void) setViewedObjectPath:(NSArray *)newPath { [[self parentEditor] setViewedObjectPath: newPath]; } @end