diff --git a/Controller.h b/Controller.h index f050b5b..63d57c0 100644 --- a/Controller.h +++ b/Controller.h @@ -12,20 +12,27 @@ #import -@interface Controller : NSObject { +@interface Controller : NSObject { IBOutlet WebView *timelineView; + IBOutlet NSWindow *timelineViewWindow; IBOutlet WebView *mentionsView; + IBOutlet NSWindow *mentionsViewWindow; ViewDelegate *viewDelegate; } @property (retain, nonatomic) IBOutlet WebView *timelineView; +@property (retain, nonatomic) IBOutlet NSWindow *timelineViewWindow; @property (retain, nonatomic) IBOutlet WebView *mentionsView; +@property (retain, nonatomic) IBOutlet NSWindow *mentionsViewWindow; @property (retain, nonatomic) IBOutlet ViewDelegate *viewDelegate; - (void)initWebViews; - (void)openNewTweetWindowInReplyTo:(NSString *)userName statusId:(NSString *)statusId; - (NSString *)pluginURL; - (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent; +- (void)unreadMentions:(NSInteger)count; +- (void)mentionsWindowDidExpose:(id)sender; + OSStatus handler(EventHandlerCallRef nextHandler, EventRef theEvent, void* userData); diff --git a/Controller.m b/Controller.m index d8ee728..127ae65 100644 --- a/Controller.m +++ b/Controller.m @@ -12,7 +12,7 @@ @implementation Controller -@synthesize timelineView, mentionsView, viewDelegate; +@synthesize timelineView, timelineViewWindow, mentionsView, mentionsViewWindow, viewDelegate; - (void)awakeFromNib { [self initWebViews]; @@ -43,7 +43,7 @@ selector:@selector(sendTweet:) name:@"sendTweet" object:nil]; - + NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager]; [appleEventManager setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:) @@ -78,7 +78,6 @@ return NO; } - #pragma mark Notifications - (IBAction)openNewTweetWindow:(id)sender { @@ -93,7 +92,6 @@ } - (void)openNewTweetWindowWithString:(NSString *)aString { - NSLog(@"testing"); [NSApp activateIgnoringOtherApps:YES]; MyDocument *newTweet = (MyDocument *)[[NSDocumentController sharedDocumentController] openUntitledDocumentAndDisplay:YES error:nil]; [newTweet withString:aString]; @@ -121,6 +119,22 @@ return nil; } +- (void)unreadMentions:(NSInteger)count { + if (![mentionsViewWindow isVisible] && count > 0) { + [timelineViewWindow setTitle:[NSString stringWithFormat:@"Twittia (@%i)", count]]; + } else { + [timelineViewWindow setTitle:[NSString stringWithFormat:@"Twittia"]]; + [mentionsView stringByEvaluatingJavaScriptFromString:@"twittia_instance.unread_mentions = 0;"]; + } +} + +// Mentions window has been visible +- (void)windowDidUpdate:(NSNotification *)notification { + if ([notification object] == mentionsViewWindow) { + [self unreadMentions:0]; + } +} + /* CARBON */ diff --git a/English.lproj/MainMenu.xib b/English.lproj/MainMenu.xib index 343e6e2..761eecf 100644 --- a/English.lproj/MainMenu.xib +++ b/English.lproj/MainMenu.xib @@ -21,9 +21,9 @@ YES - - + + YES @@ -1299,6 +1299,30 @@ 564 + + + timelineViewWindow + + + + 565 + + + + mentionsViewWindow + + + + 566 + + + + delegate + + + + 569 + @@ -2261,9 +2285,9 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{42, 357}, {397, 581}} + {{152, 238}, {397, 581}} com.apple.InterfaceBuilder.CocoaPlugin - {{42, 357}, {397, 581}} + {{152, 238}, {397, 581}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.WebKitIBPlugin @@ -2318,7 +2342,7 @@ - 564 + 569 @@ -2326,18 +2350,26 @@ Controller NSObject + + mentionsWindowDidExpose: + id + YES YES mentionsView + mentionsViewWindow timelineView + timelineViewWindow viewDelegate YES WebView + NSWindow WebView + NSWindow ViewDelegate diff --git a/TwittiaCore.js b/TwittiaCore.js index 86d5330..818de42 100644 --- a/TwittiaCore.js +++ b/TwittiaCore.js @@ -1,5 +1,4 @@ function Twittia(action, oauth_key, oauth_secret) { - this.body = document.getElementById("body"); this.max_length = 100; this.since_id; this.timeout = 2 * 60 * 1000; @@ -7,6 +6,12 @@ function Twittia(action, oauth_key, oauth_secret) { this.oauth_key = oauth_key; this.oauth_secret = oauth_secret; this.getNewData(); + this.unread_mentions = 0; + + this.body = document.createElement("ol"); + this.body.className = this.action; + document.getElementsByTagName("body")[0].appendChild(this.body); + setTimeout(function() { loadPlugin(controller.pluginURL()) }, 1); } @@ -29,6 +34,10 @@ Twittia.prototype.newStatus = function(status, supress_new_with_timeout) { var _this = this; setTimeout(function() { _this.getNewData() }, this.timeout); } + if(this.action == "mentions") { + this.unread_mentions += status.length; + controller.unreadMentions_(this.unread_mentions); + } } Twittia.prototype.getItem = function(status) { @@ -62,7 +71,7 @@ Twittia.prototype.getItem = function(status) { template.in_reply.parentNode.parentNode.insertBefore(retweeted, template.in_reply.parent); } - if(status.in_reply_to_screen_name != null) template.in_reply.innerText = status.in_reply_to_screen_name; + if(status.in_reply_to_status_id != null) template.in_reply.innerText = status.in_reply_to_screen_name; else template.in_reply.parentNode.className = "hidden"; template.in_reply.href = "http://twitter.com/" + status.in_reply_to_screen_name + "/status/" + status.in_reply_to_status_id; diff --git a/Twittia_2-Info.plist b/Twittia_2-Info.plist index 81d3b06..a2c6312 100644 --- a/Twittia_2-Info.plist +++ b/Twittia_2-Info.plist @@ -65,6 +65,7 @@ CFBundleURLSchemes twittia + twitter diff --git a/index.html b/index.html index e2c171f..759d87e 100644 --- a/index.html +++ b/index.html @@ -9,6 +9,5 @@ -
    \ No newline at end of file