glimmer 0.7.3 → 0.7.8

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.3
1
+ 0.7.8
@@ -232,6 +232,7 @@ module Glimmer
232
232
  end
233
233
 
234
234
  def invoke_property_writer(object, property_expression, value)
235
+ return if @binding_options[:read_only]
235
236
  value = convert_on_write(value)
236
237
  if property_indexed?(property_expression)
237
238
  property_method = '[]='
@@ -40,9 +40,7 @@ module Glimmer
40
40
  end
41
41
 
42
42
  def property_observer_hash
43
- # TODO simplify with ||=
44
- @property_observers = Hash.new unless @property_observers
45
- @property_observers
43
+ @property_observers ||= Hash.new
46
44
  end
47
45
 
48
46
  def property_observer_list(property_name)
@@ -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,26 +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.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)
45
65
  [model_tree_node && model_tree_node.send(tree_properties[:children])].flatten.to_a.compact.each do |child|
46
- observe(child, @tree_properties[:text])
47
- populate_tree_node(child, table_item, tree_properties)
66
+ populate_tree_node(child, tree_item, tree_properties)
48
67
  end
49
68
  end
50
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
@@ -17,7 +17,13 @@ module Glimmer
17
17
  end
18
18
 
19
19
  def interpret(parent, keyword, *args, &block)
20
- Glimmer::SWT::WidgetProxy.new(keyword, parent, args)
20
+ begin
21
+ class_name = "#{keyword.camelcase(:upper)}Proxy".to_sym
22
+ widget_class = Glimmer::SWT.const_get(class_name)
23
+ rescue
24
+ widget_class = Glimmer::SWT::WidgetProxy
25
+ end
26
+ widget_class.new(keyword, parent, args)
21
27
  end
22
28
  end
23
29
  end
@@ -25,3 +31,4 @@ module Glimmer
25
31
  end
26
32
 
27
33
  require 'glimmer/swt/widget_proxy'
34
+ require 'glimmer/swt/tree_proxy'
@@ -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 nor enable logging
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,143 @@ 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, 320
428
+ # option :height, 240
429
+ option :greeting, '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
+ }
442
+ MULTI_LINE_STRING
443
+ else
444
+ custom_shell_file_content += <<-MULTI_LINE_STRING
445
+ # before_body {
446
+ #
447
+ # }
448
+ MULTI_LINE_STRING
449
+ end
450
+
451
+ custom_shell_file_content += <<-MULTI_LINE_STRING
452
+
453
+ ## Use after_body block to setup observers for widgets in body
454
+ #
455
+ # after_body {
456
+ #
457
+ # }
458
+
459
+ ## Add widget content inside custom shell body
460
+ ## Top-most widget must be a shell or another custom shell
461
+ #
462
+ body {
463
+ shell {
464
+ # Replace example content below with custom shell content
465
+ minimum_size 320, 240
466
+ text "#{human_name(namespace)} - #{human_name(custom_shell_name)}"
467
+ grid_layout
468
+ MULTI_LINE_STRING
469
+
470
+ if %i[gem app].include?(shell_type)
471
+ custom_shell_file_content += <<-MULTI_LINE_STRING
472
+ on_about {
473
+ display_about_dialog
474
+ }
475
+ on_preferences {
476
+ display_preferences_dialog
477
+ }
478
+ MULTI_LINE_STRING
479
+ end
480
+
481
+ custom_shell_file_content += <<-MULTI_LINE_STRING
482
+ label(:center) {
483
+ text bind(self, :greeting)
484
+ font height: 40
485
+ layout_data :fill, :center, true, true
486
+ }
487
+ }
488
+ }
489
+ MULTI_LINE_STRING
490
+
491
+ if %i[gem app].include?(shell_type)
492
+ custom_shell_file_content += <<-MULTI_LINE_STRING
493
+
494
+ def display_about_dialog
495
+ message_box = MessageBox.new(swt_widget)
496
+ message_box.setText("About")
497
+ message = "#{human_name(namespace)} - #{human_name(custom_shell_name)} \#{VERSION}\n\n"
498
+ message += LICENSE
499
+ message_box.setMessage(message)
500
+ message_box.open
501
+ end
502
+
503
+ def display_preferences_dialog
504
+ dialog(swt_widget) {
505
+ text 'Preferences'
506
+ grid_layout {
507
+ margin_height 5
508
+ margin_width 5
509
+ }
510
+ group {
511
+ row_layout {
512
+ type :vertical
513
+ spacing 10
514
+ }
515
+ text 'Greeting'
516
+ font style: :bold
517
+ [
518
+ 'Hello, World!',
519
+ 'Howdy, Partner!'
520
+ ].each do |greeting_text|
521
+ button(:radio) {
522
+ text greeting_text
523
+ selection bind(self, :greeting) { |g| g == greeting_text }
524
+ layout_data {
525
+ width 160
526
+ }
527
+ on_widget_selected { |event|
528
+ self.greeting = event.widget.getText
390
529
  }
391
530
  }
392
-
393
531
  end
394
- end
532
+ }
533
+ }.open
534
+ end
535
+ MULTI_LINE_STRING
536
+ end
537
+
538
+ custom_shell_file_content += <<-MULTI_LINE_STRING
539
+ end
540
+ end
395
541
  MULTI_LINE_STRING
396
542
  end
397
543
 
@@ -408,14 +554,14 @@ class Scaffold
408
554
  # options :custom_text, :background_color
409
555
  # option :foreground_color, :red
410
556
 
411
- ## Uncomment before_body block to pre-initialize variables to use in body
557
+ ## Use before_body block to pre-initialize variables to use in body
412
558
  #
413
559
  #
414
560
  # before_body {
415
561
  #
416
562
  # }
417
563
 
418
- ## Uncomment after_body block to setup observers for widgets in body
564
+ ## Use after_body block to setup observers for widgets in body
419
565
  #
420
566
  # after_body {
421
567
  #