1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 10:17:35 +00:00

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.
This commit is contained in:
Nico Weber 2023-10-10 10:46:34 -04:00 committed by Tim Flynn
parent 44f7d7406c
commit 627b152d49
5 changed files with 45 additions and 6 deletions

View file

@ -23,4 +23,7 @@
- (void)setDelegate:(id<MacPDFViewDelegate>)delegate; - (void)setDelegate:(id<MacPDFViewDelegate>)delegate;
- (IBAction)goToNextPage:(id)sender;
- (IBAction)goToPreviousPage:(id)sender;
@end @end

View file

@ -146,6 +146,18 @@ static NSBitmapImageRep* ns_from_gfx(NonnullRefPtr<Gfx::Bitmap> bitmap_p)
return YES; 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 - (void)keyDown:(NSEvent*)event
{ {
// Calls moveLeft: or moveRight: below. // Calls moveLeft: or moveRight: below.
@ -155,15 +167,13 @@ static NSBitmapImageRep* ns_from_gfx(NonnullRefPtr<Gfx::Bitmap> bitmap_p)
// Called on left arrow. // Called on left arrow.
- (IBAction)moveLeft:(id)sender - (IBAction)moveLeft:(id)sender
{ {
int current_page = _page_index + 1; [self goToPreviousPage:self];
[self goToPage:current_page - 1];
} }
// Called on right arrow. // Called on right arrow.
- (IBAction)moveRight:(id)sender - (IBAction)moveRight:(id)sender
{ {
int current_page = _page_index + 1; [self goToNextPage:self];
[self goToPage:current_page + 1];
} }
#pragma mark - State restoration #pragma mark - State restoration

View file

@ -18,7 +18,11 @@ NS_ASSUME_NONNULL_BEGIN
@interface MacPDFWindowController : NSWindowController <MacPDFViewDelegate, NSOutlineViewDelegate, NSToolbarDelegate> @interface MacPDFWindowController : NSWindowController <MacPDFViewDelegate, NSOutlineViewDelegate, NSToolbarDelegate>
- (instancetype)initWithDocument:(MacPDFDocument*)document; - (instancetype)initWithDocument:(MacPDFDocument*)document;
- (IBAction)goToNextPage:(id)sender;
- (IBAction)goToPreviousPage:(id)sender;
- (IBAction)showGoToPageDialog:(id)sender; - (IBAction)showGoToPageDialog:(id)sender;
- (void)pdfDidInitialize; - (void)pdfDidInitialize;
@end @end

View file

@ -122,6 +122,16 @@
_outlineView.delegate = self; _outlineView.delegate = self;
} }
- (IBAction)goToNextPage:(id)sender
{
[_pdfView goToNextPage:sender];
}
- (IBAction)goToPreviousPage:(id)sender
{
[_pdfView goToPreviousPage:sender];
}
- (IBAction)showGoToPageDialog:(id)sender - (IBAction)showGoToPageDialog:(id)sender
{ {
auto alert = [[NSAlert alloc] init]; auto alert = [[NSAlert alloc] init];

View file

@ -639,10 +639,22 @@
<modifierMask key="keyEquivalentModifierMask"/> <modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Go" id="u8F-oH-oMu"> <menu key="submenu" title="Go" id="u8F-oH-oMu">
<items> <items>
<menuItem title="Go to Page…" keyEquivalent="g" id="Ou1-5M-LzJ"> <menuItem title="Previous Page" keyEquivalent="" id="Ou1-5M-LzJ">
<modifierMask key="keyEquivalentModifierMask" option="YES"/>
<connections>
<action selector="goToPreviousPage:" target="-1" id="e1c-zc-WR6"/>
</connections>
</menuItem>
<menuItem title="Next Page" keyEquivalent="" id="mfm-mG-pLT">
<modifierMask key="keyEquivalentModifierMask" option="YES"/>
<connections>
<action selector="goToNextPage:" target="-1" id="lt2-m9-Iyp"/>
</connections>
</menuItem>
<menuItem title="Go to Page…" keyEquivalent="g" id="pzP-g1-BeT">
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/> <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
<connections> <connections>
<action selector="showGoToPageDialog:" target="-1" id="hmq-Sy-pJC"/> <action selector="showGoToPageDialog:" target="-1" id="fPI-BN-18g"/>
</connections> </connections>
</menuItem> </menuItem>
</items> </items>