MacPDF: Show current page and page count in subtitle

This commit is contained in:
Nico Weber 2023-09-24 22:00:38 -04:00 committed by Andreas Kling
parent bd19fcc039
commit e67d8cfb2a
4 changed files with 29 additions and 3 deletions

View file

@ -14,7 +14,7 @@
NS_ASSUME_NONNULL_BEGIN
@interface LagomPDFDocument : NSDocument
@interface LagomPDFDocument : NSDocument <LagomPDFViewDelegate>
{
IBOutlet LagomPDFView* _pdfView;
}

View file

@ -68,6 +68,7 @@
NSLog(@"failed to load 2: %@", @(err.error().message().characters()));
} else {
[_pdfView setDocument:_doc->make_weak_ptr()];
[self pageChanged];
}
}
@ -82,6 +83,8 @@
{
[super windowControllerDidLoadNib:aController];
[_pdfView setDelegate:self];
if (_doc) {
if (auto handler = _doc->security_handler(); handler && !handler->has_user_password()) {
[self promptForPassword:aController.window];
@ -166,4 +169,10 @@
}];
}
- (void)pageChanged
{
[_pdfView.window setSubtitle:
[NSString stringWithFormat:@"Page %d of %d", [_pdfView page], _doc -> get_page_count()]];
}
@end

View file

@ -15,11 +15,16 @@
#include <AK/WeakPtr.h>
#include <LibPDF/Document.h>
@protocol LagomPDFViewDelegate
- (void)pageChanged;
@end
@interface LagomPDFView : NSView
{
}
- (void)setDocument:(WeakPtr<PDF::Document>)doc;
- (void)goToPage:(int)page;
- (int)page;
- (void)setDelegate:(id<LagomPDFViewDelegate>)delegate;
@end

View file

@ -16,6 +16,7 @@
WeakPtr<PDF::Document> _doc;
NSBitmapImageRep* _cachedBitmap;
int _page_index;
__weak id<LagomPDFViewDelegate> _delegate;
}
@end
@ -82,6 +83,17 @@ static NSBitmapImageRep* ns_from_gfx(NonnullRefPtr<Gfx::Bitmap> bitmap_p)
_page_index = new_index;
[self invalidateRestorableState];
[self invalidateCachedBitmap];
[_delegate pageChanged];
}
- (int)page
{
return _page_index + 1;
}
- (void)setDelegate:(id<LagomPDFViewDelegate>)delegate
{
_delegate = delegate;
}
#pragma mark Drawing