MacPDF: Add a toolbar with a standard sidebar button

This commit is contained in:
Nico Weber 2023-10-03 10:03:16 -04:00 committed by Andreas Kling
parent 1f1a596a46
commit ae1b179474
2 changed files with 27 additions and 1 deletions

View file

@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
@class MacPDFDocument;
@interface MacPDFWindowController : NSWindowController <MacPDFViewDelegate>
@interface MacPDFWindowController : NSWindowController <MacPDFViewDelegate, NSToolbarDelegate>
- (instancetype)initWithDocument:(MacPDFDocument*)document;
- (IBAction)showGoToPageDialog:(id)sender;

View file

@ -32,6 +32,11 @@
window.contentView = _pdfView;
[_pdfView setDelegate:self];
NSToolbar* toolbar = [[NSToolbar alloc] initWithIdentifier:@"MacPDFToolbar"];
toolbar.delegate = self;
toolbar.displayMode = NSToolbarDisplayModeIconOnly;
[window setToolbar:toolbar];
_pdfDocument = document;
return self;
}
@ -73,4 +78,25 @@
[NSString stringWithFormat:@"Page %d of %d", [_pdfView page], _pdfDocument.pdf->get_page_count()]];
}
#pragma mark - NSToolbarDelegate
- (NSArray<NSToolbarItemIdentifier>*)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar
{
return [self toolbarDefaultItemIdentifiers:toolbar];
}
- (NSArray<NSToolbarItemIdentifier>*)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
{
return @[ NSToolbarToggleSidebarItemIdentifier ];
}
- (NSToolbarItem*)toolbar:(NSToolbar*)toolbar
itemForItemIdentifier:(NSToolbarItemIdentifier)itemIdentifier
willBeInsertedIntoToolbar:(BOOL)flag
{
// Not called for standard identifiers, but the implementation of the method must exist, or else:
// ERROR: invalid delegate <MacPDFWindowController: 0x600003054c80> (does not implement all required methods)
return nil;
}
@end