-
Notifications
You must be signed in to change notification settings - Fork 4
/
ui.js
137 lines (104 loc) · 3.84 KB
/
ui.js
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
@import 'helper.js'
@import 'MochaJSDelegate.js'
COScript.currentCOScript().setShouldKeepAround_(true)
var config = {
width: 680,
height: 400,
topHeight: 50,
backgroundColor: NSColor.colorWithCalibratedRed_green_blue_alpha(231/255, 232/255, 232/255, 1.0)
}
var manager = {
delegateClass: new MochaJSDelegate(),
delegate: null,
dataSourceClass: new MochaJSDelegate(),
dataSource: null,
items: ["one", "two", "three"],
setup: function() {
this.dataSourceClass.setHandlerForSelector("numberOfRowsInTableView:", function(tableView) {
log("numberOfRowsInTableView")
return 10
})
this.dataSourceClass.setHandlerForSelector("tableView:objectValueForTableColumn:row:", function(tableView, column, row) {
log("objectValueForTableColumn")
return "hello"
})
this.delegateClass.setHandlerForSelector("tableView:didClickTableColumn:", function(tableView, column) {
log("didClickTableColumn")
})
this.delegateClass.setHandlerForSelector("tableView:rowViewForRow:", function(tableView, row) {
log("didClickTableColumn")
return NSTableRowView.alloc().init()
})
this.delegate = this.delegateClass.getClassInstance()
this.dataSource = this.dataSourceClass.getClassInstance()
}
}
var ui = {
tableView: null,
makeModalWindow: function() {
var window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(
NSMakeRect(0, 0, config.width, config.height), NSTitledWindowMask, NSBackingStoreBuffered, false)
window.backgroundColor = config.backgroundColor
return window
},
makeContainerView: function(context) {
var view = NSView.alloc().init()
var topView = this.makeTopView(context)
var tableViewContainer = this.makeTableView()
view.addSubview(tableViewContainer)
view.addSubview(topView)
topView.frame = NSMakeRect(0, config.height - config.topHeight, config.width, config.topHeight)
return view
},
makeTextField: function() {
var textField = NSTextField.alloc().init()
textField.editable = true
textField.setFont(NSFont.systemFontOfSize(28))
textField.textColor = NSColor.blackColor()
textField.stringValue = "hello world"
textField.cell().setPlaceholderString("Search")
textField.bezeled = false
textField.drawsBackground = false
textField.bordered = false
textField.cell().usesSingleLineMode = true
textField.cell().wraps = true
textField.focusRingType = NSFocusRingTypeNone
return textField
},
makeSearchImageView: function(plugin) {
var imageView = NSImageView.alloc().init()
imageView.frame = NSMakeRect(0, 0, 100, 100)
imageView.image = helper.getImage(plugin)
return imageView
},
makeTableView: function() {
var rect = NSMakeRect(0, 0, config.width, config.height - config.topHeight)
var container = NSScrollView.alloc().init()
container.frame = rect
var tableView = NSTableView.alloc().init()
this.tableView = tableView
tableView.frame = rect
var column = NSTableColumn.alloc().initWithIdentifier("")
column.width = config.width
tableView.addTableColumn(column)
tableView.focusRingType = NSFocusRingTypeNone
// tableView.headerView = null
manager.setup()
tableView.setDataSource_(manager.dataSource)
tableView.setDelegate_(manager.delegate)
container.documentView = tableView
container.hasVerticalScroller = true
container.backgroundColor = NSColor.redColor()
return container
},
makeTopView: function(context) {
var view = NSView.alloc().init()
var textField = this.makeTextField()
var imageView = this.makeSearchImageView(context.plugin)
view.addSubview(textField)
view.addSubview(imageView)
imageView.frame = NSMakeRect(5, config.topHeight - 39, 26, 26)
textField.frame = NSMakeRect(40, config.topHeight - 45, config.width - 55, 40)
return view
}
}