|
@@ -17,6 +17,8 @@
|
|
#import "CPDFListSignatureAnnotation+Private.h"
|
|
#import "CPDFListSignatureAnnotation+Private.h"
|
|
#import "CStampSignatureObject.h"
|
|
#import "CStampSignatureObject.h"
|
|
#import "NSGeometry+PDFListView.h"
|
|
#import "NSGeometry+PDFListView.h"
|
|
|
|
+#import "CPDFSelection+PDFListView.h"
|
|
|
|
+#import <objc/runtime.h>
|
|
|
|
|
|
@implementation CPDFListView (Extension)
|
|
@implementation CPDFListView (Extension)
|
|
|
|
|
|
@@ -103,4 +105,63 @@
|
|
return annotation;
|
|
return annotation;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+- (void)checkSpelling:(id)sender {
|
|
|
|
+ CPDFSelection *selection = [self currentSelection];
|
|
|
|
+ CPDFPage *page;
|
|
|
|
+ NSUInteger idx, i, first, iMax = [[self document] pageCount];
|
|
|
|
+ BOOL didWrap = NO;
|
|
|
|
+ NSRange range;
|
|
|
|
+
|
|
|
|
+ if ([selection hasCharacters]) {
|
|
|
|
+ page = [selection safeLastPage];
|
|
|
|
+ idx = [selection safeIndexOfLastCharacterOnPage:page];
|
|
|
|
+ if (idx == NSNotFound)
|
|
|
|
+ idx = 0;
|
|
|
|
+ } else {
|
|
|
|
+ page = [self currentPage];
|
|
|
|
+ idx = 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (self.spellingTag == 0) {
|
|
|
|
+ self.spellingTag = [NSSpellChecker uniqueSpellDocumentTag];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ i = first = [page pageIndex];
|
|
|
|
+ while (YES) {
|
|
|
|
+ range = [[NSSpellChecker sharedSpellChecker] checkSpellingOfString:[page string] startingAt:0 language:nil wrap:NO inSpellDocumentWithTag:self.spellingTag wordCount:NULL];
|
|
|
|
+ if (range.location != NSNotFound) break;
|
|
|
|
+ if (didWrap && i == first) break;
|
|
|
|
+ if (++i >= iMax) {
|
|
|
|
+ i = 0;
|
|
|
|
+ didWrap = YES;
|
|
|
|
+ }
|
|
|
|
+ page = [[self document] pageAtIndex:i];
|
|
|
|
+ idx = 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (range.location != NSNotFound) {
|
|
|
|
+ selection = [page selectionForRange:range];
|
|
|
|
+ [self setCurrentSelection:selection];
|
|
|
|
+ [self goToRect:[selection boundsForPage:page] onPage:page];
|
|
|
|
+ [[NSSpellChecker sharedSpellChecker] updateSpellingPanelWithMisspelledWord:[selection string]];
|
|
|
|
+ } else NSBeep();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+- (void)showGuessPanel:(id)sender {
|
|
|
|
+ [self checkSpelling:sender];
|
|
|
|
+ [[[NSSpellChecker sharedSpellChecker] spellingPanel] orderFront:self];
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+- (void)ignoreSpelling:(id)sender {
|
|
|
|
+ [[NSSpellChecker sharedSpellChecker] ignoreWord:[[sender selectedCell] stringValue] inSpellDocumentWithTag:self.spellingTag];
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+- (void)setSpellingTag:(NSInteger)spellingTag {
|
|
|
|
+ objc_setAssociatedObject(self, @selector(spellingTag), @(spellingTag), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+- (NSInteger)spellingTag {
|
|
|
|
+ return [objc_getAssociatedObject(self, @selector(spellingTag)) integerValue];
|
|
|
|
+}
|
|
|
|
+
|
|
@end
|
|
@end
|