From fb7f3b833d31cb7dcae259c6a9a0118cdeafc96c Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 16 Sep 2023 16:21:49 +0200 Subject: Make a document-based application Add the basic necessities for a document-based application. This is what I came up with on 2023-09-10. The `DocumentWindowController` was just an initial idea and doesn't do anything: we create the required window controller in `Document`. The `CFBundleDocumentTypes` entry enables us to interact with text files. This confirms that the "Open Recent" menu does get added automatically below the "Open" menu. --- src/Document.m | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/Document.m (limited to 'src/Document.m') diff --git a/src/Document.m b/src/Document.m new file mode 100644 index 0000000..7b514eb --- /dev/null +++ b/src/Document.m @@ -0,0 +1,38 @@ +#import "Document.h" + +@implementation Document + +- (id)init +{ + self = [super init]; + if (self) { + } + return self; +} + +// TODO: Are window controllers deallocated automatically by the parent? +// [[NSWindowController alloc] initWithWindow:]? + +- (void)makeWindowControllers +{ + // DocumentWindowController *controller = [[DocumentWindowController alloc] init]; + + NSWindow *window = [[NSWindow alloc] + initWithContentRect:NSMakeRect(0, 0, 600, 500) + styleMask: + NSWindowStyleMaskTitled + | NSWindowStyleMaskClosable + | NSWindowStyleMaskMiniaturizable + | NSWindowStyleMaskResizable + backing:NSBackingStoreBuffered + defer:NO]; + // [window setFrameAutosaveName:@"document"]; // document name? + + NSWindowController *window_controller = [[NSWindowController alloc] + initWithWindow:window]; + // [window_controller setShouldCascadeWindows:YES]; + + [self addWindowController:window_controller]; +} + +@end -- cgit v1.2.3