glimmer-dsl-libui 0.9.0 → 0.9.2

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.
@@ -94,9 +94,6 @@ module Glimmer
94
94
  # Mac
95
95
  .DS_Store
96
96
 
97
- # Warbler
98
- Jars.lock
99
-
100
97
  # Gladiator (Glimmer Editor)
101
98
  .gladiator
102
99
  .gladiator-scratchpad
@@ -104,7 +101,6 @@ module Glimmer
104
101
  # Glimmer
105
102
  /dist/
106
103
  /packages/
107
- /vendor/jars/
108
104
  MULTI_LINE_STRING
109
105
 
110
106
  GEMFILE_PREFIX = <<~MULTI_LINE_STRING
@@ -116,19 +112,17 @@ module Glimmer
116
112
  MULTI_LINE_STRING
117
113
  GEMFILE_APP_MIDFIX = <<~MULTI_LINE_STRING
118
114
 
119
- gem 'glimmer-dsl-swt', '~> #{VERSION}'
115
+ gem 'glimmer-dsl-libui', '~> #{VERSION}'
120
116
  MULTI_LINE_STRING
121
117
  GEMFILE_GEM_MIDFIX = <<~MULTI_LINE_STRING
122
118
 
123
- gem 'glimmer-dsl-swt', '~> #{VERSION.split('.')[0...2].join('.')}'
119
+ gem 'glimmer-dsl-libui', '~> #{VERSION.split('.')[0...2].join('.')}'
124
120
  MULTI_LINE_STRING
125
121
  GEMFILE_SUFFIX = <<~MULTI_LINE_STRING
126
122
 
127
123
  group :development do
128
- gem 'jar-dependencies', '0.4.1'
129
124
  gem 'rspec', '~> 3.5.0'
130
125
  gem 'juwelier', '2.4.9'
131
- gem 'warbler', '2.0.5'
132
126
  gem 'simplecov', '>= 0'
133
127
  end
134
128
  MULTI_LINE_STRING
@@ -139,13 +133,13 @@ module Glimmer
139
133
  common_app(app_name)
140
134
  end
141
135
 
142
- def common_app(app_name, shell_type = :app, shell_options = {})
136
+ def common_app(app_name, window_type = :app, window_options = {})
143
137
  gem_name = file_name(app_name)
144
138
  gem_summary = human_name(app_name)
145
139
  return puts("The directory '#{gem_name}' already exists. Please either remove or pick a different name.") if Dir.exist?(gem_name)
146
- system "jruby -S gem install bundler --no-document" if OS.windows? # resolves freezing issue with warbler and bundler 2.2.29 included in JRuby
147
- system "jruby -S gem install juwelier -v2.4.9 --no-document" unless juwelier_exist?
148
- system "jruby -S juwelier --markdown --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
140
+ # system "ruby -S gem install bundler --no-document" if OS.windows? # resolves freezing issue with warbler and bundler 2.2.29 included in JRuby
141
+ system "ruby -S gem install juwelier -v2.4.9 --no-document" unless juwelier_exist?
142
+ system "ruby -S juwelier --markdown --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
149
143
  return puts('Your Git user.name and/or github.user are missing! Please add in for Juwelier to help Glimmer with Scaffolding.') if `git config --get github.user`.strip.empty? || `git config --get user.name`.strip.empty?
150
144
  cd gem_name
151
145
  rm_rf 'lib'
@@ -154,13 +148,13 @@ module Glimmer
154
148
  write '.ruby-gemset', app_name
155
149
  write 'VERSION', '1.0.0'
156
150
  write 'LICENSE.txt', "Copyright (c) #{Time.now.year} #{app_name}"
157
- write 'Gemfile', gemfile(shell_type)
151
+ write 'Gemfile', gemfile(window_type)
158
152
  write 'Rakefile', gem_rakefile(app_name, nil, gem_name)
159
153
  mkdir 'app'
160
154
  write "app/#{file_name(app_name)}.rb", app_main_file(app_name)
161
155
  mkdir_p "app/#{file_name(app_name)}/model"
162
156
  mkdir_p "app/#{file_name(app_name)}/view"
163
- custom_shell('AppView', current_dir_name, shell_type)
157
+ custom_window(class_name(app_name), current_dir_name, window_type, custom_window_class_name: 'Application')
164
158
 
165
159
  mkdir_p 'icons/windows'
166
160
  icon_file = "icons/windows/#{human_name(app_name)}.ico"
@@ -189,31 +183,29 @@ module Glimmer
189
183
  system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n rspec --init\n'"
190
184
  end
191
185
  write 'spec/spec_helper.rb', spec_helper_file
192
- if OS.mac?
193
- system "bash -c '#{RVM_FUNCTION}\n cd .\n JRUBY_OPTS=\"$JRUBY_OPTS -J-XstartOnFirstThread\" glimmer run\n'"
194
- elsif OS.linux?
186
+ if OS.mac? || OS.linux?
195
187
  system "bash -c '#{RVM_FUNCTION}\n cd .\n glimmer run\n'"
196
188
  else
197
189
  system "glimmer run"
198
190
  end
199
191
  end
200
192
 
201
- def custom_shell(custom_shell_name, namespace, shell_type = nil, shell_options = {})
193
+ def custom_window(custom_window_name, namespace, window_type = nil, window_options = {})
202
194
  namespace ||= current_dir_name
203
195
  root_dir = File.exist?('app') ? 'app' : 'lib'
204
196
  parent_dir = "#{root_dir}/#{file_name(namespace)}/view"
205
- return puts("The file '#{parent_dir}/#{file_name(custom_shell_name)}.rb' already exists. Please either remove or pick a different name.") if File.exist?("#{parent_dir}/#{file_name(custom_shell_name)}.rb")
197
+ return puts("The file '#{parent_dir}/#{file_name(custom_window_name)}.rb' already exists. Please either remove or pick a different name.") if File.exist?("#{parent_dir}/#{file_name(custom_window_name)}.rb")
206
198
  mkdir_p parent_dir unless File.exist?(parent_dir)
207
- write "#{parent_dir}/#{file_name(custom_shell_name)}.rb", custom_shell_file(custom_shell_name, namespace, shell_type, shell_options)
199
+ write "#{parent_dir}/#{file_name(custom_window_name)}.rb", custom_window_file(custom_window_name, namespace, window_type, window_options)
208
200
  end
209
201
 
210
- def custom_widget(custom_widget_name, namespace)
202
+ def custom_control(custom_control_name, namespace)
211
203
  namespace ||= current_dir_name
212
204
  root_dir = File.exist?('app') ? 'app' : 'lib'
213
205
  parent_dir = "#{root_dir}/#{file_name(namespace)}/view"
214
- return puts("The file '#{parent_dir}/#{file_name(custom_widget_name)}.rb' already exists. Please either remove or pick a different name.") if File.exist?("#{parent_dir}/#{file_name(custom_widget_name)}.rb")
206
+ return puts("The file '#{parent_dir}/#{file_name(custom_control_name)}.rb' already exists. Please either remove or pick a different name.") if File.exist?("#{parent_dir}/#{file_name(custom_control_name)}.rb")
215
207
  mkdir_p parent_dir unless File.exist?(parent_dir)
216
- write "#{parent_dir}/#{file_name(custom_widget_name)}.rb", custom_widget_file(custom_widget_name, namespace)
208
+ write "#{parent_dir}/#{file_name(custom_control_name)}.rb", custom_control_file(custom_control_name, namespace)
217
209
  end
218
210
 
219
211
  def custom_shape(custom_shape_name, namespace)
@@ -225,13 +217,13 @@ module Glimmer
225
217
  write "#{parent_dir}/#{file_name(custom_shape_name)}.rb", custom_shape_file(custom_shape_name, namespace)
226
218
  end
227
219
 
228
- def custom_shell_gem(custom_shell_name, namespace)
229
- gem_name = "glimmer-cs-#{compact_name(custom_shell_name)}"
230
- gem_summary = "#{human_name(custom_shell_name)} - Glimmer Custom Shell"
220
+ def custom_window_gem(custom_window_name, namespace)
221
+ gem_name = "glimmer-cs-#{compact_name(custom_window_name)}"
222
+ gem_summary = "#{human_name(custom_window_name)} - Glimmer Custom Window"
231
223
  begin
232
- custom_shell_keyword = dsl_widget_name(custom_shell_name)
233
- MAIN_OBJECT.method(custom_shell_keyword)
234
- return puts("CustomShell keyword `#{custom_shell_keyword}` is unavailable (occupied by a built-in Ruby method)! Please pick a different name.")
224
+ custom_window_keyword = dsl_control_name(custom_window_name)
225
+ MAIN_OBJECT.method(custom_window_keyword)
226
+ return puts("CustomWindow keyword `#{custom_window_keyword}` is unavailable (occupied by a built-in Ruby method)! Please pick a different name.")
235
227
  rescue NameError
236
228
  # No Op (keyword is not taken by a built in Ruby method)
237
229
  end
@@ -239,13 +231,13 @@ module Glimmer
239
231
  gem_name += "-#{compact_name(namespace)}"
240
232
  gem_summary += " (#{human_name(namespace)})"
241
233
  else
242
- return puts('Namespace is required! Usage: glimmer scaffold:gem:customshell[name,namespace]') unless `git config --get github.user`.to_s.strip == 'AndyObtiva'
234
+ return puts('Namespace is required! Usage: glimmer scaffold:gem:customwindow[name,namespace]') unless `git config --get github.user`.to_s.strip == 'AndyObtiva'
243
235
  namespace = 'glimmer'
244
236
  end
245
237
  return puts("The directory '#{gem_name}' already exists. Please either remove or pick a different name.") if Dir.exist?(gem_name)
246
- system "jruby -S gem install bundler --no-document" if OS.windows? # resolves freezing issue with warbler and bundler 2.2.29 included in JRuby
247
- system "jruby -S gem install juwelier -v2.4.9 --no-document" unless juwelier_exist?
248
- system "jruby -S juwelier --markdown --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
238
+ # system "ruby -S gem install bundler --no-document" if OS.windows? # resolves freezing issue with warbler and bundler 2.2.29 included in JRuby
239
+ system "ruby -S gem install juwelier -v2.4.9 --no-document" unless juwelier_exist?
240
+ system "ruby -S juwelier --markdown --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
249
241
  return puts('Your Git user.name and/or github.user are missing! Please add in for Juwelier to help Glimmer with Scaffolding.') if `git config --get github.user`.strip.empty? && `git config --get user.name`.strip.empty?
250
242
  cd gem_name
251
243
  write '.gitignore', GITIGNORE
@@ -253,15 +245,15 @@ module Glimmer
253
245
  write '.ruby-gemset', gem_name
254
246
  write 'VERSION', '1.0.0'
255
247
  write 'Gemfile', GEM_GEMFILE
256
- write 'Rakefile', gem_rakefile(custom_shell_name, namespace, gem_name)
257
- append "lib/#{gem_name}.rb", gem_main_file(custom_shell_name, namespace)
258
- custom_shell(custom_shell_name, namespace, :gem)
248
+ write 'Rakefile', gem_rakefile(custom_window_name, namespace, gem_name)
249
+ append "lib/#{gem_name}.rb", gem_main_file(custom_window_name, namespace)
250
+ custom_window(custom_window_name, namespace, :gem)
259
251
 
260
252
  mkdir_p "lib/#{gem_name}"
261
- write "lib/#{gem_name}/launch.rb", gem_launch_file(gem_name, custom_shell_name, namespace)
253
+ write "lib/#{gem_name}/launch.rb", gem_launch_file(gem_name, custom_window_name, namespace)
262
254
  mkdir_p 'bin'
263
- write "bin/#{file_name(custom_shell_name)}", app_bin_command_file(gem_name, custom_shell_name, namespace)
264
- FileUtils.chmod 0755, "bin/#{file_name(custom_shell_name)}"
255
+ write "bin/#{file_name(custom_window_name)}", app_bin_command_file(gem_name, custom_window_name, namespace)
256
+ FileUtils.chmod 0755, "bin/#{file_name(custom_window_name)}"
265
257
  if OS.windows?
266
258
  system "bundle"
267
259
  system "rspec --init"
@@ -285,9 +277,7 @@ module Glimmer
285
277
  cp File.expand_path('../../../../icons/scaffold_app.png', __FILE__), icon_file
286
278
  puts "Created #{current_dir_name}/#{icon_file}"
287
279
 
288
- if OS.mac?
289
- system "bash -c '#{RVM_FUNCTION}\n cd .\n JRUBY_OPTS=\"$JRUBY_OPTS -J-XstartOnFirstThread\" glimmer run\n'"
290
- elsif OS.linux?
280
+ if OS.mac? || OS.linux?
291
281
  system "bash -c '#{RVM_FUNCTION}\n cd .\n glimmer run\n'"
292
282
  else
293
283
  system "glimmer run"
@@ -299,21 +289,21 @@ module Glimmer
299
289
  puts 'Run `rake release` to release into rubygems.org once ready.'
300
290
  end
301
291
 
302
- def custom_widget_gem(custom_widget_name, namespace)
303
- gem_name = "glimmer-cw-#{compact_name(custom_widget_name)}"
304
- gem_summary = "#{human_name(custom_widget_name)} - Glimmer Custom Widget"
292
+ def custom_control_gem(custom_control_name, namespace)
293
+ gem_name = "glimmer-cw-#{compact_name(custom_control_name)}"
294
+ gem_summary = "#{human_name(custom_control_name)} - Glimmer Custom Control"
305
295
  if namespace
306
296
  gem_name += "-#{compact_name(namespace)}"
307
297
  gem_summary += " (#{human_name(namespace)})"
308
298
  else
309
- return puts('Namespace is required! Usage: glimmer scaffold:custom_widget_gem[custom_widget_name,namespace]') unless `git config --get github.user`.to_s.strip == 'AndyObtiva'
299
+ return puts('Namespace is required! Usage: glimmer scaffold:custom_control_gem[custom_control_name,namespace]') unless `git config --get github.user`.to_s.strip == 'AndyObtiva'
310
300
  namespace = 'glimmer'
311
301
  end
312
302
 
313
303
  return puts("The directory '#{gem_name}' already exists. Please either remove or pick a different name.") if Dir.exist?(gem_name)
314
- system "jruby -S gem install bundler --no-document" if OS.windows? # resolves freezing issue with warbler and bundler 2.2.29 included in JRuby
315
- system "jruby -S gem install juwelier -v2.4.9 --no-document" unless juwelier_exist?
316
- system "jruby -S juwelier --markdown --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
304
+ # system "ruby -S gem install bundler --no-document" if OS.windows? # resolves freezing issue with warbler and bundler 2.2.29 included in JRuby
305
+ system "ruby -S gem install juwelier -v2.4.9 --no-document" unless juwelier_exist?
306
+ system "ruby -S juwelier --markdown --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
317
307
  return puts('Your Git user.name and/or github.user are missing! Please add in for Juwelier to help Glimmer with Scaffolding.') if `git config --get github.user`.strip.empty? && `git config --get user.name`.strip.empty?
318
308
  cd gem_name
319
309
  write '.gitignore', GITIGNORE
@@ -322,8 +312,8 @@ module Glimmer
322
312
  write 'VERSION', '1.0.0'
323
313
  write 'Gemfile', GEM_GEMFILE
324
314
  write 'Rakefile', gem_rakefile
325
- append "lib/#{gem_name}.rb", gem_main_file(custom_widget_name, namespace)
326
- custom_widget(custom_widget_name, namespace)
315
+ append "lib/#{gem_name}.rb", gem_main_file(custom_control_name, namespace)
316
+ custom_control(custom_control_name, namespace)
327
317
  if OS.windows?
328
318
  system "bundle"
329
319
  system "rspec --init"
@@ -350,9 +340,9 @@ module Glimmer
350
340
  end
351
341
 
352
342
  return puts("The directory '#{gem_name}' already exists. Please either remove or pick a different name.") if Dir.exist?(gem_name)
353
- system "jruby -S gem install bundler --no-document" if OS.windows? # resolves freezing issue with warbler and bundler 2.2.29 included in JRuby
354
- system "jruby -S gem install juwelier -v2.4.9 --no-document" unless juwelier_exist?
355
- system "jruby -S juwelier --markdown --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
343
+ # system "ruby -S gem install bundler --no-document" if OS.windows? # resolves freezing issue with warbler and bundler 2.2.29 included in JRuby
344
+ system "ruby -S gem install juwelier -v2.4.9 --no-document" unless juwelier_exist?
345
+ system "ruby -S juwelier --markdown --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
356
346
  return puts('Your Git user.name and/or github.user are missing! Please add in for Juwelier to help Glimmer with Scaffolding.') if `git config --get github.user`.strip.empty? && `git config --get user.name`.strip.empty?
357
347
  cd gem_name
358
348
  write '.gitignore', GITIGNORE
@@ -406,7 +396,7 @@ module Glimmer
406
396
  def file_name(app_name)
407
397
  app_name.underscore
408
398
  end
409
- alias dsl_widget_name file_name
399
+ alias dsl_control_name file_name
410
400
 
411
401
  def human_name(app_name)
412
402
  app_name.underscore.titlecase
@@ -416,7 +406,7 @@ module Glimmer
416
406
  gem_name.underscore.camelcase.downcase
417
407
  end
418
408
 
419
- def gemfile(shell_type)
409
+ def gemfile(window_type)
420
410
  APP_GEMFILE
421
411
  end
422
412
 
@@ -427,9 +417,9 @@ module Glimmer
427
417
  begin
428
418
  require 'bundler/setup'
429
419
  Bundler.require(:default)
430
- rescue
420
+ rescue StandardError, Gem::LoadError
431
421
  # this runs when packaged as a gem (no bundler)
432
- require 'glimmer-dsl-swt'
422
+ require 'glimmer-dsl-libui'
433
423
  # add more gems if needed
434
424
  end
435
425
 
@@ -439,25 +429,23 @@ module Glimmer
439
429
  APP_ROOT = File.expand_path('../..', __FILE__)
440
430
  VERSION = File.read(File.join(APP_ROOT, 'VERSION'))
441
431
  LICENSE = File.read(File.join(APP_ROOT, 'LICENSE.txt'))
442
- Display.app_name = '#{human_name(app_name)}'
443
- Display.app_version = VERSION
444
432
  end
445
433
 
446
- require '#{file_name(app_name)}/view/app_view'
434
+ require '#{file_name(app_name)}/view/#{file_name(app_name)}'
447
435
  MULTI_LINE_STRING
448
436
  end
449
437
 
450
- def gem_main_file(custom_widget_name, namespace = nil)
451
- custom_widget_file_path = ''
452
- custom_widget_file_path += "#{file_name(namespace)}/" if namespace
453
- custom_widget_file_path += "view"
454
- custom_widget_file_path += "/#{file_name(custom_widget_name)}"
438
+ def gem_main_file(custom_control_name, namespace = nil)
439
+ custom_control_file_path = ''
440
+ custom_control_file_path += "#{file_name(namespace)}/" if namespace
441
+ custom_control_file_path += "view"
442
+ custom_control_file_path += "/#{file_name(custom_control_name)}"
455
443
 
456
444
  <<~MULTI_LINE_STRING
457
445
  $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
458
446
 
459
- require 'glimmer-dsl-swt'
460
- require '#{custom_widget_file_path}'
447
+ require 'glimmer-dsl-libui'
448
+ require '#{custom_control_file_path}'
461
449
  MULTI_LINE_STRING
462
450
  end
463
451
 
@@ -465,67 +453,52 @@ module Glimmer
465
453
  <<~MULTI_LINE_STRING
466
454
  require_relative '../#{file_name(app_name)}'
467
455
 
468
- #{class_name(app_name)}::View::AppView.launch
456
+ #{class_name(app_name)}::View::#{class_name(app_name)}.launch
469
457
  MULTI_LINE_STRING
470
458
  end
471
459
 
472
- def app_bin_command_file(app_name_or_gem_name, custom_shell_name=nil, namespace=nil)
473
- if custom_shell_name.nil?
460
+ def app_bin_command_file(app_name_or_gem_name, custom_window_name=nil, namespace=nil)
461
+ if custom_window_name.nil?
474
462
  runner = "File.expand_path('../../app/#{file_name(app_name_or_gem_name)}/launch.rb', __FILE__)"
475
463
  else
476
464
  runner = "File.expand_path('../../lib/#{app_name_or_gem_name}/launch.rb', __FILE__)"
477
465
  end
478
466
  <<~MULTI_LINE_STRING
479
- #!/usr/bin/env jruby
467
+ #!/usr/bin/env ruby
480
468
 
481
469
  runner = #{runner}
482
470
 
483
- # Detect if inside a JAR file or not
484
- if runner.include?('uri:classloader')
485
- require runner
486
- else
487
- require 'glimmer/launcher'
488
-
489
- launcher = Glimmer::Launcher.new([runner] + ARGV)
490
- launcher.launch
491
- end
471
+ require 'glimmer/launcher'
472
+
473
+ launcher = Glimmer::Launcher.new([runner] + ARGV)
474
+ launcher.launch
492
475
  MULTI_LINE_STRING
493
476
  end
494
477
 
495
- def gem_launch_file(gem_name, custom_shell_name, namespace)
478
+ def gem_launch_file(gem_name, custom_window_name, namespace)
496
479
  # TODO change this so that it does not mix Glimmer unto the main object
497
480
  <<~MULTI_LINE_STRING
498
481
  require_relative '../#{gem_name}'
499
482
 
500
- #{class_name(namespace)}::View::#{class_name(custom_shell_name)}.launch
483
+ #{class_name(namespace)}::View::#{class_name(custom_window_name)}.launch
501
484
  MULTI_LINE_STRING
502
485
  end
503
486
 
504
- def gem_rakefile(custom_shell_name = nil, namespace = nil, gem_name = nil)
487
+ def gem_rakefile(custom_window_name = nil, namespace = nil, gem_name = nil)
505
488
  rakefile_content = File.read('Rakefile')
506
489
  lines = rakefile_content.split("\n")
507
490
  require_rake_line_index = lines.index(lines.detect {|l| l.include?("require 'rake'") })
508
491
  lines.insert(require_rake_line_index, "require 'glimmer/launcher'")
509
492
  gem_files_line_index = lines.index(lines.detect {|l| l.include?('# dependencies defined in Gemfile') })
510
- if custom_shell_name
511
- lines.insert(gem_files_line_index, " gem.files = Dir['VERSION', 'LICENSE.txt', 'app/**/*', 'bin/**/*', 'config/**/*', 'db/**/*', 'docs/**/*', 'fonts/**/*', 'icons/**/*', 'images/**/*', 'lib/**/*', 'script/**/*', 'sounds/**/*', 'vendor/**/*', 'videos/**/*']")
512
- # the second executable is needed for warbler as it matches the gem name, which is the default expected file (alternatively in the future, we could do away with it and configure warbler to use the other file)
513
- lines.insert(gem_files_line_index+1, " gem.require_paths = ['vendor', 'lib', 'app']")
514
- lines.insert(gem_files_line_index+2, " gem.executables = ['#{file_name(custom_shell_name)}']") if custom_shell_name
493
+ if custom_window_name
494
+ lines.insert(gem_files_line_index, " gem.files = Dir['VERSION', 'LICENSE.txt', 'app/**/*', 'bin/**/*', 'config/**/*', 'db/**/*', 'docs/**/*', 'fonts/**/*', 'icons/**/*', 'images/**/*', 'lib/**/*', 'script/**/*', 'sounds/**/*', 'videos/**/*']")
495
+ lines.insert(gem_files_line_index+1, " gem.require_paths = ['lib', 'app']")
496
+ lines.insert(gem_files_line_index+2, " gem.executables = ['#{file_name(custom_window_name)}']") if custom_window_name
515
497
  else
516
498
  lines.insert(gem_files_line_index, " gem.files = Dir['VERSION', 'LICENSE.txt', 'lib/**/*']")
517
499
  end
518
500
  lines << "\nrequire 'glimmer/rake_task'\n"
519
- file_content = lines.join("\n")
520
- if custom_shell_name
521
- file_content << <<~MULTI_LINE_STRING
522
- Glimmer::RakeTask::Package.jpackage_extra_args =
523
- " --name '#{human_name(custom_shell_name)}'" +
524
- " --description '#{human_name(custom_shell_name)}'"
525
- # You can add more options from https://docs.oracle.com/en/java/javase/16/jpackage/packaging-tool-user-guide.pdf
526
- MULTI_LINE_STRING
527
- end
528
- file_content
501
+ lines.join("\n")
529
502
  end
530
503
 
531
504
  def spec_helper_file
@@ -538,7 +511,7 @@ module Glimmer
538
511
  ]
539
512
  configure_block_line_index = lines.index(lines.detect {|l| l.include?('RSpec.configure do') }) + 1
540
513
  lines[configure_block_line_index...configure_block_line_index] = [
541
- ' # The following ensures rspec tests that instantiate and set Glimmer DSL widgets in @target get cleaned after',
514
+ ' # The following ensures rspec tests that instantiate and set Glimmer DSL controls in @target get cleaned after',
542
515
  ' config.after do',
543
516
  ' @target.dispose if @target && @target.respond_to?(:dispose)',
544
517
  ' Glimmer::DSL::Engine.reset',
@@ -549,197 +522,184 @@ module Glimmer
549
522
  lines.join("\n")
550
523
  end
551
524
 
552
- def custom_shell_file(custom_shell_name, namespace, shell_type, shell_options = {})
525
+ def custom_window_file(custom_window_name, namespace, window_type, window_options = {})
526
+ window_options ||= {}
527
+ window_options[:custom_window_class_name] ||= 'CustomWindow'
553
528
  namespace_type = class_name(namespace) == class_name(current_dir_name) ? 'class' : 'module'
554
529
 
555
- custom_shell_file_content = <<-MULTI_LINE_STRING
530
+ custom_window_file_content = <<-MULTI_LINE_STRING
556
531
  #{namespace_type} #{class_name(namespace)}
557
532
  module View
558
- class #{class_name(custom_shell_name)}
559
- include Glimmer::UI::CustomShell
533
+ class #{class_name(custom_window_name)}
534
+ include Glimmer::LibUI::#{window_options[:custom_window_class_name]}
560
535
 
561
536
  MULTI_LINE_STRING
562
537
 
563
- if shell_type == :gem
564
- custom_shell_file_content += <<-MULTI_LINE_STRING
538
+ if window_type == :gem
539
+ custom_window_file_content += <<-MULTI_LINE_STRING
565
540
  APP_ROOT = File.expand_path('../../../..', __FILE__)
566
541
  VERSION = File.read(File.join(APP_ROOT, 'VERSION'))
567
542
  LICENSE = File.read(File.join(APP_ROOT, 'LICENSE.txt'))
568
- Display.app_name = '#{human_name(custom_shell_name)}'
569
- Display.app_version = VERSION
543
+ MULTI_LINE_STRING
544
+ end
570
545
 
546
+ if %i[gem app].include?(window_type)
547
+ custom_window_file_content += <<-MULTI_LINE_STRING
548
+ GREETINGS = [
549
+ 'Hello, World!',
550
+ 'Howdy, Partner!'
551
+ ]
571
552
  MULTI_LINE_STRING
572
553
  end
573
554
 
574
- custom_shell_file_content += <<-MULTI_LINE_STRING
575
- ## Add options like the following to configure CustomShell by outside consumers
555
+ custom_window_file_content += <<-MULTI_LINE_STRING
556
+
557
+ ## Add options like the following to configure CustomWindow by outside consumers
576
558
  #
577
559
  # options :title, :background_color
578
560
  # option :width, default: 320
579
561
  # option :height, default: 240
580
- option :greeting, default: 'Hello, World!'
562
+ MULTI_LINE_STRING
563
+
564
+ if %i[gem app].include?(window_type)
565
+ custom_window_file_content += <<-MULTI_LINE_STRING
566
+
567
+ # GREETING Array selected index
568
+ option :greeting_index, default: 0
569
+ MULTI_LINE_STRING
570
+ end
571
+
572
+ custom_window_file_content += <<-MULTI_LINE_STRING
581
573
 
582
- ## Use before_body block to pre-initialize variables to use in body
583
- #
574
+ ## Use before_body block to pre-initialize variables to use in body and
575
+ # to setup application menu
584
576
  #
585
577
  MULTI_LINE_STRING
586
578
 
587
- if %i[gem app].include?(shell_type)
588
- custom_shell_file_content += <<-MULTI_LINE_STRING
579
+ if %i[gem app].include?(window_type)
580
+ custom_window_file_content += <<-MULTI_LINE_STRING
589
581
  before_body do
590
- @display = display {
591
- on_about do
592
- display_about_dialog
593
- end
582
+ menu('File') {
583
+ menu_item('Preferences...') {
584
+ on_clicked do
585
+ display_preferences_dialog
586
+ end
587
+ }
594
588
 
595
- on_preferences do
596
- display_preferences_dialog
589
+ # Enables quitting with CMD+Q on Mac with Mac Quit menu item
590
+ quit_menu_item if OS.mac?
591
+ }
592
+ menu('Help') {
593
+ if OS.mac?
594
+ about_menu_item {
595
+ on_clicked do
596
+ display_about_dialog
597
+ end
598
+ }
597
599
  end
600
+
601
+ menu_item('About') {
602
+ on_clicked do
603
+ display_about_dialog
604
+ end
605
+ }
598
606
  }
599
607
  end
600
608
  MULTI_LINE_STRING
601
609
  else
602
- custom_shell_file_content += <<-MULTI_LINE_STRING
610
+ custom_window_file_content += <<-MULTI_LINE_STRING
603
611
  # before_body do
604
612
  #
605
613
  # end
606
614
  MULTI_LINE_STRING
607
615
  end
608
616
 
609
- custom_shell_file_content += <<-MULTI_LINE_STRING
617
+ custom_window_file_content += <<-MULTI_LINE_STRING
610
618
 
611
- ## Use after_body block to setup observers for widgets in body
619
+ ## Use after_body block to setup observers for controls in body
612
620
  #
613
621
  # after_body do
614
622
  #
615
623
  # end
616
624
 
617
- ## Add widget content inside custom shell body
618
- ## Top-most widget must be a shell or another custom shell
625
+ ## Add control content inside custom window body
626
+ ## Top-most control must be a window or another custom window
619
627
  #
620
628
  body {
621
- shell {
622
- # Replace example content below with custom shell content
623
- minimum_size '420, 240'
624
- image File.join(APP_ROOT, 'icons', 'windows', "#{human_name(current_dir_name)}.ico") if OS.windows?
625
- image File.join(APP_ROOT, 'icons', 'linux', "#{human_name(current_dir_name)}.png") unless OS.windows?
626
- text "#{human_name(namespace)}#{' - ' + human_name(custom_shell_name)}"
627
- grid_layout
628
- label(:center) {
629
- text <= [self, :greeting]
630
- font height: 40
631
- layout_data :fill, :center, true, true
632
- }
633
- MULTI_LINE_STRING
629
+ window {
630
+ # Replace example content below with custom window content
631
+ content_size 240, 240
632
+ title '#{human_name(namespace)}'
634
633
 
635
- if %i[gem app].include?(shell_type)
636
- custom_shell_file_content += <<-MULTI_LINE_STRING
634
+ margined true
637
635
 
638
- menu_bar {
639
- menu {
640
- text '&File'
641
-
642
- menu_item {
643
- text '&Preferences...'
644
-
645
- on_widget_selected do
646
- display_preferences_dialog
647
- end
648
- }
649
- }
650
- menu {
651
- text '&Help'
652
-
653
- menu_item {
654
- text '&About...'
655
-
656
- on_widget_selected do
657
- display_about_dialog
658
- end
659
- }
660
- }
636
+ label {
637
+ text <= [self, :greeting_index, on_read: -> { greeting }]
661
638
  }
662
- MULTI_LINE_STRING
663
- end
664
-
665
- custom_shell_file_content += <<-MULTI_LINE_STRING
666
639
  }
667
640
  }
668
641
  MULTI_LINE_STRING
669
642
 
670
- if %i[gem app].include?(shell_type)
671
- custom_shell_file_content += <<-MULTI_LINE_STRING
643
+ if %i[gem app].include?(window_type)
644
+ custom_window_file_content += <<-MULTI_LINE_STRING
645
+
646
+ def greeting
647
+ GREETINGS[greeting_index]
648
+ end
672
649
 
673
650
  def display_about_dialog
674
- message_box(body_root) {
675
- text 'About'
676
- message "#{human_name(namespace)}#{" - #{human_name(custom_shell_name)}" if shell_type == :gem} \#{VERSION}\\n\\n\#{LICENSE}"
677
- }.open
651
+ message = "#{human_name(namespace)}#{" - #{human_name(custom_window_name)}" if window_type == :gem} \#{VERSION}\\n\\n\#{LICENSE}"
652
+ msg_box('About', message)
678
653
  end
679
654
 
680
655
  MULTI_LINE_STRING
681
656
  end
682
657
 
683
- if %i[gem app].include?(shell_type)
684
- custom_shell_file_content += <<-MULTI_LINE_STRING
658
+ if %i[gem app].include?(window_type)
659
+ custom_window_file_content += <<-MULTI_LINE_STRING
685
660
  def display_preferences_dialog
686
- dialog(swt_widget) {
687
- grid_layout {
688
- margin_height 5
689
- margin_width 5
690
- }
661
+ window {
662
+ title 'Preferences'
663
+ content_size 200, 100
691
664
 
692
- text 'Preferences'
665
+ margined true
693
666
 
694
- group {
695
- row_layout {
696
- type :vertical
697
- spacing 10
698
- }
667
+ vertical_box {
668
+ padded true
699
669
 
700
- text 'Greeting'
701
- font style: :bold
670
+ label('Greeting:') {
671
+ stretchy false
672
+ }
702
673
 
703
- [
704
- 'Hello, World!',
705
- 'Howdy, Partner!'
706
- ].each do |greeting_text|
707
- button(:radio) {
708
- layout_data {
709
- width 160
710
- }
711
-
712
- text greeting_text
713
- selection <= [self, :greeting, on_read: ->(g) { g == greeting_text }]
714
-
715
- on_widget_selected do |event|
716
- self.greeting = event.widget.getText
717
- end
718
- }
719
- end
674
+ radio_buttons {
675
+ stretchy false
676
+
677
+ items GREETINGS
678
+ selected <=> [self, :greeting_index]
679
+ }
720
680
  }
721
- }.open
681
+ }.show
722
682
  end
723
683
  MULTI_LINE_STRING
724
684
  end
725
685
 
726
- custom_shell_file_content += <<-MULTI_LINE_STRING
686
+ custom_window_file_content += <<-MULTI_LINE_STRING
727
687
  end
728
688
  end
729
689
  end
730
690
  MULTI_LINE_STRING
731
691
  end
732
692
 
733
- def custom_widget_file(custom_widget_name, namespace)
693
+ def custom_control_file(custom_control_name, namespace)
734
694
  namespace_type = class_name(namespace) == class_name(current_dir_name) ? 'class' : 'module'
735
695
 
736
696
  <<-MULTI_LINE_STRING
737
697
  #{namespace_type} #{class_name(namespace)}
738
698
  module View
739
- class #{class_name(custom_widget_name)}
740
- include Glimmer::UI::CustomWidget
699
+ class #{class_name(custom_control_name)}
700
+ include Glimmer::LibUI::CustomControl
741
701
 
742
- ## Add options like the following to configure CustomWidget by outside consumers
702
+ ## Add options like the following to configure CustomControl by outside consumers
743
703
  #
744
704
  # options :custom_text, :background_color
745
705
  # option :foreground_color, default: :red
@@ -751,21 +711,21 @@ end
751
711
  #
752
712
  # end
753
713
 
754
- ## Use after_body block to setup observers for widgets in body
714
+ ## Use after_body block to setup observers for controls in body
755
715
  #
756
716
  # after_body do
757
717
  #
758
718
  # end
759
719
 
760
- ## Add widget content under custom widget body
720
+ ## Add control content under custom control body
761
721
  ##
762
- ## If you want to add a shell as the top-most widget,
763
- ## consider creating a custom shell instead
764
- ## (Glimmer::UI::CustomShell offers shell convenience methods, like show and hide)
722
+ ## If you want to add a window as the top-most control,
723
+ ## consider creating a custom window instead
724
+ ## (Glimmer::LibUI::CustomWindow offers window convenience methods, like show and hide)
765
725
  #
766
726
  body {
767
- # Replace example content below with custom widget content
768
- label(*swt_constants) {
727
+ # Replace example content below with custom control content
728
+ label {
769
729
  background :red
770
730
  }
771
731
  }
@@ -783,7 +743,7 @@ end
783
743
  #{namespace_type} #{class_name(namespace)}
784
744
  module View
785
745
  class #{class_name(custom_shape_name)}
786
- include Glimmer::UI::CustomShape
746
+ include Glimmer::LibUI::CustomShape
787
747
 
788
748
  ## Add options like the following to configure CustomShape by outside consumers
789
749
  #