Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed "Move to Folder..." on 10.10.2; Added s and tab+enter shortcuts (flag, send) #34

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
xcuserdata/
GMailinator.xcodeproj/project.xcworkspace/xcshareddata/
Binary file added GMailinator.mailbundle.zip
Binary file not shown.
59 changes: 59 additions & 0 deletions GMailinator/GMailinator.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
}

@implementation GMailinator
{
NSDate *_tabDate;
}

+ (void)initialize {
[GMailinator registerBundle];
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -183,11 +203,50 @@ - (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;

}
}

- (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
1 change: 1 addition & 0 deletions GMailinator/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<string>Copyright © 2013 Michael Lai. All rights reserved.</string>
<key>SupportedPluginCompatibilityUUIDs</key>
<array>
<string>60D52D22-7491-4CA7-95BA-88215BD88F8E</string>
<string>B61772F2-9975-4EC0-B22F-9A277C46ADD2</string>
<string>0A13A9ED-4864-4F07-AE70-60FB2F7EA63D</string>
<string>DAFFB2B4-77BC-4C25-8CE1-2405E652D54B</string>
Expand Down
9 changes: 8 additions & 1 deletion GMailinator/SearchManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
13 changes: 9 additions & 4 deletions GMailinator/SearchPopup.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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)
// {
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ in progress. Tested with Mail for OS X 10.8.4.
<tr><td>k</td><td>Go to next message/thread</td></tr>
<tr><td>/</td><td>Mailbox search</td></tr>
<tr><td>l</td><td>Move to folder (opens dialog)</td></tr>
<tr><td>s</td><td>Flag</td></tr>
<tr><td>tab, then enter</td><td>Send message</td></tr>
</table>

## How to install
Expand Down