From 627b152d49b37601eca271f42ccb7ff4e5ec0173 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 10 Oct 2023 10:46:34 -0400 Subject: [PATCH] MacPDF: Make opt-up and opt-down always go to previous / next page When the outline has focus, arrow keys navigate the outline instead of changing the current page. Add opt-up and opt-down as a way to move by one page even when the outline has focus. (This matches Preview.app.) xib change: Added two menu Previous Page with key equivalent opt-up and Next Page with key equivalent opt-down to Go menu and bound them to goToPreviousPage: and goToNextPage: on First Responder. When the outline has focus, the responder chain is outline -> window, so also add the actions on the window controller, and let that forward to the PDF view. --- Meta/Lagom/Contrib/MacPDF/MacPDFView.h | 3 +++ Meta/Lagom/Contrib/MacPDF/MacPDFView.mm | 18 ++++++++++++++---- .../Contrib/MacPDF/MacPDFWindowController.h | 4 ++++ .../Contrib/MacPDF/MacPDFWindowController.mm | 10 ++++++++++ Meta/Lagom/Contrib/MacPDF/MainMenu.xib | 16 ++++++++++++++-- 5 files changed, 45 insertions(+), 6 deletions(-) diff --git a/Meta/Lagom/Contrib/MacPDF/MacPDFView.h b/Meta/Lagom/Contrib/MacPDF/MacPDFView.h index e23684a91b..f96c2d9016 100644 --- a/Meta/Lagom/Contrib/MacPDF/MacPDFView.h +++ b/Meta/Lagom/Contrib/MacPDF/MacPDFView.h @@ -23,4 +23,7 @@ - (void)setDelegate:(id)delegate; +- (IBAction)goToNextPage:(id)sender; +- (IBAction)goToPreviousPage:(id)sender; + @end diff --git a/Meta/Lagom/Contrib/MacPDF/MacPDFView.mm b/Meta/Lagom/Contrib/MacPDF/MacPDFView.mm index 9b9fcc6088..89d11184ec 100644 --- a/Meta/Lagom/Contrib/MacPDF/MacPDFView.mm +++ b/Meta/Lagom/Contrib/MacPDF/MacPDFView.mm @@ -146,6 +146,18 @@ static NSBitmapImageRep* ns_from_gfx(NonnullRefPtr bitmap_p) return YES; } +- (IBAction)goToNextPage:(id)sender +{ + int current_page = _page_index + 1; + [self goToPage:current_page + 1]; +} + +- (IBAction)goToPreviousPage:(id)sender +{ + int current_page = _page_index + 1; + [self goToPage:current_page - 1]; +} + - (void)keyDown:(NSEvent*)event { // Calls moveLeft: or moveRight: below. @@ -155,15 +167,13 @@ static NSBitmapImageRep* ns_from_gfx(NonnullRefPtr bitmap_p) // Called on left arrow. - (IBAction)moveLeft:(id)sender { - int current_page = _page_index + 1; - [self goToPage:current_page - 1]; + [self goToPreviousPage:self]; } // Called on right arrow. - (IBAction)moveRight:(id)sender { - int current_page = _page_index + 1; - [self goToPage:current_page + 1]; + [self goToNextPage:self]; } #pragma mark - State restoration diff --git a/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.h b/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.h index 818bfd901e..92bd2d4977 100644 --- a/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.h +++ b/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.h @@ -18,7 +18,11 @@ NS_ASSUME_NONNULL_BEGIN @interface MacPDFWindowController : NSWindowController - (instancetype)initWithDocument:(MacPDFDocument*)document; + +- (IBAction)goToNextPage:(id)sender; +- (IBAction)goToPreviousPage:(id)sender; - (IBAction)showGoToPageDialog:(id)sender; + - (void)pdfDidInitialize; @end diff --git a/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.mm b/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.mm index 022c2af2ea..39a892bd5f 100644 --- a/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.mm +++ b/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.mm @@ -122,6 +122,16 @@ _outlineView.delegate = self; } +- (IBAction)goToNextPage:(id)sender +{ + [_pdfView goToNextPage:sender]; +} + +- (IBAction)goToPreviousPage:(id)sender +{ + [_pdfView goToPreviousPage:sender]; +} + - (IBAction)showGoToPageDialog:(id)sender { auto alert = [[NSAlert alloc] init]; diff --git a/Meta/Lagom/Contrib/MacPDF/MainMenu.xib b/Meta/Lagom/Contrib/MacPDF/MainMenu.xib index fbc59300b7..32ab8ed996 100644 --- a/Meta/Lagom/Contrib/MacPDF/MainMenu.xib +++ b/Meta/Lagom/Contrib/MacPDF/MainMenu.xib @@ -639,10 +639,22 @@ - + + + + + + + + + + + + + - +