/** EOModelerEditor.m
Compound editors subclass this to send an EOMSelectionChangeNotification and manage the selection arrays.
*/ - (void)setSelectionPath:(NSArray *)newSelection { NSUInteger indexOfLast = NSNotFound; NSRange allButLastElement; if ((newSelection) && ([newSelection count] > 0)) { indexOfLast = [newSelection indexOfObject:[newSelection lastObject]]; } /* 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) { ASSIGN(_viewedObjectPath, [NSArray array]); ASSIGN(_selectionWithinViewedObject, [NSArray array]); } else { allButLastElement.location = 0; allButLastElement.length = indexOfLast; ASSIGN(_viewedObjectPath, [newSelection subarrayWithRange:allButLastElement]); ASSIGN(_selectionWithinViewedObject, [newSelection lastObject]); } [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 @implementation EOModelerCompoundEditor(activation) /* * gdl2 extension. */ - (void) activateSelection { id selection; if ([[self selectionWithinViewedObject] count] == 0) return; selection = [[self selectionWithinViewedObject] objectAtIndex:0]; #if DEBUG_STUFF == 1 GSPrintf(stderr, @"viewing %@(%@)\n", NSStringFromClass([selection class]), [(EOModel *)selection name]); #endif if ([[self activeEditor] canSupportCurrentSelection]) [self activateEmbeddedEditor: [self activeEditor]]; else { NSArray *friends = [[self activeEditor] friendEditorClasses]; int editorsCount; int i,j,c; /* first look for instances of our friend classes that can support the current selection */ for (i = 0, c = [friends count]; i < c; i++) { for (j = 0,editorsCount = [_editors count]; j < editorsCount; j++) { id friendEditor = [_editors objectAtIndex:j]; id friendClass = [friends objectAtIndex:i]; if ([friendEditor isKindOfClass: friendClass]) { if ([friendEditor canSupportCurrentSelection]) { [self activateEmbeddedEditor:friendEditor]; return; } } } } /* instantiate friends to see if we can support the current selection */ for (i = 0,c = [friends count]; i < c; i++) { id friendClass = [friends objectAtIndex:i]; id friend = [[friendClass alloc] initWithParentEditor:self]; if ([friend canSupportCurrentSelection]) { [self activateEmbeddedEditor:friend]; RELEASE(friend); return; } RELEASE(friend); } /* look for any old editor this isn't very nice... * because it only works with registered editors, and we can only * register instances of editors, so a) can't load on demand non-friend * editors, or b) we should register instances of all editors */ for (i = 0, c = [_editors count]; i < c; i++) { id anEditor = [_editors objectAtIndex:i]; if ([anEditor canSupportCurrentSelection]) { [self activateEmbeddedEditor:anEditor]; return; } } } } @end