glimmer-dsl-opal 0.7.5 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +35 -0
  3. data/README.md +756 -139
  4. data/VERSION +1 -1
  5. data/lib/glimmer-dsl-opal.rb +16 -4
  6. data/lib/glimmer-dsl-opal/ext/class.rb +10 -0
  7. data/lib/{file.rb → glimmer-dsl-opal/ext/file.rb} +0 -0
  8. data/lib/glimmer-dsl-opal/ext/glimmer/dsl/engine.rb +46 -0
  9. data/lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb +1 -1
  10. data/lib/glimmer-dsl-opal/samples/hello/hello_browser.rb +23 -0
  11. data/lib/glimmer-dsl-opal/samples/hello/hello_computed.rb +27 -0
  12. data/lib/glimmer-dsl-opal/samples/hello/hello_computed/contact.rb +21 -0
  13. data/lib/glimmer-dsl-opal/samples/hello/hello_list_multi_selection.rb +62 -32
  14. data/lib/glimmer-dsl-opal/samples/hello/hello_list_single_selection.rb +47 -22
  15. data/lib/glimmer-dsl-opal/samples/hello/hello_menu_bar.rb +241 -0
  16. data/lib/glimmer-dsl-opal/samples/hello/hello_message_box.rb +37 -0
  17. data/lib/glimmer-dsl-opal/samples/hello/hello_pop_up_context_menu.rb +84 -0
  18. data/lib/glimmer-dsl-opal/samples/hello/hello_world.rb +3 -3
  19. data/lib/glimmer/config/opal_logger.rb +16 -0
  20. data/lib/glimmer/data_binding/observable_element.rb +1 -1
  21. data/lib/glimmer/dsl/opal/custom_widget_expression.rb +1 -1
  22. data/lib/glimmer/dsl/opal/dsl.rb +2 -0
  23. data/lib/glimmer/dsl/opal/menu_bar_expression.rb +54 -0
  24. data/lib/glimmer/dsl/opal/menu_expression.rb +61 -0
  25. data/lib/glimmer/dsl/opal/shell_expression.rb +0 -4
  26. data/lib/glimmer/dsl/opal/widget_expression.rb +3 -2
  27. data/lib/glimmer/dsl/opal/widget_listener_expression.rb +2 -2
  28. data/lib/glimmer/swt/custom/checkbox_group.rb +2 -2
  29. data/lib/glimmer/swt/custom/radio_group.rb +2 -2
  30. data/lib/glimmer/swt/display_proxy.rb +4 -4
  31. data/lib/glimmer/swt/event_listener_proxy.rb +14 -4
  32. data/lib/glimmer/swt/grid_layout_proxy.rb +1 -0
  33. data/lib/glimmer/swt/label_proxy.rb +27 -3
  34. data/lib/{glimmer-dsl-opal/ext/struct.rb → glimmer/swt/latest_message_box_proxy.rb} +16 -11
  35. data/lib/glimmer/swt/latest_shell_proxy.rb +55 -0
  36. data/lib/glimmer/swt/list_proxy.rb +15 -0
  37. data/lib/glimmer/swt/menu_item_proxy.rb +174 -0
  38. data/lib/glimmer/swt/menu_proxy.rb +273 -0
  39. data/lib/glimmer/swt/message_box_proxy.rb +79 -63
  40. data/lib/glimmer/swt/property_owner.rb +2 -0
  41. data/lib/glimmer/swt/radio_proxy.rb +1 -1
  42. data/lib/glimmer/swt/shell_proxy.rb +34 -189
  43. data/lib/glimmer/swt/tab_folder_proxy.rb +43 -0
  44. data/lib/glimmer/swt/table_column_proxy.rb +3 -2
  45. data/lib/glimmer/swt/table_editor.rb +1 -1
  46. data/lib/glimmer/swt/table_item_proxy.rb +7 -5
  47. data/lib/glimmer/swt/table_proxy.rb +10 -0
  48. data/lib/glimmer/swt/widget_proxy.rb +325 -31
  49. data/lib/glimmer/ui/custom_shell.rb +2 -2
  50. data/lib/glimmer/ui/custom_widget.rb +3 -3
  51. data/lib/net/http.rb +30 -2
  52. metadata +45 -8
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.5
1
+ 0.9.3
@@ -33,12 +33,18 @@ if RUBY_ENGINE == 'opal'
33
33
  # TODO look into making append_path work (causing some trouble right now)
34
34
  # Opal.append_path File.expand_path('../glimmer-dsl-opal/missing', __FILE__)
35
35
  # Opal.append_path GLIMMER_DSL_OPAL_MISSING
36
+ module Kernel
37
+ def include_package(package)
38
+ # No Op (just a shim)
39
+ end
40
+ end
36
41
 
37
42
  require 'opal-parser'
38
43
  require 'native' # move this to opal-async
39
44
  require 'opal-async'
40
45
  require 'async/ext'
41
46
  require 'to_collection'
47
+ require 'pure-struct'
42
48
  require 'os'
43
49
  require 'file'
44
50
  require 'display'
@@ -49,14 +55,17 @@ if RUBY_ENGINE == 'opal'
49
55
  # require 'glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.structure.min.css'
50
56
  # require 'glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.theme.min.css'
51
57
  require 'opal-jquery'
58
+ require 'opal/jquery/local_storage'
52
59
 
53
60
  require 'facets/hash/symbolize_keys'
54
- require 'glimmer-dsl-opal/ext/struct'
61
+ require 'glimmer-dsl-opal/ext/class'
62
+ require 'glimmer-dsl-opal/ext/file'
55
63
  require 'glimmer'
56
64
  require 'glimmer-dsl-opal/ext/exception'
57
65
  require 'glimmer-dsl-opal/ext/date'
66
+ require 'glimmer-dsl-opal/ext/glimmer/dsl/engine'
58
67
  require 'uri'
59
-
68
+
60
69
  # Spiking async logging
61
70
  # logger = Glimmer::Config.logger
62
71
  # original_add_method = logger.class.instance_method(:add)
@@ -68,14 +77,17 @@ if RUBY_ENGINE == 'opal'
68
77
  # end
69
78
 
70
79
  require 'glimmer/dsl/opal/dsl'
71
-
80
+ require 'glimmer/config/opal_logger'
72
81
  require 'glimmer-dsl-xml'
73
82
  require 'glimmer-dsl-css'
74
83
  Element.alias_native :replace_with, :replaceWith
75
84
  Element.alias_native :select
76
85
 
77
- # Glimmer::Config.loop_max_count = 20
86
+ # Glimmer::Config.loop_max_count = 20 # TODO disable
78
87
 
88
+ original_logger_level = Glimmer::Config.logger.level
89
+ Glimmer::Config.logger = Glimmer::Config::OpalLogger.new(STDOUT)
90
+ Glimmer::Config.logger.level = original_logger_level
79
91
  Glimmer::Config.excluded_keyword_checkers << lambda do |method_symbol, *args|
80
92
  method = method_symbol.to_s
81
93
  result = false
@@ -0,0 +1,10 @@
1
+ class Class
2
+ def inherited(klass)
3
+ @descendants ||= []
4
+ @descendants << klass
5
+ end
6
+
7
+ def descendants
8
+ @descendants.to_collection.map { |klass| [klass] + (klass.descendants if klass.respond_to?(:descendants)).to_a }.flatten.compact
9
+ end
10
+ end
@@ -0,0 +1,46 @@
1
+ # Copyright (c) 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
+ require 'glimmer/swt/latest_shell_proxy'
23
+ require 'glimmer/swt/latest_message_box_proxy'
24
+
25
+ module Glimmer
26
+ module DSL
27
+ class Engine
28
+ class << self
29
+ def interpret_expression(expression, keyword, *args, &block)
30
+ work = lambda do
31
+ expression.interpret(parent, keyword, *args, &block).tap do |ui_object|
32
+ add_content(ui_object, expression, &block)
33
+ dsl_stack.pop
34
+ end
35
+ end
36
+ if ['shell', 'message_box'].include?(keyword) && Glimmer::SWT::DisplayProxy.instance.shells.empty?
37
+ Document.ready?(&work)
38
+ Glimmer::SWT.const_get("Latest#{keyword.camelcase(:upper)}Proxy").new
39
+ else
40
+ work.call
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -61,7 +61,7 @@ class TicTacToe
61
61
  end
62
62
 
63
63
  def display_game_over_message(message_text)
64
- message_box(@shell) {
64
+ message_box {
65
65
  text 'Game Over'
66
66
  message message_text
67
67
  }.open
@@ -1,7 +1,30 @@
1
+ # Copyright (c) 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
+
1
22
  include Glimmer
2
23
 
3
24
  shell {
25
+ text 'Hello, Browser!'
4
26
  minimum_size 1024, 860
27
+
5
28
  browser {
6
29
  url 'https://brightonresort.com/about'
7
30
  }
@@ -1,3 +1,24 @@
1
+ # Copyright (c) 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
+
1
22
  require_relative 'hello_computed/contact'
2
23
 
3
24
  class HelloComputed
@@ -14,6 +35,7 @@ class HelloComputed
14
35
  def launch
15
36
  shell {
16
37
  text 'Hello, Computed!'
38
+
17
39
  composite {
18
40
  grid_layout {
19
41
  num_columns 2
@@ -21,6 +43,7 @@ class HelloComputed
21
43
  horizontal_spacing 20
22
44
  vertical_spacing 10
23
45
  }
46
+
24
47
  label {text 'First &Name: '}
25
48
  text {
26
49
  text bind(@contact, :first_name)
@@ -29,6 +52,7 @@ class HelloComputed
29
52
  grab_excess_horizontal_space true
30
53
  }
31
54
  }
55
+
32
56
  label {text '&Last Name: '}
33
57
  text {
34
58
  text bind(@contact, :last_name)
@@ -37,6 +61,7 @@ class HelloComputed
37
61
  grab_excess_horizontal_space true
38
62
  }
39
63
  }
64
+
40
65
  label {text '&Year of Birth: '}
41
66
  text {
42
67
  text bind(@contact, :year_of_birth)
@@ -45,6 +70,7 @@ class HelloComputed
45
70
  grab_excess_horizontal_space true
46
71
  }
47
72
  }
73
+
48
74
  label {text 'Name: '}
49
75
  label {
50
76
  text bind(@contact, :name, computed_by: [:first_name, :last_name])
@@ -53,6 +79,7 @@ class HelloComputed
53
79
  grab_excess_horizontal_space true
54
80
  }
55
81
  }
82
+
56
83
  label {text 'Age: '}
57
84
  label {
58
85
  text bind(@contact, :age, on_write: :to_i, computed_by: [:year_of_birth])
@@ -1,3 +1,24 @@
1
+ # Copyright (c) 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
+
1
22
  class HelloComputed
2
23
  class Contact
3
24
  attr_accessor :first_name, :last_name, :year_of_birth
@@ -1,41 +1,71 @@
1
- class Person
2
- attr_accessor :provinces, :provinces_options
3
-
4
- def initialize
5
- self.provinces_options=[
6
- "",
7
- "Quebec",
8
- "Ontario",
9
- "Manitoba",
10
- "Saskatchewan",
11
- "Alberta",
12
- "British Columbia",
13
- "Nova Skotia",
14
- "Newfoundland"
15
- ]
16
- self.provinces = ["Quebec", "Manitoba", "Alberta"]
17
- end
18
-
19
- def reset_provinces
20
- self.provinces = ["Quebec", "Manitoba", "Alberta"]
21
- end
22
- end
1
+ # Copyright (c) 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.
23
21
 
24
22
  class HelloListMultiSelection
23
+ class Person
24
+ attr_accessor :provinces, :provinces_options
25
+
26
+ def initialize
27
+ self.provinces_options = [
28
+ '',
29
+ 'Alberta',
30
+ 'British Columbia',
31
+ 'Manitoba',
32
+ 'New Brunswick',
33
+ 'Newfoundland and Labrador',
34
+ 'Northwest Territories',
35
+ 'Nova Scotia',
36
+ 'Nunavut',
37
+ 'Ontario',
38
+ 'Prince Edward Island',
39
+ 'Quebec',
40
+ 'Saskatchewan',
41
+ 'Yukon'
42
+ ]
43
+ reset_provinces
44
+ end
45
+
46
+ def reset_provinces
47
+ self.provinces = ['Quebec', 'Manitoba', 'Alberta']
48
+ end
49
+ end
50
+
25
51
  include Glimmer
52
+
26
53
  def launch
27
54
  person = Person.new
55
+
28
56
  shell {
29
- composite {
30
- list(:multi) {
31
- selection bind(person, :provinces)
32
- }
33
- button {
34
- text "Reset"
35
- on_widget_selected do
36
- person.reset_provinces
37
- end
38
- }
57
+ grid_layout
58
+
59
+ text 'Hello, List Multi Selection!'
60
+
61
+ list(:multi) {
62
+ selection bind(person, :provinces)
63
+ }
64
+
65
+ button {
66
+ text 'Reset Selections To Default Values'
67
+
68
+ on_widget_selected { person.reset_provinces }
39
69
  }
40
70
  }.open
41
71
  end
@@ -1,31 +1,56 @@
1
- class Person
2
- attr_accessor :country, :country_options
3
-
4
- def initialize
5
- self.country_options=["", "Canada", "US", "Mexico"]
6
- self.country = "Canada"
7
- end
8
-
9
- def reset_country
10
- self.country = "Canada"
11
- end
12
- end
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.
13
21
 
14
22
  class HelloListSingleSelection
23
+ class Person
24
+ attr_accessor :country, :country_options
25
+
26
+ def initialize
27
+ self.country_options = ['', 'Canada', 'US', 'Mexico']
28
+ reset_country
29
+ end
30
+
31
+ def reset_country
32
+ self.country = 'Canada'
33
+ end
34
+ end
35
+
15
36
  include Glimmer
37
+
16
38
  def launch
17
39
  person = Person.new
40
+
18
41
  shell {
19
- composite {
20
- list {
21
- selection bind(person, :country)
22
- }
23
- button {
24
- text "Reset"
25
- on_widget_selected do
26
- person.reset_country
27
- end
28
- }
42
+ grid_layout
43
+
44
+ text 'Hello, List Single Selection!'
45
+
46
+ list {
47
+ selection bind(person, :country)
48
+ }
49
+
50
+ button {
51
+ text 'Reset Selection To Default Value'
52
+
53
+ on_widget_selected { person.reset_country }
29
54
  }
30
55
  }.open
31
56
  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