-
Notifications
You must be signed in to change notification settings - Fork 3
/
CustomPresenceWindowController.m
79 lines (69 loc) · 2.23 KB
/
CustomPresenceWindowController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// CustomPresenceWindowController.m
// Jabber
//
// Created by David Chisnall on 10/10/2004.
// Copyright 2004 __MyCompanyName__. All rights reserved.
//
#import "CustomPresenceWindowController.h"
#import "JabberApp.h"
#import "TRUserDefaults.h"
@implementation CustomPresenceWindowController
- (void) windowWillLoad
{
presences = [[[NSUserDefaults standardUserDefaults] dictionaryForKey:@"CustomPresence"] keysSortedByValueUsingSelector:@selector(compare:)];
}
- (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox
{
return [presences count];
}
- (NSUInteger)comboBox:(NSComboBox *)aComboBox indexOfItemWithStringValue:(NSString *)aString
{
return [presences indexOfObject:aString];
}
- (void) showPresenceNamed:(NSString*)_name
{
[message setString:[[NSUserDefaults standardUserDefaults] customMessageNamed:_name]];
[presence selectItemAtIndex:([[NSUserDefaults standardUserDefaults] customPresenceNamed:_name] /10) - 1];
}
- (void)comboBoxSelectionDidChange:(NSNotification *)notification
{
[self showPresenceNamed:[presences objectAtIndex:[name indexOfSelectedItem]]];
}
- (NSString *)comboBox:(NSComboBox *)aComboBox completedString:(NSString *)uncompletedString
{
NSEnumerator * enumerator = [presences objectEnumerator];
NSString * completedString;
unsigned int length = [uncompletedString length];
while((completedString = [enumerator nextObject]))
{
if([completedString length] > length)
{
if([[completedString substringToIndex:length] caseInsensitiveCompare:uncompletedString] == NSOrderedSame)
{
[self showPresenceNamed:completedString];
return completedString;
}
}
}
return uncompletedString;
}
- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)_index
{
return [presences objectAtIndex:_index];
}
- (IBAction) okay:(id) sender
{
//TODO: Make this less of an hack
[(JabberApp*)[NSApp delegate] setPresence:(([presence indexOfSelectedItem] + 1) * 10) withMessage:[message string]];
if(![[name stringValue] isEqualToString:@""])
{
[[NSUserDefaults standardUserDefaults] setCustomPresence:(([presence indexOfSelectedItem] + 1) * 10) withMessage:[message string] named:[name stringValue]];
}
[[self window] close];
}
- (IBAction) cancel:(id) sender
{
[[self window] close];
}
@end