Revision: 2323 http://skim-app.svn.sourceforge.net/skim-app/?rev=2323&view=rev Author: hofman Date: 2007-06-17 02:32:48 -0700 (Sun, 17 Jun 2007)
Log Message: ----------- Add script command to get the first/last index of a selection. Modified Paths: -------------- trunk/PDFSelection_SKExtensions.h trunk/PDFSelection_SKExtensions.m trunk/Skim.sdef Modified: trunk/PDFSelection_SKExtensions.h =================================================================== --- trunk/PDFSelection_SKExtensions.h 2007-06-16 23:57:27 UTC (rev 2322) +++ trunk/PDFSelection_SKExtensions.h 2007-06-17 09:32:48 UTC (rev 2323) @@ -54,19 +54,28 @@ @end +#pragma mark - + [EMAIL PROTECTED] SKJoinCommand : NSScriptCommand [EMAIL PROTECTED] + +#pragma mark - // We cannot set properties for a list of specifiers, so we get properties using some script commands @interface SKBoundsCommand : NSScriptCommand @end +#pragma mark - @interface SKTextCommand : NSScriptCommand @end +#pragma mark - @interface SKPagesCommand : NSScriptCommand @end +#pragma mark - [EMAIL PROTECTED] SKJoinCommand : NSScriptCommand [EMAIL PROTECTED] SKIndexCommand : NSScriptCommand @end Modified: trunk/PDFSelection_SKExtensions.m =================================================================== --- trunk/PDFSelection_SKExtensions.m 2007-06-16 23:57:27 UTC (rev 2322) +++ trunk/PDFSelection_SKExtensions.m 2007-06-17 09:32:48 UTC (rev 2323) @@ -323,7 +323,39 @@ @end +#pragma mark - [EMAIL PROTECTED] SKJoinCommand + +- (id)performDefaultImplementation { + id dP = [self directParameter]; + NSDictionary *args = [self evaluatedArguments]; + id other = [args objectForKey:@"To"]; + BOOL continuous = [[args objectForKey:@"Continuous"] boolValue]; + PDFSelection *selection = [PDFSelection selectionWithSpecifier:dP]; + PDFSelection *otherSelection = other ? [PDFSelection selectionWithSpecifier:other] : nil; + + if (selection == nil) + selection = otherSelection; + if (otherSelection) + [selection addSelection:otherSelection]; + + if (continuous) { + NSArray *pages = [selection pages]; + PDFPage *firstPage = [pages objectAtIndex:0]; + PDFPage *lastPage = [pages lastObject]; + int firstIndex = [selection safeRangeAtIndex:0 onPage:firstPage].location; + int lastIndex = NSMaxRange([selection safeRangeAtIndex:[selection safeNumberOfRangesOnPage:lastPage] - 1 onPage:lastPage]) - 1; + selection = [[firstPage document] selectionFromPage:firstPage atCharacterIndex:firstIndex toPage:lastPage atCharacterIndex:lastIndex]; + } + + return selection ? [selection objectSpecifier] : [NSArray array]; +} + [EMAIL PROTECTED] + +#pragma mark - + @implementation SKBoundsCommand - (id)performDefaultImplementation { @@ -367,6 +399,7 @@ @end +#pragma mark - @implementation SKTextCommand @@ -387,7 +420,7 @@ if (page == nil || [page isEqual:dPO]) textStorage = [dPO richText]; } else if ([dPO isKindOfClass:[PDFAnnotation class]]) { - if (page == nil || [[dPO page] isEqual:dPO]) + if (page == nil || [page isEqual:[dPO page]]) textStorage = [dPO textContents]; } else { attrString = [[PDFSelection selectionWithSpecifier:dP onPage:page] attributedString]; @@ -398,8 +431,9 @@ @end +#pragma mark - [EMAIL PROTECTED] SKPagesCommand [EMAIL PROTECTED] SKIndexCommand - (id)performDefaultImplementation { id dP = [self directParameter]; @@ -407,48 +441,58 @@ if ([dP isKindOfClass:[NSArray class]] == NO) dPO = [dP objectsByEvaluatingSpecifier]; + NSDictionary *args = [self evaluatedArguments]; + PDFPage *page = [args objectForKey:@"Page"]; + BOOL last = [[args objectForKey:@"Last"] boolValue]; + unsigned int index = NSNotFound; + if ([dPO isKindOfClass:[SKDocument class]]) { - return [dPO valueForKey:@"pages"]; + index = [[NSApp orderedDocuments] indexOfObjectIdenticalTo:dPO]; } else if ([dPO isKindOfClass:[PDFPage class]]) { - return [NSArray arrayWithObjects:dPO, nil]; + index = [[page document] indexForPage:dPO]; } else if ([dPO isKindOfClass:[PDFAnnotation class]]) { - return [NSArray arrayWithObjects:[dPO page], nil]; + index = [[(page ? (id)page : (id)[page containingDocument]) valueForKey:@"notes"] indexOfObjectIdenticalTo:dPO]; } else { - PDFSelection *selection = [PDFSelection selectionWithSpecifier:dP]; - return selection ? [selection pages] : [NSArray array]; + PDFSelection *selection = [PDFSelection selectionWithSpecifier:dP onPage:page]; + NSArray *pages = [selection pages]; + if ([pages count] && (page = [pages objectAtIndex:last ? [pages count] - 1 : 0])) { + int count = [selection safeNumberOfRangesOnPage:page]; + if (count > 0) { + NSRange range = [selection safeRangeAtIndex:last ? count - 1 : 0 onPage:page]; + if (range.length) { + index = last ? NSMaxRange(range) - 1 : range.location; + } + } + } } - return nil; + return [NSNumber numberWithInt:index == NSNotFound ? -1 : (int)index + 1]; } @end +#pragma mark - [EMAIL PROTECTED] SKJoinCommand [EMAIL PROTECTED] SKPagesCommand - (id)performDefaultImplementation { id dP = [self directParameter]; - NSDictionary *args = [self evaluatedArguments]; - id other = [args objectForKey:@"To"]; - BOOL continuous = [[args objectForKey:@"Continuous"] boolValue]; - PDFSelection *selection = [PDFSelection selectionWithSpecifier:dP]; - PDFSelection *otherSelection = other ? [PDFSelection selectionWithSpecifier:other] : nil; + id dPO = nil; + if ([dP isKindOfClass:[NSArray class]] == NO) + dPO = [dP objectsByEvaluatingSpecifier]; - if (selection == nil) - selection = otherSelection; - if (otherSelection) - [selection addSelection:otherSelection]; - - if (continuous) { - NSArray *pages = [selection pages]; - PDFPage *firstPage = [pages objectAtIndex:0]; - PDFPage *lastPage = [pages lastObject]; - int firstIndex = [selection safeRangeAtIndex:0 onPage:firstPage].location; - int lastIndex = NSMaxRange([selection safeRangeAtIndex:[selection safeNumberOfRangesOnPage:lastPage] - 1 onPage:lastPage]) - 1; - selection = [[firstPage document] selectionFromPage:firstPage atCharacterIndex:firstIndex toPage:lastPage atCharacterIndex:lastIndex]; + if ([dPO isKindOfClass:[SKDocument class]]) { + return [dPO valueForKey:@"pages"]; + } else if ([dPO isKindOfClass:[PDFPage class]]) { + return [NSArray arrayWithObjects:dPO, nil]; + } else if ([dPO isKindOfClass:[PDFAnnotation class]]) { + return [NSArray arrayWithObjects:[dPO page], nil]; + } else { + PDFSelection *selection = [PDFSelection selectionWithSpecifier:dP]; + return selection ? [selection pages] : [NSArray array]; } - return selection ? [selection objectSpecifier] : [NSArray array]; + return nil; } @end Modified: trunk/Skim.sdef =================================================================== --- trunk/Skim.sdef 2007-06-16 23:57:27 UTC (rev 2322) +++ trunk/Skim.sdef 2007-06-17 09:32:48 UTC (rev 2323) @@ -113,6 +113,9 @@ <responds-to name="get text for"> <cocoa method=""/> </responds-to> + <responds-to name="get index for"> + <cocoa method=""/> + </responds-to> <responds-to name="get pages for"> <cocoa method=""/> </responds-to> @@ -575,6 +578,9 @@ <responds-to name="get text for"> <cocoa method=""/> </responds-to> + <responds-to name="get index for"> + <cocoa method=""/> + </responds-to> <responds-to name="get pages for"> <cocoa method=""/> </responds-to> @@ -659,6 +665,9 @@ <responds-to name="get text for"> <cocoa method=""/> </responds-to> + <responds-to name="get index for"> + <cocoa method=""/> + </responds-to> <responds-to name="get pages for"> <cocoa method=""/> </responds-to> @@ -947,11 +956,11 @@ <type type="specifier" list="yes"/> <cocoa key="From"/> </parameter> - <parameter name="backward" code="Back" type="boolean" optional="yes" + <parameter name="backward search" code="Back" type="boolean" optional="yes" description="Search backward?"> <cocoa key="Backward"/> </parameter> - <parameter name="case sensitive" code="casS" type="boolean" optional="yes" + <parameter name="case sensitive search" code="casS" type="boolean" optional="yes" description="Is the search case sensitive?"> <cocoa key="CaseSensitive"/> </parameter> @@ -973,7 +982,7 @@ <cocoa key="To"/> <type type="specifier" list="yes"/> </parameter> - <parameter name="continuous" type="boolean" code="conI" optional="yes" + <parameter name="continuous selection" type="boolean" code="conI" optional="yes" description="Join to a continuous selection?"> <cocoa key="Continuous"/> </parameter> @@ -1025,12 +1034,36 @@ description="The text of the object."/> </command> + <command name="get index for" code="SKIMIndx" + description="Get the index of a document, page, note, or selection."> + <cocoa class="SKIndexCommand"/> + <synonym name="index for"/> + <direct-parameter + description="The document, page, note, or selection."> + <type type="document"/> + <type type="page"/> + <type type="note"/> + <type type="specifier" list="yes"/> + </direct-parameter> + <parameter name="on" type="page" code="on " optional="yes" + description="The page on which to get the index."> + <cocoa key="Page"/> + </parameter> + <parameter name="last" type="boolean" code="Last" optional="yes" + description="Gets the index of the last character of a selection."> + <cocoa key="Last"/> + </parameter> + <result type="integer" + description="The index for the object. Returns -1 if no index was found."> + </result> + </command> + <command name="get pages for" code="SKIMPags" description="Get the pages of a document, page, note, or selection."> <cocoa class="SKPagesCommand"/> <synonym name="pages for"/> <direct-parameter - description="The document, page, note or selection."> + description="The document, page, note, or selection."> <type type="document"/> <type type="page"/> <type type="note"/> 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