VocalEasel/Sources/VLPDFWindow.mm

83 lines
1.8 KiB
Plaintext
Raw 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
- (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) {
2006-11-10 08:09:18 +00:00
VLDocument *doc = [self document];
NSURL * pdfURL = [doc fileURLWithExtension:@"pdf"];
if (!pdfURL) {
NSString * path = [doc workPath];
NSFileWrapper * wrapper =
[[[NSFileWrapper alloc] initWithPath:path] autorelease];
//
// 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)
pdfURL =
[NSURL fileURLWithPath:
[path stringByAppendingPathComponent: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