adium 3313:a534d21369d5: Fixes #13987. Allow accounts to overrid...
commits at adium.im
commits at adium.im
Sun Sep 19 18:41:50 UTC 2010
details: http://hg.adium.im/adium/rev/a534d21369d5
revision: 3313:a534d21369d5
author: Robert Vehse
date: Sun Sep 19 20:41:15 2010 +0200
Fixes #13987. Allow accounts to override the suffix/prefix for chat autocomplete. Add the "@" sign as a prefix and remove ":" as a suffix for Twitter. "mlei" and "wbowling" worked together on this patch.
diffs (126 lines):
diff -r f4e790addbdf -r a534d21369d5 Frameworks/Adium Framework/Source/AIAccount.h
--- a/Frameworks/Adium Framework/Source/AIAccount.h Sun Sep 19 03:46:18 2010 +0200
+++ b/Frameworks/Adium Framework/Source/AIAccount.h Sun Sep 19 20:41:15 2010 +0200
@@ -336,6 +336,16 @@
- (BOOL)chatShouldAutocompleteUID:(AIChat *)inChat;
/*!
+ * @brief Suffix for autocompleted contacts
+ */
+- (NSString *)suffixForAutocomplete:(AIChat *)inChat forPartialWordRange:(NSRange)charRange;
+
+/*!
+ * @brief Prefix for autocompleted contacts
+ */
+- (NSString *)prefixForAutocomplete:(AIChat *)inChat forPartialWordRange:(NSRange)charRange;
+
+/*!
* @brief Does the account support sending notifications?
*/
- (BOOL)supportsSendingNotifications;
diff -r f4e790addbdf -r a534d21369d5 Frameworks/Adium Framework/Source/AIAccount.m
--- a/Frameworks/Adium Framework/Source/AIAccount.m Sun Sep 19 03:46:18 2010 +0200
+++ b/Frameworks/Adium Framework/Source/AIAccount.m Sun Sep 19 20:41:15 2010 +0200
@@ -933,6 +933,28 @@
return NO;
}
+/*!
+ * @brief Suffix for autocompleted contacts
+ */
+- (NSString *)suffixForAutocomplete:(AIChat *)inChat forPartialWordRange:(NSRange)charRange
+{
+ NSString *suffix = nil;
+ if (charRange.location == 0)
+ {
+ suffix = @": ";
+ }
+ return suffix;
+}
+
+/*!
+ * @brief Prefix for autocompleted contacts
+ */
+- (NSString *)prefixForAutocomplete:(AIChat *)inChat forPartialWordRange:(NSRange)charRange
+{
+ return nil;
+}
+
+
-(NSMenu*)actionMenuForChat:(AIChat*)chat
{
return nil;
diff -r f4e790addbdf -r a534d21369d5 Plugins/Dual Window Interface/AIMessageViewController.m
--- a/Plugins/Dual Window Interface/AIMessageViewController.m Sun Sep 19 03:46:18 2010 +0200
+++ b/Plugins/Dual Window Interface/AIMessageViewController.m Sun Sep 19 20:41:15 2010 +0200
@@ -1050,13 +1050,28 @@
NSMutableArray *completions = nil;
if (self.chat.isGroupChat) {
- NSString *suffix = nil;
+ NSString *suffix = [self.chat.account suffixForAutocomplete:self.chat forPartialWordRange:charRange];
+ NSString *prefix = [self.chat.account prefixForAutocomplete:self.chat forPartialWordRange:charRange];
NSString *partialWord = [textView.textStorage.string substringWithRange:charRange];
BOOL autoCompleteUID = [self.chat.account chatShouldAutocompleteUID:self.chat];
- //At the start of a line, append ": "
- if (charRange.location == 0) {
- suffix = @": ";
+ // Check to see if the prefix is already present
+ if (charRange.location != 0 && charRange.location >= prefix.length) {
+ prefix = [[textView.textStorage.string substringWithRange:
+ NSMakeRange(charRange.location-prefix.length, prefix.length)] isEqualToString:prefix] ? nil : prefix;
+ }
+
+ // If we need to add a prefix, insert it into the text, then call [textView complete:] again; return early with no completions.
+ if (prefix.length > 0) {
+ [textView.textStorage insertAttributedString:[[NSAttributedString alloc] initWithString:prefix] atIndex:charRange.location];
+ [textView complete:nil];
+ return nil;
+ }
+
+ // Check to see if the suffix is already present
+ if (charRange.location + charRange.length + suffix.length <= textView.textStorage.string.length ) {
+ suffix = [[textView.textStorage.string substringWithRange:
+ NSMakeRange(charRange.location + charRange.length, suffix.length)] isEqualToString:suffix] ? nil : suffix;
}
completions = [NSMutableArray array];
@@ -1074,8 +1089,9 @@
completion = aliasOrDisplayName;
}
- // Add what we came up with to the completions list (with suffix if at beginning of line)
- [completions addObject:(suffix ? [completion stringByAppendingString:suffix] : completion)];
+ // Add what we came up with to the completions list (with suffix and prefix if required)
+ NSString *completionWithSuffix = (suffix ? [completion stringByAppendingString:suffix] : completion);
+ [completions addObject:(prefix ? [prefix stringByAppendingString:completionWithSuffix] : completionWithSuffix)];
}
if ([self.chat.displayName rangeOfString:partialWord options:(NSDiacriticInsensitiveSearch | NSCaseInsensitiveSearch | NSAnchoredSearch)].location != NSNotFound) {
diff -r f4e790addbdf -r a534d21369d5 Plugins/Twitter Plugin/AITwitterAccount.m
--- a/Plugins/Twitter Plugin/AITwitterAccount.m Sun Sep 19 03:46:18 2010 +0200
+++ b/Plugins/Twitter Plugin/AITwitterAccount.m Sun Sep 19 20:41:15 2010 +0200
@@ -356,6 +356,22 @@
}
/*!
+ * @brief Suffix for autocompleted contacts
+ */
+- (NSString *)suffixForAutocomplete:(AIChat *)inChat forPartialWordRange:(NSRange)charRange
+{
+ return nil;
+}
+
+/*!
+ * @brief Prefix for autocompleted contacts
+ */
+- (NSString *)prefixForAutocomplete:(AIChat *)inChat forPartialWordRange:(NSRange)charRange
+{
+ return @"@";
+}
+
+/*!
* @brief A chat opened.
*
* If this is a group chat which belongs to us, aka a timeline chat, set it up how we want it.
More information about the commits
mailing list