forked from shabble/mouseterm
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMTProfile.m
111 lines (91 loc) · 2.75 KB
/
MTProfile.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#import <Cocoa/Cocoa.h>
#import "Mouse.h"
#import "MTProfile.h"
@implementation NSObject (MTProfile)
static NSString* mouseKeys[] = {
@"mouseLeftClick",
@"mouseMiddleClick",
@"mouseRightClick",
@"mouseWheel",
@"mouseWheelEmulation",
};
- (BOOL) MouseTerm_buttonEnabled: (MouseButton) button
{
NSString* key;
switch (button)
{
case MOUSE_BUTTON1:
key = @"mouseLeftClick";
break;
case MOUSE_BUTTON3:
key = @"mouseMiddleClick";
break;
case MOUSE_BUTTON2:
key = @"mouseRightClick";
break;
case MOUSE_WHEEL_UP:
case MOUSE_WHEEL_DOWN:
key = @"mouseWheel";
break;
default:
return YES;
}
return [[self MouseTerm_mouseValueForKey: key] boolValue];
}
- (BOOL) MouseTerm_emulationEnabled
{
return [[self MouseTerm_mouseValueForKey: @"mouseWheelEmulation"]
boolValue];
}
- (id) MouseTerm_mouseValueForKey: (NSString*) key
{
NSMutableDictionary* values = [self valueForKey: @"values"];
id value = [values objectForKey: key];
if ([value isKindOfClass: [NSData class]])
{
[self MouseTerm_setMouseValue:
[NSUnarchiver unarchiveObjectWithData: value]
forKey: key];
value = [self MouseTerm_mouseValueForKey: key];
}
if (value == nil)
value = [NSNumber numberWithBool: YES];
return value;
}
- (void) MouseTerm_setMouseValue: (id) value forKey: (NSString*) key
{
NSMutableDictionary* values = [self valueForKey: @"values"];
[values setObject: value forKey: key];
// Terrible hack to trigger preferences saving
id cursorType = [values objectForKey: @"CursorType"];
[self setValue: [NSNumber numberWithInt:-1] forKey: @"CursorType"];
[self setValue: cursorType forKey: @"CursorType"];
}
- (id) MouseTerm_valueForKey: (NSString*) key
{
if ([key hasPrefix: @"mouse"])
return [self MouseTerm_mouseValueForKey: key];
return [self MouseTerm_valueForKey: key];
}
- (void) MouseTerm_setValue: (id) value forKey: (NSString*) key
{
if ([key hasPrefix: @"mouse"])
return [self MouseTerm_setMouseValue: value forKey: key];
return [self MouseTerm_setValue: value forKey: key];
}
- (id) MouseTerm_propertyListRepresentation
{
size_t i;
NSMutableDictionary* plist = [[self MouseTerm_propertyListRepresentation]
mutableCopy];
for (i = 0; i < sizeof(mouseKeys) / sizeof(mouseKeys[0]); ++i)
{
NSString* key = mouseKeys[i];
id value = [self MouseTerm_mouseValueForKey: key];
if (value)
[plist setObject: [NSArchiver archivedDataWithRootObject: value]
forKey: key];
}
return [plist autorelease];
}
@end