-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreferencesController.rb
More file actions
81 lines (67 loc) · 2.41 KB
/
PreferencesController.rb
File metadata and controls
81 lines (67 loc) · 2.41 KB
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
class PreferencesController < NSWindowController
BackgroundColorKey = 'backgroundColor'
TextColorKey = 'textColor'
TwitterSearchQueryKey = 'twitterSearchQuery'
BackgroundColorChangedNotification = 'BackgroundColorChangedNotification'
TextColorChangedNotification = 'TextColorChangedNotification'
TwitterSearchQueryChangedNotification = 'TwitterSearchQueryChangedNotification'
attr_accessor :backgroundColorWell, :textColorWell, :twitterSearchQueryTextField
def self.registerUserDefaults
defaults = {}
defaults[BackgroundColorKey] = NSArchiver.archivedDataWithRootObject(NSColor.blackColor)
defaults[TextColorKey] = NSArchiver.archivedDataWithRootObject(NSColor.whiteColor)
defaults[TwitterSearchQueryKey] = '#MacRuby'
NSUserDefaults.standardUserDefaults.registerDefaults(defaults)
end
registerUserDefaults
def init
if(!super.initWithWindowNibName("Preferences"))
return nil
else
return self
end
end
def windowDidLoad
textColorWell.color = textColor
backgroundColorWell.color = backgroundColor
twitterSearchQueryTextField.stringValue = twitterSearchQuery
end
def textColor
unarchiveColorForKey(TextColorKey)
end
def backgroundColor
unarchiveColorForKey(BackgroundColorKey)
end
def twitterSearchQuery
NSUserDefaults.standardUserDefaults.stringForKey(TwitterSearchQueryKey)
end
def changeBackgroundColor(sender)
archiveColor(backgroundColorWell.color, BackgroundColorKey)
postNotification(BackgroundColorChangedNotification)
end
def changeTextColor(sender)
archiveColor(textColorWell.color, TextColorKey)
postNotification(TextColorChangedNotification)
end
def changeTwitterSearchQuery(sender)
NSUserDefaults.standardUserDefaults.setObject(twitterSearchQueryTextField.stringValue, forKey: TwitterSearchQueryKey)
postNotification(TwitterSearchQueryChangedNotification)
end
private
def unarchiveColorForKey(key)
NSUnarchiver.unarchiveObjectWithData(
NSUserDefaults.standardUserDefaults.dataForKey(key)
)
end
def archiveColor(color,key)
NSUserDefaults.standardUserDefaults.setObject(
NSArchiver.archivedDataWithRootObject(color),
forKey: key
)
end
def postNotification(key)
NSNotificationCenter.defaultCenter.postNotificationName(
key,
object: self)
end
end