Revision: 2495
          http://skim-app.svn.sourceforge.net/skim-app/?rev=2495&view=rev
Author:   hofman
Date:     2007-07-13 09:39:31 -0700 (Fri, 13 Jul 2007)

Log Message:
-----------
Implement spell checking. 

Modified Paths:
--------------
    trunk/SKPDFView.h
    trunk/SKPDFView.m

Modified: trunk/SKPDFView.h
===================================================================
--- trunk/SKPDFView.h   2007-07-12 19:39:46 UTC (rev 2494)
+++ trunk/SKPDFView.h   2007-07-13 16:39:31 UTC (rev 2495)
@@ -111,6 +111,8 @@
     int trackingRect;
     NSMutableArray *hoverRects;
     int hoverRect;
+    
+    int spellingTag;
 }
 
 - (SKToolMode)toolMode;

Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m   2007-07-12 19:39:46 UTC (rev 2494)
+++ trunk/SKPDFView.m   2007-07-13 16:39:31 UTC (rev 2495)
@@ -150,6 +150,8 @@
     toolMode = [[NSUserDefaults standardUserDefaults] 
integerForKey:SKLastToolModeKey];
     annotationMode = [[NSUserDefaults standardUserDefaults] 
integerForKey:SKLastAnnotationModeKey];
     
+    spellingTag = [NSSpellChecker uniqueSpellDocumentTag];
+    
     hideNotes = NO;
     
     autohidesCursor = NO;
@@ -205,6 +207,7 @@
 }
 
 - (void)dealloc {
+    [[NSSpellChecker sharedSpellChecker] 
closeSpellDocumentWithTag:spellingTag];
     [[NSUserDefaultsController sharedUserDefaultsController] 
removeObserver:self forKeys:
         [NSArray arrayWithObjects:SKReadingBarColorKey, SKReadingBarInvertKey, 
nil]];
     [[NSNotificationCenter defaultCenter] removeObserver:self];
@@ -1232,6 +1235,60 @@
     }
 }
 
+- (void)checkSpellingStartingAtIndex:(int)index onPage:(PDFPage *)page {
+    unsigned int i, first = [[self document] indexForPage:page];
+    unsigned int count = [[self document] pageCount];
+    BOOL didWrap = NO;
+    i = first;
+    NSRange range = NSMakeRange(NSNotFound, 0);
+    
+    while (YES) {
+        range = [[NSSpellChecker sharedSpellChecker] 
checkSpellingOfString:[page string] startingAt:index language:nil wrap:NO 
inSpellDocumentWithTag:spellingTag wordCount:NULL];
+        if (range.location != NSNotFound) break;
+        if (++i >= count) {
+            i = 0;
+            didWrap = YES;
+        }
+        if (didWrap && i > first) break;
+        page = [[self document] pageAtIndex:i];
+        index = 0;
+    }
+    
+    if (range.location != NSNotFound) {
+        PDFSelection *selection = [page selectionForRange:range];
+        [self setCurrentSelection:selection];
+        [self scrollRect:[selection boundsForPage:page] inPageToVisible:page];
+        [[NSSpellChecker sharedSpellChecker] 
updateSpellingPanelWithMisspelledWord:[selection string]];
+    } else NSBeep();
+}
+
+- (void)checkSpelling:(id)sender {
+    PDFSelection *selection = [self currentSelection];
+    PDFPage *page = [self currentPage];
+    int index = 0;
+    if ([[selection pages] count]) {
+        page = [[selection pages] lastObject];
+        index = NSMaxRange([selection safeRangeAtIndex:[selection 
safeNumberOfRangesOnPage:page] - 1 onPage:page]);
+    }
+    [self checkSpellingStartingAtIndex:index onPage:page];
+}
+
+- (void)showGuessPanel:(id)sender {
+    PDFSelection *selection = [self currentSelection];
+    PDFPage *page = [self currentPage];
+    int index = 0;
+    if ([[selection pages] count]) {
+        page = [[selection pages] objectAtIndex:0];
+        index = [selection safeRangeAtIndex:0 onPage:page].location;
+    }
+    [self checkSpellingStartingAtIndex:index onPage:page];
+    [[[NSSpellChecker sharedSpellChecker] spellingPanel] orderFront:self];
+}
+
+- (void)ignoreSpelling:(id)sender {
+    [[NSSpellChecker sharedSpellChecker] ignoreWord:[[sender selectedCell] 
stringValue] inSpellDocumentWithTag:spellingTag];
+}
+
 #pragma mark Tracking mousemoved fix
 
 - (void)setFrame:(NSRect)frame {


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

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to