diff options
author | randomguy3 <randomguy3@7c02a99a-9b00-45e3-bf44-6f3dd7fddb64> | 2012-01-10 18:27:19 +0000 |
---|---|---|
committer | randomguy3 <randomguy3@7c02a99a-9b00-45e3-bf44-6f3dd7fddb64> | 2012-01-10 18:27:19 +0000 |
commit | 924aad8f38e277547b104977dd48ef2be7c702f8 (patch) | |
tree | b7c731f461c3dcad3ea87b79e8e916a8387c7dfa /tikzit/src/linux/PreviewRenderer.m | |
parent | e77f7c4f027d9fefb609bef3c97df9b8ff0c2a31 (diff) |
GTK: Allow the path to pdflatex to be configured
git-svn-id: https://tikzit.svn.sourceforge.net/svnroot/tikzit/trunk@377 7c02a99a-9b00-45e3-bf44-6f3dd7fddb64
Diffstat (limited to 'tikzit/src/linux/PreviewRenderer.m')
-rw-r--r-- | tikzit/src/linux/PreviewRenderer.m | 67 |
1 files changed, 46 insertions, 21 deletions
diff --git a/tikzit/src/linux/PreviewRenderer.m b/tikzit/src/linux/PreviewRenderer.m index 6f80982..98c328e 100644 --- a/tikzit/src/linux/PreviewRenderer.m +++ b/tikzit/src/linux/PreviewRenderer.m @@ -16,21 +16,28 @@ */ #import "PreviewRenderer.h" + #import "CairoRenderContext.h" +#import "Configuration.h" +#import "Preambles.h" +#import "TikzDocument.h" @implementation PreviewRenderer +@synthesize preambles,document; + - (id) init { [self release]; self = nil; return nil; } -- (id) initWithPreambles:(Preambles*)p { +- (id) initWithPreambles:(Preambles*)p config:(Configuration*)c { self = [super init]; if (self) { document = nil; + config = [c retain]; preambles = [p retain]; pdfDocument = NULL; pdfPage = NULL; @@ -39,6 +46,23 @@ return self; } +- (void) dealloc { + [document release]; + [config release]; + [preambles release]; + + if (pdfDocument) { + g_object_unref (pdfDocument); + pdfDocument = NULL; + } + if (pdfPage) { + g_object_unref (pdfPage); + pdfPage = NULL; + } + + [super dealloc]; +} + - (BOOL) update { NSError *error = nil; BOOL result = [self updateWithError:&error]; @@ -85,11 +109,14 @@ NSString *pdfFile = [NSString stringWithFormat:@"file://%@/tikzit.pdf", tempDir]; [tex writeToFile:texFile atomically:YES]; - // run pdflatex in a bash shell NSTask *latexTask = [[NSTask alloc] init]; [latexTask setCurrentDirectoryPath:tempDir]; + // GNUStep is clever enough to use PATH - [latexTask setLaunchPath:@"pdflatex"]; + NSString *path = [config stringEntry:@"pdflatex" + inGroup:@"Previews" + withDefault:@"pdflatex"]; + [latexTask setLaunchPath:path]; NSArray *args = [NSArray arrayWithObjects: @"-fmt=latex", @@ -105,15 +132,27 @@ NSFileHandle *latexOut = [pout fileHandleForReading]; - [latexTask launch]; - [latexTask waitUntilExit]; + BOOL success = NO; + + NS_DURING { + [latexTask launch]; + [latexTask waitUntilExit]; + } NS_HANDLER { + NSString *desc = [NSString stringWithFormat:@"Failed to run '%@'", path]; + NSMutableDictionary *errorDetail = [NSMutableDictionary dictionaryWithCapacity:2]; + [errorDetail setValue:desc forKey:NSLocalizedDescriptionKey]; + *error = [NSError errorWithDomain:TZErrorDomain code:TZ_ERR_IO userInfo:errorDetail]; + + // remove all temporary files + [[NSFileManager defaultManager] removeFileAtPath:tempDir handler:NULL]; + + return NO; + } NS_ENDHANDLER NSData *data = [latexOut readDataToEndOfFile]; NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; - BOOL success = NO; - if ([latexTask terminationStatus] != 0) { if (error) { NSMutableDictionary *errorDetail = [NSMutableDictionary dictionaryWithCapacity:2]; @@ -156,20 +195,6 @@ return pdfPage ? YES : NO; } -- (Preambles*) preambles { - return preambles; -} - -- (TikzDocument*) document { - return document; -} - -- (void) setDocument:(TikzDocument*)doc { - [doc retain]; - [document release]; - document = doc; -} - - (double) width { double w = 0.0; if (pdfPage) |