Override the initWithContentsOfFile:ofType: method so that it will not call NSRunAlertPanel

This commit is contained in:
Gregory John Casamento 2023-12-13 03:58:27 -05:00
parent 7ffe4dd25b
commit f346a46a58
2 changed files with 47 additions and 8 deletions

View file

@ -24,10 +24,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
*/
#include "GormPrivate.h"
#include <GormCore/GormDocument.h>
#include <GormCore/GormDocumentController.h>
#include "GormPrivate.h"
@implementation GormDocumentController
- (id) currentDocument

View file

@ -27,6 +27,36 @@
#import "GormToolPrivate.h"
#import "AppDelegate.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wobjc-protocol-method-implementation"
// Smash this method in NSDocument to prevent it from popping up an NSRunAlertPanel
@interface NSDocument (__ReplaceLoadPrivate__)
- (id) initWithContentsOfFile: (NSString *)fileName ofType: (NSString *)fileType;
@end
@implementation NSDocument (__ReplaceLoadPrivate__)
- (id) initWithContentsOfFile: (NSString *)fileName ofType: (NSString *)fileType
{
self = [self init];
if (self != nil)
{
[self setFileType: fileType];
[self setFileName: fileName];
if (![self readFromFile: fileName ofType: fileType])
{
NSLog(@"Load failed, could not load file");
DESTROY(self);
}
}
return self;
}
@end
#pragma GCC diagnostic pop
// AppDelegate...
@implementation AppDelegate
@ -291,20 +321,28 @@
file = [opt value];
}
if (file != nil)
NS_DURING
{
_doc = [dc openDocumentWithContentsOfFile: file display: NO];
if (_doc == nil)
if (file != nil)
{
NSLog(@"Unable to load document %@", file);
_doc = [dc openDocumentWithContentsOfFile: file display: NO];
if (_doc == nil)
{
NSLog(@"Unable to load document %@", file);
return;
}
}
else
{
NSLog(@"No document specified");
return;
}
}
else
NS_HANDLER
{
NSLog(@"No document specified");
return;
NSLog(@"Exception: %@", [localException reason]);
}
NS_ENDHANDLER;
NSDebugLog(@"Document = %@", _doc);