VocalEasel/Sources/VLPDFWindow.mm

86 lines
1.9 KiB
Plaintext
Raw Permalink Normal View History

2006-10-26 08:21:50 +00:00
//
2007-04-27 06:41:34 +00:00
// File: VLPDFWindow.mm - Manipulate preview window
2006-10-26 08:21:50 +00:00
//
2007-04-27 06:41:34 +00:00
// Author(s):
//
// (MN) Matthias Neeracher
//
2011-08-29 00:01:49 +00:00
// Copyright <20> 2005-2011 Matthias Neeracher
2006-10-26 08:21:50 +00:00
//
#import "VLPDFWindow.h"
#import "VLPDFView.h"
2006-11-10 08:09:18 +00:00
#import "VLDocument.h"
2006-10-26 08:21:50 +00:00
@implementation VLPDFWindow
- (id)init
{
return self = [super initWithWindowNibName:@"VLPDFWindow"];
}
2006-10-26 08:21:50 +00:00
- (NSString *)windowTitleForDocumentDisplayName:(NSString *)displayName
{
return [displayName stringByAppendingString: @" - Output"];
}
- (void)synchronizeWindowTitleWithDocumentName
{
[super synchronizeWindowTitleWithDocumentName];
[self reloadPDF];
}
- (IBAction)showWindow:(id)sender
{
[super showWindow:sender];
}
2006-10-26 08:21:50 +00:00
- (void)reloadPDF
{
if (pdfView) {
VLDocument *doc = [sheetWin document];
2006-11-10 08:09:18 +00:00
NSURL * pdfURL = [doc fileURLWithExtension:@"pdf"];
if (!pdfURL) {
2011-09-03 20:34:53 +00:00
NSURL * workURL = [doc workURL];
2006-11-10 08:09:18 +00:00
NSFileWrapper * wrapper =
2011-09-03 20:34:53 +00:00
[[[NSFileWrapper alloc] initWithURL:workURL options:0 error:nil] autorelease];
2006-11-10 08:09:18 +00:00
//
// Find newest pdf file
//
NSEnumerator * w = [[wrapper fileWrappers] objectEnumerator];
NSString * pdfPath = nil;
NSDate * pdfDate = nil;
while (wrapper = [w nextObject]) {
NSString * path = [wrapper filename];
if (![[path pathExtension] isEqual:@"pdf"])
continue;
NSDate * date = [[wrapper fileAttributes]
objectForKey:NSFileModificationDate];
if (!pdfPath || [date compare:pdfDate]==NSOrderedAscending) {
pdfPath = path;
pdfDate = date;
}
}
2006-11-10 08:09:18 +00:00
if (pdfPath)
2011-09-03 20:34:53 +00:00
pdfURL = [workURL URLByAppendingPathComponent:pdfPath];
}
2006-11-10 08:09:18 +00:00
if (pdfURL) {
PDFDocument * pdfDoc =
[[[PDFDocument alloc] initWithURL:pdfURL] autorelease];
[(PDFView *)pdfView setDocument: pdfDoc];
[pdfView setNeedsDisplay:YES];
}
2006-10-26 08:21:50 +00:00
}
}
- (IBAction)printDocument:(id)sender
{
[pdfView printWithInfo: [NSPrintInfo sharedPrintInfo] autoRotate: YES];
}
- (void)windowDidLoad
{
}
@end