adium-1.4 2803:b3e9b2313de9: Added a `%variant%` keyword for mes...
commits at adium.im
commits at adium.im
Mon Nov 23 21:32:15 UTC 2009
details: http://hg.adium.im/adium-1.4/rev/b3e9b2313de9
revision: 2803:b3e9b2313de9
author: Evan Schoenberg
date: Mon Nov 23 15:32:55 2009 -0600
Added a `%variant%` keyword for message styles, and rearranged code a bit so that an AIWebkitMessageViewStyle keeps track of its active variant rather than AIWebKitMessageViewController doing so and passing it back to the activeStyle with various invocations.
Fixes #12702
(transplanted from 31f6f4c62d78801f4dc74a0a85eb573c9398b747)
diffs (217 lines):
diff -r f90fc352471c -r b3e9b2313de9 Plugins/WebKit Message View/AIWebKitMessageViewController.h
--- a/Plugins/WebKit Message View/AIWebKitMessageViewController.h Mon Nov 23 14:41:32 2009 -0600
+++ b/Plugins/WebKit Message View/AIWebKitMessageViewController.h Mon Nov 23 15:32:55 2009 -0600
@@ -40,7 +40,6 @@
//Style & Variant
AIWebkitMessageViewStyle *messageStyle;
NSString *activeStyle;
- NSString *activeVariant;
NSString *preferenceGroup;
//User icon masking
diff -r f90fc352471c -r b3e9b2313de9 Plugins/WebKit Message View/AIWebKitMessageViewController.m
--- a/Plugins/WebKit Message View/AIWebKitMessageViewController.m Mon Nov 23 14:41:32 2009 -0600
+++ b/Plugins/WebKit Message View/AIWebKitMessageViewController.m Mon Nov 23 15:32:55 2009 -0600
@@ -201,7 +201,6 @@
//Clean up style/variant info
[messageStyle release]; messageStyle = nil;
[activeStyle release]; activeStyle = nil;
- [activeVariant release]; activeVariant = nil;
[preferenceGroup release]; preferenceGroup = nil;
//Cleanup content processing
@@ -265,7 +264,7 @@
NSString *variantKey = [plugin styleSpecificKey:@"Variant" forStyle:activeStyle];
//Variant changes we can apply immediately. All other changes require us to reload the view
if (!firstTime && [key isEqualToString:variantKey]) {
- [activeVariant release]; activeVariant = [[prefDict objectForKey:variantKey] retain];
+ messageStyle.activeVariant = [prefDict objectForKey:variantKey];
[self _updateVariantWithoutPrimingView];
} else if (shouldReflectPreferenceChanges) {
@@ -345,7 +344,6 @@
//Cleanup first
[messageStyle autorelease]; messageStyle = nil;
[activeStyle release]; activeStyle = nil;
- [activeVariant release]; activeVariant = nil;
//Load the message style
messageStyle = [[plugin currentMessageStyleForChat:chat] retain];
@@ -356,18 +354,21 @@
activeStyle, preferenceGroup]];
//Get the prefered variant (or the default if a prefered is not available)
- activeVariant = [[adium.preferenceController preferenceForKey:[plugin styleSpecificKey:@"Variant" forStyle:activeStyle]
- group:preferenceGroup] retain];
- if (!activeVariant) activeVariant = [[messageStyle defaultVariant] retain];
+ NSString *activeVariant;
+ activeVariant = [adium.preferenceController preferenceForKey:[plugin styleSpecificKey:@"Variant" forStyle:activeStyle]
+ group:preferenceGroup];
+ if (!activeVariant)
+ activeVariant = [messageStyle defaultVariant];
if (!activeVariant) {
/* If the message style doesn't specify a default variant, choose the first one.
* Note: Old styles (styleVersion < 3) will always report a variant for defaultVariant.
*/
NSArray *availableVariants = [messageStyle availableVariants];
if ([availableVariants count]) {
- activeVariant = [[availableVariants objectAtIndex:0] retain];
+ activeVariant = [availableVariants objectAtIndex:0];
}
}
+ messageStyle.activeVariant = activeVariant;
NSDictionary *prefDict = [adium.preferenceController preferencesForGroup:preferenceGroup];
@@ -457,7 +458,7 @@
{
//We can only change the variant if the web view is ready. If it's not ready we wait a bit and try again.
if (webViewIsReady) {
- [webView stringByEvaluatingJavaScriptFromString:[messageStyle scriptForChangingVariant:activeVariant]];
+ [webView stringByEvaluatingJavaScriptFromString:[messageStyle scriptForChangingVariant]];
} else {
[self performSelector:@selector(_updateVariantWithoutPrimingView) withObject:nil afterDelay:NEW_CONTENT_RETRY_DELAY];
}
@@ -490,7 +491,7 @@
//Hack: this will re-set us for all the delegates, but that shouldn't matter
[delegateProxy addDelegate:self forView:webView];
- [[webView mainFrame] loadHTMLString:[messageStyle baseTemplateWithVariant:activeVariant chat:chat] baseURL:nil];
+ [[webView mainFrame] loadHTMLString:[messageStyle baseTemplateForChat:chat] baseURL:nil];
if(chat.isGroupChat && chat.supportsTopic) {
// Force a topic update, so we set our topic appropriately.
diff -r f90fc352471c -r b3e9b2313de9 Plugins/WebKit Message View/AIWebkitMessageViewStyle.h
--- a/Plugins/WebKit Message View/AIWebkitMessageViewStyle.h Mon Nov 23 14:41:32 2009 -0600
+++ b/Plugins/WebKit Message View/AIWebkitMessageViewStyle.h Mon Nov 23 15:32:55 2009 -0600
@@ -77,9 +77,10 @@
* @see AIWebKitMessageViewController
*/
@interface AIWebkitMessageViewStyle : NSObject {
- NSInteger styleVersion;
+ NSInteger styleVersion;
NSBundle *styleBundle;
NSString *stylePath;
+ NSString *activeVariant;
//Templates
NSString *headerHTML;
@@ -148,6 +149,14 @@
- (void) reloadStyle;
/*!
+ * @brief The name of the active variant.
+ *
+ * This is only a store; if it is changed, the changing object is responsible for making
+ * any appropriate calls to update the display
+ */
+ at property (nonatomic, retain) NSString *activeVariant;
+
+/*!
* Returns YES if this style is considered legacy
*
* Legacy/outdated styles may perform sub-optimally because they lack beneficial changes made in modern styles.
@@ -160,7 +169,7 @@
*
* The base template is basically the empty view, and serves as the starting point of all content insertion.
*/
-- (NSString *)baseTemplateWithVariant:(NSString *)variant chat:(AIChat *)chat;
+- (NSString *)baseTemplateForChat:(AIChat *)chat;
/*!
* @brief Returns the template for inserting content
@@ -180,9 +189,9 @@
- (NSString *)scriptForAppendingContent:(AIContentObject *)content similar:(BOOL)contentIsSimilar willAddMoreContentObjects:(BOOL)willAddMoreContentObjects replaceLastContent:(BOOL)replaceLastContent;
/*!
- * @brief Returns the BOM script for changing the view's variant
+ * @brief Returns the BOM script for changing the view's variant to the active variant
*/
-- (NSString *)scriptForChangingVariant:(NSString *)variant;
+- (NSString *)scriptForChangingVariant;
/*!
* @brief Returns the BOM script for scrolling after adding multiple content objects
diff -r f90fc352471c -r b3e9b2313de9 Plugins/WebKit Message View/AIWebkitMessageViewStyle.m
--- a/Plugins/WebKit Message View/AIWebkitMessageViewStyle.m Mon Nov 23 14:41:32 2009 -0600
+++ b/Plugins/WebKit Message View/AIWebkitMessageViewStyle.m Mon Nov 23 15:32:55 2009 -0600
@@ -119,6 +119,8 @@
@implementation AIWebkitMessageViewStyle
+ at synthesize activeVariant;
+
+ (id)messageViewStyleFromBundle:(NSBundle *)inBundle
{
return [[[self alloc] initWithBundle:inBundle] autorelease];
@@ -231,6 +233,8 @@
[timeStampFormatter release];
[statusIconPathCache release];
+
+ self.activeVariant = nil;
[super dealloc];
}
@@ -319,7 +323,7 @@
//Templates ------------------------------------------------------------------------------------------------------------
#pragma mark Templates
-- (NSString *)baseTemplateWithVariant:(NSString *)variant chat:(AIChat *)chat
+- (NSString *)baseTemplateForChat:(AIChat *)chat
{
NSMutableString *templateHTML;
@@ -339,14 +343,14 @@
if ((styleVersion < 3) && usingCustomTemplateHTML) {
templateHTML = [NSMutableString stringWithFormat:baseHTML, //Template
[[NSURL fileURLWithPath:stylePath] absoluteString], //Base path
- [self pathForVariant:variant], //Variant path
+ [self pathForVariant:self.activeVariant], //Variant path
headerContent,
(footerHTML ? footerHTML : @"")];
} else {
templateHTML = [NSMutableString stringWithFormat:baseHTML, //Template
[[NSURL fileURLWithPath:stylePath] absoluteString], //Base path
styleVersion < 3 ? @"" : @"@import url( \"main.css\" );", //Import main.css for new enough styles
- [self pathForVariant:variant], //Variant path
+ [self pathForVariant:self.activeVariant], //Variant path
headerContent,
(footerHTML ? footerHTML : @"")];
}
@@ -598,11 +602,9 @@
return [NSString stringWithFormat:script, [self _escapeStringForPassingToScript:newHTML]];
}
-- (NSString *)scriptForChangingVariant:(NSString *)variant
+- (NSString *)scriptForChangingVariant
{
- AILogWithSignature(@"%@",[NSString stringWithFormat:@"setStylesheet(\"mainStyle\",\"%@\");",[self pathForVariant:variant]]);
-
- return [NSString stringWithFormat:@"setStylesheet(\"mainStyle\",\"%@\");",[self pathForVariant:variant]];
+ return [NSString stringWithFormat:@"setStylesheet(\"mainStyle\",\"%@\");",[self pathForVariant:self.activeVariant]];
}
- (NSString *)scriptForScrollingAfterAddingMultipleContentObjects
@@ -863,7 +865,10 @@
[inString replaceKeyword:@"%serviceIconPath%"
withString:[AIServiceIcons pathForServiceIconForServiceID:content.chat.account.service.serviceID
type:AIServiceIconLarge]];
-
+
+ [inString replaceKeyword:@"%variant%"
+ withString:self.activeVariant];
+
//message stuff
if ([content isKindOfClass:[AIContentMessage class]]) {
@@ -1283,6 +1288,9 @@
[inString safeReplaceCharactersInRange:range withString:(bodyTag ? (NSString *)bodyTag : @"")];
}
}
+
+ [inString replaceKeyword:@"%variant%"
+ withString:self.activeVariant];
return inString;
}
More information about the commits
mailing list