* DBModeler/Modeler.m (_newDocumentWithModel:): Don't release the

model.
        (-new:): Release the model here.
        (-newFromDatabase:): Ditto, and add error handling.
        (-open:): Ditto.
        (-application:openFile:): New method.
        * EOModeler/EOModelerDocument.m (-saveAs:): Add error handling, and
        remove check for an existing name.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@21445 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
ratmice 2005-07-10 19:45:21 +00:00
parent e96b810ebf
commit e6d526b03c
3 changed files with 87 additions and 30 deletions

View file

@ -1,3 +1,14 @@
2005-07-10 Matt Rice <ratmice@yahoo.com>
* DBModeler/Modeler.m (_newDocumentWithModel:): Don't release the
model.
(-new:): Release the model here.
(-newFromDatabase:): Ditto, and add error handling.
(-open:): Ditto.
(-application:openFile:): New method.
* EOModeler/EOModelerDocument.m (-saveAs:): Add error handling, and
remove check for an existing name.
2005-07-10 Peter Cooper <comrade@obverse.com.au>
* DBModeler/GNUmakefile: Add Info-gnustep.plist to project.

View file

@ -44,6 +44,7 @@
#include <AppKit/NSOpenPanel.h>
#include <Foundation/NSObject.h>
#include <Foundation/NSFileManager.h>
@interface NSMenu (im_lazy)
-(id <NSMenuItem>) addItemWithTitle: (NSString *)s;
@ -227,7 +228,6 @@
EOModelerDocument *newModelerDoc;
EOModelerCompoundEditor *editor;
newModelerDoc = [[EOModelerDocument alloc] initWithModel: newModel];
RELEASE(newModel);
editor = (EOModelerCompoundEditor*)[newModelerDoc addDefaultEditor];
[EOMApp setCurrentEditor: editor];
[EOMApp addDocument: newModelerDoc];
@ -246,29 +246,42 @@
modelName=[NSString stringWithFormat:@"Model_%u",++nDocs];
[newModel setName:modelName];
[self _newDocumentWithModel:newModel];
RELEASE(newModel);
}
- (void) newFromDatabase:(id)sender
{
NSString *adaptorName;
EOAdaptor *adaptor;
EOAdaptorChannel *channel;
EOAdaptorContext *ctxt;
EOModel *newModel;
AdaptorsPanel *adaptorsPanel = [[AdaptorsPanel alloc] init];
adaptorName = [adaptorsPanel runAdaptorsPanel];
RELEASE(adaptorsPanel);
adaptor = [EOAdaptor adaptorWithName:adaptorName];
[adaptor setConnectionDictionary:[adaptor runLoginPanel]];
ctxt = [adaptor createAdaptorContext];
channel = [ctxt createAdaptorChannel];
[channel openChannel];
newModel = [channel describeModelWithTableNames:[channel describeTableNames]];
[newModel setConnectionDictionary:[adaptor connectionDictionary]];
[newModel setName: [[adaptor connectionDictionary] objectForKey:@"databaseName"]];
[channel closeChannel];
[self _newDocumentWithModel:newModel];
if (adaptorName)
{
EOAdaptor *adaptor;
EOAdaptorChannel *channel;
EOAdaptorContext *ctxt;
EOModel *newModel;
NSDictionary *connDict;
adaptor = [EOAdaptor adaptorWithName:adaptorName];
connDict = [adaptor runLoginPanel];
if (connDict)
{
[adaptor setConnectionDictionary:[adaptor runLoginPanel]];
ctxt = [adaptor createAdaptorContext];
channel = [ctxt createAdaptorChannel];
[channel openChannel];
newModel = [channel describeModelWithTableNames:[channel describeTableNames]];
[newModel setConnectionDictionary:[adaptor connectionDictionary]];
[newModel setName: [[adaptor connectionDictionary] objectForKey:@"databaseName"]];
[channel closeChannel];
[self _newDocumentWithModel:newModel];
RELEASE(newModel);
}
}
}
- (BOOL) validateMenuItem:(NSMenuItem *)menuItem
@ -299,11 +312,34 @@
[EOMInspectorController showInspector];
}
- (void) application:(NSApplication *)theApp openFile:(NSString *)filename
{
NSFileManager *fm = [NSFileManager defaultManager];
NSString *pathExt = [[filename pathExtension] lowercaseString];
if ([fm isReadableFileAtPath:filename] == YES
&& ([pathExt isEqual:@"eomodeld"]
|| [pathExt isEqual:@"eomodel"]))
{
EOModel *model;
NS_DURING
model = [[EOModel alloc] initWithContentsOfFile:filename];
NS_HANDLER
return;
NS_ENDHANDLER
[self _newDocumentWithModel:model];
RELEASE(model);
}
}
- (void) open:(id)sender
{
NSOpenPanel *panel = [NSOpenPanel openPanel];
NSFileManager *fm = [NSFileManager defaultManager];
if ([panel runModalForTypes:[NSArray arrayWithObject:@"eomodeld"]] == NSOKButton)
if ([panel runModalForTypes:[NSArray arrayWithObjects:@"eomodeld",@"eomodel",nil]] == NSOKButton)
{
NSArray *modelPaths = [panel filenames];
int i,c;
@ -311,10 +347,23 @@
for (i = 0, c = [modelPaths count]; i < c; i++)
{
NSString *modelPath = [modelPaths objectAtIndex:i];
EOModel *model = [[EOModel alloc] initWithContentsOfFile:modelPath];
[self _newDocumentWithModel:model];
RELEASE(model);
NSString *pathExt = [[modelPath pathExtension] lowercaseString];
if ([fm isReadableFileAtPath:modelPath] == YES
&& ([pathExt isEqual:@"eomodeld"]
|| [pathExt isEqual:@"eomodel"]))
{
EOModel *model;
NS_DURING
model = [[EOModel alloc] initWithContentsOfFile:modelPath];
NS_HANDLER
return;
NS_ENDHANDLER
[self _newDocumentWithModel:model];
RELEASE(model);
}
}
}
}

View file

@ -408,18 +408,15 @@ showOnSuccess:(BOOL)bar;
- (void)saveAs:(id)sender
{
NSString *path = [_model path];
if (!path)
{
id savePanel = [NSSavePanel savePanel];
int result = [savePanel runModal];
NSString *path;
id savePanel = [NSSavePanel savePanel];
int result = [savePanel runModal];
if (result == NSOKButton)
{
path = [savePanel filename];
}
if (result == NSOKButton)
{
path = [savePanel filename];
[self saveToPath: path];
}
[self saveToPath: path];
}
- (void)revertToSaved:(id)sender