diff --git a/.gitignore b/.gitignore index e9f3e7b..051b3c1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store xcuserdata/ +GMailinator.xcodeproj/project.xcworkspace/xcshareddata/ \ No newline at end of file diff --git a/GMailinator.mailbundle.zip b/GMailinator.mailbundle.zip new file mode 100644 index 0000000..8d732dd Binary files /dev/null and b/GMailinator.mailbundle.zip differ diff --git a/GMailinator/GMailinator.m b/GMailinator/GMailinator.m index d6fd5af..945cdd0 100644 --- a/GMailinator/GMailinator.m +++ b/GMailinator/GMailinator.m @@ -8,6 +8,9 @@ } @implementation GMailinator +{ + NSDate *_tabDate; +} + (void)initialize { [GMailinator registerBundle]; @@ -46,6 +49,16 @@ + (void)load { class_addMethod(c, overrideSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)); class_replaceMethod(c, originalSelector, method_getImplementation(overrideMethod), method_getTypeEncoding(overrideMethod)); + + // Add shortcuts to the message editor + c = NSClassFromString(@"MessageWebHTMLView"); + originalSelector = @selector(keyDown:); + overrideSelector = @selector(overrideMessageEditorKeyDown:); + originalMethod = class_getInstanceMethod(c, originalSelector); + overrideMethod = class_getInstanceMethod(self, overrideSelector); + + class_addMethod(c, overrideSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)); + class_replaceMethod(c, originalSelector, method_getImplementation(overrideMethod), method_getTypeEncoding(overrideMethod)); } + (void)registerBundle @@ -128,6 +141,13 @@ - (void)overrideMailKeyDown:(NSEvent*)event { [self overrideMailKeyDown: newEvent]; break; } + case 's': { + CGEventRef cgEvent = CGEventCreateKeyboardEvent(NULL, 0x25, true); // l + CGEventSetFlags(cgEvent, kCGEventFlagMaskCommand | kCGEventFlagMaskShift); + NSEvent *newEvent = [NSEvent eventWithCGEvent: cgEvent]; + [self overrideMailKeyDown: newEvent]; + break; + } default: [self overrideMailKeyDown:event]; break; @@ -183,6 +203,13 @@ - (void)overrideMessagesKeyDown:(NSEvent*)event { [self overrideMessagesKeyDown: newEvent]; break; } + case 's': { + CGEventRef cgEvent = CGEventCreateKeyboardEvent(NULL, 0x25, true); // l + CGEventSetFlags(cgEvent, kCGEventFlagMaskCommand | kCGEventFlagMaskShift); + NSEvent *newEvent = [NSEvent eventWithCGEvent: cgEvent]; + [self overrideMessagesKeyDown: newEvent]; + break; + } default: [self overrideMessagesKeyDown:event]; break; @@ -190,4 +217,36 @@ - (void)overrideMessagesKeyDown:(NSEvent*)event { } } +- (void)overrideMessageEditorKeyDown:(NSEvent*)event { + unichar key = [[event characters] characterAtIndex:0]; + + switch (key) { + case '\t': { + _tabDate = [NSDate date]; + [self overrideMessageEditorKeyDown:event]; + break; + } + case '\r': { + if (_tabDate) { + double timePassed_ms = [_tabDate timeIntervalSinceNow] * -1000.0; + if (timePassed_ms < 500) { + CGEventRef cgEvent = CGEventCreateKeyboardEvent(NULL, 2, true); // D + CGEventSetFlags(cgEvent, kCGEventFlagMaskCommand | kCGEventFlagMaskShift); + NSEvent *newEvent = [NSEvent eventWithCGEvent: cgEvent]; + [self overrideMessageEditorKeyDown: newEvent]; + break; + } else { + _tabDate = nil; // avoid unnecessary calculations later + } + } + [self overrideMessageEditorKeyDown:event]; + break; + } + default: + [self overrideMessageEditorKeyDown:event]; + break; + } +} + + @end diff --git a/GMailinator/Info.plist b/GMailinator/Info.plist index cb7fb11..d948658 100644 --- a/GMailinator/Info.plist +++ b/GMailinator/Info.plist @@ -26,6 +26,7 @@ Copyright © 2013 Michael Lai. All rights reserved. SupportedPluginCompatibilityUUIDs + 60D52D22-7491-4CA7-95BA-88215BD88F8E B61772F2-9975-4EC0-B22F-9A277C46ADD2 0A13A9ED-4864-4F07-AE70-60FB2F7EA63D DAFFB2B4-77BC-4C25-8CE1-2405E652D54B diff --git a/GMailinator/SearchManager.m b/GMailinator/SearchManager.m index f7747fd..85dbf37 100644 --- a/GMailinator/SearchManager.m +++ b/GMailinator/SearchManager.m @@ -95,10 +95,17 @@ - (NSMenuItem *) newMenuItemWithTitle:(NSString *)title action:(SEL)action andKe - (void) setContextMenu:(NSMenu *)menu { - NSMenuItem* moveFolderItem = [self newMenuItemWithTitle: @"Move to Folder..." action: @selector(moveToFolder:) andKeyEquivalent: @"l" inMenu: [[NSApplication sharedApplication] mainMenu] withTitle: @"Move Again" offset: 1]; + // create "Move to Folder..." menu item just below the existing "Move Again" menuitem + NSMenuItem* moveFolderItem = [self newMenuItemWithTitle: @"Move to Folder..." + action: @selector(moveToFolder:) + andKeyEquivalent: @"l" + inMenu: [[NSApplication sharedApplication] mainMenu] + withTitle: @"Move Again" + offset: 1]; [moveFolderItem setTarget: self]; [moveFolderItem setKeyEquivalentModifierMask: 0]; + // lookup existing "Move to" and "Copy to" menuitems NSMenu* messagesMenu = [moveFolderItem menu]; NSArray *items = [messagesMenu itemArray]; for (int iI = 0; iI < [items count]; iI++) { diff --git a/GMailinator/SearchPopup.m b/GMailinator/SearchPopup.m index 6e87912..1b56cb4 100644 --- a/GMailinator/SearchPopup.m +++ b/GMailinator/SearchPopup.m @@ -18,7 +18,6 @@ - (void)setSubmenu:(NSMenu*)sm { - (void)addMenu:(NSMenu *)menu toDictionary:(NSMutableDictionary *)dict withPath:(NSMutableArray *)path atLevel:(int)depth { NSArray *items = [menu itemArray]; - for (int i = 0; i < [items count]; ++i) { NSMenuItem *menuItem = [items objectAtIndex:i]; @@ -57,9 +56,13 @@ - (void)showWithSender: sender andTitle: (NSString *)title { // update menu items [[submenu delegate] menuNeedsUpdate: submenu ]; + // set message handling to copy / move - //[submenu _sendMenuOpeningNotification]; - [submenu performSelector:@selector(_sendMenuOpeningNotification)]; + if ([submenu respondsToSelector:@selector(_sendMenuOpeningNotification:)]) { // Yosemite 10.10.2 + [submenu performSelector:@selector(_sendMenuOpeningNotification:)]; + } else if ([submenu respondsToSelector:@selector(_sendMenuOpeningNotification)]) { + [submenu performSelector:@selector(_sendMenuOpeningNotification)]; + } // if ([p lastFolder] != nil) // { @@ -137,7 +140,9 @@ - (BOOL)control:(NSControl*)control textView:(NSTextView*)textView doCommandBySe { // [parent setLastFolder: selectedResult objectAtIndex:0]]; NSMenuItem *menuItem = [selectedResult objectForKey:@"menuItem"]; - [[menuItem menu] performActionForItemAtIndex:[[menuItem menu] indexOfItem:menuItem]]; + NSMenu *menu = [menuItem menu]; + NSInteger index = [menu indexOfItem:menuItem]; + [menu performActionForItemAtIndex:index]; } [searchWindow orderOut:nil]; diff --git a/README.md b/README.md index 76fe2da..ed72a18 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ in progress. Tested with Mail for OS X 10.8.4. kGo to next message/thread /Mailbox search lMove to folder (opens dialog) + sFlag + tab, then enterSend message ## How to install