-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathPreferences.rb
executable file
·156 lines (127 loc) · 5.59 KB
/
Preferences.rb
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# Preferences.rb
# Leonhard
#
# Created by greg on 28/07/10.
# Copyright 2010, 2011 Gregoire Lejeune. All rights reserved.
class Preferences
include GVUtils
attr_accessor :mainWindow
attr_accessor :preferencesWindow
attr_accessor :graphVizPath
attr_accessor :autoGenerate
attr_accessor :autocomplete
attr_accessor :suuAutomaticallyChecksForUpdates
attr_accessor :suuInterval
attr_accessor :suuAutomaticallyDownloadsUpdates
attr_accessor :editorFont
def initialize
@suuIntervalsDef = {
"Every hour" => 3600,
"Every day" => 86400,
"Every week" => 604800,
"Every month" => 2592000
}
end
def awakeFromNib
# Change notifier for graphVizPath
NSNotificationCenter.defaultCenter().addObserver(self, selector: :"graphVizPathDidChange:", name:NSControlTextDidChangeNotification, object:graphVizPath)
# default preferences
@userDefaultsPrefs = NSUserDefaults.standardUserDefaults()
# Fragaria
@userDefaultsPrefs.setObject(NSNumber.numberWithBool(true), forKey:"LineWrapNewDocuments")
@userDefaultsPrefs.setObject(NSNumber.numberWithBool(true), forKey:"IndentWithSpaces")
@userDefaultsPrefs.setObject(NSNumber.numberWithBool(false), forKey:"AutocompleteSuggestAutomatically") if @userDefaultsPrefs.valueForKey("AutocompleteSuggestAutomatically").nil?
@userDefaultsPrefs.setObject(2, forKey:"TabWidth")
@userDefaultsPrefs.setObject(2, forKey:"IndentWidth")
@userDefaultsPrefs.setObject(NSArchiver.archivedDataWithRootObject(NSFont.fontWithName("Courier", size:13)), forKey:"TextFont")
_currentFont = NSUnarchiver.unarchiveObjectWithData(@userDefaultsPrefs.valueForKey("TextFont"))
@editorFont.font = _currentFont
@editorFont.stringValue = "#{_currentFont.fontName} - #{_currentFont.pointSize}"
# Leonhard
@userDefaultsPrefs.setObject("", forKey:"GraphVizPath") if @userDefaultsPrefs.valueForKey("GraphVizPath").nil?
@userDefaultsPrefs.setObject(false, forKey:"Autogenerate") if @userDefaultsPrefs.valueForKey("Autogenerate").nil?
# Set preferences values
@graphVizPath.stringValue = @userDefaultsPrefs.valueForKey("GraphVizPath").clone
@autoGenerate.state = @userDefaultsPrefs.valueForKey("Autogenerate")
@autocomplete.state = @userDefaultsPrefs.valueForKey("AutocompleteSuggestAutomatically")
# SUUpdater
@suuAutomaticallyChecksForUpdates.state = SUUpdater.sharedUpdater.automaticallyChecksForUpdates
@suuInterval.removeAllItems
@suuInterval.addItemsWithTitles(@suuIntervalsDef.keys)
@suuInterval.selectItemWithTitle(@suuIntervalsDef.invert[Integer(SUUpdater.sharedUpdater.updateCheckInterval)])
@suuAutomaticallyDownloadsUpdates.state = SUUpdater.sharedUpdater.automaticallyDownloadsUpdates
# Verify graphviz path
graphVizPathChange()
end
def closePreferencesWindow(sender)
@userDefaultsPrefs.setObject(@graphVizPath.stringValue(), forKey: "GraphVizPath")
@userDefaultsPrefs.setObject((@autoGenerate.state == 1), forKey: "Autogenerate")
@userDefaultsPrefs.setObject((@autocomplete.state == 1), forKey: "AutocompleteSuggestAutomatically")
@userDefaultsPrefs.synchronize
# SUU
SUUpdater.sharedUpdater.setAutomaticallyChecksForUpdates(@suuAutomaticallyChecksForUpdates.state == 1)
SUUpdater.sharedUpdater.setUpdateCheckInterval(@suuIntervalsDef[@suuInterval.titleOfSelectedItem])
SUUpdater.sharedUpdater.setAutomaticallyDownloadsUpdates(@suuAutomaticallyDownloadsUpdates.state == 1)
NSApp.endSheet(@preferencesWindow)
@preferencesWindow.orderOut(sender)
end
def showPreferencesWindow(sender)
NSApp.beginSheet(@preferencesWindow, modalForWindow:@mainWindow, modalDelegate:nil, didEndSelector:nil, contextInfo:nil)
end
def chooseGraphVizPath(sender)
panel = NSOpenPanel.openPanel()
panel.title = "Select GraphViz Path"
panel.canChooseFiles = false
panel.canChooseDirectories = true
ret = panel.runModal()
if ret == NSFileHandlingPanelOKButton
graphVizPath.stringValue = panel.URL.path
graphVizPathChange()
end
end
def graphVizPathChange
if find_executable("dot", [graphVizPath.stringValue]).nil?
graphVizPath.textColor = NSColor.redColor()
else
graphVizPath.textColor = NSColor.blackColor()
end
end
def graphVizPathDidChange(aNotifier)
if aNotifier.object == graphVizPath
graphVizPathChange()
end
end
def autogenerate?
@userDefaultsPrefs.valueForKey("Autogenerate")
end
def gvPath
@userDefaultsPrefs.valueForKey("GraphVizPath")
end
def changeEditorFont(sender)
NSLog("FONT :")
_currentFont = NSUnarchiver.unarchiveObjectWithData(@userDefaultsPrefs.valueForKey("TextFont"))
if _currentFont.nil?
_currentFont = NSFont.systemFontOfSize(NSFont.systemFontSize)
end
NSFontManager.sharedFontManager.setSelectedFont(_currentFont, isMultiple:false)
NSFontManager.sharedFontManager.orderFrontFontPanel(self)
NSFontManager.sharedFontManager.setDelegate(self)
NSFontManager.sharedFontManager.setAction(:changeFont)
@preferencesWindow.makeFirstResponder(@preferencesWindow)
end
def changeFont(sender)
NSLog("in changeFont")
fontManager = NSFontManager.sharedFontManager
selectedFont = fontManager.selectedFont
unless selectedFont.nil?
panelFont = fontManager.convertFont(selectedFont)
fontSize = NSNumber.numberWithFloat(panelFont.pointSize)
fontName = panelFont.fontName
@editorFont.stringValue = "#{fontName} - #{fontSize}"
@editorFont.font = panelFont
end
end
def [](x)
@userDefaultsPrefs.valueForKey(x)
end
end