From 70d4afbdede5efbbfe5f6648a77d6d3d0fc0bd4f Mon Sep 17 00:00:00 2001 From: emsquared Date: Tue, 7 Aug 2012 18:31:34 -0400 Subject: [PATCH] Improvements to #307 --- Classes/Headers/IRCWorld.h | 20 +- Classes/Headers/TPCPreferences.h | 3 - Classes/IRC/IRCWorld.m | 93 ++++-- .../TPCPreferencesMigrationAssistant.m | 2 - Classes/Preferences/TPCPreferences.m | 12 - Classes/Views/Channel View/TVCLogController.m | 38 ++- Resources/Info.plist | 4 +- .../English.lproj/TDCPreferences.xib | 264 +----------------- 8 files changed, 111 insertions(+), 325 deletions(-) diff --git a/Classes/Headers/IRCWorld.h b/Classes/Headers/IRCWorld.h index 524e1bf961..7ff02c2c74 100755 --- a/Classes/Headers/IRCWorld.h +++ b/Classes/Headers/IRCWorld.h @@ -146,16 +146,20 @@ - (void)destroyAllEvidence; +- (void)updateReadinessState:(TVCLogController *)controller; + - (TVCLogController *)createLogWithClient:(IRCClient *)client channel:(IRCChannel *)channel; @end +#pragma mark - + @interface TKMessageBlockOperation : NSOperation -@property (nonatomic, retain) TVCLogController *controller; -@property (nonatomic, assign) BOOL special; -+ (TKMessageBlockOperation *) operationWithBlock:(void(^)(void))block - forController:(TVCLogController *)controller - withSpecialPriority:(BOOL)special; -+ (TKMessageBlockOperation *) operationWithBlock:(void(^)(void))block - forController:(TVCLogController *)controller; -+ (TKMessageBlockOperation *) operationWithBlock:(void(^)(void))block; +@property (nonatomic, weak) TVCLogController *controller; + ++ (TKMessageBlockOperation *)operationWithBlock:(void(^)(void))block + forController:(TVCLogController *)controller + withSpecialPriority:(BOOL)special; + ++ (TKMessageBlockOperation *)operationWithBlock:(void(^)(void))block + forController:(TVCLogController *)controller; @end \ No newline at end of file diff --git a/Classes/Headers/TPCPreferences.h b/Classes/Headers/TPCPreferences.h index fa6687a779..d681268ffb 100755 --- a/Classes/Headers/TPCPreferences.h +++ b/Classes/Headers/TPCPreferences.h @@ -102,9 +102,6 @@ typedef enum TXHostmaskBanFormat : NSInteger { + (NSString *)gitBuildReference; -+ (TXNSDouble)viewLoopConsoleDelay; -+ (TXNSDouble)viewLoopChannelDelay; - + (NSDictionary *)textualInfoPlist; + (NSDictionary *)systemInfoPlist; diff --git a/Classes/IRC/IRCWorld.m b/Classes/IRC/IRCWorld.m index c048d499ba..24f79c12ce 100755 --- a/Classes/IRC/IRCWorld.m +++ b/Classes/IRC/IRCWorld.m @@ -54,9 +54,9 @@ - (id)init self.clients = [NSMutableArray new]; self.messageOperationQueue = [NSOperationQueue new]; + self.messageOperationQueue.name = @"IRCWordMessageOperationQueue"; self.messageOperationQueue.maxConcurrentOperationCount = 1; -// Only 1 at a time or else we get a race condition and out of order messages } return self; @@ -1353,51 +1353,86 @@ - (void)serverListKeyDown:(NSEvent *)e [self logKeyDown:e]; } -@end +#pragma mark - -@implementation TKMessageBlockOperation -+ (TKMessageBlockOperation *) operationWithBlock:(void(^)(void))block - forController:(TVCLogController *)controller - withSpecialPriority:(BOOL)special -{ - TKMessageBlockOperation * retval = [TKMessageBlockOperation new]; - retval.completionBlock = block; - retval.controller = controller; - retval.special = special; - retval.queuePriority = retval.priority; - return retval; +- (void)updateReadinessState:(TVCLogController *)controller +{ + NSArray *queues = [self.messageOperationQueue operations]; + + for (TKMessageBlockOperation *op in queues) { + if (op.controller == controller) { + [op willChangeValueForKey:@"isReady"]; + [op didChangeValueForKey:@"isReady"]; + } + } } -+ (TKMessageBlockOperation *) operationWithBlock:(void(^)(void))block - forController:(TVCLogController *)controller -{ return [self operationWithBlock:block forController:controller withSpecialPriority:NO]; } +@end -+ (TKMessageBlockOperation *) operationWithBlock:(void(^)(void))block -{ return [self operationWithBlock:block forController:nil withSpecialPriority:NO]; } +#pragma mark - -- (id) init +@interface TKMessageBlockOperation () /* @private */ +@property (nonatomic, assign) BOOL isSpecial; +@end + +@implementation TKMessageBlockOperation + ++ (TKMessageBlockOperation *)operationWithBlock:(void(^)(void))block + forController:(TVCLogController *)controller + withSpecialPriority:(BOOL)special { - if (self = [super init]) { - self.special = NO; + if (PointerIsEmpty(controller) || PointerIsEmpty(block)) { + return nil; } - return self; + + TKMessageBlockOperation *retval = [TKMessageBlockOperation new]; + + retval.controller = controller; + retval.isSpecial = special; + + retval.queuePriority = retval.priority; + retval.completionBlock = block; + + return retval; } -- (NSOperationQueuePriority) priority ++ (TKMessageBlockOperation *)operationWithBlock:(void(^)(void))block + forController:(TVCLogController *)controller { - if (!self.controller) return NSOperationQueuePriorityVeryHigh; - id target = self.controller.channel ?: self.controller.client; + return [self operationWithBlock:block forController:controller withSpecialPriority:NO]; +} + +- (NSOperationQueuePriority)priority +{ + id target = self.controller.channel; id selected = self.controller.world.selected; + + if (PointerIsEmpty(target)) { + target = self.controller.client; + } + + // ---- // + NSOperationQueuePriority retval = NSOperationQueuePriorityLow; - if ((target || selected) && target == selected) retval += 4L; - if (self.special) retval += 4L; + // ---- // + + if ((target || selected) && target == selected) { + retval += 4L; + } + + if (self.isSpecial) { + retval += 4L; + } + + // ---- // + return retval; } -- (BOOL) isReady +- (BOOL)isReady { - if (!self.controller) return YES; return ([self.controller.view isLoading] == NO); } + @end diff --git a/Classes/Preferences/Migration Assistant/TPCPreferencesMigrationAssistant.m b/Classes/Preferences/Migration Assistant/TPCPreferencesMigrationAssistant.m index 417dbbf193..d5f1c391d2 100644 --- a/Classes/Preferences/Migration Assistant/TPCPreferencesMigrationAssistant.m +++ b/Classes/Preferences/Migration Assistant/TPCPreferencesMigrationAssistant.m @@ -209,8 +209,6 @@ + (void)convertExistingGlobalPreferences [self.class migrateGlobalPreference:@"LogHighlights" from:@"Preferences.General.log_highlights"]; [self.class migrateGlobalPreference:@"LogTranscript" from:@"Preferences.General.log_transcript"]; [self.class migrateGlobalPreference:@"LogTranscriptDestination" from:@"Preferences.General.transcript_folder"]; - [self.class migrateGlobalPreference:@"LogViewMessageQueueLoopDelay -> Channel" from:@"Preferences.Experimental.view_loop_channel_delay"]; - [self.class migrateGlobalPreference:@"LogViewMessageQueueLoopDelay -> Console" from:@"Preferences.Experimental.view_loop_console_delay"]; [self.class migrateGlobalPreference:@"MainWindowTransparencyLevel" from:@"Preferences.Theme.transparency"]; [self.class migrateGlobalPreference:@"NicknameHighlightMatchingType" from:@"Preferences.Keyword.matching_method"]; [self.class migrateGlobalPreference:@"OpenClickedLinksInBackgroundBrowser" from:@"Preferences.General.open_browser_in_background"]; diff --git a/Classes/Preferences/TPCPreferences.m b/Classes/Preferences/TPCPreferences.m index 403911e403..422bfe1c38 100755 --- a/Classes/Preferences/TPCPreferences.m +++ b/Classes/Preferences/TPCPreferences.m @@ -732,16 +732,6 @@ + (TXHostmaskBanFormat)banFormat return (TXHostmaskBanFormat)[_NSUserDefaults() integerForKey:@"DefaultBanCommandHostmaskFormat"]; } -+ (TXNSDouble)viewLoopConsoleDelay -{ - return [_NSUserDefaults() doubleForKey:@"LogViewMessageQueueLoopDelay -> Console"]; -} - -+ (TXNSDouble)viewLoopChannelDelay -{ - return [_NSUserDefaults() doubleForKey:@"LogViewMessageQueueLoopDelay -> Channel"]; -} - + (BOOL)displayDockBadge { return [_NSUserDefaults() boolForKey:@"DisplayDockBadges"]; @@ -1390,8 +1380,6 @@ + (void)initPreferences [d setInteger:TXNoticeSendServerConsoleType forKey:@"DestinationOfNonserverNotices"]; [d setInteger:TXUserDoubleClickQueryAction forKey:@"UserListDoubleClickAction"]; - [d setDouble:0.05 forKey:@"LogViewMessageQueueLoopDelay -> Console"]; - [d setDouble:0.07 forKey:@"LogViewMessageQueueLoopDelay -> Channel"]; [d setDouble:12.0 forKey:@"Theme -> Font Size"]; [d setDouble:1.0 forKey:@"MainWindowTransparencyLevel"]; diff --git a/Classes/Views/Channel View/TVCLogController.m b/Classes/Views/Channel View/TVCLogController.m index 8db6497992..0d0c851a80 100755 --- a/Classes/Views/Channel View/TVCLogController.m +++ b/Classes/Views/Channel View/TVCLogController.m @@ -861,7 +861,7 @@ - (void)writeLine:(id)line if (PointerIsEmpty(body)) return nil; // ---- // - + if ([line isKindOfClass:GRMustacheTemplate.class]) { attrs[@"lineNumber"] = @(self.lineNumber); @@ -875,19 +875,19 @@ - (void)writeLine:(id)line // ---- // - if (self.maxLines > 0 && (self.count - 10) > self.maxLines) { - [self setNeedsLimitNumberOfLines]; - } + if (isSpecial == NO) { + if (self.maxLines > 0 && (self.count - 10) > self.maxLines) { + [self setNeedsLimitNumberOfLines]; + } - if ([attrs[@"highlightAttributeRepresentation"] isEqualToString:@"true"]) { - [self.highlightedLineNumbers safeAddObject:@(self.lineNumber)]; - } + if ([attrs[@"highlightAttributeRepresentation"] isEqualToString:@"true"]) { + [self.highlightedLineNumbers safeAddObject:@(self.lineNumber)]; + } - [self executeScriptCommand:@"newMessagePostedToDisplay" withArguments:@[@(self.lineNumber)]]; + [self executeScriptCommand:@"newMessagePostedToDisplay" withArguments:@[@(self.lineNumber)]]; - // ---- // + // ---- // - if (isSpecial == NO) { [self.logFile writePropertyListEntry:[context dictionaryValue] toKey:[NSNumberWithInteger(self.lineNumber) integerWithLeadingZero:10]]; } @@ -896,14 +896,17 @@ - (void)writeLine:(id)line } // ---- // - + return nil; } copy]; + [self enqueueMessageBlock:messageBlock fromSender:self isSpecial:isSpecial]; } - (void)enqueueMessageBlock:(id)messageBlock fromSender:(TVCLogController *)sender -{ [self enqueueMessageBlock:messageBlock fromSender:sender isSpecial:NO]; } +{ + [self enqueueMessageBlock:messageBlock fromSender:sender isSpecial:NO]; +} - (void)enqueueMessageBlock:(id)messageBlock fromSender:(TVCLogController *)sender isSpecial:(BOOL)special { @@ -912,7 +915,7 @@ - (void)enqueueMessageBlock:(id)messageBlock fromSender:(TVCLogController *)send } forController:sender withSpecialPriority:special]]; } -- (void) handleMessageBlock:(id)messageBlock isSpecial:(BOOL)special +- (void)handleMessageBlock:(id)messageBlock isSpecial:(BOOL)special { // Internally, TVCLogMessageBlock should only return a // BOOL as NSValue or NSString absolute value. @@ -930,10 +933,11 @@ - (void) handleMessageBlock:(id)messageBlock isSpecial:(BOOL)special // ---- // if ([stslt isKindOfClass:NSString.class]) { - if (PointerIsNotEmpty(stslt)) { + if (NSObjectIsNotEmpty(stslt)) { [[NSOperationQueue mainQueue] addOperationWithBlock:^{ [self appendToDocumentBody:stslt]; }]; + rrslt = YES; } } else { @@ -942,7 +946,9 @@ - (void) handleMessageBlock:(id)messageBlock isSpecial:(BOOL)special // ---- // - if (!rrslt) [self enqueueMessageBlock:messageBlock fromSender:self isSpecial:special]; + if (rrslt == NO) { + [self enqueueMessageBlock:messageBlock fromSender:self isSpecial:special]; + } } #pragma mark - @@ -1104,6 +1110,8 @@ - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame { [self executeScriptCommand:@"viewFinishedLoading" withArguments:@[]]; + [self.world updateReadinessState:self]; + self.loaded = YES; self.loadingImages = 0; diff --git a/Resources/Info.plist b/Resources/Info.plist index 829e711822..92238a9400 100755 --- a/Resources/Info.plist +++ b/Resources/Info.plist @@ -47,8 +47,8 @@ TXBundleBuildCodeName Turtle Soup TXBundleBuildNumber - 12291 + 12318 TXBundleBuildReference - 2.1.1-276-g6e71f93-debug + 2.1.1-280-ga62ce8d-debug diff --git a/Resources/Localization/English.lproj/TDCPreferences.xib b/Resources/Localization/English.lproj/TDCPreferences.xib index 9426944fb9..b33d0c3743 100755 --- a/Resources/Localization/English.lproj/TDCPreferences.xib +++ b/Resources/Localization/English.lproj/TDCPreferences.xib @@ -4477,7 +4477,7 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA NSView - + 268 @@ -4485,7 +4485,6 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA 268 {{47, 28}, {440, 50}} - _NS:9 {250, 750} YES @@ -4507,7 +4506,6 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA 268 {{44, 113}, {357, 28}} - YES @@ -4526,7 +4524,6 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA 268 {{178, 147}, {230, 22}} - YES @@ -4605,7 +4602,6 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA 268 {{29, 151}, {158, 16}} - YES @@ -4624,7 +4620,6 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA 268 {{29, 86}, {172, 16}} - YES @@ -4640,8 +4635,6 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA {534, 188} - - NSView @@ -4652,9 +4645,8 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA 268 - {{65, 52}, {404, 66}} + {{65, 39}, {404, 66}} - _NS:9 {250, 750} YES @@ -4674,9 +4666,8 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA 12 - {{44, 166}, {438, 5}} + {{44, 153}, {438, 5}} - _NS:9 {0, 0} @@ -4696,37 +4687,11 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA 0 NO - - - 12 - {{44, 251}, {438, 5}} - - - - _NS:9 - {0, 0} - - 67108864 - 0 - Box - - - - 3 - MCAwLjgwMDAwMDAxMTkAA - - - 3 - 2 - 0 - NO - 268 - {{61, 132}, {117, 16}} + {{61, 119}, {117, 16}} - YES @@ -4743,10 +4708,9 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA 268 - {{57, 276}, {274, 18}} + {{57, 174}, {274, 18}} - - + _NS:239 YES @@ -4767,90 +4731,11 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA NO - - - 268 - {{71, 191}, {169, 16}} - - - - YES - - 68157504 - 272630784 - View Loop Delay (Channel):* - - - - - - NO - - - - 268 - {{245, 189}, {207, 19}} - - - - YES - - -1804599231 - 272761856 - - - - YES - - - - NO - - - - 268 - {{71, 216}, {168, 16}} - - - - YES - - 68157504 - 272630784 - View Loop Delay (Console):* - - - - - - NO - - - - 268 - {{245, 214}, {207, 19}} - - - - YES - - -1804599231 - 272761856 - - - - YES - - - - NO - 268 - {{58, 300}, {184, 18}} + {{58, 198}, {184, 18}} - _NS:239 YES @@ -4874,9 +4759,8 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA 268 - {{45, 333}, {357, 28}} + {{45, 231}, {357, 28}} - YES @@ -4891,9 +4775,8 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA NO - {534, 385} + {534, 283} - NSView @@ -7539,62 +7422,6 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA 7166 - - - title - - - - 6756 - - - - value: values.LogViewMessageQueueLoopDelay -> Console - - - - - - value: values.LogViewMessageQueueLoopDelay -> Console - value - values.LogViewMessageQueueLoopDelay -> Console - - NSContinuouslyUpdatesValue - - - 2 - - - 7211 - - - - title - - - - 6762 - - - - value: values.LogViewMessageQueueLoopDelay -> Channel - - - - - - value: values.LogViewMessageQueueLoopDelay -> Channel - value - values.LogViewMessageQueueLoopDelay -> Channel - - NSContinuouslyUpdatesValue - - - 2 - - - 7210 - enabled: values.LogTranscript @@ -10070,15 +9897,10 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA - - - - + - - Hidden Settings @@ -10254,58 +10076,6 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA - - 6752 - - - - - - - - 6753 - - - - - - - - 6754 - - - - - 6755 - - - - - 6758 - - - - - - - - 6759 - - - - - - - - 6760 - - - - - 6761 - - - 6784 @@ -10513,11 +10283,6 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA - - 7027 - - - 7028 @@ -11553,14 +11318,6 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -11642,7 +11399,6 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin