Skip to content

Commit

Permalink
_dummyItemWithTag function; control-[ -> ESC
Browse files Browse the repository at this point in the history
  • Loading branch information
scrod committed Feb 8, 2011
1 parent abbd650 commit e260128
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
1 change: 0 additions & 1 deletion NotesTableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ typedef struct _ViewLocationContext {
- (NoteAttributeColumn*)noteAttributeColumnForIdentifier:(NSString*)identifier;

- (void)incrementNoteSelection:(id)sender;
- (void)incrementNoteSelectionWithDummyItem:(unichar) keyChar;

- (id)labelsListSource;
- (void)setLabelsListSource:(id)labelsSource;
Expand Down
25 changes: 11 additions & 14 deletions NotesTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#define SYNTHETIC_TAGS_COLUMN_INDEX 200

static NSMenuItem* _dummyItemWithTag(NotesTableView *tv, NSInteger aTag);
static void _CopyItemWithSelectorFromMenu(NSMenu *destMenu, NSMenu *sourceMenu, SEL aSel, id target);

@implementation NotesTableView
Expand Down Expand Up @@ -874,10 +875,9 @@ - (BOOL)performKeyEquivalent:(NSEvent *)theEvent {

BOOL isControlKeyPressed = (mods & NSControlKeyMask) != 0;
BOOL isCommandKeyPressed = (mods & NSCommandKeyMask) != 0;
BOOL isShiftKeyPressed = (mods & NSShiftKeyMask) != 0;

// Also catch Ctrl-J/-K to match the shortcuts of other apps
if ((isControlKeyPressed || isCommandKeyPressed) && (!isShiftKeyPressed)) {
if ((isControlKeyPressed || isCommandKeyPressed) && ((mods & NSShiftKeyMask) == 0)) {

// Determine the keyChar:
unichar keyChar = ' ';
Expand All @@ -893,32 +893,35 @@ - (BOOL)performKeyEquivalent:(NSEvent *)theEvent {
if (mods & NSAlternateKeyMask) {
[self selectRowAndScroll:((keyChar == kNext_Tag) ? [self numberOfRows] - 1 : 0)];
} else {
[self incrementNoteSelectionWithDummyItem: keyChar];
[self incrementNoteSelection:_dummyItemWithTag(self, keyChar)];
}
return YES;
}

// Handle N and P, but only when Control is pressed
if ( (keyChar == 'n' || keyChar == 'p') && (!isCommandKeyPressed)) {
// Determine if the note editing pane is selected:
BOOL isEditorFirstResponder = [[[NSApp mainWindow] firstResponder] isKindOfClass: [LinkingEditor class]];
if (!isEditorFirstResponder) {
[self incrementNoteSelectionWithDummyItem: (keyChar == 'n') ? kNext_Tag : kPrev_Tag];
if (![[[self window] firstResponder] isKindOfClass:[LinkingEditor class]]) {
[self incrementNoteSelection: _dummyItemWithTag(self, (keyChar == 'n' ? kNext_Tag : kPrev_Tag))];
return YES;
}
}

// Make Control-[ equivalent to Escape
if ( (keyChar == '[' ) && (!isCommandKeyPressed)) {
AppController* appDelegate = (AppController*)[NSApp delegate];
[appDelegate bringFocusToControlField:nil];
[self cancelOperation:nil];
return YES;
}
}

return [super performKeyEquivalent:theEvent];
}

static NSMenuItem* _dummyItemWithTag(NotesTableView *tv, NSInteger aTag) {
if (!tv->dummyItem) tv->dummyItem = [[NSMenuItem alloc] init];
[tv->dummyItem setTag:aTag];
return tv->dummyItem;
}

- (void)incrementNoteSelection:(id)sender {

Expand All @@ -937,12 +940,6 @@ - (void)incrementNoteSelection:(id)sender {
[self selectRowAndScroll:rowNumber];
}

- (void)incrementNoteSelectionWithDummyItem:(unichar) keyChar {
if (!dummyItem) dummyItem = [[NSMenuItem alloc] init];
[dummyItem setTag:keyChar];
[self incrementNoteSelection:dummyItem];
}

- (void)deselectAll:(id)sender {

[super deselectAll:sender];
Expand Down

0 comments on commit e260128

Please sign in to comment.