glimmer-dsl-swt 4.17.2.0 → 4.17.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.17.2.0
1
+ 4.17.3.0
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: glimmer-dsl-swt 4.17.2.0 ruby lib
5
+ # stub: glimmer-dsl-swt 4.17.3.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "glimmer-dsl-swt".freeze
9
- s.version = "4.17.2.0"
9
+ s.version = "4.17.3.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["AndyMaleh".freeze]
14
- s.date = "2020-09-25"
14
+ s.date = "2020-10-18"
15
15
  s.description = "Glimmer DSL for SWT (JRuby Desktop Development GUI Library)".freeze
16
16
  s.email = "andy.am@gmail.com".freeze
17
17
  s.executables = ["glimmer".freeze, "girb".freeze]
@@ -120,6 +120,8 @@ Gem::Specification.new do |s|
120
120
  "samples/hello/hello_combo.rb",
121
121
  "samples/hello/hello_computed.rb",
122
122
  "samples/hello/hello_computed/contact.rb",
123
+ "samples/hello/hello_custom_shell.rb",
124
+ "samples/hello/hello_custom_widget.rb",
123
125
  "samples/hello/hello_drag_and_drop.rb",
124
126
  "samples/hello/hello_list_multi_selection.rb",
125
127
  "samples/hello/hello_list_single_selection.rb",
@@ -143,10 +145,10 @@ Gem::Specification.new do |s|
143
145
  end
144
146
 
145
147
  if s.respond_to? :add_runtime_dependency then
146
- s.add_runtime_dependency(%q<glimmer>.freeze, ["~> 1.0.0"])
148
+ s.add_runtime_dependency(%q<glimmer>.freeze, ["~> 1.0.1"])
147
149
  s.add_runtime_dependency(%q<super_module>.freeze, ["~> 1.4.1"])
148
150
  s.add_runtime_dependency(%q<nested_inherited_jruby_include_package>.freeze, ["~> 0.3.0"])
149
- s.add_runtime_dependency(%q<puts_debuggerer>.freeze, ["~> 0.10.1"])
151
+ s.add_runtime_dependency(%q<puts_debuggerer>.freeze, ["~> 0.10.2"])
150
152
  s.add_runtime_dependency(%q<rake-tui>.freeze, [">= 0.2.3", "< 2.0.0"])
151
153
  s.add_runtime_dependency(%q<git-glimmer>.freeze, ["= 1.7.0"])
152
154
  s.add_runtime_dependency(%q<logging>.freeze, [">= 2.3.0", "< 3.0.0"])
@@ -162,10 +164,10 @@ Gem::Specification.new do |s|
162
164
  s.add_development_dependency(%q<simplecov>.freeze, ["~> 0.16.1"])
163
165
  s.add_development_dependency(%q<simplecov-lcov>.freeze, ["~> 0.7.0"])
164
166
  else
165
- s.add_dependency(%q<glimmer>.freeze, ["~> 1.0.0"])
167
+ s.add_dependency(%q<glimmer>.freeze, ["~> 1.0.1"])
166
168
  s.add_dependency(%q<super_module>.freeze, ["~> 1.4.1"])
167
169
  s.add_dependency(%q<nested_inherited_jruby_include_package>.freeze, ["~> 0.3.0"])
168
- s.add_dependency(%q<puts_debuggerer>.freeze, ["~> 0.10.1"])
170
+ s.add_dependency(%q<puts_debuggerer>.freeze, ["~> 0.10.2"])
169
171
  s.add_dependency(%q<rake-tui>.freeze, [">= 0.2.3", "< 2.0.0"])
170
172
  s.add_dependency(%q<git-glimmer>.freeze, ["= 1.7.0"])
171
173
  s.add_dependency(%q<logging>.freeze, [">= 2.3.0", "< 3.0.0"])
@@ -144,6 +144,7 @@ Glimmer::Config.excluded_keyword_checkers << lambda do |method_symbol, *args|
144
144
  result ||= method == 'dispose' && is_a?(Glimmer::UI::CustomWidget) && respond_to?(method)
145
145
  result ||= ['drag_source_proxy', 'drop_target_proxy'].include?(method) && is_a?(Glimmer::UI::CustomWidget)
146
146
  result ||= method == 'post_initialize_child'
147
+ result ||= method == 'handle'
147
148
  result ||= method.end_with?('=')
148
149
  result ||= ['finish_edit!', 'search', 'all_tree_items', 'depth_first_search'].include?(method) && is_a?(Glimmer::UI::CustomWidget) && body_root.respond_to?(method)
149
150
  end
@@ -22,6 +22,12 @@
22
22
  $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
23
23
 
24
24
  # External requires
25
+ if !['', 'false'].include?(ENV['GLIMMER_BUNDLER_SETUP'].to_s.strip.downcase)
26
+ bundler_group = ENV['GLIMMER_BUNDLER_SETUP'].to_s.strip.downcase
27
+ bundler_group = 'default' if bundler_group == 'true'
28
+ require 'bundler'
29
+ Bundler.setup(bundler_group)
30
+ end
25
31
  require 'java'
26
32
  require 'puts_debuggerer' if ("#{ENV['pd']}#{ENV['PD']}").to_s.downcase.include?('true')
27
33
  require 'glimmer'
@@ -80,6 +80,7 @@ module Glimmer
80
80
  selected_table_items = [parent.swt_widget.getItems.first].to_java(TableItem) if selected_table_items.empty? && !parent.swt_widget.getItems.empty?
81
81
  parent.swt_widget.setSelection(selected_table_items) unless selected_table_items.empty?
82
82
  parent.sort
83
+ parent.swt_widget.redraw if parent&.swt_widget&.respond_to?(:redraw)
83
84
  end
84
85
  end
85
86
  end
@@ -19,7 +19,10 @@
19
19
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
- require 'bundler/setup' if ARGV.include?('--bundler') && File.exist?(File.expand_path('./Gemfile'))
22
+ if ARGV.include?('--bundler') && File.exist?(File.expand_path('./Gemfile'))
23
+ require 'bundler'
24
+ Bundler.setup(:default)
25
+ end
23
26
  require 'fileutils'
24
27
  require 'os'
25
28
 
@@ -29,7 +32,7 @@ module Glimmer
29
32
 
30
33
  TEXT_USAGE = <<~MULTI_LINE_STRING
31
34
  Glimmer (Ruby Desktop Development GUI Library) - JRuby Gem: glimmer-dsl-swt v#{File.read(File.expand_path('../../../VERSION', __FILE__))}
32
- Usage: glimmer [--bundler] [--quiet] [--debug] [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-jruby-option]...] (application.rb or task[task_args]) [[application2.rb]...]
35
+ Usage: glimmer [--bundler] [--pd] [--quiet] [--debug] [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-jruby-option]...] (application.rb or task[task_args]) [[application2.rb]...]
33
36
 
34
37
  Runs Glimmer applications and tasks.
35
38
 
@@ -39,8 +42,9 @@ module Glimmer
39
42
  Optionally, extra Glimmer options, JRuby options, and/or environment variables may be passed in.
40
43
 
41
44
  Glimmer options:
42
- - "--bundler" : Activates Glimmer gems with `bundler/setup` to ensure they match Gemfile (passes -G to jruby on app run)
43
- - "--quiet" : Does not announce file path of Glimmer application being launched
45
+ - "--bundler=GROUP" : Activates gems in Bundler default group in Gemfile
46
+ - "--pd=BOOLEAN" : Requires puts_debuggerer to enable pd method
47
+ - "--quiet=BOOLEAN" : Does not announce file path of Glimmer application being launched
44
48
  - "--debug" : Displays extra debugging information, passes "--debug" to JRuby, and enables debug logging
45
49
  - "--log-level=VALUE" : Sets Glimmer's Ruby logger level ("ERROR" / "WARN" / "INFO" / "DEBUG"; default is none)
46
50
 
@@ -52,9 +56,11 @@ module Glimmer
52
56
 
53
57
  GLIMMER_LIB_LOCAL = File.expand_path(File.join('lib', 'glimmer-dsl-swt.rb'))
54
58
  GLIMMER_LIB_GEM = 'glimmer-dsl-swt'
55
- GLIMMER_OPTIONS = %w[--log-level --quiet --bundler]
59
+ GLIMMER_OPTIONS = %w[--log-level --quiet --bundler --pd]
56
60
  GLIMMER_OPTION_ENV_VAR_MAPPING = {
57
- '--log-level' => 'GLIMMER_LOGGER_LEVEL'
61
+ '--log-level' => 'GLIMMER_LOGGER_LEVEL' ,
62
+ '--bundler' => 'GLIMMER_BUNDLER_SETUP' ,
63
+ '--pd' => 'PD' ,
58
64
  }
59
65
  REGEX_RAKE_TASK_WITH_ARGS = /^([^\[]+)\[?([^\]]*)\]?$/
60
66
 
@@ -105,7 +111,6 @@ module Glimmer
105
111
 
106
112
  def launch(application, jruby_options: [], env_vars: {}, glimmer_options: {})
107
113
  jruby_options_string = jruby_options.join(' ') + ' ' if jruby_options.any?
108
- bundler_require = '-G' if glimmer_options['--bundler']
109
114
  env_vars = env_vars.merge(glimmer_option_env_vars(glimmer_options))
110
115
  env_vars_string = env_vars.map do |k,v|
111
116
  if OS.windows? && ENV['PROMPT'] # detect command prompt (or powershell)
@@ -137,7 +142,7 @@ module Glimmer
137
142
  @@mutex.synchronize do
138
143
  puts "Launching Glimmer Application: #{application}" if jruby_options_string.to_s.include?('--debug') || glimmer_options['--quiet'].to_s.downcase != 'true'
139
144
  end
140
- command = "#{env_vars_string} jruby #{bundler_require} #{jruby_options_string}#{jruby_os_specific_options} #{devmode_require}-r #{the_glimmer_lib} -S #{application}"
145
+ command = "#{env_vars_string} jruby #{jruby_options_string}#{jruby_os_specific_options} #{devmode_require}-r #{the_glimmer_lib} -S #{application}"
141
146
  if !env_vars_string.empty? && OS.windows?
142
147
  command = "bash -c \"#{command}\"" if ENV['SHELL'] # do in Windows Git Bash only
143
148
  command = "cmd /C \"#{command}\"" if ENV['PROMPT'] # do in Windows Command Prompt only (or Powershell)
@@ -198,6 +203,9 @@ module Glimmer
198
203
 
199
204
  def display_tasks
200
205
  if OS.windows?
206
+ require 'rake'
207
+ Rake::TaskManager.record_task_metadata = true
208
+ require_relative 'rake_task'
201
209
  tasks = Rake.application.tasks
202
210
  task_lines = tasks.reject do |task|
203
211
  task.comment.nil?
@@ -205,8 +213,6 @@ module Glimmer
205
213
  max_task_size = tasks.map(&:name_with_args).map(&:size).max + 1
206
214
  task_name = task.name_with_args.sub('glimmer:', '')
207
215
  line = "glimmer #{task_name.ljust(max_task_size)} # #{task.comment}"
208
- bound = TTY::Screen.width - 6
209
- line.size <= bound ? line : "#{line[0..(bound - 3)]}..."
210
216
  end
211
217
  puts task_lines.to_a
212
218
  else
@@ -48,6 +48,20 @@ require_relative '../ext/glimmer/config.rb'
48
48
  require 'puts_debuggerer' if ("#{ENV['pd']}#{ENV['PD']}").to_s.downcase.include?('true')
49
49
 
50
50
  namespace :glimmer do
51
+ desc 'Runs Glimmer app or custom shell gem in the current directory, unless app_path is specified, then runs it instead (app_path is optional)'
52
+ task :run, [:app_path] do |t, args|
53
+ require_relative 'launcher'
54
+ if args[:app_path].nil?
55
+ require 'fileutils'
56
+ current_directory_name = File.basename(FileUtils.pwd)
57
+ assumed_shell_script = File.join('.', 'bin', current_directory_name)
58
+ assumed_shell_script = Dir.glob('./bin/*').detect {|f| File.file?(f)} if !File.exist?(assumed_shell_script)
59
+ Glimmer::Launcher.new([assumed_shell_script]).launch
60
+ else
61
+ Glimmer::Launcher.new([args[:app_path]]).launch
62
+ end
63
+ end
64
+
51
65
  namespace :sample do
52
66
  task :requires do
53
67
  require_relative 'rake_task/sample'
@@ -76,6 +90,16 @@ namespace :glimmer do
76
90
  Glimmer::RakeTask::Package.clean
77
91
  end
78
92
 
93
+ desc 'Generate gemspec'
94
+ task :gemspec do
95
+ Glimmer::RakeTask::Package.gemspec
96
+ end
97
+
98
+ desc 'Generate gem'
99
+ task :gem do
100
+ Glimmer::RakeTask::Package.gem
101
+ end
102
+
79
103
  desc 'Generate JAR config file'
80
104
  task :config do
81
105
  Glimmer::RakeTask::Package.config
@@ -100,11 +124,15 @@ namespace :glimmer do
100
124
 
101
125
  desc 'Package app for distribution (generating config, jar, and native files) (type is optional)'
102
126
  task :package, [:type] do |t, args|
103
- Rake::Task['gemspec:generate'].execute
127
+ Rake::Task['glimmer:package:gemspec'].execute
104
128
  Rake::Task['glimmer:package:lock_jars'].execute
105
129
  Rake::Task['glimmer:package:config'].execute
106
130
  Rake::Task['glimmer:package:jar'].execute
107
- Rake::Task['glimmer:package:native'].execute(args)
131
+ if OS.linux?
132
+ Rake::Task['glimmer:package:gem'].execute
133
+ else
134
+ Rake::Task['glimmer:package:native'].execute(args)
135
+ end
108
136
  end
109
137
 
110
138
  desc 'Scaffold Glimmer application directory structure to build a new app'
@@ -134,6 +162,12 @@ namespace :glimmer do
134
162
  task :custom_widget, [:name, :namespace] => :customwidget
135
163
  task :"custom-widget", [:name, :namespace] => :customwidget
136
164
 
165
+ desc 'Desktopify a web app'
166
+ task :desktopify, [:app_name, :website] do |t, args|
167
+ require_relative 'rake_task/scaffold'
168
+ Glimmer::RakeTask::Scaffold.desktopify(args[:app_name], args[:website])
169
+ end
170
+
137
171
  namespace :gem do
138
172
  desc 'Scaffold Glimmer::UI::CustomShell subclass (full window view) under its own Ruby gem + app project (namespace is required) [alt: scaffold:gem:cs]'
139
173
  task :customshell, [:name, :namespace] do |t, args|
@@ -35,6 +35,22 @@ module Glimmer
35
35
  FileUtils.rm_rf('packages')
36
36
  end
37
37
 
38
+ def gemspec
39
+ system 'rake gemspec:generate'
40
+ end
41
+
42
+ def gem
43
+ system 'rake build'
44
+ end
45
+
46
+ def lock_jars
47
+ puts 'Locking gem jar-dependencies by downloading and storing in vendor/jars...'
48
+ FileUtils.mkdir_p('vendor/jars')
49
+ command = "lock_jars --vendor-dir vendor/jars"
50
+ puts command
51
+ system command
52
+ end
53
+
38
54
  def config
39
55
  project_name = File.basename(File.expand_path('.'))
40
56
  if !File.exists?('config/warble.rb')
@@ -72,18 +88,13 @@ module Glimmer
72
88
  system('warble')
73
89
  end
74
90
 
75
- def lock_jars
76
- puts 'Locking gem jar-dependencies by downloading & storing in vendor/jars...'
77
- FileUtils.mkdir_p('vendor/jars')
78
- command = "lock_jars --vendor-dir vendor/jars"
79
- puts command
80
- system command
81
- end
82
-
83
91
  def native(native_type=nil, native_extra_args)
84
- puts "Generating native executable with javapackager/jpackage..."
92
+ puts "Generating native executable with javapackager/jpackage..."
93
+ java_version = `java -version`
94
+ puts "WARNING! Glimmer Packaging Pre-Requisite Java Version 1.8.0_241 Is Not Found!" unless java_version.include?('1.8.0_241')
85
95
  require 'facets/string/titlecase'
86
96
  require 'facets/string/underscore'
97
+ require 'facets/string/camelcase'
87
98
  project_name = File.basename(File.expand_path('.'))
88
99
  version_file = File.expand_path('./VERSION')
89
100
  version = (File.read(version_file).strip if File.exists?(version_file) && File.file?(version_file)) rescue nil
@@ -93,7 +104,7 @@ module Glimmer
93
104
  human_name = project_name.underscore.titlecase
94
105
  icon = "package/#{OS.mac? ? 'macosx' : 'windows'}/#{human_name}.#{OS.mac? ? 'icns' : 'ico'}"
95
106
  if (`javapackager`.to_s.include?('Usage: javapackager') rescue nil)
96
- command = "javapackager -deploy -native #{native_type} -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\" -BinstalldirChooser=true -Bvendor=\"#{human_name}\" -Bwin.menuGroup=\"#{human_name}\" "
107
+ command = "javapackager -deploy -native #{native_type} -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.camelcase(:upper)}\" -Bmac.category=\"public.app-category.business\" -BinstalldirChooser=true -Bvendor=\"#{human_name}\" -Bwin.menuGroup=\"#{human_name}\" "
97
108
  command += " -BsystemWide=false " if OS.windows?
98
109
  command += " -BjvmOptions=-XstartOnFirstThread " if OS.mac?
99
110
  command += " -BappVersion=#{version} -Bmac.CFBundleVersion=#{version} " if version
@@ -121,10 +121,20 @@ module Glimmer
121
121
  MULTI_LINE_STRING
122
122
 
123
123
  def app(app_name)
124
+ common_app(app_name)
125
+ end
126
+
127
+ def desktopify(app_name, website)
128
+ common_app(app_name, :desktopify, website: website)
129
+ end
130
+
131
+ def common_app(app_name, shell_type = :app, shell_options = {})
124
132
  gem_name = file_name(app_name)
125
133
  gem_summary = human_name(app_name)
134
+ return puts("The directory '#{gem_name}' already exists. Please either remove or pick a different name.") if Dir.exist?(gem_name)
126
135
  system "jruby -S gem install juwelier -v2.4.9 --no-document" unless juwelier_exists?
127
136
  system "jruby -r git-glimmer -S juwelier --markdown --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
137
+ 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?
128
138
  cd gem_name
129
139
  rm_rf 'lib'
130
140
  write '.gitignore', GITIGNORE
@@ -132,13 +142,17 @@ module Glimmer
132
142
  write '.ruby-gemset', app_name
133
143
  write 'VERSION', '1.0.0'
134
144
  write 'LICENSE.txt', "Copyright (c) #{Time.now.year} #{app_name}"
135
- write 'Gemfile', GEMFILE
145
+ write 'Gemfile', gemfile(shell_type)
136
146
  write 'Rakefile', gem_rakefile(app_name, nil, gem_name)
137
147
  mkdir 'app'
138
148
  write "app/#{file_name(app_name)}.rb", app_main_file(app_name)
139
149
  mkdir 'app/models'
140
150
  mkdir 'app/views'
141
- custom_shell('AppView', current_dir_name, :app)
151
+ if shell_type == :desktopify
152
+ custom_shell('AppView', current_dir_name, shell_type, shell_options)
153
+ else
154
+ custom_shell('AppView', current_dir_name, shell_type)
155
+ end
142
156
 
143
157
  mkdir_p 'package/windows'
144
158
  icon_file = "package/windows/#{human_name(app_name)}.ico"
@@ -155,14 +169,17 @@ module Glimmer
155
169
  cp File.expand_path('../../../../icons/scaffold_app.png', __FILE__), icon_file
156
170
  puts "Created #{current_dir_name}/#{icon_file}"
157
171
 
158
- mkdir 'bin'
159
- write "bin/#{file_name(app_name)}", app_bin_file(app_name)
172
+ mkdir_p "app/#{file_name(app_name)}"
173
+ write "app/#{file_name(app_name)}/launch.rb", app_launch_file(app_name)
174
+ mkdir_p 'bin'
175
+ write "bin/#{file_name(app_name)}", app_bin_command_file(app_name)
176
+ FileUtils.chmod 0755, "bin/#{file_name(app_name)}"
160
177
  if OS.windows?
161
178
  system "bundle"
162
179
  system "rspec --init"
163
180
  else
164
- system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n rspec --init\n'"
165
- end
181
+ system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n rspec --init\n'"
182
+ end
166
183
  write 'spec/spec_helper.rb', spec_helper_file
167
184
  if OS.windows?
168
185
  system "glimmer package[image]"
@@ -172,23 +189,25 @@ module Glimmer
172
189
  if OS.mac?
173
190
  system "open packages/bundles/#{human_name(app_name).gsub(' ', '\ ')}.app"
174
191
  else
175
- system "glimmer bin/#{file_name(app_name)}"
192
+ system "glimmer run"
176
193
  end
177
- end
194
+ end
178
195
  end
179
196
 
180
- def custom_shell(custom_shell_name, namespace, shell_type = nil)
197
+ def custom_shell(custom_shell_name, namespace, shell_type = nil, shell_options = {})
181
198
  namespace ||= current_dir_name
182
199
  root_dir = File.exists?('app') ? 'app' : 'lib'
183
200
  parent_dir = "#{root_dir}/views/#{file_name(namespace)}"
201
+ 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")
184
202
  mkdir_p parent_dir unless File.exists?(parent_dir)
185
- write "#{parent_dir}/#{file_name(custom_shell_name)}.rb", custom_shell_file(custom_shell_name, namespace, shell_type)
203
+ write "#{parent_dir}/#{file_name(custom_shell_name)}.rb", custom_shell_file(custom_shell_name, namespace, shell_type, shell_options)
186
204
  end
187
205
 
188
206
  def custom_widget(custom_widget_name, namespace)
189
207
  namespace ||= current_dir_name
190
208
  root_dir = File.exists?('app') ? 'app' : 'lib'
191
209
  parent_dir = "#{root_dir}/views/#{file_name(namespace)}"
210
+ 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")
192
211
  mkdir_p parent_dir unless File.exists?(parent_dir)
193
212
  write "#{parent_dir}/#{file_name(custom_widget_name)}.rb", custom_widget_file(custom_widget_name, namespace)
194
213
  end
@@ -210,8 +229,10 @@ module Glimmer
210
229
  return puts('Namespace is required! Usage: glimmer scaffold:gem:customshell[name,namespace]') unless `git config --get github.user`.to_s.strip == 'AndyObtiva'
211
230
  namespace = 'glimmer'
212
231
  end
232
+ return puts("The directory '#{gem_name}' already exists. Please either remove or pick a different name.") if Dir.exist?(gem_name)
213
233
  system "jruby -S gem install juwelier -v2.4.9 --no-document" unless juwelier_exists?
214
234
  system "jruby -r git-glimmer -S juwelier --markdown --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
235
+ 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?
215
236
  cd gem_name
216
237
  write '.gitignore', GITIGNORE
217
238
  write '.ruby-version', RUBY_VERSION
@@ -222,9 +243,13 @@ module Glimmer
222
243
  append "lib/#{gem_name}.rb", gem_main_file(custom_shell_name, namespace)
223
244
  mkdir 'lib/views'
224
245
  custom_shell(custom_shell_name, namespace, :gem)
225
- mkdir 'bin'
226
- write "bin/#{gem_name}", gem_bin_file(gem_name, custom_shell_name, namespace)
227
- write "bin/#{file_name(custom_shell_name)}", gem_bin_command_file(gem_name)
246
+
247
+ mkdir_p "lib/#{file_name(namespace)}/#{file_name(custom_shell_name)}"
248
+ write "lib/#{file_name(namespace)}/#{file_name(custom_shell_name)}/launch.rb", gem_launch_file(gem_name, custom_shell_name, namespace)
249
+ mkdir_p 'bin'
250
+ write "bin/#{gem_name}", gem_bin_command_file(gem_name, custom_shell_name, namespace)
251
+ FileUtils.chmod 0755, "bin/#{gem_name}"
252
+ write "bin/#{file_name(custom_shell_name)}", gem_bin_command_file(gem_name, custom_shell_name, namespace)
228
253
  FileUtils.chmod 0755, "bin/#{file_name(custom_shell_name)}"
229
254
  if OS.windows?
230
255
  system "bundle"
@@ -257,7 +282,7 @@ module Glimmer
257
282
  if OS.mac?
258
283
  system "open packages/bundles/#{human_name(custom_shell_name).gsub(' ', '\ ')}.app" if OS.mac?
259
284
  else
260
- system "bin/#{file_name(custom_shell_name)}"
285
+ system "glimmer run"
261
286
  end
262
287
  end
263
288
  puts "Finished creating #{gem_name} Ruby gem."
@@ -278,8 +303,10 @@ module Glimmer
278
303
  namespace = 'glimmer'
279
304
  end
280
305
 
306
+ return puts("The directory '#{gem_name}' already exists. Please either remove or pick a different name.") if Dir.exist?(gem_name)
281
307
  system "jruby -S gem install juwelier -v2.4.9 --no-document" unless juwelier_exists?
282
308
  system "jruby -r git-glimmer -S juwelier --markdown --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
309
+ 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?
283
310
  cd gem_name
284
311
  write '.gitignore', GITIGNORE
285
312
  write '.ruby-version', RUBY_VERSION
@@ -342,6 +369,22 @@ module Glimmer
342
369
  def compact_name(gem_name)
343
370
  gem_name.underscore.camelcase.downcase
344
371
  end
372
+
373
+ def gemfile(shell_type)
374
+ if shell_type == :desktopify
375
+ lines = GEMFILE.split("\n")
376
+ require_glimmer_dsl_swt_index = lines.index(lines.detect {|l| l.include?("gem 'glimmer-dsl-swt'") })
377
+ lines[(require_glimmer_dsl_swt_index + 1)..(require_glimmer_dsl_swt_index + 1)] = [
378
+ "",
379
+ "# Enable Chromium Browser Glimmer Custom Widget gem if needed (e.g. Linux needs it to support HTML5 Video), and use `browser(:chromium)` in GUI.",
380
+ "# gem 'glimmer-cw-browser-chromium', '>= 0'",
381
+ "",
382
+ ]
383
+ lines.join("\n")
384
+ else
385
+ GEMFILE
386
+ end
387
+ end
345
388
 
346
389
  def app_main_file(app_name)
347
390
  <<~MULTI_LINE_STRING
@@ -378,40 +421,68 @@ module Glimmer
378
421
  MULTI_LINE_STRING
379
422
  end
380
423
 
381
- def app_bin_file(app_name)
424
+ def app_launch_file(app_name)
382
425
  <<~MULTI_LINE_STRING
383
- require_relative '../app/#{file_name(app_name)}'
426
+ require_relative '../#{file_name(app_name)}'
384
427
 
385
428
  #{class_name(app_name)}.new.open
386
429
  MULTI_LINE_STRING
387
430
  end
388
431
 
389
- def gem_bin_file(gem_name, custom_shell_name, namespace)
390
- # TODO change this so that it does not mix Glimmer unto the main object
432
+ def app_bin_command_file(app_name)
391
433
  <<~MULTI_LINE_STRING
392
- require_relative '../lib/#{gem_name}'
434
+ #!/usr/bin/env jruby
393
435
 
394
- class #{class_name(custom_shell_name)}App
395
- include Glimmer
436
+ runner = File.expand_path("../../app/#{file_name(app_name)}/launch.rb", __FILE__)
396
437
 
397
- def open
398
- #{dsl_widget_name(custom_shell_name)}.open
438
+ # Detect if inside a JAR file or not
439
+ if runner.include?('uri:classloader')
440
+ require runner
441
+ else
442
+ require 'glimmer/launcher'
443
+
444
+ launcher = Glimmer::Launcher.new([runner] + ARGV)
445
+ launcher.launch
446
+ end
447
+ MULTI_LINE_STRING
448
+ end
449
+
450
+ def gem_launch_file(gem_name, custom_shell_name, namespace)
451
+ # TODO change this so that it does not mix Glimmer unto the main object
452
+ <<~MULTI_LINE_STRING
453
+ require_relative '../../#{gem_name}'
454
+
455
+ module #{class_name(namespace)}
456
+ class #{class_name(custom_shell_name)}
457
+ class App
458
+ include Glimmer
459
+
460
+ def open
461
+ #{dsl_widget_name(custom_shell_name)}.open
462
+ end
463
+ end
399
464
  end
400
465
  end
401
466
 
402
- #{class_name(custom_shell_name)}App.new.open
467
+ #{class_name(namespace)}::#{class_name(custom_shell_name)}::App.new.open
403
468
  MULTI_LINE_STRING
404
469
  end
405
470
 
406
- def gem_bin_command_file(gem_name)
471
+ def gem_bin_command_file(gem_name, custom_shell_name, namespace)
407
472
  <<~MULTI_LINE_STRING
408
473
  #!/usr/bin/env jruby
409
474
 
410
- require 'glimmer/launcher'
475
+ runner = File.expand_path("../../lib/#{file_name(namespace)}/#{file_name(custom_shell_name)}/launch.rb", __FILE__)
411
476
 
412
- runner = File.expand_path("../#{gem_name}", __FILE__)
413
- launcher = Glimmer::Launcher.new([runner] + ARGV)
414
- launcher.launch
477
+ # Detect if inside a JAR file or not
478
+ if runner.include?('uri:classloader')
479
+ require runner
480
+ else
481
+ require 'glimmer/launcher'
482
+
483
+ launcher = Glimmer::Launcher.new([runner] + ARGV)
484
+ launcher.launch
485
+ end
415
486
  MULTI_LINE_STRING
416
487
  end
417
488
 
@@ -422,7 +493,8 @@ module Glimmer
422
493
  lines.insert(require_rake_line_index, "require 'glimmer/launcher'")
423
494
  gem_files_line_index = lines.index(lines.detect {|l| l.include?('# dependencies defined in Gemfile') })
424
495
  if custom_shell_name
425
- lines.insert(gem_files_line_index, " gem.files = Dir['VERSION', 'LICENSE.txt', 'lib/**/*', 'app/**/*', 'bin/**/*', 'vendor/**/*', 'package/**/*']")
496
+ lines.insert(gem_files_line_index, " gem.files = Dir['VERSION', 'LICENSE.txt', 'app/**/*', 'bin/**/*', 'config/**/*', 'db/**/*', 'docs/**/*', 'fonts/**/*', 'icons/**/*', 'images/**/*', 'lib/**/*', 'package/**/*', 'script/**/*', 'sounds/**/*', 'vendor/**/*', 'videos/**/*']")
497
+ # 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)
426
498
  lines.insert(gem_files_line_index+1, " gem.executables = ['#{gem_name}', '#{file_name(custom_shell_name)}']")
427
499
  lines.insert(gem_files_line_index+2, " gem.require_paths = ['vendor', 'lib', 'app']")
428
500
  else
@@ -438,7 +510,7 @@ module Glimmer
438
510
  " -name '#{human_name(custom_shell_name)}'" +
439
511
  " -title '#{human_name(custom_shell_name)}'" +
440
512
  " -Bmac.CFBundleName='#{human_name(custom_shell_name)}'" +
441
- " -Bmac.CFBundleIdentifier='org.#{namespace ? compact_name(namespace) : compact_name(custom_shell_name)}.application.#{compact_name(custom_shell_name).capitalize}'"
513
+ " -Bmac.CFBundleIdentifier='org.#{namespace ? compact_name(namespace) : compact_name(custom_shell_name)}.application.#{compact_name(custom_shell_name).camelcase(:upper)}'"
442
514
  # " -BlicenseType=" +
443
515
  # " -Bmac.category=" +
444
516
  # " -Bmac.signing-key-developer-id-app="
@@ -468,7 +540,7 @@ module Glimmer
468
540
  lines.join("\n")
469
541
  end
470
542
 
471
- def custom_shell_file(custom_shell_name, namespace, shell_type)
543
+ def custom_shell_file(custom_shell_name, namespace, shell_type, shell_options = {})
472
544
  namespace_type = class_name(namespace) == class_name(current_dir_name) ? 'class' : 'module'
473
545
 
474
546
  custom_shell_file_content = <<-MULTI_LINE_STRING
@@ -493,14 +565,14 @@ module Glimmer
493
565
  # options :title, :background_color
494
566
  # option :width, default: 320
495
567
  # option :height, default: 240
496
- option :greeting, default: 'Hello, World!'
568
+ #{'# ' if shell_type == :desktopify}option :greeting, default: 'Hello, World!'
497
569
 
498
570
  ## Use before_body block to pre-initialize variables to use in body
499
571
  #
500
572
  #
501
573
  MULTI_LINE_STRING
502
574
 
503
- if %i[gem app].include?(shell_type)
575
+ if %i[gem app desktopify].include?(shell_type)
504
576
  custom_shell_file_content += <<-MULTI_LINE_STRING
505
577
  before_body {
506
578
  Display.setAppName('#{shell_type == :gem ? human_name(custom_shell_name) : human_name(namespace)}')
@@ -510,7 +582,7 @@ module Glimmer
510
582
  display_about_dialog
511
583
  }
512
584
  on_preferences {
513
- display_preferences_dialog
585
+ #{shell_type == :desktopify ? 'display_about_dialog' : 'display_preferences_dialog'}
514
586
  }
515
587
  }
516
588
  }
@@ -537,40 +609,72 @@ module Glimmer
537
609
  body {
538
610
  shell {
539
611
  # Replace example content below with custom shell content
540
- minimum_size 320, 240
612
+ minimum_size #{shell_type == :desktopify ? '1024, 768' : '320, 240'}
541
613
  image File.join(APP_ROOT, 'package', 'windows', "#{human_name(shell_type == :gem ? custom_shell_name : current_dir_name)}.ico") if OS.windows?
542
614
  text "#{human_name(namespace)} - #{human_name(custom_shell_name)}"
615
+
616
+ MULTI_LINE_STRING
617
+
618
+ if shell_type == :desktopify
619
+ custom_shell_file_content += <<-MULTI_LINE_STRING
620
+ browser {
621
+ url "#{shell_options[:website]}"
622
+ }
623
+ MULTI_LINE_STRING
624
+ else
625
+ custom_shell_file_content += <<-MULTI_LINE_STRING
543
626
  grid_layout
544
627
  label(:center) {
545
628
  text bind(self, :greeting)
546
629
  font height: 40
547
630
  layout_data :fill, :center, true, true
548
- }
631
+ }
632
+ MULTI_LINE_STRING
633
+ end
634
+
635
+ if %i[gem app desktopify].include?(shell_type)
636
+ custom_shell_file_content += <<-MULTI_LINE_STRING
637
+
549
638
  menu_bar {
550
639
  menu {
551
640
  text '&File'
641
+ menu_item {
642
+ text '&About...'
643
+ on_widget_selected {
644
+ display_about_dialog
645
+ }
646
+ }
552
647
  menu_item {
553
648
  text '&Preferences...'
554
649
  on_widget_selected {
555
- display_preferences_dialog
650
+ #{shell_type == :desktopify ? 'display_about_dialog' : 'display_preferences_dialog'}
556
651
  }
557
652
  }
558
653
  }
559
654
  }
655
+ MULTI_LINE_STRING
656
+ end
657
+
658
+ custom_shell_file_content += <<-MULTI_LINE_STRING
560
659
  }
561
660
  }
562
- MULTI_LINE_STRING
563
-
564
- if %i[gem app].include?(shell_type)
661
+ MULTI_LINE_STRING
662
+
663
+ if %i[gem app desktopify].include?(shell_type)
565
664
  custom_shell_file_content += <<-MULTI_LINE_STRING
566
665
 
567
666
  def display_about_dialog
568
667
  message_box(body_root) {
569
668
  text 'About'
570
- message "#{human_name(namespace)} - #{human_name(custom_shell_name)} \#{VERSION}\\n\\n\#{LICENSE}"
669
+ message "#{human_name(namespace)}#{" - #{human_name(custom_shell_name)}" if shell_type == :gem} \#{VERSION}\\n\\n\#{LICENSE}"
571
670
  }.open
572
671
  end
573
672
 
673
+ MULTI_LINE_STRING
674
+ end
675
+
676
+ if %i[gem app].include?(shell_type)
677
+ custom_shell_file_content += <<-MULTI_LINE_STRING
574
678
  def display_preferences_dialog
575
679
  dialog(swt_widget) {
576
680
  text 'Preferences'