-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.rb
More file actions
executable file
·135 lines (103 loc) · 3.27 KB
/
Controller.rb
File metadata and controls
executable file
·135 lines (103 loc) · 3.27 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
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
# Controller.rb
# mister t
#
# Created by Cameron Adamez on 3/18/10.
require 'yaml'
FONT_DATA = File.expand_path('~/test.yml')
class Controller
attr_writer :fontListView, :fontSampleView, :tokenView, :variantComboBox
attr_accessor :fonts
def awakeFromNib
retrieve_font_data
ncenter = NSNotificationCenter.defaultCenter
ncenter.addObserver self,
selector:'tableViewSelectionDidChange:',
name:NSTableViewSelectionDidChangeNotification,
object: nil
ncenter.addObserver self,
selector:'textDidEndEditing:',
name:NSTextDidEndEditingNotification,
object: nil
@variantComboBox.usesDataSource = true
@variantComboBox.dataSource = self
@variantComboBox.selectItemAtIndex 0
@fontListView.dataSource = self
@fontListView.reloadData
@fontListView.selectRowIndexes(NSIndexSet.indexSetWithIndex(0), byExtendingSelection:false)
end
def retrieve_font_data
if File.exist?(FONT_DATA)
@fonts = YAML.load_file(FONT_DATA)
else
create_font_list
end
end
# def fontSetChanged(notification)
# @fontListView.reloadData
# end
def numberOfRowsInTableView(view)
@fonts ? @fonts.size : 0
end
def tableView(view, objectValueForTableColumn:column, row:index)
@fonts[index].name
end
def tableViewSelectionDidChange(notification)
sample_view
@tokenView.objectValue = @fonts[@fontListView.selectedRow].tags
end
def textDidEndEditing(notification)
@fonts[@fontListView.selectedRow].add_tags @tokenView.objectValue
save
end
#def show_tags(tags)
# unless tags === '' || nil
# #@tokenView.objectValue = tags.join(', ')
# @tokenView.objectValue = tags
# else
# @tokenView.objectValue = []
# end
#end
def addTag(sender)
save
end
def clearTag(sender)
@fonts[@fontListView.selectedRow].clear_tags
save
end
def numberOfItemsInComboBox(comboBox)
@fonts[@fontListView.selectedRow].variants.length
end
def comboBox(cbox, objectValueForItemAtIndex:index)
@fonts[@fontListView.selectedRow].variants[index][1]
end
#def comboBox(cbox, indexOfItemWithStringValue:str)
# @fonts[@fontListView.selectedRow].variants.indexOfObject(str)
#end
#def comboBox(cbox, completedString:str)
# This method is received after each character typed by the user,
# because we have checked the "completes" flag for genreComboBox in IB.
# Given the inputString the user has typed, see if we can find a genre with the prefix,
# and return it as the suggested complete string.
# NSString *candidate = [self firstGenreMatchingPrefix:inputString];
# return (candidate ? candidate : inputString);
#end
private
def save
File.open('/Users/camo/test.yml', 'w+') {|f| f << @fonts.to_yaml}
end
def sample_view
sample_en = "The quick brown fox jumps over the lazy dog?!"
sample_ja = "足が早い茶色のキツネがぐうたら犬を飛び越える。"
fontname = @fonts[@fontListView.selectedRow].name
@fontSampleView.font = NSFont.fontWithName(fontname, size:24)
@fontSampleView.stringValue = sample_en
end
def create_font_list
#This should just return a freaking array of objects, not this whole other BS!
@fonts = []
MTFonts.new.each do |f|
@fonts << MTFont.new(f)
end
save
end
end