From 67f6baead0795321591aeb4173a8e3b52b450ea0 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Mon, 2 Oct 2023 19:45:38 -0400 Subject: [PATCH] MacPDF: Introduce MacPDFWindowController I'd like to add a sidebar, and NSSplitViewItem apparently isn't accessibly in .xib files without contortions. So I want to move to creating the window in code, and this is a step towards that. No behavior change. --- Meta/Lagom/Contrib/MacPDF/CMakeLists.txt | 1 + Meta/Lagom/Contrib/MacPDF/MacPDFDocument.mm | 5 +++-- .../Contrib/MacPDF/MacPDFWindowController.h | 21 +++++++++++++++++++ .../Contrib/MacPDF/MacPDFWindowController.mm | 20 ++++++++++++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.h create mode 100644 Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.mm diff --git a/Meta/Lagom/Contrib/MacPDF/CMakeLists.txt b/Meta/Lagom/Contrib/MacPDF/CMakeLists.txt index a37f9f68bd..b5695ae6fa 100644 --- a/Meta/Lagom/Contrib/MacPDF/CMakeLists.txt +++ b/Meta/Lagom/Contrib/MacPDF/CMakeLists.txt @@ -19,6 +19,7 @@ add_executable(MacPDF MACOSX_BUNDLE AppDelegate.mm MacPDFDocument.mm MacPDFView.mm + MacPDFWindowController.mm ) target_compile_options(MacPDF PRIVATE -fobjc-arc diff --git a/Meta/Lagom/Contrib/MacPDF/MacPDFDocument.mm b/Meta/Lagom/Contrib/MacPDF/MacPDFDocument.mm index 80644a24a5..021701572e 100644 --- a/Meta/Lagom/Contrib/MacPDF/MacPDFDocument.mm +++ b/Meta/Lagom/Contrib/MacPDF/MacPDFDocument.mm @@ -8,6 +8,7 @@ #import +#import "MacPDFWindowController.h" #include @interface MacPDFDocument () @@ -71,9 +72,9 @@ } } -- (NSString*)windowNibName +- (void)makeWindowControllers { - return @"MacPDFDocument"; + [self addWindowController:[[MacPDFWindowController alloc] initWithDocument:self]]; } - (void)windowControllerDidLoadNib:(NSWindowController*)aController diff --git a/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.h b/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.h new file mode 100644 index 0000000000..5861eddc59 --- /dev/null +++ b/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023, Nico Weber + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include "CocoaWrapper.h" + +NS_ASSUME_NONNULL_BEGIN + +@class MacPDFDocument; + +@interface MacPDFWindowController : NSWindowController + +- (instancetype)initWithDocument:(MacPDFDocument*)document; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.mm b/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.mm new file mode 100644 index 0000000000..c75795a9dc --- /dev/null +++ b/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.mm @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023, Nico Weber + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#import "MacPDFWindowController.h" + +@implementation MacPDFWindowController + +- (instancetype)initWithDocument:(MacPDFDocument*)document +{ + if (self = [super initWithWindowNibName:@"MacPDFDocument" owner:self]; !self) + return nil; + + return self; +} + + +@end