Revision: 4200
http://skim-app.svn.sourceforge.net/skim-app/?rev=4200&view=rev
Author: hofman
Date: 2008-07-13 04:47:28 -0700 (Sun, 13 Jul 2008)
Log Message:
-----------
reorganize code in synchronizer, avoids some unnecessary checks.
Modified Paths:
--------------
trunk/SKPDFSynchronizer.h
trunk/SKPDFSynchronizer.m
Modified: trunk/SKPDFSynchronizer.h
===================================================================
--- trunk/SKPDFSynchronizer.h 2008-07-13 10:37:42 UTC (rev 4199)
+++ trunk/SKPDFSynchronizer.h 2008-07-13 11:47:28 UTC (rev 4200)
@@ -72,8 +72,8 @@
- (NSString *)fileName;
- (void)setFileName:(NSString *)newFileName;
-- (void)findFileLineForLocation:(NSPoint)point inRect:(NSRect)rect
atPageIndex:(unsigned int)pageIndex;
-- (void)findPageLocationForLine:(int)line inFile:(NSString *)file;
+- (void)findFileAndLineForLocation:(NSPoint)point inRect:(NSRect)rect
atPageIndex:(unsigned int)pageIndex;
+- (void)findPageAndLocationForLine:(int)line inFile:(NSString *)file;
- (void)stopDOServer;
Modified: trunk/SKPDFSynchronizer.m
===================================================================
--- trunk/SKPDFSynchronizer.m 2008-07-13 10:37:42 UTC (rev 4199)
+++ trunk/SKPDFSynchronizer.m 2008-07-13 11:47:28 UTC (rev 4200)
@@ -80,8 +80,8 @@
@protocol SKPDFSynchronizerServerThread
- (oneway void)cleanup;
-- (oneway void)serverFindFileLineForLocation:(NSPoint)point
inRect:(NSRect)rect atPageIndex:(unsigned int)pageIndex;
-- (oneway void)serverFindPageLocationForLine:(int)line inFile:(bycopy NSString
*)file;
+- (oneway void)serverFindFileAndLineForLocation:(NSPoint)point
inRect:(NSRect)rect atPageIndex:(unsigned int)pageIndex;
+- (oneway void)serverFindPageAndLocationForLine:(int)line inFile:(bycopy
NSString *)file;
@end
@protocol SKPDFSynchronizerMainThread
@@ -240,12 +240,12 @@
#pragma mark | Finding
-- (void)findFileLineForLocation:(NSPoint)point inRect:(NSRect)rect
atPageIndex:(unsigned int)pageIndex {
- [serverOnServerThread serverFindFileLineForLocation:point inRect:rect
atPageIndex:pageIndex];
+- (void)findFileAndLineForLocation:(NSPoint)point inRect:(NSRect)rect
atPageIndex:(unsigned int)pageIndex {
+ [serverOnServerThread serverFindFileAndLineForLocation:point inRect:rect
atPageIndex:pageIndex];
}
-- (void)findPageLocationForLine:(int)line inFile:(NSString *)file {
- [serverOnServerThread serverFindPageLocationForLine:line inFile:file];
+- (void)findPageAndLocationForLine:(int)line inFile:(NSString *)file {
+ [serverOnServerThread serverFindPageAndLocationForLine:line inFile:file];
}
#pragma mark Main thread
@@ -340,6 +340,8 @@
#pragma mark | Parsing and Finding
+#pragma mark || PDFSync
+
- (BOOL)parsePdfsyncFile:(NSString *)theFileName {
[pages removeAllObjects];
@@ -451,49 +453,6 @@
return rv;
}
-- (BOOL)parseSynctexFile:(NSString *)theFileName {
- BOOL rv = NO;
-#ifdef SYNCTEX_FEATURE
- if (scanner)
- synctex_scanner_free(scanner);
- if (scanner = synctex_scanner_new_with_output_file([theFileName
fileSystemRepresentation])) {
- [self
setSyncFileName:SKPathFromFileSystemRepresentation(synctex_scanner_get_synctex(scanner))];
- isPdfsync = NO;
- rv = YES;
- }
-#endif
- return rv;
-}
-
-- (BOOL)parseSyncFileIfNeeded {
- NSString *theFileName = [self fileName];
- BOOL rv = NO;
-
- if (theFileName) {
- NSString *theSyncFileName = [self syncFileName];
-
- if (theSyncFileName && SKFileExistsAtPath(theSyncFileName)) {
- NSDate *modDate = SKFileModificationDateAtPath(theFileName);
- NSDate *currentModDate = [self lastModDate];
-
- if (currentModDate && [modDate compare:currentModDate] !=
NSOrderedDescending)
- rv = YES;
- else if (isPdfsync)
- rv = [self parsePdfsyncFile:theSyncFileName];
- else
- rv = [self parseSynctexFile:theFileName];
- } else {
- theSyncFileName = [theFileName
stringByReplacingPathExtension:SKPDFSynchronizerPdfsyncExtension];
-
- if (SKFileExistsAtPath(theSyncFileName))
- rv = [self parsePdfsyncFile:theSyncFileName];
- else
- rv = [self parseSynctexFile:theFileName];
- }
- }
- return rv;
-}
-
- (BOOL)pdfsyncFindFileLine:(int *)line file:(NSString **)file
forLocation:(NSPoint)point inRect:(NSRect)rect atPageIndex:(unsigned
int)pageIndex {
BOOL rv = NO;
if (pageIndex < [pages count]) {
@@ -604,6 +563,22 @@
return rv;
}
+#pragma mark || SyncTeX
+
+- (BOOL)parseSynctexFile:(NSString *)theFileName {
+ BOOL rv = NO;
+#ifdef SYNCTEX_FEATURE
+ if (scanner)
+ synctex_scanner_free(scanner);
+ if (scanner = synctex_scanner_new_with_output_file([theFileName
fileSystemRepresentation])) {
+ [self
setSyncFileName:SKPathFromFileSystemRepresentation(synctex_scanner_get_synctex(scanner))];
+ isPdfsync = NO;
+ rv = [self shouldKeepRunning];
+ }
+#endif
+ return rv;
+}
+
- (BOOL)synctexFindFileLine:(int *)line file:(NSString **)file
forLocation:(NSPoint)point inRect:(NSRect)rect atPageIndex:(unsigned
int)pageIndex {
BOOL rv = NO;
#ifdef SYNCTEX_FEATURE
@@ -635,39 +610,67 @@
return rv;
}
-- (oneway void)serverFindFileLineForLocation:(NSPoint)point
inRect:(NSRect)rect atPageIndex:(unsigned int)pageIndex {
- int foundLine = -1;
- NSString *foundFile = nil;
- BOOL success = NO;
+#pragma mark || Generic
+
+- (BOOL)parseSyncFileIfNeeded {
+ NSString *theFileName = [self fileName];
+ BOOL rv = NO;
- if ([self shouldKeepRunning] && [self parseSyncFileIfNeeded]) {
- if ([self shouldKeepRunning]) {
- if (isPdfsync)
- success = [self pdfsyncFindFileLine:&foundLine file:&foundFile
forLocation:point inRect:rect atPageIndex:pageIndex];
+ if (theFileName) {
+ NSString *theSyncFileName = [self syncFileName];
+
+ if (theSyncFileName && SKFileExistsAtPath(theSyncFileName)) {
+ NSDate *modDate = SKFileModificationDateAtPath(theFileName);
+ NSDate *currentModDate = [self lastModDate];
+
+ if (currentModDate && [modDate compare:currentModDate] !=
NSOrderedDescending)
+ rv = YES;
+ else if (isPdfsync)
+ rv = [self parsePdfsyncFile:theSyncFileName];
else
- success = [self synctexFindFileLine:&foundLine file:&foundFile
forLocation:point inRect:rect atPageIndex:pageIndex];
+ rv = [self parseSynctexFile:theFileName];
+ } else {
+ theSyncFileName = [theFileName
stringByReplacingPathExtension:SKPDFSynchronizerPdfsyncExtension];
+
+ if (SKFileExistsAtPath(theSyncFileName))
+ rv = [self parsePdfsyncFile:theSyncFileName];
+ else
+ rv = [self parseSynctexFile:theFileName];
}
}
-
- if (success && [self shouldKeepRunning])
- [serverOnMainThread serverFoundLine:foundLine inFile:foundFile];
+ return rv;
}
-- (oneway void)serverFindPageLocationForLine:(int)line inFile:(bycopy NSString
*)file {
- unsigned int foundPageIndex = NSNotFound;
- NSPoint foundPoint = NSZeroPoint;
-
- if ([self shouldKeepRunning] && file && [self parseSyncFileIfNeeded] &&
[lines objectForKey:file]) {
- if ([self shouldKeepRunning]) {
- if (isPdfsync)
- [self pdfsyncFindPage:&foundPageIndex location:&foundPoint
forLine:line inFile:file];
- else
- [self synctexFindPage:&foundPageIndex location:&foundPoint
forLine:line inFile:file];
- }
+- (oneway void)serverFindFileAndLineForLocation:(NSPoint)point
inRect:(NSRect)rect atPageIndex:(unsigned int)pageIndex {
+ if ([self shouldKeepRunning] && [self parseSyncFileIfNeeded]) {
+ int foundLine = -1;
+ NSString *foundFile = nil;
+ BOOL success = NO;
+
+ if (isPdfsync)
+ success = [self pdfsyncFindFileLine:&foundLine file:&foundFile
forLocation:point inRect:rect atPageIndex:pageIndex];
+ else
+ success = [self synctexFindFileLine:&foundLine file:&foundFile
forLocation:point inRect:rect atPageIndex:pageIndex];
+
+ if (success && [self shouldKeepRunning])
+ [serverOnMainThread serverFoundLine:foundLine inFile:foundFile];
}
-
- if ([self shouldKeepRunning])
- [serverOnMainThread serverFoundLocation:foundPoint
atPageIndex:foundPageIndex];
}
+- (oneway void)serverFindPageAndLocationForLine:(int)line inFile:(bycopy
NSString *)file {
+ if (file && [self shouldKeepRunning] && [self parseSyncFileIfNeeded]) {
+ unsigned int foundPageIndex = NSNotFound;
+ NSPoint foundPoint = NSZeroPoint;
+ BOOL success = NO;
+
+ if (isPdfsync)
+ success = [self pdfsyncFindPage:&foundPageIndex
location:&foundPoint forLine:line inFile:file];
+ else
+ success = [self synctexFindPage:&foundPageIndex
location:&foundPoint forLine:line inFile:file];
+
+ if (success && [self shouldKeepRunning])
+ [serverOnMainThread serverFoundLocation:foundPoint
atPageIndex:foundPageIndex];
+ }
+}
+
@end
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit