Skip to content

Commit

Permalink
Finish new template engine. Very unstable.
Browse files Browse the repository at this point in the history
  • Loading branch information
emsquared committed Jul 25, 2012
1 parent d987731 commit 4c2c37d
Show file tree
Hide file tree
Showing 277 changed files with 1,143 additions and 1,565 deletions.
9 changes: 0 additions & 9 deletions Classes/Dialogs/Preferences/TDCPreferencesController.m
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,6 @@ - (void)updateTheme

- (void)onChangedTheme:(id)sender
{
TXNSDouble oldRenderVersion = self.world.viewTheme.other.renderingEngineVersion;
TXNSDouble newRenderVersion = 0;

NSMenuItem *item = [self.themeButton selectedItem];

NSString *newThemeName = nil;
Expand All @@ -522,12 +519,6 @@ - (void)onChangedTheme:(id)sender
[TPCPreferences setThemeName:newThemeName];

[self onStyleChanged:nil];

newRenderVersion = self.world.viewTheme.other.renderingEngineVersion;

if (NSDissimilarObjects(oldRenderVersion, newRenderVersion)) {
[self.world destroyAllEvidence];
}
}

- (void)onSelectFont:(id)sender
Expand Down
2 changes: 2 additions & 0 deletions Classes/Headers/NSStringHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@
- (NSInteger)stringPositionIgnoringCase:(NSString *)needle;

- (NSArray *)split:(NSString *)delimiter;

- (NSString *)trim;
- (NSString *)trimNewlines;

- (id)attributedStringWithIRCFormatting:(NSFont *)defaultFont followFormattingPreference:(BOOL)formattingPreference;
- (id)attributedStringWithIRCFormatting:(NSFont *)defaultFont;
Expand Down
1 change: 0 additions & 1 deletion Classes/Headers/TPCOtherTheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
@property (nonatomic, assign) BOOL forceInvertSidebarColors;
@property (nonatomic, strong) NSColor *underlyingWindowColor;
@property (nonatomic, assign) TXNSDouble indentationOffset;
@property (nonatomic, assign) TXNSDouble renderingEngineVersion;

- (void)reload;

Expand Down
2 changes: 0 additions & 2 deletions Classes/Headers/TVCLogController.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ typedef BOOL (^TVCLogMessageBlock)(void);
- (void)restorePosition;
- (void)notifyDidBecomeVisible;

- (BOOL)viewIsTemplateBased;

- (void)nextHighlight;
- (void)previousHighlight;
- (BOOL)highlightAvailable:(BOOL)previous;
Expand Down
1 change: 1 addition & 0 deletions Classes/Headers/TVCLogLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ typedef enum TVCLogLineType : NSInteger {
TVCLogLineInviteType,
TVCLogLineWebsiteType,
TVCLogLineDebugType,
TVCLogLineRawHTMLType,
} TVCLogLineType;

typedef enum TVCLogMemberType : NSInteger {
Expand Down
4 changes: 4 additions & 0 deletions Classes/Headers/TVCLogRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ TEXTUAL_EXTERN NSString *logEscapeWithNil(NSString *s);
TEXTUAL_EXTERN NSInteger mapColorValue(NSColor *color);
TEXTUAL_EXTERN NSColor *mapColorCode(NSInteger colorChar);

TEXTUAL_EXTERN NSString *TXRenderStyleTemplate(NSString *templateName,
NSDictionary *templateTokens,
TVCLogController *logController);

@interface LVCLogRenderer : NSObject
+ (NSString *)renderBody:(NSString *)body
controller:(TVCLogController *)log
Expand Down
9 changes: 8 additions & 1 deletion Classes/Helpers/Cocoa (Objective-C)/NSStringHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ - (NSString *)trim
return [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}

- (NSString *)trimNewlines
{
return [self stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
}

- (BOOL)isNumericOnly
{
NSUInteger len = self.length;
Expand Down Expand Up @@ -344,9 +349,11 @@ - (id)attributedStringWithIRCFormatting:(NSFont *)defaultFont followFormattingPr
}

NSDictionary *input = @{@"attributedStringFont": defaultFont};

TXMasterController *master = [TPCPreferences masterController];

return [LVCLogRenderer renderBody:self
controller:nil
controller:master.world.selected.log
renderType:TVCLogRendererAttributedStringType
properties:input resultInfo:NULL];
}
Expand Down
3 changes: 1 addition & 2 deletions Classes/Preferences/Themes/TPCOtherTheme.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ - (GRMustacheTemplate *)templateWithLineType:(TVCLogLineType)type
{
NSString *typestr = [TVCLogLine lineTypeString:type];

return [self templateWithName:[@"linetype_" stringByAppendingString:typestr]];
return [self templateWithName:[@"Line Types/" stringByAppendingString:typestr]];
}

- (GRMustacheTemplate *)templateWithName:(NSString *)name
Expand Down Expand Up @@ -170,7 +170,6 @@ - (void)reload
self.underlyingWindowColor = [self colorForKey:@"Underlying Window Color"];

self.indentationOffset = [self doubleForKey:@"Indentation Offset"];
self.renderingEngineVersion = [self doubleForKey:@"Rendering Engine Version"];

// ---- //

Expand Down
105 changes: 69 additions & 36 deletions Classes/Views/Channel View/LVCLogRenderer.m
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,21 @@ NSInteger mapColorValue(NSColor *color)
return nil;
}

NSString *TXRenderStyleTemplate(NSString *templateName, NSDictionary *templateTokens, TVCLogController *logController)
{
GRMustacheTemplate *tmpl = [logController.theme.other templateWithName:templateName];

if (PointerIsNotEmpty(tmpl)) {
NSString *aHtml = [tmpl renderObject:templateTokens];

if (NSObjectIsNotEmpty(aHtml)) {
return aHtml;
}
}

return nil;
}

static NSMutableAttributedString *renderAttributedRange(NSMutableAttributedString *body, attr_t attr, NSInteger start, NSInteger len, NSFont *font)
{
NSRange r = NSMakeRange(start, len);
Expand Down Expand Up @@ -239,63 +254,77 @@ NSInteger mapColorValue(NSColor *color)
static NSString *renderRange(NSString *body, attr_t attr, NSInteger start, NSInteger len, TVCLogController *log)
{
NSString *content = [body safeSubstringWithRange:NSMakeRange(start, len)];

if (attr & _rendererURLAttribute) {

NSMutableDictionary *templateTokens = [NSMutableDictionary dictionary];

if (attr & _rendererURLAttribute)
{
NSString *link = content;

if ([link contains:@"://"] == NO) {
link = [NSString stringWithFormat:@"http://%@", link];
}

templateTokens[@"anchorLocation"] = link;
templateTokens[@"anchorTitle"] = logEscape(content);

return TXRenderStyleTemplate(@"renderedStandardAnchorLinkResource", templateTokens, log);
}
else if (attr & _rendererChannelNameAttribute)
{
templateTokens[@"channelName"] = logEscape(content);

return [NSString stringWithFormat:@"<a href=\"%@\" class=\"url\" oncontextmenu=\"Textual.openURLManagementContextualMenu()\">%@</a>", link, logEscape(content)];
} else if (attr & _rendererChannelNameAttribute) {
return [NSString stringWithFormat:@"<span class=\"channel\" ondblclick=\"Textual.channelNameDoubleClicked()\" oncontextmenu=\"Textual.openChannelNameContextualMenu()\">%@</span>", logEscape(content)];
} else {
BOOL matchedUser = NO;

return TXRenderStyleTemplate(@"renderedChannelNameLinkResource", templateTokens, log);
}
else
{
content = logEscape(content);

NSMutableString *s = [NSMutableString string];

templateTokens[@"messageFragment"] = content;

// --- //

if (attr & _rendererConversationTrackerAttribute) {
IRCClient *client = log.client;
IRCUser *user = [log.channel findMember:content options:NSCaseInsensitiveSearch];
IRCClient *client = log.client;
IRCUser *user = [log.channel findMember:content options:NSCaseInsensitiveSearch];

if (PointerIsEmpty(user) == NO) {
if ([user.nick isEqualNoCase:client.myNick] == NO) {
matchedUser = YES;

[s appendFormat:@"<span class=\"inline_nickname\" ondblclick=\"Textual.inlineNicknameDoubleClicked()\" oncontextmenu=\"Textual.openInlineNicknameContextualMenu()\" colornumber=\"%d\">", [user colorNumber]];
templateTokens[@"inlineNicknameMatchFound"] = @(YES);
templateTokens[@"inlineNicknameColorNumber"] = @(user.colorNumber);
}
}
}

// --- //

if (attr & _effectMask) {
[s appendString:@"<span class=\"effect\" style=\""];
templateTokens[@"fragmentContainsFormattingSymbols"] = @(YES);

if (attr & _rendererBoldFormatAttribute) [s appendString:@"font-weight:bold;"];
if (attr & _rendererItalicFormatAttribute) [s appendString:@"font-style:italic;"];
if (attr & _rendererUnderlineFormatAttribute) [s appendString:@"text-decoration:underline;"];
if (attr & _rendererBoldFormatAttribute) {
templateTokens[@"fragmentIsBold"] = @(YES);
}

[s appendString:@"\""];
if (attr & _rendererItalicFormatAttribute) {
templateTokens[@"fragmentIsItalicized"] = @(YES);
}

if (attr & _rendererTextColorAttribute) [s appendFormat:@" color-number=\"%d\"", (attr & _textColorMask)];
if (attr & _rendererBackgroundColorAttribute) [s appendFormat:@" bgcolor-number=\"%d\"", (attr & _backgroundColorMask) >> 4];
if (attr & _rendererUnderlineFormatAttribute) {
templateTokens[@"fragmentIsUnderlined"] = @(YES);
}

[s appendFormat:@">%@</span>", content];
} else {
if (matchedUser == NO) {
return content;
} else {
[s appendString:content];
if (attr & _rendererTextColorAttribute) {
templateTokens[@"fragmentTextColor"] = @(attr & _textColorMask);
}

if (attr & _rendererBackgroundColorAttribute) {
templateTokens[@"fragmentBackgroundColor"] = @((attr & _backgroundColorMask) >> 4);
}
}

// --- //

if (matchedUser) {
[s appendString:@"</span>"];
}

return s;
return TXRenderStyleTemplate(@"formattedMessageFragment", templateTokens, log);
}
}

Expand All @@ -310,6 +339,8 @@ + (NSString *)renderBody:(NSString *)body
NSMutableDictionary *resultInfo = [NSMutableDictionary dictionary];

BOOL renderLinks = [inputDictionary boolForKey:@"renderLinks"];
BOOL isNormalMsg = [inputDictionary boolForKey:@"normalMessage"];

BOOL exactWordMatching = ([TPCPreferences keywordMatchingMethod] == TXNicknameHighlightExactMatchType);
BOOL regexWordMatching = ([TPCPreferences keywordMatchingMethod] == TXNicknameHighlightRegularExpressionMatchType);

Expand Down Expand Up @@ -536,7 +567,7 @@ + (NSString *)renderBody:(NSString *)body
} else {
NSString *curchan;

if (log) {
if (log && isNormalMsg) {
curchan = log.channel.name;
}

Expand Down Expand Up @@ -674,7 +705,7 @@ + (NSString *)renderBody:(NSString *)body
/* Conversation Tracking */

if ([TPCPreferences trackConversations]) {
if (log) {
if (log && isNormalMsg) {
IRCChannel *log_channel = log.channel;

if (log_channel) {
Expand Down Expand Up @@ -768,7 +799,9 @@ + (NSString *)renderBody:(NSString *)body
if (drawingType == TVCLogRendererAttributedStringType) {
result = renderAttributedRange(result, t, start, n, attributedStringFont);
} else {
[result appendString:renderRange(body, t, start, n, log)];
NSString *renderedRange = renderRange(body, t, start, n, log);

[result appendString:renderedRange.trimNewlines];
}

start += n;
Expand Down
Loading

0 comments on commit 4c2c37d

Please sign in to comment.