glimmer-dsl-swt 4.17.0.0 → 4.17.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,652 +0,0 @@
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
- require 'fileutils'
23
- require 'os'
24
- require 'facets'
25
-
26
- # TODO refactor to nest under RakeTask namespace
27
-
28
- MAIN_OBJECT = self
29
-
30
- class Scaffold
31
- class << self
32
- include FileUtils
33
-
34
- VERSION = File.read(File.expand_path('../../../VERSION', __FILE__)).strip
35
- RUBY_VERSION = File.read(File.expand_path('../../../RUBY_VERSION', __FILE__)).strip
36
-
37
- # TODO externalize all constants into scaffold/files
38
-
39
- GITIGNORE = <<~MULTI_LINE_STRING
40
- *.gem
41
- *.rbc
42
- /.config
43
- /coverage/
44
- /InstalledFiles
45
- /pkg/
46
- /spec/reports/
47
- /spec/examples.txt
48
- /test/tmp/
49
- /test/version_tmp/
50
- /tmp/
51
-
52
- # Used by dotenv library to load environment variables.
53
- # .env
54
-
55
- ## Specific to RubyMotion:
56
- .dat*
57
- .repl_history
58
- build/
59
- *.bridgesupport
60
- build-iPhoneOS/
61
- build-iPhoneSimulator/
62
-
63
- ## Specific to RubyMotion (use of CocoaPods):
64
- #
65
- # We recommend against adding the Pods directory to your .gitignore. However
66
- # you should judge for yourself, the pros and cons are mentioned at:
67
- # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
68
- #
69
- # vendor/Pods/
70
-
71
- ## Documentation cache and generated files:
72
- /.yardoc/
73
- /_yardoc/
74
- /doc/
75
- /rdoc/
76
-
77
- ## Environment normalization:
78
- /.bundle/
79
- /vendor/bundle
80
- /lib/bundler/man/
81
-
82
- # for a library or gem, you might want to ignore these files since the code is
83
- # intended to run in multiple environments; otherwise, check them in:
84
- # Gemfile.lock
85
- # .ruby-version
86
- # .ruby-gemset
87
-
88
- # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
89
- .rvmrc
90
-
91
- # Mac
92
- .DS_Store
93
-
94
- # Gladiator (Glimmer Editor)
95
- .gladiator
96
-
97
- # Glimmer
98
- dist
99
- packages
100
- vendor/jars
101
- MULTI_LINE_STRING
102
-
103
- GEMFILE = <<~MULTI_LINE_STRING
104
- # frozen_string_literal: true
105
-
106
- source 'https://rubygems.org'
107
-
108
- git_source(:github) {|repo_name| "https://github.com/\#{repo_name}" }
109
-
110
- gem 'glimmer-dsl-swt', '~> #{VERSION}'
111
-
112
- group :development do
113
- gem 'rspec', '~> 3.5.0'
114
- gem 'git-glimmer', '1.7.0'
115
- gem 'jeweler', '2.3.9'
116
- gem 'simplecov', '>= 0'
117
- end
118
- MULTI_LINE_STRING
119
-
120
- RVM_FUNCTION = <<~MULTI_LINE_STRING
121
- # Load RVM into a shell session *as a function*
122
- if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
123
-
124
- # First try to load from a user install
125
- source "$HOME/.rvm/scripts/rvm"
126
-
127
- elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
128
-
129
- # Then try to load from a root install
130
- source "/usr/local/rvm/scripts/rvm"
131
-
132
- fi
133
- MULTI_LINE_STRING
134
-
135
- def app(app_name)
136
- gem_name = file_name(app_name)
137
- gem_summary = human_name(app_name)
138
- system "jruby -r git-glimmer -S jeweler --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
139
- cd gem_name
140
- rm_rf 'lib'
141
- write '.gitignore', GITIGNORE
142
- write '.ruby-version', RUBY_VERSION
143
- write '.ruby-gemset', app_name
144
- write 'VERSION', '1.0.0'
145
- write 'LICENSE.txt', "Copyright (c) #{Time.now.year} #{app_name}"
146
- write 'Gemfile', GEMFILE
147
- write 'Rakefile', gem_rakefile(app_name, nil, gem_name)
148
- mkdir 'app'
149
- write "app/#{file_name(app_name)}.rb", app_main_file(app_name)
150
- mkdir 'app/models'
151
- mkdir 'app/views'
152
- custom_shell('AppView', current_dir_name, :app)
153
-
154
- mkdir_p 'package/windows'
155
- icon_file = "package/windows/#{human_name(app_name)}.ico"
156
- cp File.expand_path('../../../icons/scaffold_app.ico', __FILE__), icon_file
157
- puts "Created #{current_dir_name}/#{icon_file}"
158
-
159
- mkdir_p 'package/macosx'
160
- icon_file = "package/macosx/#{human_name(app_name)}.icns"
161
- cp File.expand_path('../../../icons/scaffold_app.icns', __FILE__), icon_file
162
- puts "Created #{current_dir_name}/#{icon_file}"
163
-
164
- mkdir_p 'package/linux'
165
- icon_file = "package/linux/#{human_name(app_name)}.png"
166
- cp File.expand_path('../../../icons/scaffold_app.png', __FILE__), icon_file
167
- puts "Created #{current_dir_name}/#{icon_file}"
168
-
169
- mkdir 'bin'
170
- write "bin/#{file_name(app_name)}", app_bin_file(app_name)
171
- write 'spec/spec_helper.rb', spec_helper_file
172
- if OS.windows?
173
- system "bundle"
174
- system "glimmer package[image]"
175
- system "\"packages/bundles/#{human_name(app_name)}/#{human_name(app_name)}.exe\""
176
- else
177
- system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n glimmer package\n'"
178
- if OS.mac?
179
- system "open packages/bundles/#{human_name(app_name).gsub(' ', '\ ')}.app"
180
- else
181
- system "glimmer bin/#{file_name(app_name)}"
182
- end
183
- end
184
- end
185
-
186
- def custom_shell(custom_shell_name, namespace, shell_type = nil)
187
- namespace ||= current_dir_name
188
- root_dir = File.exists?('app') ? 'app' : 'lib'
189
- parent_dir = "#{root_dir}/views/#{file_name(namespace)}"
190
- mkdir_p parent_dir unless File.exists?(parent_dir)
191
- write "#{parent_dir}/#{file_name(custom_shell_name)}.rb", custom_shell_file(custom_shell_name, namespace, shell_type)
192
- end
193
-
194
- def custom_widget(custom_widget_name, namespace)
195
- namespace ||= current_dir_name
196
- root_dir = File.exists?('app') ? 'app' : 'lib'
197
- parent_dir = "#{root_dir}/views/#{file_name(namespace)}"
198
- mkdir_p parent_dir unless File.exists?(parent_dir)
199
- write "#{parent_dir}/#{file_name(custom_widget_name)}.rb", custom_widget_file(custom_widget_name, namespace)
200
- end
201
-
202
- def custom_shell_gem(custom_shell_name, namespace)
203
- gem_name = "glimmer-cs-#{compact_name(custom_shell_name)}"
204
- gem_summary = "#{human_name(custom_shell_name)} - Glimmer Custom Shell"
205
- begin
206
- custom_shell_keyword = dsl_widget_name(custom_shell_name)
207
- MAIN_OBJECT.method(custom_shell_keyword)
208
- return puts("CustomShell keyword `#{custom_shell_keyword}` is unavailable (occupied by a built-in Ruby method)! Please pick a different name.")
209
- rescue NameError
210
- # No Op (keyword is not taken by a built in Ruby method)
211
- end
212
- if namespace
213
- gem_name += "-#{compact_name(namespace)}"
214
- gem_summary += " (#{human_name(namespace)})"
215
- else
216
- return puts('Namespace is required! Usage: glimmer scaffold:gem:customshell[name,namespace]') unless `git config --get github.user`.to_s.strip == 'AndyObtiva'
217
- namespace = 'glimmer'
218
- end
219
- system "jruby -r git-glimmer -S jeweler --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
220
- cd gem_name
221
- write '.gitignore', GITIGNORE
222
- write '.ruby-version', RUBY_VERSION
223
- write '.ruby-gemset', gem_name
224
- write 'VERSION', '1.0.0'
225
- write 'Gemfile', GEMFILE
226
- write 'Rakefile', gem_rakefile(custom_shell_name, namespace, gem_name)
227
- append "lib/#{gem_name}.rb", gem_main_file(custom_shell_name, namespace)
228
- mkdir 'lib/views'
229
- custom_shell(custom_shell_name, namespace, :gem)
230
- mkdir 'bin'
231
- write "bin/#{gem_name}", gem_bin_file(gem_name, custom_shell_name, namespace)
232
- write "bin/#{file_name(custom_shell_name)}", gem_bin_command_file(gem_name)
233
- FileUtils.chmod 0755, "bin/#{file_name(custom_shell_name)}"
234
- write 'spec/spec_helper.rb', spec_helper_file
235
-
236
- mkdir_p 'package/windows'
237
- icon_file = "package/windows/#{human_name(custom_shell_name)}.ico"
238
- cp File.expand_path('../../../icons/scaffold_app.ico', __FILE__), icon_file
239
- puts "Created #{current_dir_name}/#{icon_file}"
240
-
241
- mkdir_p 'package/macosx'
242
- icon_file = "package/macosx/#{human_name(custom_shell_name)}.icns"
243
- cp File.expand_path('../../../icons/scaffold_app.icns', __FILE__), icon_file
244
- puts "Created #{current_dir_name}/#{icon_file}"
245
-
246
- mkdir_p 'package/linux'
247
- icon_file = "package/linux/#{human_name(custom_shell_name)}.png"
248
- cp File.expand_path('../../../icons/scaffold_app.png', __FILE__), icon_file
249
- puts "Created #{current_dir_name}/#{icon_file}"
250
-
251
- if OS.windows?
252
- system "bundle"
253
- system "glimmer package[image]"
254
- system "\"packages/bundles/#{human_name(custom_shell_name)}/#{human_name(custom_shell_name)}.exe\""
255
- else
256
- system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n glimmer package\n'"
257
- if OS.mac?
258
- system "open packages/bundles/#{human_name(custom_shell_name).gsub(' ', '\ ')}.app" if OS.mac?
259
- else
260
- system "bin/#{file_name(custom_shell_name)}"
261
- end
262
- end
263
- puts "Finished creating #{gem_name} Ruby gem."
264
- puts 'Edit Rakefile to configure gem details.'
265
- puts 'Run `rake` to execute specs.'
266
- puts 'Run `rake build` to build gem.'
267
- puts 'Run `rake release` to release into rubygems.org once ready.'
268
- end
269
-
270
- def custom_widget_gem(custom_widget_name, namespace)
271
- 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'
272
- gem_name = "glimmer-cw-#{compact_name(custom_widget_name)}"
273
- gem_summary = "#{human_name(custom_widget_name)} - Glimmer Custom Widget"
274
- if namespace
275
- gem_name += "-#{compact_name(namespace)}"
276
- gem_summary += " (#{human_name(namespace)})"
277
- else
278
- namespace = 'glimmer'
279
- end
280
- system "jruby -r git-glimmer -S jeweler --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
281
- cd gem_name
282
- write '.gitignore', GITIGNORE
283
- write '.ruby-version', RUBY_VERSION
284
- write '.ruby-gemset', gem_name
285
- write 'VERSION', '1.0.0'
286
- write 'Gemfile', GEMFILE
287
- write 'Rakefile', gem_rakefile
288
- write 'spec/spec_helper.rb', spec_helper_file
289
- append "lib/#{gem_name}.rb", gem_main_file(custom_widget_name, namespace)
290
- mkdir 'lib/views'
291
- custom_widget(custom_widget_name, namespace)
292
- if OS.windows?
293
- system "bundle"
294
- else
295
- system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n'"
296
- end
297
- puts "Finished creating #{gem_name} Ruby gem."
298
- puts 'Edit Rakefile to configure gem details.'
299
- puts 'Run `rake` to execute specs.'
300
- puts 'Run `rake build` to build gem.'
301
- puts 'Run `rake release` to release into rubygems.org once ready.'
302
- end
303
-
304
- private
305
-
306
- def write(file, content)
307
- File.write file, content
308
- file_path = File.expand_path(file)
309
- puts "Created #{current_dir_name}/#{file}"
310
- end
311
-
312
- def append(file, content)
313
- File.open(file, 'a') do |f|
314
- f.write(content)
315
- end
316
- end
317
-
318
- def current_dir_name
319
- File.basename(File.expand_path('.'))
320
- end
321
-
322
- def class_name(app_name)
323
- app_name.underscore.camelcase(:upper)
324
- end
325
-
326
- def file_name(app_name)
327
- app_name.underscore
328
- end
329
- alias dsl_widget_name file_name
330
-
331
- def human_name(app_name)
332
- app_name.underscore.titlecase
333
- end
334
-
335
- def compact_name(gem_name)
336
- gem_name.underscore.camelcase.downcase
337
- end
338
-
339
- def app_main_file(app_name)
340
- <<~MULTI_LINE_STRING
341
- $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
342
-
343
- require 'bundler/setup'
344
- Bundler.require(:default)
345
- require 'views/#{file_name(app_name)}/app_view'
346
-
347
- class #{class_name(app_name)}
348
- include Glimmer
349
-
350
- APP_ROOT = File.expand_path('../..', __FILE__)
351
- VERSION = File.read(File.join(APP_ROOT, 'VERSION'))
352
- LICENSE = File.read(File.join(APP_ROOT, 'LICENSE.txt'))
353
-
354
- def open
355
- app_view.open
356
- end
357
- end
358
- MULTI_LINE_STRING
359
- end
360
-
361
- def gem_main_file(custom_widget_name, namespace = nil)
362
- custom_widget_file_path = "views"
363
- custom_widget_file_path += "/#{file_name(namespace)}" if namespace
364
- custom_widget_file_path += "/#{file_name(custom_widget_name)}"
365
-
366
- <<~MULTI_LINE_STRING
367
- $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
368
-
369
- require 'glimmer-dsl-swt'
370
- require '#{custom_widget_file_path}'
371
- MULTI_LINE_STRING
372
- end
373
-
374
- def app_bin_file(app_name)
375
- <<~MULTI_LINE_STRING
376
- require_relative '../app/#{file_name(app_name)}'
377
-
378
- #{class_name(app_name)}.new.open
379
- MULTI_LINE_STRING
380
- end
381
-
382
- def gem_bin_file(gem_name, custom_shell_name, namespace)
383
- # TODO change this so that it does not mix Glimmer unto the main object
384
- <<~MULTI_LINE_STRING
385
- require_relative '../lib/#{gem_name}'
386
-
387
- class #{class_name(custom_shell_name)}App
388
- include Glimmer
389
-
390
- def open
391
- #{dsl_widget_name(custom_shell_name)}.open
392
- end
393
- end
394
-
395
- #{class_name(custom_shell_name)}App.new.open
396
- MULTI_LINE_STRING
397
- end
398
-
399
- def gem_bin_command_file(gem_name)
400
- <<~MULTI_LINE_STRING
401
- #!/usr/bin/env jruby
402
-
403
- require 'glimmer/launcher'
404
-
405
- runner = File.expand_path("../#{gem_name}", __FILE__)
406
- launcher = Glimmer::Launcher.new([runner] + ARGV)
407
- launcher.launch
408
- MULTI_LINE_STRING
409
- end
410
-
411
- def gem_rakefile(custom_shell_name = nil, namespace = nil, gem_name = nil)
412
- rakefile_content = File.read('Rakefile')
413
- lines = rakefile_content.split("\n")
414
- require_rake_line_index = lines.index(lines.detect {|l| l.include?("require 'rake'") })
415
- lines.insert(require_rake_line_index, "require 'glimmer/launcher'")
416
- gem_files_line_index = lines.index(lines.detect {|l| l.include?('# dependencies defined in Gemfile') })
417
- if custom_shell_name
418
- lines.insert(gem_files_line_index, " gem.files = Dir['VERSION', 'LICENSE.txt', 'lib/**/*', 'app/**/*', 'bin/**/*', 'vendor/**/*', 'package/**/*']")
419
- lines.insert(gem_files_line_index+1, " gem.executables = ['#{gem_name}', '#{file_name(custom_shell_name)}']")
420
- lines.insert(gem_files_line_index+2, " gem.require_paths = ['vendor', 'lib', 'app']")
421
- else
422
- lines.insert(gem_files_line_index, " gem.files = Dir['VERSION', 'LICENSE.txt', 'lib/**/*']")
423
- end
424
- spec_pattern_line_index = lines.index(lines.detect {|l| l.include?('spec.pattern =') })
425
- lines.insert(spec_pattern_line_index+1, " spec.ruby_opts = [Glimmer::Launcher.jruby_swt_options]")
426
- lines << "\nrequire 'glimmer/rake_task'\n"
427
- file_content = lines.join("\n")
428
- if custom_shell_name
429
- file_content << <<~MULTI_LINE_STRING
430
- Glimmer::Package.javapackager_extra_args =
431
- " -name '#{human_name(custom_shell_name)}'" +
432
- " -title '#{human_name(custom_shell_name)}'" +
433
- " -Bmac.CFBundleName='#{human_name(custom_shell_name)}'" +
434
- " -Bmac.CFBundleIdentifier='org.#{namespace ? compact_name(namespace) : compact_name(custom_shell_name)}.application.#{compact_name(custom_shell_name).capitalize}'"
435
- # " -BlicenseType=" +
436
- # " -Bmac.category=" +
437
- # " -Bmac.signing-key-developer-id-app="
438
- MULTI_LINE_STRING
439
- end
440
- file_content
441
- end
442
-
443
- def spec_helper_file
444
- content = File.read('spec/spec_helper.rb')
445
- lines = content.split("\n")
446
- require_line_index = lines.index(lines.detect {|l| l.include?(current_dir_name) })
447
- lines[require_line_index..require_line_index] = [
448
- "require 'bundler/setup'",
449
- 'Bundler.require(:default, :development)',
450
- ]
451
- configure_block_line_index = lines.index(lines.detect {|l| l.include?('RSpec.configure do') }) + 1
452
- lines[configure_block_line_index...configure_block_line_index] = [
453
- ' # The following ensures rspec tests that instantiate and set Glimmer DSL widgets in @target get cleaned after',
454
- ' config.after do',
455
- ' @target.dispose if @target && @target.respond_to?(:dispose)',
456
- ' Glimmer::DSL::Engine.reset',
457
- ' end',
458
- ]
459
-
460
- lines << "\nrequire 'glimmer/rake_task'\n"
461
- lines.join("\n")
462
- end
463
-
464
- def custom_shell_file(custom_shell_name, namespace, shell_type)
465
- namespace_type = class_name(namespace) == class_name(current_dir_name) ? 'class' : 'module'
466
-
467
- custom_shell_file_content = <<-MULTI_LINE_STRING
468
- #{namespace_type} #{class_name(namespace)}
469
- class #{class_name(custom_shell_name)}
470
- include Glimmer::UI::CustomShell
471
-
472
- MULTI_LINE_STRING
473
-
474
- if shell_type == :gem
475
- custom_shell_file_content += <<-MULTI_LINE_STRING
476
- APP_ROOT = File.expand_path('../../../..', __FILE__)
477
- VERSION = File.read(File.join(APP_ROOT, 'VERSION'))
478
- LICENSE = File.read(File.join(APP_ROOT, 'LICENSE.txt'))
479
-
480
- MULTI_LINE_STRING
481
- end
482
-
483
- custom_shell_file_content += <<-MULTI_LINE_STRING
484
- ## Add options like the following to configure CustomShell by outside consumers
485
- #
486
- # options :title, :background_color
487
- # option :width, default: 320
488
- # option :height, default: 240
489
- option :greeting, default: 'Hello, World!'
490
-
491
- ## Use before_body block to pre-initialize variables to use in body
492
- #
493
- #
494
- MULTI_LINE_STRING
495
-
496
- if %i[gem app].include?(shell_type)
497
- custom_shell_file_content += <<-MULTI_LINE_STRING
498
- before_body {
499
- Display.setAppName('#{shell_type == :gem ? human_name(custom_shell_name) : human_name(namespace)}')
500
- Display.setAppVersion(VERSION)
501
- @display = display {
502
- on_about {
503
- display_about_dialog
504
- }
505
- on_preferences {
506
- display_preferences_dialog
507
- }
508
- }
509
- }
510
- MULTI_LINE_STRING
511
- else
512
- custom_shell_file_content += <<-MULTI_LINE_STRING
513
- # before_body {
514
- #
515
- # }
516
- MULTI_LINE_STRING
517
- end
518
-
519
- custom_shell_file_content += <<-MULTI_LINE_STRING
520
-
521
- ## Use after_body block to setup observers for widgets in body
522
- #
523
- # after_body {
524
- #
525
- # }
526
-
527
- ## Add widget content inside custom shell body
528
- ## Top-most widget must be a shell or another custom shell
529
- #
530
- body {
531
- shell {
532
- # Replace example content below with custom shell content
533
- minimum_size 320, 240
534
- image File.join(APP_ROOT, 'package', 'windows', "#{human_name(shell_type == :gem ? custom_shell_name : current_dir_name)}.ico") if OS.windows?
535
- text "#{human_name(namespace)} - #{human_name(custom_shell_name)}"
536
- grid_layout
537
- label(:center) {
538
- text bind(self, :greeting)
539
- font height: 40
540
- layout_data :fill, :center, true, true
541
- }
542
- menu_bar {
543
- menu {
544
- text '&File'
545
- menu_item {
546
- text '&Preferences...'
547
- on_widget_selected {
548
- display_preferences_dialog
549
- }
550
- }
551
- }
552
- }
553
- }
554
- }
555
- MULTI_LINE_STRING
556
-
557
- if %i[gem app].include?(shell_type)
558
- custom_shell_file_content += <<-MULTI_LINE_STRING
559
-
560
- def display_about_dialog
561
- message_box(body_root) {
562
- text 'About'
563
- message "#{human_name(namespace)} - #{human_name(custom_shell_name)} \#{VERSION}\\n\\n\#{LICENSE}"
564
- }.open
565
- end
566
-
567
- def display_preferences_dialog
568
- dialog(swt_widget) {
569
- text 'Preferences'
570
- grid_layout {
571
- margin_height 5
572
- margin_width 5
573
- }
574
- group {
575
- row_layout {
576
- type :vertical
577
- spacing 10
578
- }
579
- text 'Greeting'
580
- font style: :bold
581
- [
582
- 'Hello, World!',
583
- 'Howdy, Partner!'
584
- ].each do |greeting_text|
585
- button(:radio) {
586
- text greeting_text
587
- selection bind(self, :greeting) { |g| g == greeting_text }
588
- layout_data {
589
- width 160
590
- }
591
- on_widget_selected { |event|
592
- self.greeting = event.widget.getText
593
- }
594
- }
595
- end
596
- }
597
- }.open
598
- end
599
- MULTI_LINE_STRING
600
- end
601
-
602
- custom_shell_file_content += <<-MULTI_LINE_STRING
603
- end
604
- end
605
- MULTI_LINE_STRING
606
- end
607
-
608
- def custom_widget_file(custom_widget_name, namespace)
609
- namespace_type = class_name(namespace) == class_name(current_dir_name) ? 'class' : 'module'
610
-
611
- <<~MULTI_LINE_STRING
612
- #{namespace_type} #{class_name(namespace)}
613
- class #{class_name(custom_widget_name)}
614
- include Glimmer::UI::CustomWidget
615
-
616
- ## Add options like the following to configure CustomWidget by outside consumers
617
- #
618
- # options :custom_text, :background_color
619
- # option :foreground_color, default: :red
620
-
621
- ## Use before_body block to pre-initialize variables to use in body
622
- #
623
- #
624
- # before_body {
625
- #
626
- # }
627
-
628
- ## Use after_body block to setup observers for widgets in body
629
- #
630
- # after_body {
631
- #
632
- # }
633
-
634
- ## Add widget content under custom widget body
635
- ##
636
- ## If you want to add a shell as the top-most widget,
637
- ## consider creating a custom shell instead
638
- ## (Glimmer::UI::CustomShell offers shell convenience methods, like show and hide)
639
- #
640
- body {
641
- # Replace example content below with custom widget content
642
- label {
643
- background :red
644
- }
645
- }
646
-
647
- end
648
- end
649
- MULTI_LINE_STRING
650
- end
651
- end
652
- end