mirror of
https://github.com/gnustep/libs-gdl2.git
synced 2025-04-23 13:10:48 +00:00
* EOModeler/EOMInspector.h
* EOModeler/EOMInspector.m: Cleanups. (selectedObjects): Reimplement. (selectedObject): Return last viewed path if no selection was made. * EOModeler/EOModelerDocument.m: Reimplement. * EOModeler/EOMInspectorController.m (init): Ditto. (-_selectionChanged:): Ditto. (-_selectInspector:): Implement and renamed from selectInspector:. * EOModeler/EOModelerEditor.h * EOModeler/EOModelerEditor.m: Add documentation. (-initWithDocument:): Initialize instance variable. (-debugSelectionPath): Implement. (-[EOModelerCompoundEditor initWithDocument:]): Remove initializtation. (-[EOModelerCompoundEditor selectionDidChange]): Implement. (-[EOModelerCompoundEditor setSelectionPath:]): Call selectionDidChange instead of sending notifcation directly. (-[EOModelerCompoundEditor viewSelectedObject]): Implement. (-[EOModelerEmbedibleEditor dealloc]): Implement. (-[EOModelerEmbedibleEditor initWithParentEditor:]): Observe EOMSelectionChangedNotification. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@23396 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
bf90955152
commit
5109a54a70
7 changed files with 479 additions and 121 deletions
22
ChangeLog
22
ChangeLog
|
@ -30,6 +30,28 @@
|
|||
Implement.
|
||||
(subjectChanged): Reimplement.
|
||||
(tableViewSelectionDidChange:): Ditto.
|
||||
|
||||
* EOModeler/EOMInspector.h
|
||||
* EOModeler/EOMInspector.m: Cleanups.
|
||||
(selectedObjects): Reimplement.
|
||||
(selectedObject): Return last viewed path if no selection was made.
|
||||
* EOModeler/EOModelerDocument.m: Reimplement.
|
||||
* EOModeler/EOMInspectorController.m (init): Ditto.
|
||||
(-_selectionChanged:): Ditto.
|
||||
(-_selectInspector:): Implement and renamed from selectInspector:.
|
||||
* EOModeler/EOModelerEditor.h
|
||||
* EOModeler/EOModelerEditor.m: Add documentation.
|
||||
(-initWithDocument:): Initialize instance variable.
|
||||
(-debugSelectionPath): Implement.
|
||||
(-[EOModelerCompoundEditor initWithDocument:]): Remove
|
||||
initializtation.
|
||||
(-[EOModelerCompoundEditor selectionDidChange]): Implement.
|
||||
(-[EOModelerCompoundEditor setSelectionPath:]): Call
|
||||
selectionDidChange instead of sending notifcation directly.
|
||||
(-[EOModelerCompoundEditor viewSelectedObject]): Implement.
|
||||
(-[EOModelerEmbedibleEditor dealloc]): Implement.
|
||||
(-[EOModelerEmbedibleEditor initWithParentEditor:]): Observe
|
||||
EOMSelectionChangedNotification.
|
||||
|
||||
2006-05-09 Matt Rice <ratmice@yahoo.com>
|
||||
David Ayers <ayers@fsfe.org>
|
||||
|
|
|
@ -48,6 +48,11 @@
|
|||
- (void) prepareForDisplay;
|
||||
- (void) refresh;
|
||||
- (id) selectedObject;
|
||||
|
||||
- (NSString *)displayName;
|
||||
- (float) displayOrder;
|
||||
- (NSImage *)image;
|
||||
- (NSImage *)hilightedImage;
|
||||
@end
|
||||
|
||||
#endif // __EOMInspector_H__
|
||||
|
|
|
@ -151,7 +151,6 @@ static NSMapTable *_inspectorsByClass;
|
|||
|
||||
- (void) load
|
||||
{
|
||||
NSLog(@"loading inspector %@",NSStringFromClass([self class]));
|
||||
if (![NSBundle loadNibNamed:NSStringFromClass([self class])
|
||||
owner: self])
|
||||
NSLog(@"failed to load: %@.gorm", NSStringFromClass([self class]));
|
||||
|
@ -189,7 +188,11 @@ static NSMapTable *_inspectorsByClass;
|
|||
|
||||
- (NSArray *) selectedObjects
|
||||
{
|
||||
return [[EOMApp currentEditor] selectionWithinViewedObject];
|
||||
NSArray *sel = [[EOMApp currentEditor] selectionWithinViewedObject];
|
||||
if (![sel count])
|
||||
sel = [NSArray arrayWithObject:
|
||||
[[[EOMApp currentEditor] viewedObjectPath] lastObject]];
|
||||
return sel;
|
||||
}
|
||||
|
||||
- (id) selectedObject
|
||||
|
@ -198,8 +201,8 @@ static NSMapTable *_inspectorsByClass;
|
|||
|
||||
if ([selection count])
|
||||
return [selection objectAtIndex:0];
|
||||
|
||||
return nil;
|
||||
else
|
||||
return [[[EOMApp currentEditor] viewedObjectPath] lastObject];
|
||||
}
|
||||
|
||||
- (BOOL) isAdvanced
|
||||
|
|
|
@ -30,10 +30,11 @@
|
|||
#include <EOModeler/EOMInspectorController.h>
|
||||
#include <EOModeler/EOModelerEditor.h>
|
||||
|
||||
#include <AppKit/NSWindow.h>
|
||||
#include <AppKit/NSScrollView.h>
|
||||
#include <AppKit/NSBox.h>
|
||||
#include <AppKit/NSButtonCell.h>
|
||||
#include <AppKit/NSMatrix.h>
|
||||
#include <AppKit/NSScrollView.h>
|
||||
#include <AppKit/NSPanel.h>
|
||||
|
||||
#include <Foundation/NSNotification.h>
|
||||
#include <Foundation/NSException.h>
|
||||
|
@ -41,28 +42,55 @@
|
|||
|
||||
static EOMInspectorController *_sharedInspectorController;
|
||||
|
||||
static NSBox *_placeHolderView;
|
||||
static NSMatrix *_iconBar;
|
||||
|
||||
@interface EOMInspectorController(Private)
|
||||
- (void) _selectionChanged:(NSNotification *)notif;
|
||||
@end
|
||||
|
||||
@implementation EOMInspectorController
|
||||
|
||||
- (id) init
|
||||
{
|
||||
NSButtonCell *iconCell;
|
||||
NSSize scrollSize;
|
||||
|
||||
if (_sharedInspectorController)
|
||||
[[NSException exceptionWithName: NSInternalInconsistencyException
|
||||
reason: @"EOMInspectorController is a singleton"
|
||||
userInfo:nil] raise];
|
||||
self = [super init];
|
||||
window = [[NSWindow alloc] initWithContentRect:NSMakeRect(220, 536, 272, 388)
|
||||
scrollSize = [NSScrollView frameSizeForContentSize:NSMakeSize(256, 64)
|
||||
hasHorizontalScroller:YES
|
||||
hasVerticalScroller:NO
|
||||
borderType:NSNoBorder];
|
||||
window = [[NSPanel alloc] initWithContentRect:NSMakeRect(220, 536, 272, 388+scrollSize.height)
|
||||
styleMask:NSTitledWindowMask | NSClosableWindowMask
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:YES];
|
||||
[window setReleasedWhenClosed:NO];
|
||||
scrollView = [[NSScrollView alloc] initWithFrame: NSMakeRect(0, 0, 250, 68)];
|
||||
_placeHolderView = [[NSBox alloc] initWithFrame:NSMakeRect(0,68,250,333)];
|
||||
|
||||
[_placeHolderView setBorderType:NSNoBorder];
|
||||
|
||||
scrollView = [[NSScrollView alloc] initWithFrame: NSMakeRect(0, 388, 272, scrollSize.height)];
|
||||
scrollSize = [NSScrollView contentSizeForFrameSize:NSMakeSize(256,64)
|
||||
hasHorizontalScroller:YES
|
||||
hasVerticalScroller:NO
|
||||
borderType:NSNoBorder];
|
||||
|
||||
[scrollView setHasHorizontalScroller:YES];
|
||||
[scrollView setHasVerticalScroller:NO];
|
||||
_iconBar = [[NSMatrix alloc] initWithFrame:NSMakeRect(0, 0, 272, scrollSize.height)];
|
||||
[_iconBar setAutosizesCells:NO];
|
||||
[_iconBar setCellSize:NSMakeSize(64,64)];
|
||||
[_iconBar setTarget:self];
|
||||
[_iconBar setAction:@selector(_selectInspector:)];
|
||||
iconCell = [[NSButtonCell alloc] initTextCell:@""];
|
||||
[iconCell setButtonType:NSMomentaryPushInButton];
|
||||
[iconCell setImagePosition:NSImageOnly];
|
||||
[_iconBar setPrototype:iconCell];
|
||||
[scrollView setDocumentView: _iconBar];
|
||||
|
||||
[[window contentView] addSubview: scrollView];
|
||||
|
||||
_sharedInspectorController = self;
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
|
@ -71,7 +99,6 @@ static NSBox *_placeHolderView;
|
|||
name:EOMSelectionChangedNotification
|
||||
object:nil];
|
||||
|
||||
[[window contentView] addSubview: scrollView];
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -96,24 +123,56 @@ static NSBox *_placeHolderView;
|
|||
|
||||
- (void) _selectionChanged:(NSNotification *)notif
|
||||
{
|
||||
/* load the highest ordered inspector for the new selection
|
||||
* if the current inspector can support the object, select it instead. */
|
||||
NSArray *selection = [[EOMApp currentEditor] selectionWithinViewedObject];
|
||||
NSArray *swvop = [[EOMApp currentEditor] selectionWithinViewedObject];
|
||||
id inspector;
|
||||
|
||||
|
||||
if ([selection count])
|
||||
if ([swvop count])
|
||||
{
|
||||
NSArray *inspectors = [EOMInspector allInspectorsThatCanInspectObject: [selection objectAtIndex:0]];
|
||||
/* inspectors is ordered in the lowest -displayOrder first. */
|
||||
id selection = [swvop objectAtIndex:0];
|
||||
NSArray *inspectors;
|
||||
int i, c;
|
||||
|
||||
if ([inspectors count])
|
||||
inspectors = [EOMInspector allInspectorsThatCanInspectObject: selection];
|
||||
c = [inspectors count];
|
||||
[_iconBar renewRows:1 columns:c];
|
||||
[_iconBar setNeedsDisplay:YES];
|
||||
|
||||
if (c)
|
||||
{
|
||||
inspector = [inspectors objectAtIndex:0];
|
||||
[inspector prepareForDisplay];
|
||||
if ([lastInspector view])
|
||||
[[window contentView] removeSubview:[lastInspector view]];
|
||||
for (i = 0; i < c; i++)
|
||||
{
|
||||
NSCell *aCell = [_iconBar cellAtRow:0 column:i];
|
||||
inspector = [inspectors objectAtIndex:i];
|
||||
|
||||
[aCell setImage:[inspector image]];
|
||||
[aCell setRepresentedObject:inspector];
|
||||
}
|
||||
|
||||
[_iconBar setNeedsDisplay:YES];
|
||||
|
||||
/* if the current inspector can support the object,
|
||||
select it instead. Otherwise select the first inspector.
|
||||
*/
|
||||
if ([inspectors containsObject:lastInspector])
|
||||
{
|
||||
inspector = lastInspector;
|
||||
[inspector prepareForDisplay];
|
||||
}
|
||||
else
|
||||
{
|
||||
inspector = [inspectors objectAtIndex:0];
|
||||
[inspector prepareForDisplay];
|
||||
|
||||
if ([lastInspector view] && lastInspector != inspector)
|
||||
[[window contentView] removeSubview:[lastInspector view]];
|
||||
|
||||
if ([inspector view])
|
||||
[[window contentView] addSubview:[inspector view]];
|
||||
if ([inspector view] && lastInspector != inspector)
|
||||
[[window contentView] addSubview:[inspector view]];
|
||||
|
||||
[window setTitle:[inspector displayName]];
|
||||
}
|
||||
|
||||
[[inspector view] setNeedsDisplay:YES];
|
||||
[inspector refresh];
|
||||
|
@ -132,9 +191,22 @@ static NSBox *_placeHolderView;
|
|||
}
|
||||
}
|
||||
|
||||
- (void) selectInspector:(id)sender
|
||||
- (void) _selectInspector:(id)sender
|
||||
{
|
||||
EOMInspector *inspector = [[sender selectedCell] representedObject];
|
||||
|
||||
[inspector prepareForDisplay];
|
||||
|
||||
if ([lastInspector view] && lastInspector != inspector)
|
||||
[[window contentView] removeSubview:[lastInspector view]];
|
||||
|
||||
if ([inspector view] && lastInspector != inspector)
|
||||
[[window contentView] addSubview:[inspector view]];
|
||||
|
||||
[[inspector view] setNeedsDisplay:YES];
|
||||
[inspector refresh];
|
||||
|
||||
lastInspector = inspector;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -25,10 +25,14 @@
|
|||
</license>
|
||||
**/
|
||||
|
||||
#include "EOModeler/EODefines.h"
|
||||
#include "EOModeler/EOModelerDocument.h"
|
||||
#include "EOModeler/EOModelerEditor.h"
|
||||
#include "EOModeler/EOModelerApp.h"
|
||||
|
||||
#include <AppKit/NSMenuItem.h>
|
||||
#include <AppKit/NSOpenPanel.h>
|
||||
#include <Foundation/NSUndoManager.h>
|
||||
#include <Foundation/NSNotification.h>
|
||||
|
||||
#include <EOInterface/EODisplayGroup.h>
|
||||
|
||||
#include <EOAccess/EOAdaptor.h>
|
||||
|
@ -41,13 +45,18 @@
|
|||
#include <EOControl/EOEditingContext.h>
|
||||
|
||||
#include <Foundation/NSAttributedString.h>
|
||||
#include <Foundation/NSRunLoop.h>
|
||||
#include <Foundation/NSCharacterSet.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSNotification.h>
|
||||
#include <Foundation/NSUndoManager.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
|
||||
#include "EOModeler/EODefines.h"
|
||||
#include "EOModeler/EOModelerDocument.h"
|
||||
#include "EOModeler/EOModelerEditor.h"
|
||||
#include "EOModeler/EOModelerApp.h"
|
||||
@interface ConsistencyResults : NSObject
|
||||
+ (id) sharedConsistencyPanel;
|
||||
- (int) showConsistencyCheckResults:(id)sender cancelButton:(BOOL)useCancel
|
||||
showOnSuccess:(BOOL)flag;
|
||||
@end
|
||||
|
||||
static Class _defaultEditorClass;
|
||||
static EOModelerEditor *_currentEditorForDocument;
|
||||
|
@ -76,13 +85,6 @@ NSString *EOMCheckConsistencyForModelNotification =
|
|||
@"EOMCheckConsistencyForModelNotification";
|
||||
NSString *EOMConsistencyModelObjectKey = @"EOMConsistencyModelObjectKey";
|
||||
|
||||
/* private methods for the consistency checker implemented in DBModeler */
|
||||
@interface NSObject (DBModelerPrivate)
|
||||
- (void) showConsistencyCheckResults:(id)sender
|
||||
cancelButton:(BOOL)foo
|
||||
showOnSuccess:(BOOL)bar;
|
||||
@end
|
||||
|
||||
@interface EOModelerApp (PrivateStuff)
|
||||
- (void) _setActiveDocument:(EOModelerDocument *)newDocument;
|
||||
@end
|
||||
|
@ -94,7 +96,7 @@ showOnSuccess:(BOOL)bar;
|
|||
- (id) firstSelectionOfClass:(Class)aClass
|
||||
{
|
||||
unsigned i, c;
|
||||
id obj;
|
||||
id obj = nil;
|
||||
for (i = 0, c = [self count]; i < c; i++)
|
||||
{
|
||||
obj = [self objectAtIndex:i];
|
||||
|
@ -137,8 +139,11 @@ showOnSuccess:(BOOL)bar;
|
|||
if ([[menuItem title] isEqualToString:@"Add attribute"])
|
||||
return ([selection firstSelectionOfClass:[EOEntity class]] != nil);
|
||||
else if ([[menuItem title] isEqualToString:@"Add relationship"])
|
||||
return ([selection firstSelectionOfClass:[EOAttribute class]] != nil);
|
||||
|
||||
return ([selection firstSelectionOfClass:[EOEntity class]] != nil);
|
||||
else if ([[menuItem title] isEqual:@"delete"])
|
||||
return ([[selection lastObject] count]) ? YES : NO;
|
||||
// see -delete:
|
||||
//return ([[selection lastObject] count] || [selection count] > 2) ? YES : NO;
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
@ -194,7 +199,27 @@ showOnSuccess:(BOOL)bar;
|
|||
|
||||
- (BOOL) prepareToSave
|
||||
{
|
||||
return NO; /* FIXME */
|
||||
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DisableConsistencyCheckOnSave"] == NO)
|
||||
{
|
||||
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
||||
|
||||
[center postNotificationName:EOMCheckConsistencyBeginNotification
|
||||
object:self];
|
||||
[center postNotificationName:EOMCheckConsistencyForModelNotification
|
||||
object:self
|
||||
userInfo:[NSDictionary dictionaryWithObject:[self model]
|
||||
forKey:EOMConsistencyModelObjectKey]];
|
||||
[center postNotificationName:EOMCheckConsistencyEndNotification
|
||||
object:self];
|
||||
|
||||
if ([[NSClassFromString(@"ConsistencyResults") sharedConsistencyPanel]
|
||||
showConsistencyCheckResults:self
|
||||
cancelButton:YES
|
||||
showOnSuccess:NO] == NSRunAbortedResponse)
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSString *)documentPath
|
||||
|
@ -269,9 +294,10 @@ showOnSuccess:(BOOL)bar;
|
|||
|
||||
- (void)addEntity:(id)sender
|
||||
{
|
||||
EOAttribute *attrb;
|
||||
int entityCount = [[_model entities] count];
|
||||
unsigned entityNumber;
|
||||
EOEntity *newEntity = [[EOEntity alloc] init];
|
||||
NSArray *entities = [_model entities];
|
||||
unsigned i,c;
|
||||
|
||||
if (![_editors containsObject:[EOMApp currentEditor]])
|
||||
{
|
||||
|
@ -281,25 +307,51 @@ showOnSuccess:(BOOL)bar;
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
[newEntity setName: entityCount
|
||||
? [NSString stringWithFormat: @"Entity%i",entityCount + 1]
|
||||
c = [entities count];
|
||||
entityNumber = c;
|
||||
|
||||
/* look for the largest NNNN in entity named "EntityNNNN"
|
||||
* or the total number of entities in this model whichever is greater.
|
||||
*/
|
||||
for (i = 0; i < c; i++)
|
||||
{
|
||||
NSString *name = [[entities objectAtIndex:i] name];
|
||||
|
||||
if ([name hasPrefix:@"Entity"])
|
||||
{
|
||||
NSRange range;
|
||||
unsigned tmp;
|
||||
|
||||
name = [name substringFromIndex:6];
|
||||
range = [name rangeOfCharacterFromSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]];
|
||||
if (!(range.location == NSNotFound) && !(range.length == 0))
|
||||
continue;
|
||||
range = [name rangeOfCharacterFromSet:[NSCharacterSet decimalDigitCharacterSet]];
|
||||
if (!(range.location == NSNotFound) && !(range.length == 0))
|
||||
{
|
||||
tmp = [name intValue];
|
||||
entityNumber = (entityNumber < ++tmp) ? tmp : entityNumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[newEntity setName: entityNumber
|
||||
? [NSString stringWithFormat: @"Entity%i",entityNumber]
|
||||
: @"Entity"];
|
||||
[newEntity setClassName:@"EOGenericRecord"];
|
||||
attrb = [EOAttribute new];
|
||||
[attrb setName:@"Attribute"];
|
||||
[newEntity addAttribute:attrb];
|
||||
[_editingContext insertObject:newEntity];
|
||||
[_model addEntity:AUTORELEASE(newEntity)];
|
||||
[(EOModelerCompoundEditor *)[EOMApp currentEditor] viewSelectedObject];
|
||||
[(EOModelerCompoundEditor *)[EOMApp currentEditor] setSelectionWithinViewedObject:[NSArray arrayWithObject:newEntity]];
|
||||
}
|
||||
|
||||
- (void)addAttribute:(id)sender
|
||||
{
|
||||
EOAttribute *attrb;
|
||||
EOModelerEditor *currEd = [EOMApp currentEditor];
|
||||
int attributeCount;
|
||||
unsigned int attributeNumber;
|
||||
EOEntity *entityObject;
|
||||
NSArray *attributes;
|
||||
int i,c;
|
||||
|
||||
/* the currentEditor must be in this document */
|
||||
if (![_editors containsObject:currEd])
|
||||
|
@ -311,15 +363,49 @@ showOnSuccess:(BOOL)bar;
|
|||
}
|
||||
|
||||
entityObject = [[currEd selectionPath] firstSelectionOfClass:[EOEntity class]];
|
||||
attributeCount = [[entityObject attributes] count];
|
||||
|
||||
|
||||
attributes = [entityObject attributes];
|
||||
c = [attributes count];
|
||||
attributeNumber = c;
|
||||
|
||||
/* look for the largest NNNN in attribute named "AttributeNNNN"
|
||||
* or the total number of attributes in this entity whichever is greater.
|
||||
*/
|
||||
for (i = 0; i < c; i++)
|
||||
{
|
||||
NSString *name = [[attributes objectAtIndex:i] name];
|
||||
|
||||
if ([name hasPrefix:@"Attribute"])
|
||||
{
|
||||
NSRange range;
|
||||
unsigned tmp;
|
||||
|
||||
name = [name substringFromIndex:9];
|
||||
range = [name rangeOfCharacterFromSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]];
|
||||
if (!(range.location == NSNotFound) && !(range.length == 0))
|
||||
continue;
|
||||
range = [name rangeOfCharacterFromSet:[NSCharacterSet decimalDigitCharacterSet]];
|
||||
if (!(range.location == NSNotFound) && !(range.length == 0))
|
||||
{
|
||||
tmp = [name intValue];
|
||||
attributeNumber = (attributeNumber < ++tmp) ? tmp : attributeNumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
attrb = [[EOAttribute alloc] init];
|
||||
[attrb setName: attributeCount ? [NSString stringWithFormat: @"Attribute%i", attributeCount + 1] : @"Attribute"];
|
||||
[attrb setName: attributeNumber
|
||||
? [NSString stringWithFormat: @"Attribute%i",
|
||||
attributeNumber]
|
||||
: @"Attribute"];
|
||||
[entityObject addAttribute:attrb];
|
||||
[_editingContext insertObject:attrb];
|
||||
//[[(EOModelerCompoundEditor *)[EOMApp currentEditor] activeEditor] setSelectionWithinViewedObject:[NSArray arrayWithObject: entityObject]];
|
||||
[[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow:0.001]];
|
||||
[(EOModelerCompoundEditor *)[EOMApp currentEditor] viewSelectedObject];
|
||||
|
||||
if ([[[EOMApp currentEditor] selectionWithinViewedObject] count]
|
||||
&& [[[[EOMApp currentEditor] selectionWithinViewedObject] objectAtIndex:0] isKindOfClass:[EOEntity class]])
|
||||
[(EOModelerCompoundEditor *)[EOMApp currentEditor] viewSelectedObject];
|
||||
|
||||
[(EOModelerCompoundEditor *)[EOMApp currentEditor] setSelectionWithinViewedObject:[NSArray arrayWithObject:attrb]];
|
||||
}
|
||||
|
||||
- (void)addRelationship:(id)sender
|
||||
|
@ -327,7 +413,8 @@ showOnSuccess:(BOOL)bar;
|
|||
EORelationship *newRel;
|
||||
EOEntity *srcEntity;
|
||||
EOModelerEditor *currentEditor = [EOMApp currentEditor];
|
||||
int count;
|
||||
NSArray *relationships;
|
||||
int relationshipNum, i, c;
|
||||
|
||||
if (![_editors containsObject:currentEditor])
|
||||
{
|
||||
|
@ -339,35 +426,123 @@ showOnSuccess:(BOOL)bar;
|
|||
|
||||
srcEntity = [[currentEditor selectionPath]
|
||||
firstSelectionOfClass:[EOEntity class]];
|
||||
count = [[srcEntity relationships] count];
|
||||
relationships = [srcEntity relationships];
|
||||
c = [relationships count];
|
||||
relationshipNum = c;
|
||||
|
||||
/* look for the largest NNNN in relationships named "RelationshipNNNN"
|
||||
* or the total number of relationships in this attribute whichever is greater
|
||||
*/
|
||||
for (i = 0; i < c; i++)
|
||||
{
|
||||
NSString *name = [[relationships objectAtIndex:i] name];
|
||||
|
||||
if ([name hasPrefix:@"Relationship"])
|
||||
{
|
||||
NSRange range;
|
||||
unsigned tmp;
|
||||
|
||||
name = [name substringFromIndex:12];
|
||||
range = [name rangeOfCharacterFromSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]];
|
||||
if (!(range.location == NSNotFound) && !(range.length == 0))
|
||||
continue;
|
||||
range = [name rangeOfCharacterFromSet:[NSCharacterSet decimalDigitCharacterSet]];
|
||||
if (!(range.location == NSNotFound) && !(range.length == 0))
|
||||
{
|
||||
tmp = [name intValue];
|
||||
relationshipNum = (relationshipNum < ++tmp) ? tmp : relationshipNum;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newRel = [[EORelationship alloc] init];
|
||||
[newRel setName: count
|
||||
? [NSString stringWithFormat:@"Relationship%i", count + 1]
|
||||
[newRel setName: relationshipNum
|
||||
? [NSString stringWithFormat:@"Relationship%i", relationshipNum]
|
||||
: @"Relationship"];
|
||||
[srcEntity addRelationship:newRel];
|
||||
[_editingContext insertObject:newRel];
|
||||
[(EOModelerCompoundEditor *)[EOMApp currentEditor] viewSelectedObject];
|
||||
|
||||
if ([[[EOMApp currentEditor] selectionWithinViewedObject] count]
|
||||
&& [[[[EOMApp currentEditor] selectionWithinViewedObject] objectAtIndex:0] isKindOfClass:[EOEntity class]])
|
||||
[(EOModelerCompoundEditor *)[EOMApp currentEditor] viewSelectedObject];
|
||||
[(EOModelerCompoundEditor *)[EOMApp currentEditor] setSelectionWithinViewedObject:[NSArray arrayWithObject:newRel]];
|
||||
}
|
||||
|
||||
- (void)delete:(id)sender
|
||||
{
|
||||
NSArray *objects = [[EOMApp currentEditor] selectionWithinViewedObject];
|
||||
unsigned i,c;
|
||||
unsigned i,c = [objects count];
|
||||
|
||||
for (i = 0, c = [objects count]; i < c; i++)
|
||||
if (c == 0)
|
||||
{
|
||||
id object = [objects objectAtIndex:i];
|
||||
/*
|
||||
* if there is no selection delete the viewed object.
|
||||
*/
|
||||
/*
|
||||
this is commented out (until we have undo working?) to prevent
|
||||
accidental deletion of entities
|
||||
see also -validateMenuItem:
|
||||
id object;
|
||||
|
||||
objects = [NSMutableArray arrayWithArray:[[EOMApp currentEditor] viewedObjectPath]];
|
||||
object = [objects lastObject];
|
||||
|
||||
if ([object isKindOfClass:[EOAttribute class]])
|
||||
{
|
||||
[[object entity] removeAttribute:object];
|
||||
}
|
||||
{
|
||||
[[object entity] removeAttribute:object];
|
||||
}
|
||||
else if ([object isKindOfClass:[EOEntity class]])
|
||||
{
|
||||
[[object model] removeEntity:object];
|
||||
}
|
||||
{
|
||||
[[object model] removeEntity:object];
|
||||
}
|
||||
else if ([object isKindOfClass:[EORelationship class]])
|
||||
{
|
||||
[[object entity] removeRelationship: object];
|
||||
}
|
||||
{
|
||||
[[object entity] removeRelationship: object];
|
||||
}
|
||||
[(NSMutableArray *)objects removeObjectAtIndex:[objects count] - 1];
|
||||
[[EOMApp currentEditor] setViewedObjectPath: objects];
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0, c = [objects count]; i < c; i++)
|
||||
{
|
||||
id object = [objects objectAtIndex:i];
|
||||
|
||||
if ([object isKindOfClass:[EOAttribute class]])
|
||||
{
|
||||
NSArray *refs;
|
||||
|
||||
refs = [[[object entity] model] referencesToProperty:object];
|
||||
if (![refs count])
|
||||
[[object entity] removeAttribute:object];
|
||||
else
|
||||
{
|
||||
NSMutableString *str;
|
||||
unsigned i,c;
|
||||
str = [NSMutableString stringWithFormat:@"attribute is referenced by properties\n"];
|
||||
for (i = 0, c = [refs count]; i < c; i++)
|
||||
{
|
||||
id prop = [refs objectAtIndex:i];
|
||||
NSString *tmp;
|
||||
tmp=[NSString stringWithFormat:@"%@ in %@\n",[prop name],
|
||||
[[prop entity] name]];
|
||||
[str appendString:tmp];
|
||||
}
|
||||
|
||||
NSRunAlertPanel(@"unable to remove attribute", str, @"ok", nil, nil);
|
||||
}
|
||||
}
|
||||
else if ([object isKindOfClass:[EOEntity class]])
|
||||
{
|
||||
[[object model] removeEntity:object];
|
||||
}
|
||||
else if ([object isKindOfClass:[EORelationship class]])
|
||||
{
|
||||
[[object entity] removeRelationship: object];
|
||||
}
|
||||
}
|
||||
[[EOMApp currentEditor] setSelectionWithinViewedObject:[NSArray array]];
|
||||
}
|
||||
}
|
||||
- (void)addFetchSpecification:(id)sender
|
||||
|
@ -399,19 +574,33 @@ showOnSuccess:(BOOL)bar;
|
|||
- (void)save:(id)sender
|
||||
{
|
||||
NSString *path;
|
||||
|
||||
|
||||
path = [_model path];
|
||||
|
||||
if (!path)
|
||||
[self saveAs:self];
|
||||
{
|
||||
[self saveAs:self];
|
||||
}
|
||||
else
|
||||
[self saveToPath:path];
|
||||
{
|
||||
if ([self prepareToSave] == NO)
|
||||
return;
|
||||
[self saveToPath:path];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)saveAs:(id)sender
|
||||
{
|
||||
NSString *path;
|
||||
id savePanel = [NSSavePanel savePanel];
|
||||
int result = [savePanel runModal];
|
||||
id savePanel;
|
||||
int result;
|
||||
|
||||
if ([self prepareToSave] == NO)
|
||||
return;
|
||||
|
||||
savePanel = [NSSavePanel savePanel];
|
||||
result = [savePanel runModal];
|
||||
if (result == NSOKButton)
|
||||
{
|
||||
path = [savePanel filename];
|
||||
|
@ -479,12 +668,10 @@ showOnSuccess:(BOOL)bar;
|
|||
[EOMApp removeDocument:self];
|
||||
}
|
||||
|
||||
static id consistencyChecker;
|
||||
- (void) checkConsistency:(id)sender
|
||||
{
|
||||
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
||||
|
||||
consistencyChecker = [sender representedObject];
|
||||
[center postNotificationName:EOMCheckConsistencyBeginNotification
|
||||
object:self];
|
||||
[center postNotificationName:EOMCheckConsistencyForModelNotification
|
||||
|
@ -494,20 +681,22 @@ static id consistencyChecker;
|
|||
[center postNotificationName:EOMCheckConsistencyEndNotification
|
||||
object:self];
|
||||
|
||||
[consistencyChecker showConsistencyCheckResults:self
|
||||
cancelButton:NO
|
||||
[[NSClassFromString(@"ConsistencyResults") sharedConsistencyPanel]
|
||||
showConsistencyCheckResults:self
|
||||
cancelButton:NO
|
||||
showOnSuccess:YES];
|
||||
consistencyChecker = nil;
|
||||
}
|
||||
|
||||
- (void) appendConsistencyCheckErrorText:(NSAttributedString *)errorText
|
||||
{
|
||||
[consistencyChecker appendConsistencyCheckErrorText:errorText];
|
||||
[[NSClassFromString(@"ConsistencyResults") sharedConsistencyPanel]
|
||||
appendConsistencyCheckErrorText:errorText];
|
||||
}
|
||||
|
||||
- (void) appendConsistencyCheckSuccessText:(NSAttributedString *)successText
|
||||
{
|
||||
[consistencyChecker appendConsistencyCheckSuccessText:successText];
|
||||
[[NSClassFromString(@"ConsistencyResults") sharedConsistencyPanel]
|
||||
appendConsistencyCheckSuccessText:successText];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
@class EOModelerEmbedibleEditor;
|
||||
@class NSView;
|
||||
@class NSMutableArray;
|
||||
|
||||
@class NSNotification;
|
||||
@interface EOModelerEditor : NSObject
|
||||
{
|
||||
EOModelerDocument *_document;
|
||||
|
@ -71,6 +71,8 @@
|
|||
- (NSView *)mainView;
|
||||
- (BOOL) canSupportCurrentSelection;
|
||||
- (NSArray *)friendEditorClasses;
|
||||
- (EOModelerCompoundEditor *) parentEditor;
|
||||
- (void) selectionDidChange:(NSNotification *)notif;
|
||||
@end
|
||||
|
||||
#endif // __EOModelerEditor_H__
|
||||
|
|
|
@ -25,18 +25,21 @@
|
|||
</license>
|
||||
**/
|
||||
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSObject.h>
|
||||
|
||||
#include "EOModeler/EOModelerEditor.h"
|
||||
#include "EOModeler/EOModelerDocument.h"
|
||||
#include "EOModeler/EOModelerApp.h"
|
||||
|
||||
#include <Foundation/NSNotification.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <EOControl/EOObserver.h>
|
||||
|
||||
#include <AppKit/NSView.h>
|
||||
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSNotification.h>
|
||||
#include <Foundation/NSObject.h>
|
||||
#include <Foundation/NSRunLoop.h>
|
||||
|
||||
@implementation EOModelerEditor
|
||||
- (void) dealloc
|
||||
{
|
||||
|
@ -48,6 +51,7 @@
|
|||
if ((self = [super init]))
|
||||
{
|
||||
_document = document;
|
||||
_selectionWithinViewedObject = [NSArray new];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -57,46 +61,75 @@
|
|||
return _document;
|
||||
}
|
||||
|
||||
/** Subclassses should implement, by default throws an exception */
|
||||
- (void)setSelectionPath:(NSArray *)newSelection
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
/** Subclassses should implement, by default throws an exception */
|
||||
- (NSArray *)selectionPath
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
/** Subclassses should implement, by default throws an exception */
|
||||
- (void)activate
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
/** Subclassses should implement, by default throws an exception */
|
||||
- (NSArray *)selectionWithinViewedObject
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
return [NSArray array];
|
||||
}
|
||||
|
||||
/** Subclassses should implement, by default throws an exception */
|
||||
- (void)setSelectionWithinViewedObject:(NSArray *)newSelection
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
/** Subclassses should implement, by default throws an exception */
|
||||
- (void)setViewedObjectPath:(NSArray *)newPath
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
/** Subclassses should implement, by default throws an exception */
|
||||
- (NSArray *)viewedObjectPath
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void) debugSelectionPath
|
||||
{
|
||||
int i,j;
|
||||
NSArray *_selectionPath = [self selectionPath];
|
||||
for (i = 0; i < [_selectionPath count]; i++)
|
||||
{
|
||||
id obj = [_selectionPath objectAtIndex:i];
|
||||
|
||||
if (![obj isKindOfClass:[NSArray class]])
|
||||
NSLog(@"%i %@(%@)", i, [obj class], [obj name]);
|
||||
else
|
||||
{
|
||||
for (j = 0; j < [obj count]; j++)
|
||||
{
|
||||
id obj2 = [obj objectAtIndex:j];
|
||||
NSLog(@"* %i %@(%@)", j, [obj2 class], [obj2 name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\n\n");
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation EOModelerCompoundEditor
|
||||
@implementation EOModelerCompoundEditor
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(_editors);
|
||||
|
@ -110,10 +143,16 @@
|
|||
_editors = [[NSMutableArray alloc] init];
|
||||
_activeEditor = nil;
|
||||
_viewedObjectPath = [[NSArray alloc] initWithObjects:[doc model], nil];
|
||||
_selectionWithinViewedObject = [NSArray new];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) selectionDidChange
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
postNotificationName:EOMSelectionChangedNotification
|
||||
object:_document];
|
||||
}
|
||||
|
||||
- (EOModelerEmbedibleEditor *)activeEditor
|
||||
{
|
||||
return _activeEditor;
|
||||
|
@ -186,15 +225,15 @@
|
|||
}
|
||||
|
||||
|
||||
/* setting the selection */
|
||||
|
||||
/** <p>Compound editors subclass this to send an EOMSelectionChangeNotification and manage
|
||||
the selection arrays.</p> */
|
||||
- (void)setSelectionPath:(NSArray *)newSelection
|
||||
{
|
||||
unsigned int indexOfLast = [newSelection indexOfObject:[newSelection lastObject]];
|
||||
NSRange allButLastElement;
|
||||
/* int i,j;
|
||||
/*
|
||||
int i,j;
|
||||
|
||||
|
||||
printf("%@\n",NSStringFromSelector(_cmd));
|
||||
for (i = 0; i < [newSelection count]; i++)
|
||||
{
|
||||
|
@ -210,13 +249,13 @@
|
|||
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]);
|
||||
}
|
||||
|
@ -226,14 +265,15 @@
|
|||
ASSIGN(_viewedObjectPath, [NSArray array]);
|
||||
ASSIGN(_selectionWithinViewedObject, [NSArray array]);
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:EOMSelectionChangedNotification
|
||||
object:nil];
|
||||
|
||||
[self selectionDidChange];
|
||||
}
|
||||
|
||||
/** <p>Compound editors subclass this to send an EOMSelectionChangeNotification and manage
|
||||
the selection arrays.</p> */
|
||||
- (void) setSelectionWithinViewedObject:(NSArray *) newSelection
|
||||
{
|
||||
/*
|
||||
/*
|
||||
int i,j;
|
||||
printf("%@\n",NSStringFromSelector(_cmd));
|
||||
for (i = 0; i < [newSelection count]; i++)
|
||||
|
@ -248,16 +288,19 @@
|
|||
}
|
||||
else
|
||||
printf("%@\n", [[newSelection objectAtIndex:i] class]);
|
||||
} */
|
||||
}
|
||||
*/
|
||||
ASSIGN(_selectionWithinViewedObject, newSelection);
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:EOMSelectionChangedNotification
|
||||
object:nil];
|
||||
[self selectionDidChange];
|
||||
}
|
||||
|
||||
/** <p>Compound editors subclass this to send an EOMSelectionChangeNotification and manage
|
||||
the selection arrays.</p> */
|
||||
- (void) setViewedObjectPath:(NSArray *)newPath
|
||||
{
|
||||
/*
|
||||
int i,j;
|
||||
/*
|
||||
int i,j;
|
||||
|
||||
printf("%@\n",NSStringFromSelector(_cmd));
|
||||
for (i = 0; i < [newPath count]; i++)
|
||||
{
|
||||
|
@ -272,10 +315,9 @@
|
|||
else
|
||||
printf("%@\n", [[newPath objectAtIndex:i] class]);
|
||||
}
|
||||
*/
|
||||
*/
|
||||
ASSIGN(_viewedObjectPath, newPath);
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:EOMSelectionChangedNotification
|
||||
object:nil];
|
||||
[self selectionDidChange];
|
||||
}
|
||||
|
||||
- (void)setStoredProceduresSelected:(BOOL)selected
|
||||
|
@ -296,15 +338,14 @@
|
|||
|
||||
- (void)viewSelectedObject
|
||||
{
|
||||
/*
|
||||
if (![_selectionWithinViewedObject count])
|
||||
return;
|
||||
|
||||
{
|
||||
id object = [_selectionWithinViewedObject objectAtIndex:0];
|
||||
[self setSelectionPath: [[_viewedObjectPath arrayByAddingObject: object]
|
||||
arrayByAddingObject:[NSArray array]]];
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
- (void) activate
|
||||
|
@ -315,12 +356,20 @@
|
|||
@end
|
||||
|
||||
@implementation EOModelerEmbedibleEditor
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
- (EOModelerEmbedibleEditor *) 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;
|
||||
}
|
||||
|
@ -366,33 +415,49 @@
|
|||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
/* getting the selection */
|
||||
/** 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];
|
||||
}
|
||||
|
||||
|
||||
/* setting the selection */
|
||||
|
||||
/** 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];
|
||||
|
|
Loading…
Reference in a new issue