From e7d41480fc30397d6c58886aafe85e793daeef92 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sun, 8 Oct 2023 22:42:59 -0400 Subject: [PATCH] MacPDF: Make clicking outline items have an effect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clicking an item in the outline now opens that page. This requires giving the outline view a delegate, which for some reason also has th effect of indenting expandable items ¯\_(ツ)_/¯ The vertical alignment of text still looks off, though. --- Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.h | 2 +- .../Lagom/Contrib/MacPDF/MacPDFWindowController.mm | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.h b/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.h index fb05a37ad0..818bfd901e 100644 --- a/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.h +++ b/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.h @@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN @class MacPDFDocument; -@interface MacPDFWindowController : NSWindowController +@interface MacPDFWindowController : NSWindowController - (instancetype)initWithDocument:(MacPDFDocument*)document; - (IBAction)showGoToPageDialog:(id)sender; diff --git a/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.mm b/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.mm index a49f9a2629..649a0f36e1 100644 --- a/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.mm +++ b/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.mm @@ -116,6 +116,7 @@ // FIXME: Only set data source when sidebar is open. _outlineDataSource = [[MacPDFOutlineViewDataSource alloc] initWithOutline:_pdfDocument.pdf->outline()]; _outlineView.dataSource = _outlineDataSource; + _outlineView.delegate = self; } - (IBAction)showGoToPageDialog:(id)sender @@ -175,4 +176,17 @@ return nil; } +#pragma mark - NSOutlineViewDelegate + +- (void)outlineViewSelectionDidChange:(NSNotification*)notification +{ + NSInteger row = _outlineView.selectedRow; + if (row == -1) + return; + + OutlineItemWrapper* item = [_outlineView itemAtRow:row]; + if (auto page = [item page]; page.has_value()) + [_pdfView goToPage:page.value()]; +} + @end