Previous Entry Add to Memories Tell a Friend Next Entry
Tabbing in PDF Notation Editor
[info]javiermosleyre

Pent by Bathroom Calhoun, the PDF Annotation Editor
is a sample application that employs PDF Kit to canvass, edit, and make PDF notations.


It allows you chit in Trial fashion but not in Edit way.


I necessitated to tab in Edit fashion, but was headed in the incorrect way when Can Calhoun graciously supplied this recip:


`` Grab keyDown 's in your PDFView subclass and maintain course of the current notation with `` direction ''. Manually progress the focusing by moving round-robin through the notes on the page. ''


Here is its execution:



// Add a case to [PDFViewEdit keyDown] to detect the Tab key
// and call "advanceFocus" when it is hit.
- (void) keyDown: (NSEvent *) theEvent
{
 unichar oneChar;

 // Skip out if not in edit mode.
 if (_editMode == NO)
 {
   [super keyDown: theEvent];
   return;
 }

 // Get the character from the keyDown event.
 oneChar = [[theEvent charactersIgnoringModifiers] characterAtIndex: 0];

 // Delete or Tab ?
 if ((oneChar == NSDeleteCharacter) || (oneChar == NSDeleteFunctionKey))
 {
   [self delete: self];
 }
 else if (oneChar == NSTabCharacter)
 {
   [self advanceFocus];
 }
 else
 {
   [super keyDown: theEvent];
 }
}

Add two methods toPDFViewEdit.m
and their method declarations toPDFViewEdit.h.



// Tab key was hit; move focus to the next widget.
- (void) advanceFocus
{
 if (_activeAnnotation != NULL)
 {
   PDFPage * currentPage = [_activeAnnotation page];

   // Walk array of annotations.
   NSArray *annotations = [currentPage annotations];
   int annotCount = [annotations count];

   int activeIndex = [annotations indexOfObject: _activeAnnotation];

   int newActiveIndex = [self nextAnnotIndex: activeIndex withinCount: annotCount];

   PDFAnnotation * newActiveAnnotation = [annotations objectAtIndex: newActiveIndex];

   [self selectAnnotation: newActiveAnnotation];
 }
}


// return the index of the next annot, wrapping around on the current page.
- (int) nextAnnotIndex: (int) activeIndex withinCount: (int) annotCountForPage
{
 int nextIndex = -1;

    if (activeIndex +1 < annotCountForPage)
 {
   nextIndex = activeIndex + 1;
 }
 else
 {
   nextIndex = 0; // Wrap around on page.
 }

 return nextIndex;
}

Voil, that Holds all there is to that! Thanks Bathroom!


Related posts:
Castanets - In the Vines

Undertones - The Very Best of the Undertones

Nick Cave and the Bad Seeds - Live Seeds

Bryan Ferry - Dylanesque

Wolfgang Amadeus Mozart - Piano Concertos (11 of 12)


Home