glimmer-dsl-opal 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +341 -37
- data/VERSION +1 -1
- data/lib/glimmer-dsl-opal.rb +2 -1
- data/lib/glimmer-dsl-opal/ext/glimmer/dsl/engine.rb +30 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_menu_bar.rb +241 -0
- data/lib/glimmer/dsl/opal/shell_expression.rb +0 -4
- data/lib/glimmer/swt/display_proxy.rb +4 -4
- data/lib/glimmer/swt/latest_message_box_proxy.rb +20 -0
- data/lib/glimmer/swt/list_proxy.rb +0 -18
- data/lib/glimmer/swt/menu_item_proxy.rb +95 -8
- data/lib/glimmer/swt/menu_proxy.rb +135 -24
- data/lib/glimmer/swt/message_box_proxy.rb +5 -6
- data/lib/glimmer/swt/shell_proxy.rb +3 -3
- data/lib/glimmer/swt/widget_proxy.rb +12 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f0f0793d8e8128a47664c70eefee97fb797f61cbb8026937c3f88e00004a3b2
|
4
|
+
data.tar.gz: 7482911470d0ea4c87273622642b0d544f94bd0154913d2836e81e07e6d27da9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c6dd0b2de545158edfac2173cf7793415ad6046c650650b6b371a4e0704cd7de2cb78fc11ec05d653b266856c676350a224752417954a304ef9a2a95186439f
|
7
|
+
data.tar.gz: a3bb54ba72e3d55f9352e4ea660d14497212c058cd7f463464dacef05093d74dfabbcee2997d150c00b64923a1a71f592ae706e4155a57280a9f12dfb9fb8d9c
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.9.0
|
4
|
+
|
5
|
+
- Support `menu_bar`
|
6
|
+
- Hello, Menu Bar! Sample
|
7
|
+
- Remove the need to call Document.ready? before opening a Glimmer shell
|
8
|
+
- Support opening a message_box before creating a shell
|
9
|
+
|
3
10
|
## 0.8.0
|
4
11
|
|
5
12
|
- Hello, Pop Up Context Menu! Sample
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for Opal 0.
|
1
|
+
# [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for Opal 0.9.0 (Pure Ruby Web GUI)
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/glimmer-dsl-opal.svg)](http://badge.fury.io/rb/glimmer-dsl-opal)
|
3
3
|
[![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
4
4
|
|
@@ -60,7 +60,7 @@ Tic Tac Toe on the desktop with the same exact code (using the [glimmer-dsl-swt]
|
|
60
60
|
|
61
61
|
NOTE: Glimmer DSL for Opal is an alpha project. Please help make better by contributing, adopting for small or low risk projects, and providing feedback. It is still an early alpha, so the more feedback and issues you report the better.
|
62
62
|
|
63
|
-
**Alpha Version** 0.
|
63
|
+
**Alpha Version** 0.9.0 only supports bare-minimum capabilities for the following [samples](https://github.com/AndyObtiva/glimmer-dsl-opal#samples) (originally written in [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt)):
|
64
64
|
|
65
65
|
[Hello samples](#hello-samples):
|
66
66
|
|
@@ -83,6 +83,7 @@ NOTE: Glimmer DSL for Opal is an alpha project. Please help make better by contr
|
|
83
83
|
- [Hello, Button!](#hello-button)
|
84
84
|
- [Hello, Message Box!](#hello-message-box)
|
85
85
|
- [Hello, Pop Up Context Menu!](#hello-pop-up-context-menu)
|
86
|
+
- [Hello, Menu Bar!](#hello-menu-bar)
|
86
87
|
|
87
88
|
[Elaborate samples](#elaborate-samples):
|
88
89
|
|
@@ -118,6 +119,7 @@ Widgets:
|
|
118
119
|
- `label`
|
119
120
|
- `list` (w/ optional `:multi` SWT style)
|
120
121
|
- `menu`
|
122
|
+
- `menu_bar`
|
121
123
|
- `menu_item`
|
122
124
|
- `message_box`
|
123
125
|
- `radio`
|
@@ -162,7 +164,7 @@ Event loop:
|
|
162
164
|
|
163
165
|
## Principles
|
164
166
|
|
165
|
-
- **Live purely in Rubyland via the Glimmer GUI DSL**, completely oblivious to
|
167
|
+
- **Live purely in Rubyland via the Glimmer GUI DSL**, completely oblivious to web browser technologies.
|
166
168
|
- **Forget Routers!** Glimmer DSL for Opal supports auto-routing of custom shells (windows), which are opened as separate tabs in a web browser with automatically generated routes and bookmarkable URLs.
|
167
169
|
- **HTML is strictly made for creating documents not interactive applications**. As such, software engineers can avoid it and focus on creating web applications more productively with Glimmer DSL for Opal in pure Ruby instead (just like they do in desktop development) while content creators and web designers can be the ones responsible for creating HTML documents for web content purposes only as HTML was originally intended. That way, Glimmer web GUI is used and embedded in web pages when providing users with applications while the rest of the web pages are maintained by non-engineers as pure HTML. This achieves a correct separation of responsibilities and better productivity and maintainability.
|
168
170
|
- **Approximate styles by developers via the Glimmer GUI DSL. Perfect styles by designers via pure CSS**. Developers can simply build GUI with approximate styling similar to desktop GUI without worrying about pixel-perfect aethetics. Web designers can take styling further with pure CSS since every HTML element auto-generated by Glimmer DSL for Opal has a predictable ID and CSS class. This achieves a proper separation of responsibilities between developers and designers.
|
@@ -212,7 +214,7 @@ Add the following to `Gemfile`:
|
|
212
214
|
gem 'opal-rails', '~> 1.1.2'
|
213
215
|
gem 'opal-async', '~> 1.2.0'
|
214
216
|
gem 'opal-jquery', '~> 0.4.4'
|
215
|
-
gem 'glimmer-dsl-opal', '~> 0.
|
217
|
+
gem 'glimmer-dsl-opal', '~> 0.9.0'
|
216
218
|
gem 'glimmer-dsl-xml', '~> 1.1.0', require: false
|
217
219
|
gem 'glimmer-dsl-css', '~> 1.1.0', require: false
|
218
220
|
|
@@ -600,44 +602,53 @@ require 'glimmer-dsl-opal/samples/hello/hello_list_multi_selection'
|
|
600
602
|
Or add the Glimmer code directly if you prefer to play around with it:
|
601
603
|
|
602
604
|
```ruby
|
603
|
-
class Person
|
604
|
-
attr_accessor :provinces, :provinces_options
|
605
|
-
|
606
|
-
def initialize
|
607
|
-
self.provinces_options=[
|
608
|
-
"",
|
609
|
-
"Quebec",
|
610
|
-
"Ontario",
|
611
|
-
"Manitoba",
|
612
|
-
"Saskatchewan",
|
613
|
-
"Alberta",
|
614
|
-
"British Columbia",
|
615
|
-
"Nova Skotia",
|
616
|
-
"Newfoundland"
|
617
|
-
]
|
618
|
-
self.provinces = ["Quebec", "Manitoba", "Alberta"]
|
619
|
-
end
|
620
|
-
|
621
|
-
def reset_provinces
|
622
|
-
self.provinces = ["Quebec", "Manitoba", "Alberta"]
|
623
|
-
end
|
624
|
-
end
|
625
|
-
|
626
605
|
class HelloListMultiSelection
|
606
|
+
class Person
|
607
|
+
attr_accessor :provinces, :provinces_options
|
608
|
+
|
609
|
+
def initialize
|
610
|
+
self.provinces_options = [
|
611
|
+
'',
|
612
|
+
'Alberta',
|
613
|
+
'British Columbia',
|
614
|
+
'Manitoba',
|
615
|
+
'New Brunswick',
|
616
|
+
'Newfoundland and Labrador',
|
617
|
+
'Northwest Territories',
|
618
|
+
'Nova Scotia',
|
619
|
+
'Nunavut',
|
620
|
+
'Ontario',
|
621
|
+
'Prince Edward Island',
|
622
|
+
'Quebec',
|
623
|
+
'Saskatchewan',
|
624
|
+
'Yukon'
|
625
|
+
]
|
626
|
+
reset_provinces
|
627
|
+
end
|
628
|
+
|
629
|
+
def reset_provinces
|
630
|
+
self.provinces = ['Quebec', 'Manitoba', 'Alberta']
|
631
|
+
end
|
632
|
+
end
|
633
|
+
|
627
634
|
include Glimmer
|
635
|
+
|
628
636
|
def launch
|
629
637
|
person = Person.new
|
638
|
+
|
630
639
|
shell {
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
640
|
+
grid_layout
|
641
|
+
|
642
|
+
text 'Hello, List Multi Selection!'
|
643
|
+
|
644
|
+
list(:multi) {
|
645
|
+
selection bind(person, :provinces)
|
646
|
+
}
|
647
|
+
|
648
|
+
button {
|
649
|
+
text 'Reset Selections To Default Values'
|
650
|
+
|
651
|
+
on_widget_selected { person.reset_provinces }
|
641
652
|
}
|
642
653
|
}.open
|
643
654
|
end
|
@@ -2131,6 +2142,299 @@ You should see "Hello, Pop Up Context Menu!"
|
|
2131
2142
|
![Glimmer DSL for Opal Hello Pop Up Context Menu](images/glimmer-dsl-opal-hello-pop-up-context-menu.png)
|
2132
2143
|
![Glimmer DSL for Opal Hello Pop Up Context Menu Popped Up](images/glimmer-dsl-opal-hello-pop-up-context-menu-popped-up.png)
|
2133
2144
|
|
2145
|
+
#### Hello, Menu Bar!
|
2146
|
+
|
2147
|
+
Add the following require statement to `app/assets/javascripts/application.rb`
|
2148
|
+
|
2149
|
+
```ruby
|
2150
|
+
require 'glimmer-dsl-opal/samples/hello/hello_menu_bar'
|
2151
|
+
```
|
2152
|
+
|
2153
|
+
Or add the Glimmer code directly if you prefer to play around with it:
|
2154
|
+
|
2155
|
+
```ruby
|
2156
|
+
include Glimmer
|
2157
|
+
|
2158
|
+
COLORS = [:white, :red, :yellow, :green, :blue, :magenta, :gray, :black]
|
2159
|
+
|
2160
|
+
shell {
|
2161
|
+
grid_layout {
|
2162
|
+
margin_width 0
|
2163
|
+
margin_height 0
|
2164
|
+
}
|
2165
|
+
|
2166
|
+
text 'Hello, Menu Bar!'
|
2167
|
+
|
2168
|
+
@label = label(:center) {
|
2169
|
+
font height: 50
|
2170
|
+
text 'Check Out The Menu Bar Above!'
|
2171
|
+
}
|
2172
|
+
|
2173
|
+
menu_bar {
|
2174
|
+
menu {
|
2175
|
+
text '&File'
|
2176
|
+
menu_item {
|
2177
|
+
text '&New'
|
2178
|
+
accelerator :command, :N
|
2179
|
+
|
2180
|
+
on_widget_selected {
|
2181
|
+
message_box {
|
2182
|
+
text 'New'
|
2183
|
+
message 'New file created.'
|
2184
|
+
}.open
|
2185
|
+
}
|
2186
|
+
}
|
2187
|
+
menu_item {
|
2188
|
+
text '&Open...'
|
2189
|
+
accelerator :command, :O
|
2190
|
+
|
2191
|
+
on_widget_selected {
|
2192
|
+
message_box {
|
2193
|
+
text 'Open'
|
2194
|
+
message 'Opening File...'
|
2195
|
+
}.open
|
2196
|
+
}
|
2197
|
+
}
|
2198
|
+
menu {
|
2199
|
+
text 'Open &Recent'
|
2200
|
+
menu_item {
|
2201
|
+
text 'File 1'
|
2202
|
+
on_widget_selected {
|
2203
|
+
message_box {
|
2204
|
+
text 'File 1'
|
2205
|
+
message 'File 1 Contents'
|
2206
|
+
}.open
|
2207
|
+
}
|
2208
|
+
}
|
2209
|
+
menu_item {
|
2210
|
+
text 'File 2'
|
2211
|
+
on_widget_selected {
|
2212
|
+
message_box {
|
2213
|
+
text 'File 2'
|
2214
|
+
message 'File 2 Contents'
|
2215
|
+
}.open
|
2216
|
+
}
|
2217
|
+
}
|
2218
|
+
}
|
2219
|
+
menu_item(:separator)
|
2220
|
+
menu_item {
|
2221
|
+
text 'E&xit'
|
2222
|
+
|
2223
|
+
on_widget_selected {
|
2224
|
+
exit(0)
|
2225
|
+
}
|
2226
|
+
}
|
2227
|
+
}
|
2228
|
+
menu {
|
2229
|
+
text '&Edit'
|
2230
|
+
menu_item {
|
2231
|
+
text 'Cut'
|
2232
|
+
accelerator :command, :X
|
2233
|
+
}
|
2234
|
+
menu_item {
|
2235
|
+
text 'Copy'
|
2236
|
+
accelerator :command, :C
|
2237
|
+
}
|
2238
|
+
menu_item {
|
2239
|
+
text 'Paste'
|
2240
|
+
accelerator :command, :V
|
2241
|
+
}
|
2242
|
+
}
|
2243
|
+
menu {
|
2244
|
+
text '&Options'
|
2245
|
+
|
2246
|
+
menu_item(:radio) {
|
2247
|
+
text '&Enabled'
|
2248
|
+
|
2249
|
+
on_widget_selected {
|
2250
|
+
@select_one_menu.enabled = true
|
2251
|
+
@select_multiple_menu.enabled = true
|
2252
|
+
}
|
2253
|
+
}
|
2254
|
+
@select_one_menu = menu {
|
2255
|
+
text '&Select One'
|
2256
|
+
enabled false
|
2257
|
+
|
2258
|
+
menu_item(:radio) {
|
2259
|
+
text 'Option 1'
|
2260
|
+
}
|
2261
|
+
menu_item(:radio) {
|
2262
|
+
text 'Option 2'
|
2263
|
+
}
|
2264
|
+
menu_item(:radio) {
|
2265
|
+
text 'Option 3'
|
2266
|
+
}
|
2267
|
+
}
|
2268
|
+
@select_multiple_menu = menu {
|
2269
|
+
text '&Select Multiple'
|
2270
|
+
enabled false
|
2271
|
+
|
2272
|
+
menu_item(:check) {
|
2273
|
+
text 'Option 4'
|
2274
|
+
}
|
2275
|
+
menu_item(:check) {
|
2276
|
+
text 'Option 5'
|
2277
|
+
}
|
2278
|
+
menu_item(:check) {
|
2279
|
+
text 'Option 6'
|
2280
|
+
}
|
2281
|
+
}
|
2282
|
+
}
|
2283
|
+
menu {
|
2284
|
+
text '&Format'
|
2285
|
+
menu {
|
2286
|
+
text '&Background Color'
|
2287
|
+
COLORS.each { |color_style|
|
2288
|
+
menu_item(:radio) {
|
2289
|
+
text color_style.to_s.split('_').map(&:capitalize).join(' ')
|
2290
|
+
|
2291
|
+
on_widget_selected {
|
2292
|
+
@label.background = color_style
|
2293
|
+
}
|
2294
|
+
}
|
2295
|
+
}
|
2296
|
+
}
|
2297
|
+
menu {
|
2298
|
+
text 'Foreground &Color'
|
2299
|
+
COLORS.each { |color_style|
|
2300
|
+
menu_item(:radio) {
|
2301
|
+
text color_style.to_s.split('_').map(&:capitalize).join(' ')
|
2302
|
+
|
2303
|
+
on_widget_selected {
|
2304
|
+
@label.foreground = color_style
|
2305
|
+
}
|
2306
|
+
}
|
2307
|
+
}
|
2308
|
+
}
|
2309
|
+
}
|
2310
|
+
menu {
|
2311
|
+
text '&View'
|
2312
|
+
menu_item(:radio) {
|
2313
|
+
text 'Small'
|
2314
|
+
|
2315
|
+
on_widget_selected {
|
2316
|
+
@label.font = {height: 25}
|
2317
|
+
@label.parent.pack
|
2318
|
+
}
|
2319
|
+
}
|
2320
|
+
menu_item(:radio) {
|
2321
|
+
text 'Medium'
|
2322
|
+
selection true
|
2323
|
+
|
2324
|
+
on_widget_selected {
|
2325
|
+
@label.font = {height: 50}
|
2326
|
+
@label.parent.pack
|
2327
|
+
}
|
2328
|
+
}
|
2329
|
+
menu_item(:radio) {
|
2330
|
+
text 'Large'
|
2331
|
+
|
2332
|
+
on_widget_selected {
|
2333
|
+
@label.font = {height: 75}
|
2334
|
+
@label.parent.pack
|
2335
|
+
}
|
2336
|
+
}
|
2337
|
+
}
|
2338
|
+
menu {
|
2339
|
+
text '&Help'
|
2340
|
+
menu_item {
|
2341
|
+
text '&Manual'
|
2342
|
+
accelerator :command, :shift, :M
|
2343
|
+
|
2344
|
+
on_widget_selected {
|
2345
|
+
message_box {
|
2346
|
+
text 'Manual'
|
2347
|
+
message 'Manual Contents'
|
2348
|
+
}.open
|
2349
|
+
}
|
2350
|
+
}
|
2351
|
+
menu_item {
|
2352
|
+
text '&Tutorial'
|
2353
|
+
accelerator :command, :shift, :T
|
2354
|
+
|
2355
|
+
on_widget_selected {
|
2356
|
+
message_box {
|
2357
|
+
text 'Tutorial'
|
2358
|
+
message 'Tutorial Contents'
|
2359
|
+
}.open
|
2360
|
+
}
|
2361
|
+
}
|
2362
|
+
menu_item(:separator)
|
2363
|
+
menu_item {
|
2364
|
+
text '&Report an Issue...'
|
2365
|
+
|
2366
|
+
on_widget_selected {
|
2367
|
+
message_box {
|
2368
|
+
text 'Report an Issue'
|
2369
|
+
message 'Reporting an issue...'
|
2370
|
+
}.open
|
2371
|
+
}
|
2372
|
+
}
|
2373
|
+
}
|
2374
|
+
}
|
2375
|
+
}.open
|
2376
|
+
```
|
2377
|
+
|
2378
|
+
Glimmer app on the desktop (using [`glimmer-dsl-swt`](https://github.com/AndyObtiva/glimmer-dsl-swt) gem):
|
2379
|
+
|
2380
|
+
![Hello Menu Bar](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-menu-bar.png)
|
2381
|
+
|
2382
|
+
![Hello Menu Bar File Menu](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-menu-bar-file-menu.png)
|
2383
|
+
|
2384
|
+
![Hello Menu Bar Edit Menu](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-menu-bar-edit-menu.png)
|
2385
|
+
|
2386
|
+
![Hello Menu Bar Options Menu Disabled](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-menu-bar-options-menu-disabled.png)
|
2387
|
+
|
2388
|
+
![Hello Menu Bar Options Menu Select One](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-menu-bar-options-menu-select-one.png)
|
2389
|
+
|
2390
|
+
![Hello Menu Bar Options Menu Select Multiple](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-menu-bar-options-menu-select-multiple.png)
|
2391
|
+
|
2392
|
+
![Hello Menu Bar Format Menu Background Color](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-menu-bar-format-menu-background-color.png)
|
2393
|
+
|
2394
|
+
![Hello Menu Bar Format Menu Foreground Color](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-menu-bar-format-menu-foreground-color.png)
|
2395
|
+
|
2396
|
+
![Hello Menu Bar View Menu](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-menu-bar-view-menu.png)
|
2397
|
+
|
2398
|
+
![Hello Menu Bar View Small](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-menu-bar-view-small.png)
|
2399
|
+
|
2400
|
+
![Hello Menu Bar View Large](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-menu-bar-view-large.png)
|
2401
|
+
|
2402
|
+
![Hello Menu Bar Help Menu](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-menu-bar-help-menu.png)
|
2403
|
+
|
2404
|
+
Glimmer app on the web (using `glimmer-dsl-opal` gem):
|
2405
|
+
|
2406
|
+
Start the Rails server:
|
2407
|
+
```
|
2408
|
+
rails s
|
2409
|
+
```
|
2410
|
+
|
2411
|
+
Visit `http://localhost:3000`
|
2412
|
+
|
2413
|
+
You should see "Hello, Menu Bar!"
|
2414
|
+
|
2415
|
+
![Hello Menu Bar](images/glimmer-dsl-opal-hello-menu-bar.png)
|
2416
|
+
|
2417
|
+
![Hello Menu Bar File Menu](images/glimmer-dsl-opal-hello-menu-bar-file-menu.png)
|
2418
|
+
|
2419
|
+
![Hello Menu Bar Edit Menu](images/glimmer-dsl-opal-hello-menu-bar-edit-menu.png)
|
2420
|
+
|
2421
|
+
![Hello Menu Bar Options Menu Disabled](images/glimmer-dsl-opal-hello-menu-bar-options-menu-disabled.png)
|
2422
|
+
|
2423
|
+
![Hello Menu Bar Options Menu Select One](images/glimmer-dsl-opal-hello-menu-bar-options-menu-select-one.png)
|
2424
|
+
|
2425
|
+
![Hello Menu Bar Options Menu Select Multiple](images/glimmer-dsl-opal-hello-menu-bar-options-menu-select-multiple.png)
|
2426
|
+
|
2427
|
+
![Hello Menu Bar Format Menu Background Color](images/glimmer-dsl-opal-hello-menu-bar-format-menu-background-color.png)
|
2428
|
+
|
2429
|
+
![Hello Menu Bar Format Menu Foreground Color](images/glimmer-dsl-opal-hello-menu-bar-format-menu-foreground-color.png)
|
2430
|
+
|
2431
|
+
![Hello Menu Bar View Menu](images/glimmer-dsl-opal-hello-menu-bar-view-menu.png)
|
2432
|
+
|
2433
|
+
![Hello Menu Bar View Small](images/glimmer-dsl-opal-hello-menu-bar-view-small.png)
|
2434
|
+
|
2435
|
+
![Hello Menu Bar View Large](images/glimmer-dsl-opal-hello-menu-bar-view-large.png)
|
2436
|
+
|
2437
|
+
![Hello Menu Bar Help Menu](images/glimmer-dsl-opal-hello-menu-bar-help-menu.png)
|
2134
2438
|
|
2135
2439
|
### Elaborate Samples
|
2136
2440
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.9.0
|
data/lib/glimmer-dsl-opal.rb
CHANGED
@@ -63,8 +63,9 @@ if RUBY_ENGINE == 'opal'
|
|
63
63
|
require 'glimmer'
|
64
64
|
require 'glimmer-dsl-opal/ext/exception'
|
65
65
|
require 'glimmer-dsl-opal/ext/date'
|
66
|
+
require 'glimmer-dsl-opal/ext/glimmer/dsl/engine'
|
66
67
|
require 'uri'
|
67
|
-
|
68
|
+
|
68
69
|
# Spiking async logging
|
69
70
|
# logger = Glimmer::Config.logger
|
70
71
|
# original_add_method = logger.class.instance_method(:add)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'glimmer/swt/latest_message_box_proxy'
|
2
|
+
|
3
|
+
module Glimmer
|
4
|
+
module DSL
|
5
|
+
class Engine
|
6
|
+
class << self
|
7
|
+
def interpret_expression(expression, keyword, *args, &block)
|
8
|
+
work = lambda do
|
9
|
+
expression.interpret(parent, keyword, *args, &block).tap do |ui_object|
|
10
|
+
add_content(ui_object, expression, &block)
|
11
|
+
dsl_stack.pop
|
12
|
+
end
|
13
|
+
end
|
14
|
+
if keyword == 'shell'
|
15
|
+
Document.ready?(&work)
|
16
|
+
elsif keyword == 'message_box'
|
17
|
+
if Glimmer::SWT::DisplayProxy.instance.shells.empty?
|
18
|
+
Document.ready?(&work)
|
19
|
+
Glimmer::SWT::LatestMessageBoxProxy.new
|
20
|
+
else
|
21
|
+
work.call
|
22
|
+
end
|
23
|
+
else
|
24
|
+
work.call
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,241 @@
|
|
1
|
+
# Copyright (c) 2007-2020 Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
include Glimmer
|
23
|
+
|
24
|
+
COLORS = [:white, :red, :yellow, :green, :blue, :magenta, :gray, :black]
|
25
|
+
|
26
|
+
shell {
|
27
|
+
grid_layout {
|
28
|
+
margin_width 0
|
29
|
+
margin_height 0
|
30
|
+
}
|
31
|
+
|
32
|
+
text 'Hello, Menu Bar!'
|
33
|
+
|
34
|
+
@label = label(:center) {
|
35
|
+
font height: 50
|
36
|
+
text 'Check Out The Menu Bar Above!'
|
37
|
+
}
|
38
|
+
|
39
|
+
menu_bar {
|
40
|
+
menu {
|
41
|
+
text '&File'
|
42
|
+
menu_item {
|
43
|
+
text '&New'
|
44
|
+
accelerator :command, :N
|
45
|
+
|
46
|
+
on_widget_selected {
|
47
|
+
message_box {
|
48
|
+
text 'New'
|
49
|
+
message 'New file created.'
|
50
|
+
}.open
|
51
|
+
}
|
52
|
+
}
|
53
|
+
menu_item {
|
54
|
+
text '&Open...'
|
55
|
+
accelerator :command, :O
|
56
|
+
|
57
|
+
on_widget_selected {
|
58
|
+
message_box {
|
59
|
+
text 'Open'
|
60
|
+
message 'Opening File...'
|
61
|
+
}.open
|
62
|
+
}
|
63
|
+
}
|
64
|
+
menu {
|
65
|
+
text 'Open &Recent'
|
66
|
+
menu_item {
|
67
|
+
text 'File 1'
|
68
|
+
on_widget_selected {
|
69
|
+
message_box {
|
70
|
+
text 'File 1'
|
71
|
+
message 'File 1 Contents'
|
72
|
+
}.open
|
73
|
+
}
|
74
|
+
}
|
75
|
+
menu_item {
|
76
|
+
text 'File 2'
|
77
|
+
on_widget_selected {
|
78
|
+
message_box {
|
79
|
+
text 'File 2'
|
80
|
+
message 'File 2 Contents'
|
81
|
+
}.open
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
menu_item(:separator)
|
86
|
+
menu_item {
|
87
|
+
text 'E&xit'
|
88
|
+
|
89
|
+
on_widget_selected {
|
90
|
+
exit(0)
|
91
|
+
}
|
92
|
+
}
|
93
|
+
}
|
94
|
+
menu {
|
95
|
+
text '&Edit'
|
96
|
+
menu_item {
|
97
|
+
text 'Cut'
|
98
|
+
accelerator :command, :X
|
99
|
+
}
|
100
|
+
menu_item {
|
101
|
+
text 'Copy'
|
102
|
+
accelerator :command, :C
|
103
|
+
}
|
104
|
+
menu_item {
|
105
|
+
text 'Paste'
|
106
|
+
accelerator :command, :V
|
107
|
+
}
|
108
|
+
}
|
109
|
+
menu {
|
110
|
+
text '&Options'
|
111
|
+
|
112
|
+
menu_item(:radio) {
|
113
|
+
text '&Enabled'
|
114
|
+
|
115
|
+
on_widget_selected {
|
116
|
+
@select_one_menu.enabled = true
|
117
|
+
@select_multiple_menu.enabled = true
|
118
|
+
}
|
119
|
+
}
|
120
|
+
@select_one_menu = menu {
|
121
|
+
text '&Select One'
|
122
|
+
enabled false
|
123
|
+
|
124
|
+
menu_item(:radio) {
|
125
|
+
text 'Option 1'
|
126
|
+
}
|
127
|
+
menu_item(:radio) {
|
128
|
+
text 'Option 2'
|
129
|
+
}
|
130
|
+
menu_item(:radio) {
|
131
|
+
text 'Option 3'
|
132
|
+
}
|
133
|
+
}
|
134
|
+
@select_multiple_menu = menu {
|
135
|
+
text '&Select Multiple'
|
136
|
+
enabled false
|
137
|
+
|
138
|
+
menu_item(:check) {
|
139
|
+
text 'Option 4'
|
140
|
+
}
|
141
|
+
menu_item(:check) {
|
142
|
+
text 'Option 5'
|
143
|
+
}
|
144
|
+
menu_item(:check) {
|
145
|
+
text 'Option 6'
|
146
|
+
}
|
147
|
+
}
|
148
|
+
}
|
149
|
+
menu {
|
150
|
+
text '&Format'
|
151
|
+
menu {
|
152
|
+
text '&Background Color'
|
153
|
+
COLORS.each { |color_style|
|
154
|
+
menu_item(:radio) {
|
155
|
+
text color_style.to_s.split('_').map(&:capitalize).join(' ')
|
156
|
+
|
157
|
+
on_widget_selected {
|
158
|
+
@label.background = color_style
|
159
|
+
}
|
160
|
+
}
|
161
|
+
}
|
162
|
+
}
|
163
|
+
menu {
|
164
|
+
text 'Foreground &Color'
|
165
|
+
COLORS.each { |color_style|
|
166
|
+
menu_item(:radio) {
|
167
|
+
text color_style.to_s.split('_').map(&:capitalize).join(' ')
|
168
|
+
|
169
|
+
on_widget_selected {
|
170
|
+
@label.foreground = color_style
|
171
|
+
}
|
172
|
+
}
|
173
|
+
}
|
174
|
+
}
|
175
|
+
}
|
176
|
+
menu {
|
177
|
+
text '&View'
|
178
|
+
menu_item(:radio) {
|
179
|
+
text 'Small'
|
180
|
+
|
181
|
+
on_widget_selected {
|
182
|
+
@label.font = {height: 25}
|
183
|
+
@label.parent.pack
|
184
|
+
}
|
185
|
+
}
|
186
|
+
menu_item(:radio) {
|
187
|
+
text 'Medium'
|
188
|
+
selection true
|
189
|
+
|
190
|
+
on_widget_selected {
|
191
|
+
@label.font = {height: 50}
|
192
|
+
@label.parent.pack
|
193
|
+
}
|
194
|
+
}
|
195
|
+
menu_item(:radio) {
|
196
|
+
text 'Large'
|
197
|
+
|
198
|
+
on_widget_selected {
|
199
|
+
@label.font = {height: 75}
|
200
|
+
@label.parent.pack
|
201
|
+
}
|
202
|
+
}
|
203
|
+
}
|
204
|
+
menu {
|
205
|
+
text '&Help'
|
206
|
+
menu_item {
|
207
|
+
text '&Manual'
|
208
|
+
accelerator :command, :shift, :M
|
209
|
+
|
210
|
+
on_widget_selected {
|
211
|
+
message_box {
|
212
|
+
text 'Manual'
|
213
|
+
message 'Manual Contents'
|
214
|
+
}.open
|
215
|
+
}
|
216
|
+
}
|
217
|
+
menu_item {
|
218
|
+
text '&Tutorial'
|
219
|
+
accelerator :command, :shift, :T
|
220
|
+
|
221
|
+
on_widget_selected {
|
222
|
+
message_box {
|
223
|
+
text 'Tutorial'
|
224
|
+
message 'Tutorial Contents'
|
225
|
+
}.open
|
226
|
+
}
|
227
|
+
}
|
228
|
+
menu_item(:separator)
|
229
|
+
menu_item {
|
230
|
+
text '&Report an Issue...'
|
231
|
+
|
232
|
+
on_widget_selected {
|
233
|
+
message_box {
|
234
|
+
text 'Report an Issue'
|
235
|
+
message 'Reporting an issue...'
|
236
|
+
}.open
|
237
|
+
}
|
238
|
+
}
|
239
|
+
}
|
240
|
+
}
|
241
|
+
}.open
|
@@ -28,6 +28,10 @@ module Glimmer
|
|
28
28
|
@shells ||= []
|
29
29
|
end
|
30
30
|
|
31
|
+
def message_boxes
|
32
|
+
@message_boxes ||= []
|
33
|
+
end
|
34
|
+
|
31
35
|
def render
|
32
36
|
# No rendering as body is rendered as part of ShellProxy.. this class only serves as an SWT Display utility
|
33
37
|
end
|
@@ -74,10 +78,6 @@ module Glimmer
|
|
74
78
|
]
|
75
79
|
}
|
76
80
|
end
|
77
|
-
|
78
|
-
def shells
|
79
|
-
@shells ||= []
|
80
|
-
end
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Glimmer
|
2
|
+
module SWT
|
3
|
+
class LatestMessageBoxProxy #< MessageBoxProxy
|
4
|
+
# TODO consider overriding all methods from MessageBoxProxy and proxying to them
|
5
|
+
|
6
|
+
def initialize(parent, args, block)
|
7
|
+
# No Op
|
8
|
+
end
|
9
|
+
|
10
|
+
def open
|
11
|
+
Document.ready? do
|
12
|
+
DisplayProxy.instance.message_boxes.last&.open
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -13,24 +13,6 @@ module Glimmer
|
|
13
13
|
padding-left: 10px;
|
14
14
|
padding-right: 10px;
|
15
15
|
}
|
16
|
-
li.menu-item {
|
17
|
-
padding-left: initial;
|
18
|
-
padding-right: initial;
|
19
|
-
}
|
20
|
-
.ui-menu {
|
21
|
-
/* TODO consider auto-sizing in the future */
|
22
|
-
font-size: initial;
|
23
|
-
width: 150px;
|
24
|
-
border-radius: 5px;
|
25
|
-
}
|
26
|
-
.ui-menu-item:first-child > .ui-menu-item-wrapper {
|
27
|
-
border-top-left-radius: 5px;
|
28
|
-
border-top-right-radius: 5px;
|
29
|
-
}
|
30
|
-
.ui-menu-item:last-child > .ui-menu-item-wrapper {
|
31
|
-
border-bottom-left-radius: 5px;
|
32
|
-
border-bottom-right-radius: 5px;
|
33
|
-
}
|
34
16
|
li.empty-list-item {
|
35
17
|
color: transparent;
|
36
18
|
}
|
@@ -30,20 +30,98 @@ module Glimmer
|
|
30
30
|
# Follows the Proxy Design Pattern since it's a proxy for an HTML based menu
|
31
31
|
# Follows the Adapter Design Pattern since it's adapting a Glimmer DSL for SWT widget
|
32
32
|
class MenuItemProxy < WidgetProxy
|
33
|
+
STYLE = <<~CSS
|
34
|
+
.menu-item.disabled {
|
35
|
+
background-color: lightgrey;
|
36
|
+
color: grey;
|
37
|
+
}
|
38
|
+
.menu-item.disabled .menu, .menu-item.disabled .menu * {
|
39
|
+
display: none;
|
40
|
+
opacity: 0;
|
41
|
+
}
|
42
|
+
CSS
|
43
|
+
|
44
|
+
attr_accessor :accelerator # TODO consider doing something with it
|
45
|
+
|
46
|
+
def initialize(parent, args)
|
47
|
+
args.push(:push) if args.empty?
|
48
|
+
super(parent, args)
|
49
|
+
# TODO do not add the following event till post_add_content to avoid adding if already one on_widget_selected event existed
|
50
|
+
on_widget_selected {
|
51
|
+
# No Op, just trigger selection
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
33
55
|
def post_initialize_child(child)
|
34
56
|
@children << child
|
35
57
|
end
|
36
58
|
|
59
|
+
def cascade?
|
60
|
+
args.include?(:cascade)
|
61
|
+
end
|
62
|
+
|
63
|
+
def push?
|
64
|
+
args.include?(:push)
|
65
|
+
end
|
66
|
+
|
67
|
+
def radio?
|
68
|
+
args.include?(:radio)
|
69
|
+
end
|
70
|
+
|
71
|
+
def check?
|
72
|
+
args.include?(:check)
|
73
|
+
end
|
74
|
+
|
75
|
+
def separator?
|
76
|
+
args.include?(:separator)
|
77
|
+
end
|
78
|
+
|
37
79
|
def text
|
38
80
|
@text
|
39
81
|
end
|
40
82
|
|
41
83
|
def text=(value)
|
42
84
|
@text = value
|
43
|
-
dom_element.
|
85
|
+
dom_element.find('.menu-item-text').html(@text)
|
44
86
|
@text
|
45
87
|
end
|
46
88
|
|
89
|
+
def selection
|
90
|
+
@selection
|
91
|
+
end
|
92
|
+
|
93
|
+
def selection=(value)
|
94
|
+
@selection = value
|
95
|
+
icon_suffix = check? ? 'check' : 'bullet'
|
96
|
+
dom_element.find('.menu-item-selection').toggle_class("ui-icon ui-icon-#{icon_suffix}", @selection)
|
97
|
+
@selection
|
98
|
+
end
|
99
|
+
|
100
|
+
def toggle_selection!
|
101
|
+
self.selection = !selection
|
102
|
+
end
|
103
|
+
|
104
|
+
def enabled=(value)
|
105
|
+
@enabled = value
|
106
|
+
dom_element.toggle_class('disabled', !@enabled)
|
107
|
+
@enabled
|
108
|
+
end
|
109
|
+
|
110
|
+
def div_content
|
111
|
+
div_attributes = {}
|
112
|
+
icon_suffix = check? ? 'check' : 'bullet'
|
113
|
+
div(div_attributes) {
|
114
|
+
unless separator? # empty content automatically gets a separator style in jQuery-UI
|
115
|
+
span(class: "menu-item-selection #{"ui-icon ui-icon-#{icon_suffix}" if selection}") {}
|
116
|
+
span(class: 'ui-menu-icon ui-icon ui-icon-caret-1-e') {} if cascade? && !parent.bar?
|
117
|
+
span(class: 'menu-item-text') {
|
118
|
+
@text
|
119
|
+
}
|
120
|
+
''
|
121
|
+
end
|
122
|
+
}
|
123
|
+
end
|
124
|
+
|
47
125
|
def root_menu
|
48
126
|
the_menu = parent
|
49
127
|
the_menu = the_menu.parent_menu until the_menu.root_menu?
|
@@ -60,9 +138,19 @@ module Glimmer
|
|
60
138
|
event: 'mouseup',
|
61
139
|
event_handler: -> (event_listener) {
|
62
140
|
-> (event) {
|
63
|
-
|
64
|
-
|
65
|
-
|
141
|
+
if enabled && (push? || radio? || check?)
|
142
|
+
if check?
|
143
|
+
self.toggle_selection!
|
144
|
+
elsif radio? && !selection
|
145
|
+
parent.children.detect(&:selection)&.selection = false
|
146
|
+
self.selection = true
|
147
|
+
end
|
148
|
+
if !root_menu.bar?
|
149
|
+
remove_event_listener_proxies
|
150
|
+
root_menu.close
|
151
|
+
end
|
152
|
+
event_listener.call(event)
|
153
|
+
end
|
66
154
|
}
|
67
155
|
},
|
68
156
|
},
|
@@ -74,11 +162,10 @@ module Glimmer
|
|
74
162
|
end
|
75
163
|
|
76
164
|
def dom
|
165
|
+
# TODO support rendering image
|
77
166
|
@dom ||= html {
|
78
|
-
li(id: id, class: name) {
|
79
|
-
|
80
|
-
@text
|
81
|
-
}
|
167
|
+
li(id: id, class: "#{name} #{'disabled' unless enabled}") {
|
168
|
+
div_content
|
82
169
|
}
|
83
170
|
}.to_s
|
84
171
|
end
|
@@ -45,33 +45,85 @@ module Glimmer
|
|
45
45
|
#
|
46
46
|
# Follows the Proxy Design Pattern
|
47
47
|
class MenuProxy < WidgetProxy
|
48
|
+
STYLE = <<~CSS
|
49
|
+
.menu.menu-bar {
|
50
|
+
position: absolute;
|
51
|
+
top: -30px;
|
52
|
+
border-radius: 0;
|
53
|
+
width: 100%;
|
54
|
+
}
|
55
|
+
.menu.menu-bar .menu {
|
56
|
+
border-radius: 0;
|
57
|
+
}
|
58
|
+
.menu-bar .menu-item {
|
59
|
+
width: 180px;
|
60
|
+
}
|
61
|
+
.menu-bar > .menu-item {
|
62
|
+
display: inline-block;
|
63
|
+
width: 150px;
|
64
|
+
}
|
65
|
+
li.menu-item {
|
66
|
+
padding-left: initial;
|
67
|
+
padding-right: initial;
|
68
|
+
}
|
69
|
+
.menu {
|
70
|
+
/* TODO consider auto-sizing in the future */
|
71
|
+
font-size: initial;
|
72
|
+
border-radius: 5px;
|
73
|
+
}
|
74
|
+
.menu:not(.menu-bar) {
|
75
|
+
width: 150px;
|
76
|
+
}
|
77
|
+
.menu-bar .ui-menu:not(.menu-bar) {
|
78
|
+
width: 180px;
|
79
|
+
}
|
80
|
+
.ui-menu-item:first-child > .ui-menu-item-wrapper {
|
81
|
+
border-top-left-radius: 5px;
|
82
|
+
border-top-right-radius: 5px;
|
83
|
+
}
|
84
|
+
.ui-menu-item:last-child > .ui-menu-item-wrapper {
|
85
|
+
border-bottom-left-radius: 5px;
|
86
|
+
border-bottom-right-radius: 5px;
|
87
|
+
}
|
88
|
+
.menu-bar .ui-menu-item:first-child > .ui-menu-item-wrapper {
|
89
|
+
border-top-left-radius: 0;
|
90
|
+
border-top-right-radius: 0;
|
91
|
+
}
|
92
|
+
.menu-bar .ui-menu-item:last-child > .ui-menu-item-wrapper {
|
93
|
+
border-bottom-left-radius: 0;
|
94
|
+
border-bottom-right-radius: 0;
|
95
|
+
}
|
96
|
+
|
97
|
+
CSS
|
98
|
+
|
48
99
|
attr_reader :menu_item_proxy, :menu_parent
|
49
100
|
|
50
101
|
def initialize(parent, args)
|
51
|
-
# TODO
|
52
|
-
# TODO handle :pop_up swt style
|
53
|
-
# TODO handle :cascade swt style
|
102
|
+
# TODO refactor/simplify code below
|
54
103
|
@children = []
|
55
104
|
index = args.delete(args.last) if args.last.is_a?(Numeric)
|
56
|
-
|
57
|
-
if
|
58
|
-
|
105
|
+
args = args.map {|arg| arg.is_a?(String) ? arg.to_sym : arg}
|
106
|
+
if parent.is_a?(ShellProxy)
|
107
|
+
args = args.unshift(:bar)
|
108
|
+
elsif parent.is_a?(MenuProxy)
|
109
|
+
args = args.unshift(:drop_down)
|
110
|
+
else
|
111
|
+
args = args.unshift(:pop_up)
|
59
112
|
end
|
60
|
-
|
61
113
|
if parent.is_a?(MenuProxy)
|
62
114
|
@menu_item_proxy = SWT::WidgetProxy.for('menu_item', parent, [:cascade] + [index].compact)
|
63
|
-
super(@menu_item_proxy)
|
115
|
+
super(@menu_item_proxy, args)
|
64
116
|
@menu_item_proxy.menu = self
|
65
117
|
elsif parent.is_a?(ShellProxy)
|
66
|
-
super(parent,
|
67
|
-
else
|
68
|
-
super(parent)
|
118
|
+
super(parent, args)
|
119
|
+
else # widget pop up
|
120
|
+
super(parent, args)
|
69
121
|
end
|
70
122
|
|
71
|
-
if
|
123
|
+
if bar?
|
72
124
|
# Assumes a parent shell
|
73
125
|
parent.menu_bar = self
|
74
|
-
elsif
|
126
|
+
elsif pop_up?
|
75
127
|
parent.menu = self
|
76
128
|
end
|
77
129
|
# TODO IMPLEMENT PROPERLY
|
@@ -80,6 +132,18 @@ module Glimmer
|
|
80
132
|
# }
|
81
133
|
end
|
82
134
|
|
135
|
+
def bar?
|
136
|
+
args.include?(:bar)
|
137
|
+
end
|
138
|
+
|
139
|
+
def pop_up?
|
140
|
+
args.include?(:pop_up)
|
141
|
+
end
|
142
|
+
|
143
|
+
def drop_down?
|
144
|
+
args.include?(:drop_down)
|
145
|
+
end
|
146
|
+
|
83
147
|
def text
|
84
148
|
@menu_item_proxy&.text
|
85
149
|
end
|
@@ -88,6 +152,20 @@ module Glimmer
|
|
88
152
|
@menu_item_proxy&.text = text_value
|
89
153
|
end
|
90
154
|
|
155
|
+
def enabled
|
156
|
+
if drop_down?
|
157
|
+
menu_item_proxy.enabled
|
158
|
+
else
|
159
|
+
true
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def enabled=(value)
|
164
|
+
if drop_down?
|
165
|
+
menu_item_proxy.enabled = value
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
91
169
|
def can_handle_observation_request?(observation_request, super_only: false)
|
92
170
|
super_result = super(observation_request)
|
93
171
|
if observation_request.start_with?('on_') && !super_result && !super_only
|
@@ -115,21 +193,42 @@ module Glimmer
|
|
115
193
|
end
|
116
194
|
end
|
117
195
|
|
118
|
-
def
|
196
|
+
def post_add_content
|
197
|
+
if bar?
|
198
|
+
# delay this till all children rendered (perhaps post_add_content block)
|
199
|
+
parent_dom_element.css('position', 'relative')
|
200
|
+
parent_dom_element.css('margin-top', '30px')
|
201
|
+
redraw
|
202
|
+
`$(#{path}).menu({
|
203
|
+
position: { my: "top", at: "bottom" },
|
204
|
+
icons: { submenu: "ui-icon-blank" }
|
205
|
+
});`
|
206
|
+
the_element = dom_element
|
207
|
+
the_element.on('mouseover') { |event|
|
208
|
+
if event.page_x.between?(the_element.offset.left, the_element.offset.left + the_element.width) and
|
209
|
+
event.page_y.between?(the_element.offset.top, the_element.offset.top + the_element.height)
|
210
|
+
`$(#{path}).menu('option', 'position', { my: 'left top', at: 'left bottom' });`
|
211
|
+
end
|
212
|
+
}
|
213
|
+
the_element.on('menublur') {
|
214
|
+
`$(#{path}).menu('option', 'position', { my: 'left top', at: 'right top' });`
|
215
|
+
}
|
216
|
+
minimum_width = children.to_a.map(&:dom_element).map(&:width).reduce(:+)
|
217
|
+
the_element.css('min-width', minimum_width)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
def render(custom_parent_dom_element: nil, brand_new: false)
|
119
222
|
# TODO attach to top nav bar if parent is shell
|
120
223
|
# TODO attach listener to parent to display on right click
|
121
|
-
if parent.is_a?(MenuProxy) || parent.is_a?(MenuItemProxy) || parent.menu_requested?
|
122
|
-
super
|
123
|
-
if root_menu?
|
124
|
-
|
125
|
-
`$(#{id_css}).menu();`
|
224
|
+
if parent.is_a?(MenuProxy) || parent.is_a?(MenuItemProxy) || parent.menu_requested? || parent.is_a?(ShellProxy)
|
225
|
+
super(custom_parent_dom_element: custom_parent_dom_element, brand_new: brand_new)
|
226
|
+
if root_menu? && !bar?
|
227
|
+
`$(#{path}).menu();`
|
126
228
|
@close_event_handler = lambda do |event|
|
127
|
-
if event.target.parents('.ui-menu').empty?
|
128
|
-
close
|
129
|
-
end
|
229
|
+
close if event.target.parents('.ui-menu').empty?
|
130
230
|
end
|
131
231
|
Element['body'].on('click', &@close_event_handler)
|
132
|
-
@menu_initialized = true
|
133
232
|
end
|
134
233
|
end
|
135
234
|
end
|
@@ -143,6 +242,12 @@ module Glimmer
|
|
143
242
|
!parent.is_a?(MenuProxy) && !parent.is_a?(MenuItemProxy)
|
144
243
|
end
|
145
244
|
|
245
|
+
def root_menu
|
246
|
+
the_menu = self
|
247
|
+
the_menu = the_menu.parent_menu until the_menu.root_menu?
|
248
|
+
the_menu
|
249
|
+
end
|
250
|
+
|
146
251
|
def parent_menu
|
147
252
|
parent.parent unless root_menu?
|
148
253
|
end
|
@@ -152,11 +257,17 @@ module Glimmer
|
|
152
257
|
end
|
153
258
|
|
154
259
|
def dom
|
260
|
+
css_class = name
|
261
|
+
css_class += ' menu-bar' if bar?
|
262
|
+
css_class += ' menu-drop-down' if drop_down?
|
263
|
+
css_class += ' menu-pop-up' if pop_up?
|
155
264
|
@dom ||= html {
|
156
|
-
ul(id: id, class:
|
265
|
+
ul(id: id, class: css_class) {
|
157
266
|
}
|
158
267
|
}.to_s
|
159
268
|
end
|
160
269
|
end
|
270
|
+
|
271
|
+
MenuBarProxy = MenuProxy
|
161
272
|
end
|
162
273
|
end
|
@@ -51,16 +51,15 @@ module Glimmer
|
|
51
51
|
|
52
52
|
def initialize(parent, args, block)
|
53
53
|
i = 0
|
54
|
-
@parent = parent || DisplayProxy.instance.shells.last
|
54
|
+
@parent = parent || DisplayProxy.instance.shells.last || ShellProxy.new([])
|
55
55
|
@args = args
|
56
56
|
@block = block
|
57
57
|
@children = Set.new
|
58
58
|
@enabled = true
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
59
|
+
on_widget_selected {
|
60
|
+
hide
|
61
|
+
}
|
62
|
+
DisplayProxy.instance.message_boxes << self
|
64
63
|
end
|
65
64
|
|
66
65
|
def text=(txt)
|
@@ -28,7 +28,7 @@ module Glimmer
|
|
28
28
|
|
29
29
|
# TODO consider renaming to ShellProxy to match SWT API
|
30
30
|
attr_reader :minimum_size
|
31
|
-
attr_accessor :menu_bar
|
31
|
+
attr_accessor :menu_bar
|
32
32
|
|
33
33
|
WIDTH_MIN = 130
|
34
34
|
HEIGHT_MIN = 0
|
@@ -36,7 +36,7 @@ module Glimmer
|
|
36
36
|
def initialize(args)
|
37
37
|
@args = args
|
38
38
|
@children = []
|
39
|
-
#
|
39
|
+
# TODO consider the implication of emptying the body
|
40
40
|
Document.find('body').empty unless ENV['RUBY_ENV'] == 'test'
|
41
41
|
render
|
42
42
|
@layout = FillLayoutProxy.new(self, [])
|
@@ -106,7 +106,7 @@ module Glimmer
|
|
106
106
|
def open
|
107
107
|
# TODO consider the idea of delaying rendering till the open method
|
108
108
|
# TODO make it start as hidden and show shell upon open
|
109
|
-
|
109
|
+
# DisplayProxy.instance.shells << self
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|
@@ -191,6 +191,14 @@ module Glimmer
|
|
191
191
|
def element
|
192
192
|
'div'
|
193
193
|
end
|
194
|
+
|
195
|
+
def pack(*args)
|
196
|
+
# No Op (just a shim) TODO consider if it should be implemented
|
197
|
+
end
|
198
|
+
|
199
|
+
def layout(*args)
|
200
|
+
# No Op (just a shim) TODO consider if it should be implemented
|
201
|
+
end
|
194
202
|
|
195
203
|
def enabled=(value)
|
196
204
|
@enabled = value
|
@@ -198,11 +206,13 @@ module Glimmer
|
|
198
206
|
end
|
199
207
|
|
200
208
|
def foreground=(value)
|
209
|
+
value = ColorProxy.new(value) if value.is_a?(String)
|
201
210
|
@foreground = value
|
202
211
|
dom_element.css('color', foreground.to_css) unless foreground.nil?
|
203
212
|
end
|
204
213
|
|
205
214
|
def background=(value)
|
215
|
+
value = ColorProxy.new(value) if value.is_a?(String)
|
206
216
|
@background = value
|
207
217
|
dom_element.css('background-color', background.to_css) unless background.nil?
|
208
218
|
end
|
@@ -239,9 +249,10 @@ module Glimmer
|
|
239
249
|
brand_new = @dom.nil? || old_element.empty? || brand_new
|
240
250
|
build_dom(layout: !custom_parent_dom_element) # TODO handle custom parent layout by passing parent instead of parent dom element
|
241
251
|
if brand_new
|
242
|
-
the_parent_dom_element.append(@dom)
|
252
|
+
the_parent_dom_element.append(@dom) # TODO make a method attach to allow subclasses to override if needed
|
243
253
|
else
|
244
254
|
old_element.replace_with(@dom)
|
255
|
+
old_element.replace_with(@dom)
|
245
256
|
end
|
246
257
|
observation_requests&.each do |keyword, event_listener_set|
|
247
258
|
event_listener_set.each do |event_listener|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glimmer-dsl-opal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AndyMaleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer
|
@@ -249,6 +249,7 @@ files:
|
|
249
249
|
- lib/glimmer-dsl-opal/ext/date.rb
|
250
250
|
- lib/glimmer-dsl-opal/ext/exception.rb
|
251
251
|
- lib/glimmer-dsl-opal/ext/file.rb
|
252
|
+
- lib/glimmer-dsl-opal/ext/glimmer/dsl/engine.rb
|
252
253
|
- lib/glimmer-dsl-opal/ext/struct.rb
|
253
254
|
- lib/glimmer-dsl-opal/samples/elaborate/contact_manager.rb
|
254
255
|
- lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact.rb
|
@@ -271,6 +272,7 @@ files:
|
|
271
272
|
- lib/glimmer-dsl-opal/samples/hello/hello_group.rb
|
272
273
|
- lib/glimmer-dsl-opal/samples/hello/hello_list_multi_selection.rb
|
273
274
|
- lib/glimmer-dsl-opal/samples/hello/hello_list_single_selection.rb
|
275
|
+
- lib/glimmer-dsl-opal/samples/hello/hello_menu_bar.rb
|
274
276
|
- lib/glimmer-dsl-opal/samples/hello/hello_message_box.rb
|
275
277
|
- lib/glimmer-dsl-opal/samples/hello/hello_pop_up_context_menu.rb
|
276
278
|
- lib/glimmer-dsl-opal/samples/hello/hello_radio.rb
|
@@ -352,6 +354,7 @@ files:
|
|
352
354
|
- lib/glimmer/swt/grid_layout_proxy.rb
|
353
355
|
- lib/glimmer/swt/group_proxy.rb
|
354
356
|
- lib/glimmer/swt/label_proxy.rb
|
357
|
+
- lib/glimmer/swt/latest_message_box_proxy.rb
|
355
358
|
- lib/glimmer/swt/layout_data_proxy.rb
|
356
359
|
- lib/glimmer/swt/layout_proxy.rb
|
357
360
|
- lib/glimmer/swt/list_proxy.rb
|