-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampleFull.fan
More file actions
179 lines (153 loc) · 6.2 KB
/
ExampleFull.fan
File metadata and controls
179 lines (153 loc) · 6.2 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
using afIoc
using afReflux
using fwt
using gfx
class Example {
Void main() {
RefluxBuilder(AppModule#).start |Reflux reflux, Window window| {
reflux.showPanel(EventsPanel#)
reflux.showPanel(AlienAlertPanel#)
reflux.load("example:Fantom")
}
}
}
const class AppModule {
@Contribute { serviceType=Panels# }
Void contributePanels(Configuration config) {
config["events"] = config.build(EventsPanel#)
config["alienAlert"] = config.build(AlienAlertPanel#)
}
@Contribute { serviceType=UriResolvers# }
Void contributeUriResolvers(Configuration config) {
config["myResolver"] = config.build(MyResolver#)
}
@Contribute { serviceType=GlobalCommands# }
Void contributeGlobalCommands(Configuration config) {
config["cmdLaunchNukes"] = config.build(LaunchNukesCommand#)
}
@Contribute { serviceId="afReflux.menuBar" }
Void contributeMenuBar(Configuration config, Reflux reflux) {
menu := Menu() { it.text = "Example"}
config
.set("example", menu)
.after("afReflux.editMenu")
.before("afReflux.viewMenu")
menu.add(MenuItem(Command("Monica", null) { reflux.load("example:Monica" ) } ))
menu.add(MenuItem(Command("Erica", null) { reflux.load("example:Erica" ) } ))
menu.add(MenuItem(Command("Rita", null) { reflux.load("example:Rita" ) } ))
menu.add(MenuItem(Command("Tina", null) { reflux.load("example:Tina" ) } ))
menu.add(MenuItem(Command("Sandra", null) { reflux.load("example:Sandra" ) } ))
menu.add(MenuItem(Command("Mary", null) { reflux.load("example:Mary" ) } ))
menu.add(MenuItem(Command("Jessica", null) { reflux.load("example:Jessica") } ))
}
@Contribute { serviceId="afReflux.editMenu" }
Void contributeEditMenu(Configuration config, GlobalCommands globalCmds) {
config["cmdLaunchNukes"] = MenuItem(globalCmds["cmdLaunchNukes"].command)
}
@Contribute { serviceId="afReflux.toolBar" }
Void contributeToolBar(Configuration config, GlobalCommands globalCmds) {
button := Button(globalCmds["cmdLaunchNukes"].command)
button.text = ""
config["cmdLaunchNukes"] = button
}
}
class LaunchNukesCommand : GlobalCommand {
new make(|This|in) : super.make("cmdLaunchNukes", in) {
command.icon = Image(`fan://icons/x16/sun.png`)
}
override Void doInvoke(Event? event) {
Dialog.openWarn(command.window, "Launching Nukes!")
}
}
** This panel lists all the events it receives
class EventsPanel : Panel, RefluxEvents {
Table table
EventsPanelModel model := EventsPanelModel()
new make(|This| in) : super(in) {
icon = Image(`fan://icons/x16/history.png`)
table = content = Table()
table.model = model
}
override Void onLoadSession (Str:Obj? session) { update("onLoadSession" ) }
override Void onSaveSession (Str:Obj? session) { update("onSaveSession" ) }
override Void onLoad (Resource resource) { update("onLoad" ) }
override Void onError (Error error) { update("onError" ) }
override Void onPanelShown (Panel panel) { update("onPanelShown" , panel) }
override Void onPanelHidden (Panel panel) { update("onPanelHidden" , panel) }
override Void onPanelActivated (Panel panel) { update("onPanelActivated" , panel) }
override Void onPanelDeactivated (Panel panel) { update("onPanelDeactivated" , panel) }
override Void onPanelModified (Panel panel) { update("onPanelModified" , panel) }
override Void onViewShown (View view) { update("onViewShown" , view) }
override Void onViewHidden (View view) { update("onViewHidden" , view) }
override Void onViewActivated (View view) { update("onViewActivated" , view) }
override Void onViewDeactivated (View view) { update("onViewDeactivated" , view) }
override Void onViewModified (View view) { update("onViewModified" , view) }
Void update(Str event, Obj? panel := null) {
model.events.add([event, panel?.typeof?.name ?: ""])
//Err("$event + ${panel?.typeof?.name}").trace
table.refreshAll
}
}
class EventsPanelModel : TableModel {
Str[][] events := Str[][,]
override Int numCols() { 2 }
override Int numRows() { events.size }
override Str header(Int col) { col == 0 ? "Events" : "Panel" }
override Str text(Int col, Int row) { events[row][col] }
}
** This panel, when active, enables the global cmdLaunchNukes command
class AlienAlertPanel : Panel {
@Inject GlobalCommands globalCommands
new make(|This| in) : super(in) {
icon = Image(`fan://icons/x16/warn.png`)
name = "Alien Alert!"
content = Text() {
it.bg = Color.red
it.multiLine = true
it.text = "Alien Alert!\n
Aliens are attacking!\nLaunch the Nukes!\n
Tip: Select the other tab first."
}
}
override Void onActivate() {
globalCommands["cmdLaunchNukes"].removeEnabler("alienAlert")
}
override Void onDeactivate() {
// only enable the nuke when we *aren't* active!
globalCommands["cmdLaunchNukes"].addEnabler("alienAlert") |->Bool| { true }
}
}
class MyResolver : UriResolver {
@Inject Registry registry
new make(|This|in) { in(this) }
override Resource? resolve(Str uri) {
uri.toUri.scheme == "example"
? MyResource(uri.toUri)
: null
}
}
class MyResource : Resource {
override Uri uri
override Str name
override Image? icon
new make(Uri uri) {
this.uri = uri
this.name = uri.name
this.icon = Image(`fan://icons/x16/database.png`)
}
override Type[] viewTypes() {
[MyView#]
}
}
class MyView : View {
Label label
new make(|This| in) : super(in) {
content = label = Label() {
it.bg = Color.green
}
}
override Void load(Resource resource) {
super.load(resource)
label.text = "Resource Name: ${resource.name}"
}
}