-
Notifications
You must be signed in to change notification settings - Fork 1
/
TableViewController.applescript
139 lines (115 loc) · 4.27 KB
/
TableViewController.applescript
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
(*
Copyright 2012 Kreuzverweis Solutions GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
script TableViewController
property parent : class "NSObject"
property contentSet : missing value
property contentArray : missing value
property setModified : true
property initialized : false
on addAll_(countedSet)
set setModified to true
repeat with anElement in countedSet's allObjects()
repeat with i from 1 to countedSet's countForObject_(anElement)
contentSet's addObject_(anElement)
end repeat
contentArray's addObject_(anElement)
end repeat
end addAll_
on add_row(rowValue)
set setModified to true
contentSet's addObject_(rowValue)
if (contentArray's containsObject_(rowValue) equals 0) then contentArray's addObject_(rowValue)
end add_row
on removeAll_(countedSet)
set setModified to true
repeat with anElement in countedSet's allObjects()
repeat with i from 1 to contentSet's countForObject_(anElement)
contentSet's removeObject_(anElement)
end repeat
contentArray's removeObject_(anElement)
end repeat
end removeAll_
on remove_row(rowValue)
set setModified to true
repeat with i from 1 to contentSet's countForObject_(rowValue)
contentSets's removeObject_(rowValue)
contentArray's removeObject_(rowValue)
end repeat
end remove_row
on clear()
set setModified to true
contentSet's removeAllObjects()
contentArray's removeAllObjects()
end clear
on countForObject_(anObject)
return contentSet's countForObject_(anObject)
end countForObject_
on countForRow_(row)
-- regenerateArray()
set anObject to contentArray's objectAtIndex_(row)
return countForObject_(anObject)
end countForRow_
on listsize()
return contentSet's |count|()
end listsize
on regenerateArray()
if setModified then
if contentSet's |count|() > 0 then
set roArray to contentSet's allObjects()
if not roArray is missing value then
tell current application's class "NSMutableArray" to set contentArray to its arrayWithArray_(roArray)
-- contentArray's sortUsingSelector_("localizedCaseInsensitiveCompare:")
else
tell current application's class "NSMutableArray" to set contentArray to its array()
end if
else
tell current application's class "NSMutableArray" to set contentArray to its array()
end if
set setModified to false
end if
end regenerateArray
##################################################
# TableView
(*
Below are three NSTableView methods of which two are mandatory.
Mandatory methods:
These can be found in NSTableViewDataSource.
tableView_objectValueForTableColumn_row_
numberOfRowsInTableView_
Optional method:
This is found in NSTableViewDelegate.
tableView_sortDescriptorsDidChange_
*)
on tableView_objectValueForTableColumn_row_(aTableView, aColumn, aRow)
-- regenerateArray()
set ls to listsize()
if ls is missing value then return end
if ls is 0 then return end
set resultVal to contentArray's objectAtIndex_(aRow)
if (resultVal is missing value) then return end
return resultVal
end tableView_objectValueForTableColumn_row_
on numberOfRowsInTableView_(aTableView)
if initialized then
-- regenerateArray()
return listsize()
else
return 0
end if
end numberOfRowsInTableView_
on awakeFromNib()
tell class "NSCountedSet" of current application to set contentSet to its |set|()
tell class "NSMutableArray" of current application to set contentArray to its array()
set initialized to true
end awakeFromNib
end script