glimmer 0.7.6 → 0.8.2

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.6
1
+ 0.8.2
@@ -16,6 +16,11 @@ module Glimmer
16
16
  @table = parent
17
17
  @model_binding = model_binding
18
18
  @column_properties = column_properties
19
+ if @table.respond_to?(:column_properties=)
20
+ @table.column_properties = @column_properties
21
+ else # assume custom widget
22
+ @table.body_root.column_properties = @column_properties
23
+ end
19
24
  call(@model_binding.evaluate_property)
20
25
  model = model_binding.base_model
21
26
  observe(model, model_binding.property_name_expression)
@@ -24,23 +29,27 @@ module Glimmer
24
29
  end
25
30
  end
26
31
 
27
- def call(model_collection=nil)
28
- if model_collection and model_collection.is_a?(Array)
29
- # TODO clean observer registrations
30
- observe(model_collection, @column_properties)
31
- @model_collection = model_collection
32
+ def call(new_model_collection=nil)
33
+ if new_model_collection and new_model_collection.is_a?(Array)
34
+ observe(new_model_collection, @column_properties)
35
+ @model_collection = new_model_collection
32
36
  end
33
37
  populate_table(@model_collection, @table, @column_properties)
34
38
  end
35
39
 
36
40
  def populate_table(model_collection, parent, column_properties)
41
+ selected_table_item_models = parent.swt_widget.getSelection.map(&:getData)
37
42
  parent.swt_widget.removeAll
38
43
  model_collection.each do |model|
39
44
  table_item = TableItem.new(parent.swt_widget, SWT::SWTProxy[:none])
40
45
  for index in 0..(column_properties.size-1)
41
46
  table_item.setText(index, model.send(column_properties[index]).to_s)
42
47
  end
48
+ table_item.setData(model)
43
49
  end
50
+ selected_table_items = parent.search {|item| selected_table_item_models.include?(item.getData) }
51
+ selected_table_items = [parent.swt_widget.getItems.first].to_java(TableItem) if selected_table_items.empty? && !parent.swt_widget.getItems.empty?
52
+ parent.swt_widget.setSelection(selected_table_items) unless selected_table_items.empty?
44
53
  end
45
54
  end
46
55
  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
@@ -0,0 +1,29 @@
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
+ require 'glimmer/swt/message_box_proxy'
6
+ require 'glimmer/swt/swt_proxy'
7
+
8
+ module Glimmer
9
+ module DSL
10
+ module SWT
11
+ class MessageBoxExpression < StaticExpression
12
+ include TopLevelExpression
13
+ include ParentExpression
14
+
15
+ include_package 'org.eclipse.swt.widgets'
16
+
17
+ def can_interpret?(parent, keyword, *args, &block)
18
+ keyword == 'message_box'
19
+ end
20
+
21
+ def interpret(parent, keyword, *args, &block)
22
+ potential_parent = args.first
23
+ parent = args.shift if potential_parent.is_a?(Shell) || (potential_parent.respond_to?(:swt_widget) && potential_parent.swt_widget.is_a?(Shell))
24
+ Glimmer::SWT::MessageBoxProxy.new(parent, Glimmer::SWT::SWTProxy[args])
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -32,3 +32,4 @@ end
32
32
 
33
33
  require 'glimmer/swt/widget_proxy'
34
34
  require 'glimmer/swt/tree_proxy'
35
+ require 'glimmer/swt/table_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
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')
@@ -123,6 +124,8 @@ module Glimmer
123
124
  attr_reader :jruby_options
124
125
 
125
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=')
126
129
  @application_paths = extract_application_paths(raw_options)
127
130
  @env_vars = extract_env_vars(raw_options)
128
131
  @glimmer_options = extract_glimmer_options(raw_options)
@@ -140,7 +143,7 @@ module Glimmer
140
143
  private
141
144
 
142
145
  def launch_application
143
- 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:')
144
147
  threads = @application_paths.map do |application_path|
145
148
  Thread.new do
146
149
  self.class.launch(
@@ -188,8 +191,8 @@ module Glimmer
188
191
  end.each do |glimmer_option|
189
192
  options.delete(glimmer_option)
190
193
  end.reduce({}) do |hash, glimmer_option_string|
191
- match = glimmer_option_string.match(/^([^=]+)=?(.*)$/)
192
- hash.merge(match[1] => match[2])
194
+ match = glimmer_option_string.match(/^([^=]+)=?(.+)?$/)
195
+ hash.merge(match[1] => (match[2] || 'true'))
193
196
  end
194
197
  end
195
198
  end
@@ -2,6 +2,54 @@ module Glimmer
2
2
  module Package
3
3
  class << self
4
4
  attr_accessor :javapackager_extra_args
5
+
6
+ def config
7
+ project_name = File.basename(File.expand_path('.'))
8
+ if !File.exists?('config/warble.rb')
9
+ puts 'Generating JAR configuration (config/warble.rb) to use with Warbler...'
10
+ system('mkdir -p config')
11
+ system('warble config')
12
+ new_config = File.read('config/warble.rb').split("\n").inject('') do |output, line|
13
+ if line.include?('config.dirs =')
14
+ line = line.sub('# ', '').sub(/=[^=\n]+$/, '= %w(app config db lib script bin docs fonts icons images sounds videos)')
15
+ end
16
+ if line.include?('config.includes =')
17
+ line = line.sub('# ', '').sub(/=[^=\n]+$/, "= FileList['LICENSE.txt', 'VERSION']")
18
+ end
19
+ if line.include?('config.autodeploy_dir =')
20
+ line = line.sub('# ', '')
21
+ end
22
+ output + "\n" + line
23
+ end
24
+ File.write('config/warble.rb', new_config)
25
+ end
26
+ end
27
+
28
+ def jar
29
+ system('mkdir -p dist')
30
+ puts "Generating JAR with Warbler..."
31
+ system('warble')
32
+ end
33
+
34
+ def native
35
+ require 'facets/string/titlecase'
36
+ require 'facets/string/underscore'
37
+ project_name = File.basename(File.expand_path('.'))
38
+ version_file = File.expand_path('./VERSION')
39
+ version = (File.read(version_file).strip if File.exists?(version_file) && File.file?(version_file)) rescue nil
40
+ license_file = File.expand_path('./LICENSE.txt')
41
+ license = (File.read(license_file).strip if File.exists?(license_file) && File.file?(license_file)) rescue nil
42
+ human_name = project_name.underscore.titlecase
43
+ command = "javapackager -deploy -native -outdir packages -outfile \"#{project_name}\" -srcfiles \"dist/#{project_name}.jar\" -appclass JarMain -name \"#{human_name}\" -title \"#{human_name}\" -Bmac.CFBundleName=\"#{human_name}\" -Bmac.CFBundleIdentifier=\"org.#{project_name}.application.#{project_name}\" -Bmac.category=\"public.app-category.business\" "
44
+ command += " -BjvmOptions=-XstartOnFirstThread " if OS.mac?
45
+ command += " -BappVersion=#{version} -Bmac.CFBundleVersion=#{version} " if version
46
+ command += " -srcfiles LICENSE.txt -BlicenseFile=LICENSE.txt " if license
47
+ command += " #{javapackager_extra_args} " if javapackager_extra_args
48
+ command += " #{ENV['JAVAPACKAGER_EXTRA_ARGS']} " if ENV['JAVAPACKAGER_EXTRA_ARGS']
49
+ puts "Generating DMG/PKG/APP/JNLP with javapackager..."
50
+ puts command
51
+ system command
52
+ end
5
53
  end
6
54
  end
7
55
  end
@@ -7,57 +7,26 @@ namespace :glimmer do
7
7
  namespace :package do
8
8
  desc 'Generate JAR config file'
9
9
  task :config do
10
- project_name = File.basename(File.expand_path('.'))
11
- if !File.exists?('config/warble.rb')
12
- puts 'Generating JAR configuration (config/warble.rb) to use with Warbler...'
13
- system('mkdir -p config')
14
- system('warble config')
15
- new_config = File.read('config/warble.rb').split("\n").inject('') do |output, line|
16
- if line.include?('config.dirs =')
17
- line = line.sub('# ', '').sub(/=[^=\n]+$/, '= %w(app config db lib script bin docs fonts icons images sounds videos)')
18
- end
19
- if line.include?('config.includes =')
20
- line = line.sub('# ', '').sub(/=[^=\n]+$/, "= FileList['LICENSE.txt', 'VERSION']")
21
- end
22
- if line.include?('config.autodeploy_dir =')
23
- line = line.sub('# ', '')
24
- end
25
- output + "\n" + line
26
- end
27
- File.write('config/warble.rb', new_config)
28
- end
10
+ Glimmer::Package.config
29
11
  end
30
12
 
31
13
  desc 'Generate JAR file'
32
- task :jar => 'package:config' do
33
- system('mkdir -p dist')
34
- puts "Generating JAR with Warbler..."
35
- system('warble')
14
+ task :jar do
15
+ Glimmer::Package.jar
36
16
  end
37
17
 
38
- desc 'Generate Native files (DMG/PKG/APP on the Mac)'
39
- task :native => 'package:jar' do
40
- require 'facets/string/titlecase'
41
- require 'facets/string/underscore'
42
- project_name = File.basename(File.expand_path('.'))
43
- version_file = File.expand_path('./VERSION')
44
- version = (File.read(version_file).strip if File.exists?(version_file) && File.file?(version_file)) rescue nil
45
- license_file = File.expand_path('./LICENSE.txt')
46
- license = (File.read(license_file).strip if File.exists?(license_file) && File.file?(license_file)) rescue nil
47
- human_name = project_name.underscore.titlecase
48
- command = "javapackager -deploy -native -outdir packages -outfile \"#{project_name}\" -srcfiles \"dist/#{project_name}.jar\" -appclass JarMain -name \"#{human_name}\" -title \"#{human_name}\" -BjvmOptions=-XstartOnFirstThread -Bmac.CFBundleName=\"#{human_name}\" -Bmac.CFBundleIdentifier=\"org.#{project_name}.application.#{project_name}\" -Bmac.category=\"public.app-category.business\" "
49
- command += " -BappVersion=#{version} -Bmac.CFBundleVersion=#{version} " if version
50
- command += " -srcfiles LICENSE.txt -BlicenseFile=LICENSE.txt " if license
51
- command += " #{Glimmer::Package.javapackager_extra_args} " if Glimmer::Package.javapackager_extra_args
52
- command += " #{ENV['JAVAPACKAGER_EXTRA_ARGS']} " if ENV['JAVAPACKAGER_EXTRA_ARGS']
53
- puts "Generating DMG/PKG/APP/JNLP with javapackager..."
54
- puts command
55
- system command
18
+ desc 'Generate Native files (DMG/PKG/APP on the Mac, EXE on Windows, RPM/DEB on Linux)'
19
+ task :native do
20
+ Glimmer::Package.native
56
21
  end
57
22
  end
58
23
 
59
24
  desc 'Package app for distribution (generating config, jar, and native files)'
60
- task :package => 'package:native'
25
+ task :package do
26
+ Rake::Task['glimmer:package:config'].execute
27
+ Rake::Task['glimmer:package:jar'].execute
28
+ Rake::Task['glimmer:package:native'].execute
29
+ end
61
30
 
62
31
 
63
32
  desc 'Scaffold a Glimmer application directory structure to begin building a new app'
@@ -76,9 +45,9 @@ namespace :glimmer do
76
45
  Scaffold.custom_widget(args[:custom_widget_name], args[:namespace])
77
46
  end
78
47
 
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])
48
+ desc 'Scaffold a Glimmer::UI::CustomShell subclass (represents a full window view) under its own Ruby gem + app project (namespace is required)'
49
+ task :custom_shell_gem, [:custom_shell_name, :namespace] do |t, args|
50
+ Scaffold.custom_shell_gem(args[:custom_shell_name], args[:namespace])
82
51
  end
83
52
 
84
53
  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,7 +292,8 @@ 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
@@ -312,17 +325,59 @@ class Scaffold
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
  #