Merge branch 'kq' of github.com:github/atom into kq

This commit is contained in:
Nathan Sobo 2012-04-26 11:38:38 -06:00
commit 42a3a4664f
3 changed files with 31 additions and 8 deletions

View File

@ -3,6 +3,7 @@
#import "include/cef.h"
#import "client_handler.h"
#import "native_handler.h"
#import "PathWatcher.h"
@implementation AtomController
@ -84,13 +85,9 @@
context->Exit();
}
- (bool)keyEventOfType:(cef_handler_keyevent_type_t)type
code:(int)code
modifiers:(int)modifiers
isSystemKey:(bool)isSystemKey
isAfterJavaScript:(bool)isAfterJavaScript {
- (bool)keyEventOfType:(cef_handler_keyevent_type_t)type code:(int)code modifiers:(int)modifiers isSystemKey:(bool)isSystemKey isAfterJavaScript:(bool)isAfterJavaScript {
if (isAfterJavaScript && type == KEYEVENT_RAWKEYDOWN && modifiers == KEY_META && code == 'R') {
[PathWatcher unwatchAll];
_clientHandler->GetBrowser()->ReloadIgnoreCache();
return YES;
}

View File

@ -10,5 +10,6 @@ typedef void (^WatchCallback)(NSArray *);
+ (NSString *)watchPath:(NSString *)path callback:(WatchCallback)callback;
+ (void)unwatchPath:(NSString *)path callbackId:(NSString *)callbackId;
+ (void)unwatchAll;
@end

View File

@ -10,6 +10,7 @@
- (NSString *)watchPath:(NSString *)path callback:(WatchCallback)callback;
- (void)watchFileDescriptor:(int)fd;
- (void)unwatchPath:(NSString *)path callbackId:(NSString *)callbackId;
- (void)unwatchAll;
@end
@implementation PathWatcher
@ -28,6 +29,10 @@
return [[self instance] unwatchPath:path callbackId:callbackId];
}
+ (void)unwatchAll {
return [[self instance] unwatchAll];
}
- (void)dealloc {
close(_kq);
for (NSNumber *fdNumber in [_callbacksByFileDescriptor allKeys]) {
@ -81,16 +86,36 @@
- (void)unwatchPath:(NSString *)path callbackId:(NSString *)callbackId {
@synchronized(self) {
NSNumber *fdNumber = [_fileDescriptorsByPath objectForKey:path];
NSNumber *fdNumber = [_fileDescriptorsByPath objectForKey:path];
if (!fdNumber) return;
NSMutableDictionary *callbacks = [_callbacksByFileDescriptor objectForKey:fdNumber];
if (!callbacks) return;
[callbacks removeObjectForKey:callbackId];
if (callbackId) {
[callbacks removeObjectForKey:callbackId];
}
else {
[callbacks removeAllObjects];
}
if (callbacks.count == 0) {
close([fdNumber intValue]);
[_fileDescriptorsByPath removeObjectForKey:path];
[_callbacksByFileDescriptor removeObjectForKey:fdNumber];
}
}
}
- (void)unwatchAll {
@synchronized(self) {
NSArray *paths = [_fileDescriptorsByPath allKeys];
for (NSString *path in paths) {
[self unwatchPath:path callbackId:nil];
}
}
}
- (void)watchFileDescriptor:(int)fd {
struct timespec timeout = { 0, 0 };
struct kevent event;