mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:17:34 +00:00
MacPDF: Show current page and page count in subtitle
This commit is contained in:
parent
bd19fcc039
commit
e67d8cfb2a
4 changed files with 29 additions and 3 deletions
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@interface LagomPDFDocument : NSDocument
|
@interface LagomPDFDocument : NSDocument <LagomPDFViewDelegate>
|
||||||
{
|
{
|
||||||
IBOutlet LagomPDFView* _pdfView;
|
IBOutlet LagomPDFView* _pdfView;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,7 @@
|
||||||
NSLog(@"failed to load 2: %@", @(err.error().message().characters()));
|
NSLog(@"failed to load 2: %@", @(err.error().message().characters()));
|
||||||
} else {
|
} else {
|
||||||
[_pdfView setDocument:_doc->make_weak_ptr()];
|
[_pdfView setDocument:_doc->make_weak_ptr()];
|
||||||
|
[self pageChanged];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,6 +83,8 @@
|
||||||
{
|
{
|
||||||
[super windowControllerDidLoadNib:aController];
|
[super windowControllerDidLoadNib:aController];
|
||||||
|
|
||||||
|
[_pdfView setDelegate:self];
|
||||||
|
|
||||||
if (_doc) {
|
if (_doc) {
|
||||||
if (auto handler = _doc->security_handler(); handler && !handler->has_user_password()) {
|
if (auto handler = _doc->security_handler(); handler && !handler->has_user_password()) {
|
||||||
[self promptForPassword:aController.window];
|
[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
|
@end
|
||||||
|
|
|
@ -15,11 +15,16 @@
|
||||||
#include <AK/WeakPtr.h>
|
#include <AK/WeakPtr.h>
|
||||||
#include <LibPDF/Document.h>
|
#include <LibPDF/Document.h>
|
||||||
|
|
||||||
|
@protocol LagomPDFViewDelegate
|
||||||
|
- (void)pageChanged;
|
||||||
|
@end
|
||||||
|
|
||||||
@interface LagomPDFView : NSView
|
@interface LagomPDFView : NSView
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setDocument:(WeakPtr<PDF::Document>)doc;
|
- (void)setDocument:(WeakPtr<PDF::Document>)doc;
|
||||||
- (void)goToPage:(int)page;
|
- (void)goToPage:(int)page;
|
||||||
|
- (int)page;
|
||||||
|
|
||||||
|
- (void)setDelegate:(id<LagomPDFViewDelegate>)delegate;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
WeakPtr<PDF::Document> _doc;
|
WeakPtr<PDF::Document> _doc;
|
||||||
NSBitmapImageRep* _cachedBitmap;
|
NSBitmapImageRep* _cachedBitmap;
|
||||||
int _page_index;
|
int _page_index;
|
||||||
|
__weak id<LagomPDFViewDelegate> _delegate;
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -82,6 +83,17 @@ static NSBitmapImageRep* ns_from_gfx(NonnullRefPtr<Gfx::Bitmap> bitmap_p)
|
||||||
_page_index = new_index;
|
_page_index = new_index;
|
||||||
[self invalidateRestorableState];
|
[self invalidateRestorableState];
|
||||||
[self invalidateCachedBitmap];
|
[self invalidateCachedBitmap];
|
||||||
|
[_delegate pageChanged];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (int)page
|
||||||
|
{
|
||||||
|
return _page_index + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setDelegate:(id<LagomPDFViewDelegate>)delegate
|
||||||
|
{
|
||||||
|
_delegate = delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark Drawing
|
#pragma mark Drawing
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue