Revision: 5507
          http://skim-app.svn.sourceforge.net/skim-app/?rev=5507&view=rev
Author:   hofman
Date:     2009-07-22 13:16:32 +0000 (Wed, 22 Jul 2009)

Log Message:
-----------
Add an extra optional parameter to "go to" script command and option to 
displayline script to show the reading bar from pdf-tex-sync instead of 
selecting.

Modified Paths:
--------------
    trunk/SKPDFDocument.m
    trunk/SKPDFSynchronizer.h
    trunk/SKPDFSynchronizer.m
    trunk/SKPDFSynchronizerServer.h
    trunk/SKPDFSynchronizerServer.m
    trunk/SKPDFView.h
    trunk/SKPDFView.m
    trunk/SKReadingBar.h
    trunk/SKReadingBar.m
    trunk/Skim.sdef
    trunk/displayline

Modified: trunk/SKPDFDocument.m
===================================================================
--- trunk/SKPDFDocument.m       2009-07-22 12:33:55 UTC (rev 5506)
+++ trunk/SKPDFDocument.m       2009-07-22 13:16:32 UTC (rev 5507)
@@ -1623,13 +1623,13 @@
     }
 }
 
-- (void)synchronizer:(SKPDFSynchronizer *)synchronizer 
foundLocation:(NSPoint)point atPageIndex:(NSUInteger)pageIndex 
isFlipped:(BOOL)isFlipped {
+- (void)synchronizer:(SKPDFSynchronizer *)synchronizer 
foundLocation:(NSPoint)point atPageIndex:(NSUInteger)pageIndex 
options:(NSInteger)options {
     PDFPage *page = [[self pdfDocument] pageAtIndex:pageIndex];
-    if (isFlipped)
+    if (options & SKPDFSynchronizerFlippedMask)
         point.y = NSMaxY([page boundsForBox:kPDFDisplayBoxMediaBox]) - point.y;
     if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKShouldHighlightSearchResultsKey])
         [[self mainWindowController] addTemporaryAnnotationForPoint:point 
onPage:page];
-    [[self pdfView] displayLineAtPoint:point inPageAtIndex:pageIndex];
+    [[self pdfView] displayLineAtPoint:point inPageAtIndex:pageIndex 
showReadingBar:(options & SKPDFSynchronizerShowReadingBarMask) != 0];
 }
 
 
@@ -2130,11 +2130,13 @@
         [[self pdfView] scrollAnnotationToVisible:(PDFAnnotation *)location];
     } else if ([location isKindOfClass:[SKLine class]]) {
         id source = [args objectForKey:@"Source"];
+        BOOL showBar = [[args objectForKey:@"ShowReadingBar"] boolValue];
+        NSInteger options = showBar ? SKPDFSynchronizerShowReadingBarMask : 0;
         if ([source isKindOfClass:[NSString class]])
             source = [NSURL fileURLWithPath:source];
         if ([source isKindOfClass:[NSURL class]] == NO)
             source = [self fileURL];
-        [[self synchronizer] findPageAndLocationForLine:[location index] 
inFile:[[source path] stringByReplacingPathExtension:@"tex"]];
+        [[self synchronizer] findPageAndLocationForLine:[location index] 
inFile:[[source path] stringByReplacingPathExtension:@"tex"] options:options];
     } else {
         PDFSelection *selection = [PDFSelection 
selectionWithSpecifier:[[command arguments] objectForKey:@"To"]];
         if ([[selection pages] count]) {

Modified: trunk/SKPDFSynchronizer.h
===================================================================
--- trunk/SKPDFSynchronizer.h   2009-07-22 12:33:55 UTC (rev 5506)
+++ trunk/SKPDFSynchronizer.h   2009-07-22 13:16:32 UTC (rev 5507)
@@ -38,6 +38,11 @@
 
 #import <Cocoa/Cocoa.h>
 
+enum {
+    SKPDFSynchronizerDefaultOptions = 0,
+    SKPDFSynchronizerShowReadingBarMask = 1 << 0,
+    SKPDFSynchronizerFlippedMask = 1 << 1,
+};
 
 @interface SKPDFSynchronizer : NSObject {
     id delegate;
@@ -54,7 +59,7 @@
 - (void)setFileName:(NSString *)newFileName;
 
 - (void)findFileAndLineForLocation:(NSPoint)point inRect:(NSRect)rect 
pageBounds:(NSRect)bounds atPageIndex:(NSUInteger)pageIndex;
-- (void)findPageAndLocationForLine:(NSInteger)line inFile:(NSString *)file;
+- (void)findPageAndLocationForLine:(NSInteger)line inFile:(NSString *)file 
options:(NSInteger)options;
 
 // this must be called to stop the DO server from running in the server thread
 - (void)terminate;
@@ -64,5 +69,5 @@
 
 @interface NSObject (SKPDFSynchronizerDelegate)
 - (void)synchronizer:(SKPDFSynchronizer *)synchronizer 
foundLine:(NSInteger)line inFile:(NSString *)file;
-- (void)synchronizer:(SKPDFSynchronizer *)synchronizer 
foundLocation:(NSPoint)point atPageIndex:(NSUInteger)pageIndex 
isFlipped:(BOOL)isFlipped;
+- (void)synchronizer:(SKPDFSynchronizer *)synchronizer 
foundLocation:(NSPoint)point atPageIndex:(NSUInteger)pageIndex 
options:(NSInteger)options;
 @end

Modified: trunk/SKPDFSynchronizer.m
===================================================================
--- trunk/SKPDFSynchronizer.m   2009-07-22 12:33:55 UTC (rev 5506)
+++ trunk/SKPDFSynchronizer.m   2009-07-22 13:16:32 UTC (rev 5507)
@@ -119,8 +119,8 @@
     [serverProxy findFileAndLineForLocation:point inRect:rect 
pageBounds:bounds atPageIndex:pageIndex];
 }
 
-- (void)findPageAndLocationForLine:(NSInteger)line inFile:(NSString *)file {
-    [serverProxy findPageAndLocationForLine:line inFile:file];
+- (void)findPageAndLocationForLine:(NSInteger)line inFile:(NSString *)file 
options:(NSInteger)options {
+    [serverProxy findPageAndLocationForLine:line inFile:file options:options];
 }
 
 #pragma mark | Client protocol
@@ -130,9 +130,9 @@
         [delegate synchronizer:self foundLine:line inFile:file];
 }
 
-- (oneway void)foundLocation:(NSPoint)point atPageIndex:(NSUInteger)pageIndex 
isFlipped:(BOOL)isFlipped {
-    if ([server shouldKeepRunning] && [delegate 
respondsToSelector:@selector(synchronizer:foundLocation:atPageIndex:isFlipped:)])
-        [delegate synchronizer:self foundLocation:point atPageIndex:pageIndex 
isFlipped:isFlipped];
+- (oneway void)foundLocation:(NSPoint)point atPageIndex:(NSUInteger)pageIndex 
options:(NSInteger)options {
+    if ([server shouldKeepRunning] && [delegate 
respondsToSelector:@selector(synchronizer:foundLocation:atPageIndex:options:)])
+        [delegate synchronizer:self foundLocation:point atPageIndex:pageIndex 
options:options];
 }
 
 @end

Modified: trunk/SKPDFSynchronizerServer.h
===================================================================
--- trunk/SKPDFSynchronizerServer.h     2009-07-22 12:33:55 UTC (rev 5506)
+++ trunk/SKPDFSynchronizerServer.h     2009-07-22 13:16:32 UTC (rev 5507)
@@ -43,14 +43,14 @@
 @protocol SKPDFSynchronizerServer
 - (oneway void)stopRunning; 
 - (oneway void)findFileAndLineForLocation:(NSPoint)point inRect:(NSRect)rect 
pageBounds:(NSRect)bounds atPageIndex:(NSUInteger)pageIndex;
-- (oneway void)findPageAndLocationForLine:(NSInteger)line inFile:(bycopy 
NSString *)file;
+- (oneway void)findPageAndLocationForLine:(NSInteger)line inFile:(bycopy 
NSString *)file options:(NSInteger)options;
 @end
 
 // these methods can be sent to the proxy for the client and must be 
implemented by the client
 @protocol SKPDFSynchronizerClient
 - (void)setServerProxy:(byref id)anObject;
 - (oneway void)foundLine:(NSInteger)line inFile:(bycopy NSString *)file;
-- (oneway void)foundLocation:(NSPoint)point atPageIndex:(NSUInteger)pageIndex 
isFlipped:(BOOL)isFlipped;
+- (oneway void)foundLocation:(NSPoint)point atPageIndex:(NSUInteger)pageIndex 
options:(NSInteger)options;
 @end
 
 

Modified: trunk/SKPDFSynchronizerServer.m
===================================================================
--- trunk/SKPDFSynchronizerServer.m     2009-07-22 12:33:55 UTC (rev 5506)
+++ trunk/SKPDFSynchronizerServer.m     2009-07-22 13:16:32 UTC (rev 5507)
@@ -623,7 +623,7 @@
     }
 }
 
-- (oneway void)findPageAndLocationForLine:(NSInteger)line inFile:(bycopy 
NSString *)file {
+- (oneway void)findPageAndLocationForLine:(NSInteger)line inFile:(bycopy 
NSString *)file options:(NSInteger)options {
     if (file && [self shouldKeepRunning] && [self loadSyncFileIfNeeded]) {
         NSUInteger foundPageIndex = NSNotFound;
         NSPoint foundPoint = NSZeroPoint;
@@ -636,8 +636,11 @@
         else
             success = [self synctexFindPage:&foundPageIndex 
location:&foundPoint forLine:line inFile:file];
         
-        if (success && [self shouldKeepRunning])
-            [clientProxy foundLocation:foundPoint atPageIndex:foundPageIndex 
isFlipped:isPdfsync == NO];
+        if (success && [self shouldKeepRunning]) {
+            if (isPdfsync == NO)
+                options |= SKPDFSynchronizerFlippedMask;
+            [clientProxy foundLocation:foundPoint atPageIndex:foundPageIndex 
options:options];
+        }
     }
 }
 

Modified: trunk/SKPDFView.h
===================================================================
--- trunk/SKPDFView.h   2009-07-22 12:33:55 UTC (rev 5506)
+++ trunk/SKPDFView.h   2009-07-22 13:16:32 UTC (rev 5507)
@@ -196,7 +196,7 @@
 
 - (void)scrollAnnotationToVisible:(PDFAnnotation *)annotation;
 - (void)scrollRect:(NSRect)rect inPageToVisible:(PDFPage *)page;
-- (void)displayLineAtPoint:(NSPoint)point inPageAtIndex:(NSUInteger)pageIndex;
+- (void)displayLineAtPoint:(NSPoint)point inPageAtIndex:(NSUInteger)pageIndex 
showReadingBar:(BOOL)showBar;
 
 - (void)takeSnapshot:(id)sender;
 

Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m   2009-07-22 12:33:55 UTC (rev 5506)
+++ trunk/SKPDFView.m   2009-07-22 13:16:32 UTC (rev 5507)
@@ -2280,14 +2280,22 @@
     [self scrollRect:[annotation bounds] inPageToVisible:[annotation page]];
 }
 
-- (void)displayLineAtPoint:(NSPoint)point inPageAtIndex:(NSUInteger)pageIndex {
+- (void)displayLineAtPoint:(NSPoint)point inPageAtIndex:(NSUInteger)pageIndex 
showReadingBar:(BOOL)showBar {
     if (pageIndex < [[self document] pageCount]) {
         PDFPage *page = [[self document] pageAtIndex:pageIndex];
         PDFSelection *sel = [page selectionForLineAtPoint:point];
         NSRect rect = sel ? [sel boundsForPage:page] : 
SKRectFromCenterAndSize(point, SKMakeSquareSize(10.0));
         
-        if (sel && interactionMode != SKPresentationMode && ([self toolMode] 
== SKTextToolMode || [self toolMode] == SKNoteToolMode))
-            [self setCurrentSelection:sel];
+        if (interactionMode != SKPresentationMode) {
+            if (showBar) {
+                if ([self hasReadingBar] == NO)
+                    [self toggleReadingBar];
+                [readingBar setPage:page];
+                [readingBar goToPageForPoint:point];
+            } else if (sel && ([self toolMode] == SKTextToolMode || [self 
toolMode] == SKNoteToolMode)) {
+                [self setCurrentSelection:sel];
+            }
+        }
         [self scrollRect:rect inPageToVisible:page];
     }
 }

Modified: trunk/SKReadingBar.h
===================================================================
--- trunk/SKReadingBar.h        2009-07-22 12:33:55 UTC (rev 5506)
+++ trunk/SKReadingBar.h        2009-07-22 13:16:32 UTC (rev 5507)
@@ -66,5 +66,6 @@
 - (BOOL)goToPreviousLine;
 - (BOOL)goToNextPage;
 - (BOOL)goToPreviousPage;
+- (BOOL)goToPageForPoint:(NSPoint)point;
 
 @end

Modified: trunk/SKReadingBar.m
===================================================================
--- trunk/SKReadingBar.m        2009-07-22 12:33:55 UTC (rev 5506)
+++ trunk/SKReadingBar.m        2009-07-22 13:16:32 UTC (rev 5507)
@@ -183,4 +183,14 @@
     return didMove;
 }
 
+- (BOOL)goToPageForPoint:(NSPoint)point {
+    if ([lineRects count] == 0)
+        return NO;
+    NSInteger i = [lineRects count] - numberOfLines;
+    while (--i >= 0)
+        if (NSMaxY([[lineRects objectAtIndex:i] rectValue]) >= point.y) break;
+    currentLine = MAX(0, i);
+    return YES;
+}
+
 @end

Modified: trunk/Skim.sdef
===================================================================
--- trunk/Skim.sdef     2009-07-22 12:33:55 UTC (rev 5506)
+++ trunk/Skim.sdef     2009-07-22 13:16:32 UTC (rev 5507)
@@ -1237,6 +1237,10 @@
                                description="The TeX source file. By default 
this is derived from the file. Only applies for a TeX line."> 
                                <cocoa key="Source"/> 
                        </parameter>
+                       <parameter name="showing reading bar" code="RBar" 
type="boolean" optional="yes" 
+                               description="Whether to move the reading bar 
instead of selecting. Only applies for a TeX line."> 
+                               <cocoa key="ShowReadingBar"/> 
+                       </parameter>
         </command>
 
         <command name="convert notes" code="SKIMConv"

Modified: trunk/displayline
===================================================================
--- trunk/displayline   2009-07-22 12:33:55 UTC (rev 5506)
+++ trunk/displayline   2009-07-22 13:16:32 UTC (rev 5507)
@@ -2,14 +2,19 @@
 
 # displayline (Skim)
 #
-# Usage: displayline [-r] LINE PDFFILE [TEXSOURCEFILE]
+# Usage: displayline [-r] [-b] LINE PDFFILE [TEXSOURCEFILE]
 
 # get arguments
 revert=0
-if [ "$1" == "-r" -o "$1" == "-revert" ]; then
-  revert=1
+bar=0
+while [ "${1:0:1}" == "-" ]; do
+  if [ "$1" == "-r" -o "$1" == "-revert" ]; then
+    revert=1;
+  elif [ "$1" == "-b" -o "$1" == "-readingbar" ]; then
+    bar=1
+  fi
   shift
-fi
+done
 line=$1
 file="$2"
 [ $# -gt 2 ] && source="$3" || source="${file%.pdf}.tex"
@@ -20,15 +25,16 @@
 
 # pass arguments as NULL-separated string to osascript
 # pass through cat to get them as raw bytes to preserve non-ASCII characters
-echo -ne "${line}\x00${file}\x00${source}\x00${revert}\x00" | \
+echo -ne "${line}\x00${file}\x00${source}\x00${revert}\x00${bar}\x00" | \
 /usr/bin/osascript \
   -e "set theArgv to do shell script \"/bin/cat\"" \
   -e "set AppleScript's text item delimiters to ASCII character 0" \
-  -e "set {theLine, theFile, theSource, shouldRevert} to text items of 
theArgv" \
+  -e "set {theLine, theFile, theSource, shouldRevert, shouldShowBar} to text 
items of theArgv" \
   -e "set theLine to theLine as integer" \
   -e "set theFile to POSIX file theFile" \
   -e "set theSource to POSIX file theSource" \
   -e "set shouldRevert to (shouldRevert as integer) as boolean" \
+  -e "set shouldShowBar to (shouldShowBar as integer) as boolean" \
   -e "tell application \"Skim\"" \
   -e "  activate" \
   -e "  if shouldRevert then" \
@@ -36,5 +42,5 @@
   -e "    if (count of theDocs) > 0 then revert theDocs" \
   -e "  end if" \
   -e "  open theFile" \
-  -e "  tell front document to go to TeX line theLine from theSource" \
+  -e "  tell front document to go to TeX line theLine from theSource showing 
reading bar shouldShowBar" \
   -e "end tell" -


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to