glimmer 0.7.4 → 0.8.0

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.4
1
+ 0.8.0
@@ -26,6 +26,7 @@ module Glimmer
26
26
 
27
27
  def call(model_collection=nil)
28
28
  if model_collection and model_collection.is_a?(Array)
29
+ # TODO clean observer registrations
29
30
  observe(model_collection, @column_properties)
30
31
  @model_collection = model_collection
31
32
  end
@@ -17,7 +17,12 @@ module Glimmer
17
17
  @tree = parent
18
18
  @model_binding = model_binding
19
19
  @tree_properties = [tree_properties].flatten.first.to_h
20
- call(@model_binding.evaluate_property)
20
+ if @tree.respond_to?(:tree_properties=)
21
+ @tree.tree_properties = @tree_properties
22
+ else # assume custom widget
23
+ @tree.body_root.tree_properties = @tree_properties
24
+ end
25
+ call
21
26
  model = model_binding.base_model
22
27
  observe(model, model_binding.property_name_expression)
23
28
  @tree.on_widget_disposed do |dispose_event|
@@ -25,27 +30,40 @@ module Glimmer
25
30
  end
26
31
  end
27
32
 
28
- def call(model_tree_root_node=nil)
29
- if model_tree_root_node and model_tree_root_node.respond_to?(@tree_properties[:children])
30
- observe(model_tree_root_node, @tree_properties[:text])
31
- observe(model_tree_root_node, @tree_properties[:children])
32
- @model_tree_root_node = model_tree_root_node
33
- end
33
+ def call(new_value=nil)
34
+ @model_tree_root_node = @model_binding.evaluate_property
34
35
  populate_tree(@model_tree_root_node, @tree, @tree_properties)
35
36
  end
36
37
 
37
38
  def populate_tree(model_tree_root_node, parent, tree_properties)
39
+ # TODO make it change things by delta instead of removing all
40
+ selected_tree_item_model = parent.swt_widget.getSelection.map(&:getData).first
41
+ old_tree_items = parent.all_tree_items
42
+ old_tree_item_expansion_by_data = old_tree_items.reduce({}) {|hash, ti| hash.merge(ti.getData => ti.getExpanded)}
43
+ old_tree_items.each do |tree_item|
44
+ tree_item.getData('observer_registrations').each do |key, observer_registration|
45
+ observer_registration.unregister
46
+ end
47
+ end
38
48
  parent.swt_widget.removeAll
39
49
  populate_tree_node(model_tree_root_node, parent.swt_widget, tree_properties)
50
+ parent.all_tree_items.each { |ti| ti.setExpanded(!!old_tree_item_expansion_by_data[ti.getData]) }
51
+ tree_item_to_select = parent.depth_first_search {|ti| ti.getData == selected_tree_item_model}
52
+ parent.swt_widget.setSelection(tree_item_to_select)
40
53
  end
41
54
 
42
55
  def populate_tree_node(model_tree_node, parent, tree_properties)
43
- table_item = TreeItem.new(parent, SWT::SWTProxy[:none])
44
- table_item.setData(model_tree_node)
45
- table_item.setText((model_tree_node && model_tree_node.send(tree_properties[:text])).to_s)
56
+ return if model_tree_node.nil?
57
+ # TODO anticipate default tree properties if none were passed (like literal values text and children)
58
+ tree_item = TreeItem.new(parent, SWT::SWTProxy[:none])
59
+ observer_registrations = @tree_properties.reduce({}) do |hash, key_value_pair|
60
+ hash.merge(key_value_pair.first => observe(model_tree_node, key_value_pair.last))
61
+ end
62
+ tree_item.setData('observer_registrations', observer_registrations)
63
+ tree_item.setData(model_tree_node)
64
+ tree_item.setText((model_tree_node && model_tree_node.send(tree_properties[:text])).to_s)
46
65
  [model_tree_node && model_tree_node.send(tree_properties[:children])].flatten.to_a.compact.each do |child|
47
- observe(child, @tree_properties[:text])
48
- populate_tree_node(child, table_item, tree_properties)
66
+ populate_tree_node(child, tree_item, tree_properties)
49
67
  end
50
68
  end
51
69
  end
@@ -0,0 +1,26 @@
1
+ require 'glimmer/dsl/static_expression'
2
+ require 'glimmer/dsl/parent_expression'
3
+ require 'glimmer/dsl/top_level_expression'
4
+ require 'glimmer/swt/shell_proxy'
5
+
6
+ module Glimmer
7
+ module DSL
8
+ module SWT
9
+ class DialogExpression < StaticExpression
10
+ include TopLevelExpression
11
+ include ParentExpression
12
+
13
+ def can_interpret?(parent, keyword, *args, &block)
14
+ keyword == 'dialog' and
15
+ (parent.nil? or parent.is_a?(Glimmer::SWT::ShellProxy))
16
+ end
17
+
18
+ def interpret(parent, keyword, *args, &block)
19
+ args = [parent] + args unless parent.nil?
20
+ args += [:dialog_trim, :application_modal]
21
+ Glimmer::SWT::ShellProxy.send(:new, *args)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -8,7 +8,7 @@ module Glimmer
8
8
  OPERATING_SYSTEMS_SUPPORTED = ["mac", "windows", "linux"]
9
9
 
10
10
  TEXT_USAGE_PREFIX = <<~MULTI_LINE_STRING
11
- Usage: glimmer [--debug] [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-jruby-option]...] (application.rb or task[task_args]) [[application2.rb]...]
11
+ Usage: glimmer [--quiet] [--debug] [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-jruby-option]...] (application.rb or task[task_args]) [[application2.rb]...]
12
12
 
13
13
  Runs Glimmer applications/tasks.
14
14
 
@@ -27,8 +27,9 @@ module Glimmer
27
27
  Optionally, extra Glimmer options, JRuby options and environment variables may be passed in.
28
28
 
29
29
  Glimmer options:
30
- - "--debug" : Displays extra debugging information and passes "--debug" to JRuby
31
- - "--log-level=VALUE" : Sets Glimmer's Ruby logger level ("ERROR" / "WARN" / "INFO" / "DEBUG"; default is "WARN")
30
+ - "--quiet" : Does not announce file path of Glimmer application being launched
31
+ - "--debug" : Displays extra debugging information, passes "--debug" to JRuby, and enables debug logging
32
+ - "--log-level=VALUE" : Sets Glimmer's Ruby logger level ("ERROR" / "WARN" / "INFO" / "DEBUG"; default is none)
32
33
 
33
34
  Example: glimmer samples/hello_world.rb
34
35
 
@@ -37,7 +38,7 @@ module Glimmer
37
38
 
38
39
  GLIMMER_LIB_LOCAL = File.expand_path(File.join(__FILE__, '..', '..', 'glimmer.rb'))
39
40
  GLIMMER_LIB_GEM = 'glimmer'
40
- GLIMMER_OPTIONS = %w[--log-level]
41
+ GLIMMER_OPTIONS = %w[--log-level --quiet]
41
42
  GLIMMER_OPTION_ENV_VAR_MAPPING = {
42
43
  '--log-level' => 'GLIMMER_LOGGER_LEVEL'
43
44
  }
@@ -77,8 +78,8 @@ module Glimmer
77
78
  end
78
79
 
79
80
  def glimmer_option_env_vars(glimmer_options)
80
- glimmer_options.reduce({}) do |hash, pair|
81
- hash.merge(GLIMMER_OPTION_ENV_VAR_MAPPING[pair.first] => pair.last)
81
+ GLIMMER_OPTION_ENV_VAR_MAPPING.reduce({}) do |hash, pair|
82
+ glimmer_options[pair.first] ? hash.merge(GLIMMER_OPTION_ENV_VAR_MAPPING[pair.first] => glimmer_options[pair.first]) : hash
82
83
  end
83
84
  end
84
85
 
@@ -108,7 +109,7 @@ module Glimmer
108
109
  Rake::Task[rake_task].invoke(*rake_task_args)
109
110
  else
110
111
  @@mutex.synchronize do
111
- puts "Launching Glimmer Application: #{application}" unless application.to_s.match(/(irb)|(gladiator)/)
112
+ puts "Launching Glimmer Application: #{application}" if jruby_options_string.to_s.include?('--debug') || glimmer_options['--quiet'].to_s.downcase != 'true'
112
113
  end
113
114
  command = "#{env_vars_string} jruby #{jruby_options_string}#{jruby_os_specific_options} #{devmode_require}-r #{the_glimmer_lib} -S #{application}"
114
115
  puts command if jruby_options_string.to_s.include?('--debug')
@@ -116,8 +117,15 @@ module Glimmer
116
117
  end
117
118
  end
118
119
  end
120
+
121
+ attr_reader :application_paths
122
+ attr_reader :env_vars
123
+ attr_reader :glimmer_options
124
+ attr_reader :jruby_options
119
125
 
120
126
  def initialize(raw_options)
127
+ raw_options << '--quiet' if !caller.join("\n").include?('/bin/glimmer:') && !raw_options.join.include?('--quiet=')
128
+ raw_options << '--log-level=DEBUG' if raw_options.join.include?('--debug') && !raw_options.join.include?('--log-level=')
121
129
  @application_paths = extract_application_paths(raw_options)
122
130
  @env_vars = extract_env_vars(raw_options)
123
131
  @glimmer_options = extract_glimmer_options(raw_options)
@@ -135,7 +143,7 @@ module Glimmer
135
143
  private
136
144
 
137
145
  def launch_application
138
- load File.expand_path('./Rakefile') if File.exist?(File.expand_path('./Rakefile'))
146
+ load File.expand_path('./Rakefile') if File.exist?(File.expand_path('./Rakefile')) && caller.join("\n").include?('/bin/glimmer:')
139
147
  threads = @application_paths.map do |application_path|
140
148
  Thread.new do
141
149
  self.class.launch(
@@ -183,8 +191,8 @@ module Glimmer
183
191
  end.each do |glimmer_option|
184
192
  options.delete(glimmer_option)
185
193
  end.reduce({}) do |hash, glimmer_option_string|
186
- match = glimmer_option_string.match(/^([^=]+)=?(.*)$/)
187
- hash.merge(match[1] => match[2])
194
+ match = glimmer_option_string.match(/^([^=]+)=?(.+)?$/)
195
+ hash.merge(match[1] => (match[2] || 'true'))
188
196
  end
189
197
  end
190
198
  end
@@ -76,9 +76,9 @@ namespace :glimmer do
76
76
  Scaffold.custom_widget(args[:custom_widget_name], args[:namespace])
77
77
  end
78
78
 
79
- desc 'Scaffold a Glimmer::UI::CustomShell subclass (represents a full window view) under its own Ruby gem project (namespace is required)'
80
- task :custom_shell_gem, [:custom_widget_name, :namespace] do |t, args|
81
- Scaffold.custom_shell_gem(args[:custom_widget_name], args[:namespace])
79
+ desc 'Scaffold a Glimmer::UI::CustomShell subclass (represents a full window view) under its own Ruby gem + app project (namespace is required)'
80
+ task :custom_shell_gem, [:custom_shell_name, :namespace] do |t, args|
81
+ Scaffold.custom_shell_gem(args[:custom_shell_name], args[:namespace])
82
82
  end
83
83
 
84
84
  desc 'Scaffold a Glimmer::UI::CustomWidget subclass (represents a part of a view) under its own Ruby gem project (namespace is required)'
@@ -77,7 +77,7 @@ class Scaffold
77
77
  GEMFILE_APP = <<~MULTI_LINE_STRING
78
78
  # frozen_string_literal: true
79
79
 
80
- source "https://rubygems.org"
80
+ source 'https://rubygems.org'
81
81
 
82
82
  git_source(:github) {|repo_name| "https://github.com/\#{repo_name}" }
83
83
 
@@ -91,23 +91,23 @@ class Scaffold
91
91
  GEMFILE_GEM = <<~MULTI_LINE_STRING
92
92
  # frozen_string_literal: true
93
93
 
94
- source "https://rubygems.org"
94
+ source 'https://rubygems.org'
95
95
 
96
96
  git_source(:github) {|repo_name| "https://github.com/\#{repo_name}" }
97
97
 
98
98
  gem 'glimmer', '~> #{VERSION}'
99
99
 
100
100
  group :development do
101
- gem "rspec", "~> 3.5.0"
102
- gem "jeweler", "2.3.9"
103
- gem "simplecov", ">= 0"
101
+ gem 'rspec', '~> 3.5.0'
102
+ gem 'jeweler', '2.3.9'
103
+ gem 'simplecov', '>= 0'
104
104
  end
105
105
  MULTI_LINE_STRING
106
106
 
107
107
  RAKEFILE = <<~MULTI_LINE_STRING
108
108
  require 'glimmer/rake_task'
109
109
 
110
- ## Uncomment the following section if you would like to customize javapackager
110
+ ## Use the following configuration if you would like to customize javapackager
111
111
  ## arguments for `glimmer package` command.
112
112
  #
113
113
  # Glimmer::Package.javapackager_extra_args =
@@ -146,7 +146,7 @@ class Scaffold
146
146
  write "app/#{file_name(app_name)}.rb", app_main_file(app_name)
147
147
  mkdir 'app/models'
148
148
  mkdir 'app/views'
149
- custom_shell('AppView', current_dir_name)
149
+ custom_shell('AppView', current_dir_name, :app)
150
150
  if OS.mac?
151
151
  mkdir_p 'package/macosx'
152
152
  icon_file = "package/macosx/#{human_name(app_name)}.icns"
@@ -155,18 +155,18 @@ class Scaffold
155
155
  end
156
156
  mkdir 'bin'
157
157
  write "bin/#{file_name(app_name)}", app_bin_file(app_name)
158
- FileUtils.chmod 0755, "bin/#{app_name.underscore}"
158
+ FileUtils.chmod 0755, "bin/#{file_name(app_name)}"
159
159
  system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n glimmer package\n'"
160
160
  system "open packages/bundles/#{human_name(app_name).gsub(' ', '\ ')}.app"
161
161
  # TODO generate rspec test suite
162
162
  end
163
163
 
164
- def custom_shell(custom_shell_name, namespace)
164
+ def custom_shell(custom_shell_name, namespace, shell_type = nil)
165
165
  namespace ||= current_dir_name
166
166
  root_dir = File.exists?('app') ? 'app' : 'lib'
167
167
  parent_dir = "#{root_dir}/views/#{file_name(namespace)}"
168
168
  mkdir_p parent_dir unless File.exists?(parent_dir)
169
- write "#{parent_dir}/#{file_name(custom_shell_name)}.rb", custom_shell_file(custom_shell_name, namespace)
169
+ write "#{parent_dir}/#{file_name(custom_shell_name)}.rb", custom_shell_file(custom_shell_name, namespace, shell_type)
170
170
  end
171
171
 
172
172
  def custom_widget(custom_widget_name, namespace)
@@ -179,7 +179,7 @@ class Scaffold
179
179
 
180
180
  def custom_shell_gem(custom_shell_name, namespace)
181
181
  gem_name = "glimmer-cs-#{compact_name(custom_shell_name)}"
182
- gem_summary = "Glimmer Custom Widget - #{human_name(custom_shell_name)}"
182
+ gem_summary = "#{human_name(custom_shell_name)} - Glimmer Custom Shell"
183
183
  if namespace
184
184
  gem_name += "-#{compact_name(namespace)}"
185
185
  gem_summary += " (#{human_name(namespace)})"
@@ -193,11 +193,22 @@ class Scaffold
193
193
  write '.ruby-gemset', gem_name
194
194
  write 'VERSION', '1.0.0'
195
195
  write 'Gemfile', GEMFILE_GEM
196
- write 'Rakefile', gem_rakefile
196
+ write 'Rakefile', gem_rakefile(custom_shell_name, namespace)
197
197
  append "lib/#{gem_name}.rb", gem_main_file(custom_shell_name, namespace)
198
198
  mkdir 'lib/views'
199
- custom_shell(custom_shell_name, namespace)
200
- system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n'"
199
+ custom_shell(custom_shell_name, namespace, :gem)
200
+ mkdir 'bin'
201
+ write "bin/#{gem_name}", gem_bin_file(gem_name, custom_shell_name, namespace)
202
+ write "bin/#{file_name(custom_shell_name)}", gem_bin_command_file(gem_name)
203
+ FileUtils.chmod 0755, "bin/#{file_name(custom_shell_name)}"
204
+ if OS.mac?
205
+ mkdir_p 'package/macosx'
206
+ icon_file = "package/macosx/#{human_name(custom_shell_name)}.icns"
207
+ cp File.expand_path('../../../icons/scaffold_app.icns', __FILE__), icon_file
208
+ puts "Created #{current_dir_name}/#{icon_file}"
209
+ end
210
+ system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n glimmer package\n'"
211
+ system "open packages/bundles/#{human_name(custom_shell_name).gsub(' ', '\ ')}.app"
201
212
  puts "Finished creating #{gem_name} Ruby gem."
202
213
  puts 'Edit Rakefile to configure gem details.'
203
214
  puts 'Run `rake` to execute specs.'
@@ -207,7 +218,7 @@ class Scaffold
207
218
 
208
219
  def custom_widget_gem(custom_widget_name, namespace)
209
220
  gem_name = "glimmer-cw-#{compact_name(custom_widget_name)}"
210
- gem_summary = "Glimmer Custom Widget - #{human_name(custom_widget_name)}"
221
+ gem_summary = "#{human_name(custom_widget_name)} - Glimmer Custom Widget"
211
222
  if namespace
212
223
  gem_name += "-#{compact_name(namespace)}"
213
224
  gem_summary += " (#{human_name(namespace)})"
@@ -253,19 +264,20 @@ class Scaffold
253
264
  end
254
265
 
255
266
  def class_name(app_name)
256
- app_name.camelcase(:upper)
267
+ app_name.underscore.camelcase(:upper)
257
268
  end
258
269
 
259
270
  def file_name(app_name)
260
271
  app_name.underscore
261
272
  end
273
+ alias dsl_widget_name file_name
262
274
 
263
275
  def human_name(app_name)
264
276
  app_name.underscore.titlecase
265
277
  end
266
278
 
267
279
  def compact_name(gem_name)
268
- gem_name.camelcase.downcase
280
+ gem_name.underscore.camelcase.downcase
269
281
  end
270
282
 
271
283
  def app_main_file(app_name)
@@ -280,14 +292,13 @@ class Scaffold
280
292
  include Glimmer
281
293
 
282
294
  APP_ROOT = File.expand_path('../..', __FILE__)
283
- VERSION = File.read(File.expand_path('VERSION', APP_ROOT))
295
+ VERSION = File.read(File.join(APP_ROOT, 'VERSION'))
296
+ LICENSE = File.read(File.join(APP_ROOT, 'LICENSE.txt'))
284
297
 
285
298
  def open
286
299
  app_view.open
287
300
  end
288
301
  end
289
-
290
- #{class_name(app_name)}.new.open
291
302
  MULTI_LINE_STRING
292
303
  end
293
304
 
@@ -307,22 +318,66 @@ class Scaffold
307
318
  def app_bin_file(app_name)
308
319
  <<~MULTI_LINE_STRING
309
320
  #!/usr/bin/env ruby
310
-
321
+
311
322
  require_relative '../app/#{file_name(app_name)}'
323
+
324
+ #{class_name(app_name)}.new.open
312
325
  MULTI_LINE_STRING
313
326
  end
314
327
 
315
- def gem_rakefile
328
+ def gem_bin_file(gem_name, custom_shell_name, namespace)
329
+ <<~MULTI_LINE_STRING
330
+ #!/usr/bin/env ruby
331
+
332
+ require_relative '../lib/#{gem_name}'
333
+
334
+ include Glimmer
335
+
336
+ #{dsl_widget_name(custom_shell_name)}.open
337
+ MULTI_LINE_STRING
338
+ end
339
+
340
+ def gem_bin_command_file(gem_name)
341
+ <<~MULTI_LINE_STRING
342
+ #!/usr/bin/env ruby
343
+
344
+ require 'glimmer/launcher'
345
+
346
+ runner = File.expand_path("../#{gem_name}", __FILE__)
347
+ launcher = Glimmer::Launcher.new([runner] + ARGV)
348
+ launcher.launch
349
+ MULTI_LINE_STRING
350
+ end
351
+
352
+ def gem_rakefile(custom_shell_name = nil, namespace = nil)
316
353
  rakefile_content = File.read('Rakefile')
317
354
  lines = rakefile_content.split("\n")
318
355
  require_rake_line_index = lines.index(lines.detect {|l| l.include?("require 'rake'") })
319
356
  lines.insert(require_rake_line_index, "require 'glimmer/launcher'")
320
357
  gem_files_line_index = lines.index(lines.detect {|l| l.include?('# dependencies defined in Gemfile') })
321
- lines.insert(gem_files_line_index, " gem.files = Dir['lib/**/*.rb']")
358
+ if custom_shell_name
359
+ lines.insert(gem_files_line_index, " gem.files = Dir['VERSION', 'LICENSE.txt', 'lib/**/*.rb', 'bin/**/*']")
360
+ lines.insert(gem_files_line_index+1, " gem.executables = ['#{file_name(custom_shell_name)}']")
361
+ else
362
+ lines.insert(gem_files_line_index, " gem.files = Dir['lib/**/*.rb']")
363
+ end
322
364
  spec_pattern_line_index = lines.index(lines.detect {|l| l.include?('spec.pattern =') })
323
365
  lines.insert(spec_pattern_line_index+1, " spec.ruby_opts = [Glimmer::Launcher.jruby_swt_options]")
324
- lines << "\nrequire 'glimmer/rake_task'\n"
325
- lines.join("\n")
366
+ lines << "\nrequire 'glimmer/rake_task'\n"
367
+ file_content = lines.join("\n")
368
+ if custom_shell_name
369
+ file_content << <<~MULTI_LINE_STRING
370
+ Glimmer::Package.javapackager_extra_args =
371
+ " -name '#{human_name(custom_shell_name)}'" +
372
+ " -title '#{human_name(custom_shell_name)}'" +
373
+ " -Bmac.CFBundleName='#{human_name(custom_shell_name)}'" +
374
+ " -Bmac.CFBundleIdentifier='org.#{namespace ? compact_name(namespace) : compact_name(custom_shell_name)}.application.#{compact_name(custom_shell_name)}'"
375
+ # " -BlicenseType=" +
376
+ # " -Bmac.category=" +
377
+ # " -Bmac.signing-key-developer-id-app="
378
+ MULTI_LINE_STRING
379
+ end
380
+ file_content
326
381
  end
327
382
 
328
383
  def spec_helper_file
@@ -346,52 +401,137 @@ class Scaffold
346
401
  lines.join("\n")
347
402
  end
348
403
 
349
- def custom_shell_file(custom_shell_name, namespace)
404
+ def custom_shell_file(custom_shell_name, namespace, shell_type)
350
405
  namespace_type = class_name(namespace) == class_name(current_dir_name) ? 'class' : 'module'
351
406
 
352
- <<~MULTI_LINE_STRING
353
- #{namespace_type} #{class_name(namespace)}
354
- class #{class_name(custom_shell_name)}
355
- include Glimmer::UI::CustomShell
356
-
357
- ## Add options like the following to configure CustomShell by outside consumers
358
- #
359
- # options :title, :background_color
360
- # option :width, 320
361
- # option :height, 240
362
-
363
- ## Uncomment before_body block to pre-initialize variables to use in body
364
- #
365
- #
366
- # before_body {
367
- #
368
- # }
369
-
370
- ## Uncomment after_body block to setup observers for widgets in body
371
- #
372
- # after_body {
373
- #
374
- # }
407
+ custom_shell_file_content = <<-MULTI_LINE_STRING
408
+ #{namespace_type} #{class_name(namespace)}
409
+ class #{class_name(custom_shell_name)}
410
+ include Glimmer::UI::CustomShell
411
+
412
+ MULTI_LINE_STRING
413
+
414
+ if shell_type == :gem
415
+ custom_shell_file_content += <<-MULTI_LINE_STRING
416
+ GEM_ROOT = File.expand_path('../../../..', __FILE__)
417
+ VERSION = File.read(File.join(GEM_ROOT, 'VERSION'))
418
+ LICENSE = File.read(File.join(GEM_ROOT, 'LICENSE.txt'))
375
419
 
376
- ## Add widget content inside custom shell body
377
- ## Top-most widget must be a shell or another custom shell
378
- #
379
- body {
380
- shell {
381
- # Replace example content below with custom shell content
382
- minimum_size 320, 240
383
- text "#{human_name(namespace)} - #{human_name(custom_shell_name)}"
384
- grid_layout
385
- label {
386
- text "Hello, World!"
387
- font height: 40
388
- layout_data :center, :center, true, true
389
- }
420
+ MULTI_LINE_STRING
421
+ end
422
+
423
+ custom_shell_file_content += <<-MULTI_LINE_STRING
424
+ ## Add options like the following to configure CustomShell by outside consumers
425
+ #
426
+ # options :title, :background_color
427
+ # option :width, default: 320
428
+ # option :height, default: 240
429
+ option :greeting, default: 'Hello, World!'
430
+
431
+ ## Use before_body block to pre-initialize variables to use in body
432
+ #
433
+ #
434
+ MULTI_LINE_STRING
435
+
436
+ if %i[gem app].include?(shell_type)
437
+ custom_shell_file_content += <<-MULTI_LINE_STRING
438
+ before_body {
439
+ Display.setAppName('#{shell_type == :gem ? human_name(custom_shell_name) : human_name(namespace)}')
440
+ Display.setAppVersion(VERSION)
441
+ @display = display {
442
+ on_about {
443
+ display_about_dialog
444
+ }
445
+ on_preferences {
446
+ display_preferences_dialog
447
+ }
448
+ }
449
+ }
450
+ MULTI_LINE_STRING
451
+ else
452
+ custom_shell_file_content += <<-MULTI_LINE_STRING
453
+ # before_body {
454
+ #
455
+ # }
456
+ MULTI_LINE_STRING
457
+ end
458
+
459
+ custom_shell_file_content += <<-MULTI_LINE_STRING
460
+
461
+ ## Use after_body block to setup observers for widgets in body
462
+ #
463
+ # after_body {
464
+ #
465
+ # }
466
+
467
+ ## Add widget content inside custom shell body
468
+ ## Top-most widget must be a shell or another custom shell
469
+ #
470
+ body {
471
+ shell {
472
+ # Replace example content below with custom shell content
473
+ minimum_size 320, 240
474
+ text "#{human_name(namespace)} - #{human_name(custom_shell_name)}"
475
+ grid_layout
476
+ label(:center) {
477
+ text bind(self, :greeting)
478
+ font height: 40
479
+ layout_data :fill, :center, true, true
480
+ }
481
+ }
482
+ }
483
+ MULTI_LINE_STRING
484
+
485
+ if %i[gem app].include?(shell_type)
486
+ custom_shell_file_content += <<-MULTI_LINE_STRING
487
+
488
+ def display_about_dialog
489
+ message_box = MessageBox.new(swt_widget)
490
+ message_box.setText("About")
491
+ message = "#{human_name(namespace)} - #{human_name(custom_shell_name)} \#{VERSION}\n\n"
492
+ message += LICENSE
493
+ message_box.setMessage(message)
494
+ message_box.open
495
+ end
496
+
497
+ def display_preferences_dialog
498
+ dialog(swt_widget) {
499
+ text 'Preferences'
500
+ grid_layout {
501
+ margin_height 5
502
+ margin_width 5
503
+ }
504
+ group {
505
+ row_layout {
506
+ type :vertical
507
+ spacing 10
508
+ }
509
+ text 'Greeting'
510
+ font style: :bold
511
+ [
512
+ 'Hello, World!',
513
+ 'Howdy, Partner!'
514
+ ].each do |greeting_text|
515
+ button(:radio) {
516
+ text greeting_text
517
+ selection bind(self, :greeting) { |g| g == greeting_text }
518
+ layout_data {
519
+ width 160
520
+ }
521
+ on_widget_selected { |event|
522
+ self.greeting = event.widget.getText
390
523
  }
391
524
  }
392
-
393
525
  end
394
- end
526
+ }
527
+ }.open
528
+ end
529
+ MULTI_LINE_STRING
530
+ end
531
+
532
+ custom_shell_file_content += <<-MULTI_LINE_STRING
533
+ end
534
+ end
395
535
  MULTI_LINE_STRING
396
536
  end
397
537
 
@@ -406,16 +546,16 @@ class Scaffold
406
546
  ## Add options like the following to configure CustomWidget by outside consumers
407
547
  #
408
548
  # options :custom_text, :background_color
409
- # option :foreground_color, :red
549
+ # option :foreground_color, default: :red
410
550
 
411
- ## Uncomment before_body block to pre-initialize variables to use in body
551
+ ## Use before_body block to pre-initialize variables to use in body
412
552
  #
413
553
  #
414
554
  # before_body {
415
555
  #
416
556
  # }
417
557
 
418
- ## Uncomment after_body block to setup observers for widgets in body
558
+ ## Use after_body block to setup observers for widgets in body
419
559
  #
420
560
  # after_body {
421
561
  #