glimmer-dsl-swt 4.18.3.0 → 4.18.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/README.md +48 -5
- data/VERSION +1 -1
- data/glimmer-dsl-swt.gemspec +7 -6
- data/lib/ext/glimmer/config.rb +24 -7
- data/lib/glimmer/data_binding/widget_binding.rb +14 -4
- data/lib/glimmer/swt/custom/shape.rb +3 -2
- data/lib/glimmer/swt/directory_dialog_proxy.rb +3 -3
- data/lib/glimmer/swt/display_proxy.rb +25 -4
- data/lib/glimmer/swt/file_dialog_proxy.rb +3 -3
- data/lib/glimmer/swt/shell_proxy.rb +13 -2
- data/lib/glimmer/swt/widget_listener_proxy.rb +14 -5
- data/lib/glimmer/swt/widget_proxy.rb +1 -1
- data/lib/glimmer/ui/custom_shell.rb +10 -9
- data/lib/glimmer/ui/custom_widget.rb +22 -14
- data/samples/elaborate/meta_sample.rb +81 -24
- data/samples/elaborate/tetris.rb +63 -32
- data/samples/elaborate/tetris/model/game.rb +180 -139
- data/samples/elaborate/tetris/model/tetromino.rb +28 -25
- data/samples/elaborate/tetris/view/game_over_dialog.rb +13 -17
- data/samples/elaborate/tetris/view/score_lane.rb +5 -5
- data/samples/elaborate/tetris/view/tetris_menu_bar.rb +72 -0
- data/samples/elaborate/tic_tac_toe.rb +4 -4
- data/samples/hello/hello_canvas_transform.rb +1 -1
- data/samples/hello/hello_link.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d88ee3cdf02d4610332fd450379b43ab5231e0a2e5e9941c746ea7b65bcad00
|
4
|
+
data.tar.gz: db869412b61dd6c45002cd11ebf7cdb046d02b4de9b74769ec8cd90122eafbd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 520388927363b967965f3afbbafdd753daf3c399547b87e5c60535620b12ffc694b05e14b5176b600fd1dcf7eecb4ee9c00ca41f4cbdda79ad138d2e593c836a
|
7
|
+
data.tar.gz: 5d52780657cac19b47ccec883b163b56fd1823f1701abef6e01e8b9b3109479648999506eb3dea2cb831826ab88eb562faf1c1a961f8d9c85620cfc956da7432
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
### 4.18.3.1
|
4
|
+
|
5
|
+
- Provide an auto_sync_exec all data-binding config option to automatically sync_exec GUI calls from other threads instead of requiring users to use sync_exec on model attribute-change logic. Default value to false.
|
6
|
+
- Have CustomShell::launch method take options to pass to custom shell keyword invocation
|
7
|
+
- Update Glimmer Meta-Sample to load entire gem into user directory (since some new samples rely on images)
|
8
|
+
- Update Glimmer Meta-Sample to display errors in a `dialog` instead of a `message_box` to allow scrolling
|
9
|
+
- Removed newly added CustomShell::shutdown as unnecessary (could just do CustomShell::launchd_custom_shell.close)
|
10
|
+
- Supporting deregistering Display listeners just like standard listeners via deregister
|
11
|
+
- Enhance performance of excluded keyword check
|
12
|
+
- Remove CustomWidget support for multiple before_body/after_body blocks instead of one each since it is not needed.
|
13
|
+
- Tetris Menu Bar with Game Menu -> Start, Pause, Restart, and Exit
|
14
|
+
- Tetris refactor mutation methods to end with bangs
|
15
|
+
- Add new :fill_screen style for `shell` to start app filling the screen size (not full screen mode though)
|
16
|
+
- Tetris Stop game if user does not play again in the end (instead of closing it)
|
17
|
+
- End Tetris Thread loop gracefully if game over is encountered
|
18
|
+
- Tetris use more observers instead of callbacks to Game
|
19
|
+
- Turn Tetris::Model::Game class from a singleton class to a standard class supporting instances
|
20
|
+
- Fix issue of `tetris` keyword not found when run from meta-sample app
|
21
|
+
|
3
22
|
### 4.18.3.0
|
4
23
|
|
5
24
|
- Canvas Transform DSL (DSL declared Transform objects are auto-disposed after getting used by their parent shape)
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for SWT 4.18.3.
|
1
|
+
# [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for SWT 4.18.3.1
|
2
2
|
## JRuby Desktop Development GUI Framework
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/glimmer-dsl-swt.svg)](http://badge.fury.io/rb/glimmer-dsl-swt)
|
4
4
|
[![Travis CI](https://travis-ci.com/AndyObtiva/glimmer-dsl-swt.svg?branch=master)](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-swt)
|
@@ -460,7 +460,7 @@ jgem install glimmer-dsl-swt
|
|
460
460
|
|
461
461
|
Or this command if you want a specific version:
|
462
462
|
```
|
463
|
-
jgem install glimmer-dsl-swt -v 4.18.3.
|
463
|
+
jgem install glimmer-dsl-swt -v 4.18.3.1
|
464
464
|
|
465
465
|
|
466
466
|
```
|
@@ -480,7 +480,7 @@ Note: if you're using activerecord or activesupport, keep in mind that Glimmer u
|
|
480
480
|
|
481
481
|
Add the following to `Gemfile`:
|
482
482
|
```
|
483
|
-
gem 'glimmer-dsl-swt', '~> 4.18.3.
|
483
|
+
gem 'glimmer-dsl-swt', '~> 4.18.3.1
|
484
484
|
'
|
485
485
|
```
|
486
486
|
|
@@ -539,7 +539,7 @@ bin/glimmer samples
|
|
539
539
|
Below are the full usage instructions that come up when running `glimmer` without args.
|
540
540
|
|
541
541
|
```
|
542
|
-
Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.18.3.
|
542
|
+
Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.18.3.1
|
543
543
|
|
544
544
|
|
545
545
|
|
@@ -1020,7 +1020,7 @@ Output:
|
|
1020
1020
|
|
1021
1021
|
Css glimmer-dsl-css 1.1.0 AndyMaleh Glimmer DSL for CSS
|
1022
1022
|
Opal glimmer-dsl-opal 0.10.2 AndyMaleh Glimmer DSL for Opal
|
1023
|
-
Swt glimmer-dsl-swt 4.18.3.
|
1023
|
+
Swt glimmer-dsl-swt 4.18.3.1
|
1024
1024
|
|
1025
1025
|
AndyMaleh Glimmer DSL for SWT
|
1026
1026
|
Tk glimmer-dsl-tk 0.0.6 AndyMaleh Glimmer DSL for Tk
|
@@ -2500,6 +2500,8 @@ When using a transform at the top-level (outside of shell), you get a fluent int
|
|
2500
2500
|
Example:
|
2501
2501
|
|
2502
2502
|
```ruby
|
2503
|
+
include Glimmer # make sure it is included in your class/module before using the fluent interface
|
2504
|
+
|
2503
2505
|
transform(1, 1, 4, 2, 2, 4).
|
2504
2506
|
multiply(1, 2, 3, 4,3,4).
|
2505
2507
|
scale(1, 2, 3, 4, 5, 6).
|
@@ -3774,6 +3776,41 @@ shell(:no_resize) {
|
|
3774
3776
|
|
3775
3777
|
Also, you may invoke `Display.app_version = '1.0.0'` if needed for OS app version identification reasons during development, replacing `'1.0.0'` with your application version.
|
3776
3778
|
|
3779
|
+
#### Performance Profiling
|
3780
|
+
|
3781
|
+
JRuby comes with built-in support for performance profiling via the `--profile` option (with some code shown below), which can be accepted by the `glimmer` command too:
|
3782
|
+
|
3783
|
+
`glimmer --profile path_to_glimmer_app.rb`
|
3784
|
+
|
3785
|
+
Additionally, add this code to monitor Glimmer app performance around its launch method:
|
3786
|
+
|
3787
|
+
```ruby
|
3788
|
+
require 'jruby/profiler'
|
3789
|
+
profile_data = JRuby::Profiler.profile do
|
3790
|
+
SomeGlimmerApp.launch
|
3791
|
+
end
|
3792
|
+
|
3793
|
+
profile_printer = JRuby::Profiler::HtmlProfilePrinter.new(profile_data)
|
3794
|
+
ps = java.io.PrintStream.new(STDOUT.to_outputstream)
|
3795
|
+
```
|
3796
|
+
|
3797
|
+
When monitoring app startup time performance, make sure to add a hook to the top-level `shell` `on_swt_show` event that exits the app as soon as the shell shows up to end performance profiling and get the results.
|
3798
|
+
|
3799
|
+
Example:
|
3800
|
+
|
3801
|
+
```ruby
|
3802
|
+
shell {
|
3803
|
+
# some code
|
3804
|
+
on_swt_show {
|
3805
|
+
exit(0)
|
3806
|
+
}
|
3807
|
+
}
|
3808
|
+
```
|
3809
|
+
|
3810
|
+
You may run `glimmer` with the `--profile.graph` instead for a more detailed output.
|
3811
|
+
|
3812
|
+
Learn more at the [JRuby Performance Profile WIKI page](https://github.com/jruby/jruby/wiki/Profiling-JRuby).
|
3813
|
+
|
3777
3814
|
#### Checkbox Group Widget
|
3778
3815
|
|
3779
3816
|
`checkbox_group` (or alias `check_group`) is a Glimmer built-in custom widget that displays a list of `checkbox` buttons (`button(:check)`) based on its `items` property.
|
@@ -4187,6 +4224,12 @@ This brings up the [Glimmer Meta-Sample (The Sample of Samples)](samples/elabora
|
|
4187
4224
|
|
4188
4225
|
You may edit the code of any sample before launching it by clicking on the "Launch" button. This helps you learn by experimenting with Glimmer GUI DSL syntax. To go back to original code, simply hit the "Reset" button.
|
4189
4226
|
|
4227
|
+
Note that if you fail to run any sample through the Glimmer Meta-Sample for whatever reason, you could always run directly by cloning the project, running `bundle`, and then this command (drop the "bin" if you install the glimmer-dsl-swt gem instead):
|
4228
|
+
|
4229
|
+
```ruby
|
4230
|
+
bin/glimmer samples/hello/hello_canvas_transform.rb
|
4231
|
+
```
|
4232
|
+
|
4190
4233
|
### Hello Samples
|
4191
4234
|
|
4192
4235
|
For hello-type simple samples, check the following.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
4.18.3.
|
1
|
+
4.18.3.1
|
data/glimmer-dsl-swt.gemspec
CHANGED
@@ -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.18.3.
|
5
|
+
# stub: glimmer-dsl-swt 4.18.3.1 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "glimmer-dsl-swt".freeze
|
9
|
-
s.version = "4.18.3.
|
9
|
+
s.version = "4.18.3.1"
|
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 = "2021-01-
|
14
|
+
s.date = "2021-01-27"
|
15
15
|
s.description = "Glimmer DSL for SWT (JRuby Desktop Development GUI Framework) is a native-GUI cross-platform desktop development library written in JRuby, an OS-threaded faster JVM version of Ruby. Glimmer's main innovation is a declarative Ruby DSL that enables productive and efficient authoring of desktop application user-interfaces by relying on the robust Eclipse SWT library. Glimmer additionally innovates by having built-in data-binding support, which greatly facilitates synchronizing the GUI with domain models, thus achieving true decoupling of object oriented components and enabling developers to solve business problems (test-first) without worrying about GUI concerns, or alternatively drive development GUI-first, and then write clean business models (test-first) afterwards. Not only does Glimmer provide a large set of GUI widgets, but it also supports drawing Canvas Graphics like Shapes and Animations. To get started quickly, Glimmer offers scaffolding options for Apps, Gems, and Custom Widgets. Glimmer also includes native-executable packaging support, sorely lacking in other libraries, thus enabling the delivery of desktop apps written in Ruby as truly native DMG/PKG/APP files on the Mac + App Store, MSI/EXE files on Windows, and Gem Packaged Shell Scripts on Linux.".freeze
|
16
16
|
s.email = "andy.am@gmail.com".freeze
|
17
17
|
s.executables = ["glimmer".freeze, "girb".freeze]
|
@@ -143,6 +143,7 @@ Gem::Specification.new do |s|
|
|
143
143
|
"samples/elaborate/tetris/view/game_over_dialog.rb",
|
144
144
|
"samples/elaborate/tetris/view/playfield.rb",
|
145
145
|
"samples/elaborate/tetris/view/score_lane.rb",
|
146
|
+
"samples/elaborate/tetris/view/tetris_menu_bar.rb",
|
146
147
|
"samples/elaborate/tic_tac_toe.rb",
|
147
148
|
"samples/elaborate/tic_tac_toe/board.rb",
|
148
149
|
"samples/elaborate/tic_tac_toe/cell.rb",
|
@@ -194,7 +195,7 @@ Gem::Specification.new do |s|
|
|
194
195
|
s.specification_version = 4
|
195
196
|
|
196
197
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
197
|
-
s.add_runtime_dependency(%q<glimmer>.freeze, ["~> 1.0.
|
198
|
+
s.add_runtime_dependency(%q<glimmer>.freeze, ["~> 1.0.11"])
|
198
199
|
s.add_runtime_dependency(%q<super_module>.freeze, [">= 1.4.1", "< 2.0.0"])
|
199
200
|
s.add_runtime_dependency(%q<nested_inherited_jruby_include_package>.freeze, [">= 0.3.0", "< 2.0.0"])
|
200
201
|
s.add_runtime_dependency(%q<puts_debuggerer>.freeze, [">= 0.11.0", "< 2.0.0"])
|
@@ -213,7 +214,7 @@ Gem::Specification.new do |s|
|
|
213
214
|
s.add_development_dependency(%q<simplecov>.freeze, ["~> 0.16.1"])
|
214
215
|
s.add_development_dependency(%q<simplecov-lcov>.freeze, ["~> 0.7.0"])
|
215
216
|
else
|
216
|
-
s.add_dependency(%q<glimmer>.freeze, ["~> 1.0.
|
217
|
+
s.add_dependency(%q<glimmer>.freeze, ["~> 1.0.11"])
|
217
218
|
s.add_dependency(%q<super_module>.freeze, [">= 1.4.1", "< 2.0.0"])
|
218
219
|
s.add_dependency(%q<nested_inherited_jruby_include_package>.freeze, [">= 0.3.0", "< 2.0.0"])
|
219
220
|
s.add_dependency(%q<puts_debuggerer>.freeze, [">= 0.11.0", "< 2.0.0"])
|
@@ -233,7 +234,7 @@ Gem::Specification.new do |s|
|
|
233
234
|
s.add_dependency(%q<simplecov-lcov>.freeze, ["~> 0.7.0"])
|
234
235
|
end
|
235
236
|
else
|
236
|
-
s.add_dependency(%q<glimmer>.freeze, ["~> 1.0.
|
237
|
+
s.add_dependency(%q<glimmer>.freeze, ["~> 1.0.11"])
|
237
238
|
s.add_dependency(%q<super_module>.freeze, [">= 1.4.1", "< 2.0.0"])
|
238
239
|
s.add_dependency(%q<nested_inherited_jruby_include_package>.freeze, [">= 0.3.0", "< 2.0.0"])
|
239
240
|
s.add_dependency(%q<puts_debuggerer>.freeze, [">= 0.11.0", "< 2.0.0"])
|
data/lib/ext/glimmer/config.rb
CHANGED
@@ -32,6 +32,8 @@ module Glimmer
|
|
32
32
|
'org.eclipse.swt.custom',
|
33
33
|
'org.eclipse.swt.dnd',
|
34
34
|
]
|
35
|
+
DEFAULT_AUTO_SYNC_EXEC = false
|
36
|
+
GUI_THREAD = Thread.current
|
35
37
|
|
36
38
|
class << self
|
37
39
|
# Tells Glimmer to import SWT packages into including class (default: true)
|
@@ -45,6 +47,22 @@ module Glimmer
|
|
45
47
|
@@import_swt_packages
|
46
48
|
end
|
47
49
|
|
50
|
+
# Tells Glimmer to avoid automatic use of sync_exec when invoking GUI calls from another thread (default: true)
|
51
|
+
def auto_sync_exec=(value)
|
52
|
+
@@auto_sync_exec = value
|
53
|
+
end
|
54
|
+
|
55
|
+
# Returns whether Glimmer will import SWT packages into including class
|
56
|
+
def auto_sync_exec
|
57
|
+
@@auto_sync_exec = DEFAULT_AUTO_SYNC_EXEC if !defined?(@@auto_sync_exec)
|
58
|
+
@@auto_sync_exec
|
59
|
+
end
|
60
|
+
alias auto_sync_exec? auto_sync_exec
|
61
|
+
|
62
|
+
def require_sync_exec?
|
63
|
+
Thread.current != GUI_THREAD
|
64
|
+
end
|
65
|
+
|
48
66
|
# Returns Logging Devices. Default is [:stdout, :syslog]
|
49
67
|
def logging_devices
|
50
68
|
unless defined? @@logging_devices
|
@@ -140,11 +158,10 @@ end
|
|
140
158
|
|
141
159
|
Glimmer::Config.excluded_keyword_checkers << lambda do |method_symbol, *args|
|
142
160
|
method = method_symbol.to_s
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
result ||= ['finish_edit!', 'search', 'all_tree_items', 'depth_first_search'].include?(method) && is_a?(Glimmer::UI::CustomWidget) && body_root.respond_to?(method)
|
161
|
+
return true if method == 'post_initialize_child'
|
162
|
+
return true if method == 'handle'
|
163
|
+
return true if method.end_with?('=')
|
164
|
+
return true if ['drag_source_proxy', 'drop_target_proxy'].include?(method) && is_a?(Glimmer::UI::CustomWidget)
|
165
|
+
return true if method == 'dispose' && is_a?(Glimmer::UI::CustomWidget) && respond_to?(method)
|
166
|
+
return true if ['finish_edit!', 'search', 'all_tree_items', 'depth_first_search'].include?(method) && is_a?(Glimmer::UI::CustomWidget) && body_root.respond_to?(method)
|
150
167
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Copyright (c) 2007-2021 Andy Maleh
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
# a copy of this software and associated documentation files (the
|
5
5
|
# "Software"), to deal in the Software without restriction, including
|
@@ -7,10 +7,10 @@
|
|
7
7
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
8
|
# permit persons to whom the Software is furnished to do so, subject to
|
9
9
|
# the following conditions:
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# The above copyright notice and this permission notice shall be
|
12
12
|
# included in all copies or substantial portions of the Software.
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
15
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
16
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
@@ -22,6 +22,8 @@
|
|
22
22
|
require 'glimmer/data_binding/observable'
|
23
23
|
require 'glimmer/data_binding/observer'
|
24
24
|
|
25
|
+
require 'glimmer/swt/display_proxy'
|
26
|
+
|
25
27
|
module Glimmer
|
26
28
|
module DataBinding
|
27
29
|
class WidgetBinding
|
@@ -44,7 +46,15 @@ module Glimmer
|
|
44
46
|
|
45
47
|
def call(value)
|
46
48
|
converted_value = translated_value = @translator.call(value)
|
47
|
-
|
49
|
+
|
50
|
+
update_operation = lambda do
|
51
|
+
@widget.set_attribute(@property, converted_value) unless evaluate_property == converted_value
|
52
|
+
end
|
53
|
+
if Config.auto_sync_exec? && Config.require_sync_exec?
|
54
|
+
SWT::DisplayProxy.instance.sync_exec(&update_operation)
|
55
|
+
else
|
56
|
+
update_operation.call
|
57
|
+
end
|
48
58
|
end
|
49
59
|
|
50
60
|
def evaluate_property
|
@@ -193,7 +193,7 @@ module Glimmer
|
|
193
193
|
|
194
194
|
def set_attribute(attribute_name, *args)
|
195
195
|
@properties[attribute_name] = args
|
196
|
-
if @content_added
|
196
|
+
if @content_added && !@parent.is_disposed
|
197
197
|
@parent.resetup_shape_paint_listeners
|
198
198
|
@parent.redraw
|
199
199
|
end
|
@@ -204,9 +204,10 @@ module Glimmer
|
|
204
204
|
end
|
205
205
|
|
206
206
|
def setup_paint_listener
|
207
|
+
return if @parent.is_disposed
|
207
208
|
if parent.respond_to?(:swt_display)
|
208
209
|
@paint_listener_proxy = @parent.on_swt_paint(&method(:paint))
|
209
|
-
|
210
|
+
elsif parent.respond_to?(:swt_widget)
|
210
211
|
@paint_listener_proxy = @parent.on_paint_control(&method(:paint))
|
211
212
|
end
|
212
213
|
end
|
@@ -47,13 +47,13 @@ module Glimmer
|
|
47
47
|
style_arg_last_index = args.index(style_args.last)
|
48
48
|
args[style_arg_start_index..style_arg_last_index] = SWTProxy[style_args]
|
49
49
|
end
|
50
|
+
if args.first.respond_to?(:swt_widget) && args.first.swt_widget.is_a?(Shell)
|
51
|
+
args[0] = args[0].swt_widget
|
52
|
+
end
|
50
53
|
if !args.first.is_a?(Shell)
|
51
54
|
current_shell = DisplayProxy.instance.swt_display.shells.first
|
52
55
|
args.unshift(current_shell.nil? ? ShellProxy.new : current_shell)
|
53
56
|
end
|
54
|
-
if args.first.is_a?(ShellProxy)
|
55
|
-
args[0] = args[0].swt_widget
|
56
|
-
end
|
57
57
|
parent = args[0]
|
58
58
|
@parent_proxy = parent.is_a?(Shell) ? ShellProxy.new(swt_widget: parent) : parent
|
59
59
|
@swt_widget = DirectoryDialog.new(*args)
|
@@ -39,8 +39,20 @@ module Glimmer
|
|
39
39
|
include_package 'org.eclipse.swt.widgets'
|
40
40
|
|
41
41
|
include Custom::Drawable
|
42
|
-
|
42
|
+
|
43
43
|
OBSERVED_MENU_ITEMS = ['about', 'preferences']
|
44
|
+
|
45
|
+
class FilterListener
|
46
|
+
include org.eclipse.swt.widgets.Listener
|
47
|
+
|
48
|
+
def initialize(&listener_block)
|
49
|
+
@listener_block = listener_block
|
50
|
+
end
|
51
|
+
|
52
|
+
def handleEvent(event)
|
53
|
+
@listener_block.call(event)
|
54
|
+
end
|
55
|
+
end
|
44
56
|
|
45
57
|
class << self
|
46
58
|
# Returns singleton instance
|
@@ -111,7 +123,7 @@ module Glimmer
|
|
111
123
|
observation_request = observation_request.to_s
|
112
124
|
if observation_request.start_with?('on_swt_')
|
113
125
|
constant_name = observation_request.sub(/^on_swt_/, '')
|
114
|
-
|
126
|
+
add_swt_event_filter(constant_name, &block)
|
115
127
|
elsif observation_request.start_with?('on_')
|
116
128
|
event_name = observation_request.sub(/^on_/, '')
|
117
129
|
if OBSERVED_MENU_ITEMS.include?(event_name)
|
@@ -124,10 +136,19 @@ module Glimmer
|
|
124
136
|
end
|
125
137
|
end
|
126
138
|
|
127
|
-
def
|
139
|
+
def add_swt_event_filter(swt_constant, &block)
|
128
140
|
event_type = SWTProxy[swt_constant]
|
129
|
-
@swt_display.addFilter(event_type, &block)
|
141
|
+
@swt_display.addFilter(event_type, FilterListener.new(&block))
|
130
142
|
#WidgetListenerProxy.new(@swt_display.getListeners(event_type).last)
|
143
|
+
WidgetListenerProxy.new(
|
144
|
+
swt_display: @swt_display,
|
145
|
+
event_type: event_type,
|
146
|
+
filter: true,
|
147
|
+
swt_listener: block,
|
148
|
+
widget_add_listener_method: 'addFilter',
|
149
|
+
swt_listener_class: FilterListener,
|
150
|
+
swt_listener_method: 'handleEvent'
|
151
|
+
)
|
131
152
|
end
|
132
153
|
end
|
133
154
|
end
|
@@ -48,13 +48,13 @@ module Glimmer
|
|
48
48
|
style_arg_last_index = args.index(style_args.last)
|
49
49
|
args[style_arg_start_index..style_arg_last_index] = SWTProxy[style_args]
|
50
50
|
end
|
51
|
+
if args.first.respond_to?(:swt_widget) && args.first.swt_widget.is_a?(Shell)
|
52
|
+
args[0] = args[0].swt_widget
|
53
|
+
end
|
51
54
|
if !args.first.is_a?(Shell)
|
52
55
|
current_shell = DisplayProxy.instance.swt_display.shells.first
|
53
56
|
args.unshift(current_shell.nil? ? ShellProxy.new : current_shell)
|
54
57
|
end
|
55
|
-
if args.first.is_a?(ShellProxy)
|
56
|
-
args[0] = args[0].swt_widget
|
57
|
-
end
|
58
58
|
parent = args[0]
|
59
59
|
@parent_proxy = parent.is_a?(Shell) ? ShellProxy.new(swt_widget: parent) : parent
|
60
60
|
@swt_widget = FileDialog.new(*args)
|
@@ -45,11 +45,17 @@ module Glimmer
|
|
45
45
|
if swt_widget
|
46
46
|
@swt_widget = swt_widget
|
47
47
|
else
|
48
|
-
if args.first.is_a?(
|
48
|
+
if args.first.respond_to?(:swt_widget) && args.first.swt_widget.is_a?(Shell)
|
49
49
|
@parent_proxy = args[0]
|
50
50
|
args[0] = args[0].swt_widget
|
51
51
|
end
|
52
|
-
style_args = args.select {|arg| arg.is_a?(Symbol) || arg.is_a?(String)}
|
52
|
+
style_args = args.select {|arg| arg.is_a?(Symbol) || arg.is_a?(String)}.map(&:to_sym)
|
53
|
+
fill_screen = nil
|
54
|
+
if style_args.include?(:fill_screen)
|
55
|
+
args.delete(:fill_screen)
|
56
|
+
style_args.delete(:fill_screen)
|
57
|
+
fill_screen = true
|
58
|
+
end
|
53
59
|
if style_args.any?
|
54
60
|
style_arg_start_index = args.index(style_args.first)
|
55
61
|
style_arg_last_index = args.index(style_args.last)
|
@@ -67,6 +73,7 @@ module Glimmer
|
|
67
73
|
# TODO make this an option not the default
|
68
74
|
shell_swt_display = Glimmer::SWT::DisplayProxy.instance.swt_display
|
69
75
|
on_swt_show do
|
76
|
+
@swt_widget.set_size(@display.bounds.width, @display.bounds.height) if fill_screen
|
70
77
|
Thread.new do
|
71
78
|
sleep(0.25)
|
72
79
|
shell_swt_display.async_exec do
|
@@ -110,6 +117,10 @@ module Glimmer
|
|
110
117
|
def nested?
|
111
118
|
!swt_widget&.parent.nil?
|
112
119
|
end
|
120
|
+
|
121
|
+
def disposed?
|
122
|
+
swt_widget.isDisposed
|
123
|
+
end
|
113
124
|
|
114
125
|
def hide
|
115
126
|
@swt_widget.setVisible(false)
|
@@ -26,10 +26,12 @@ module Glimmer
|
|
26
26
|
# Follows the Proxy Design Pattern
|
27
27
|
class WidgetListenerProxy
|
28
28
|
|
29
|
-
attr_reader :swt_widget, :swt_listener, :widget_add_listener_method, :swt_listener_class, :swt_listener_method, :event_type, :swt_constant
|
29
|
+
attr_reader :swt_widget, :swt_display, :swt_listener, :widget_add_listener_method, :swt_listener_class, :swt_listener_method, :event_type, :swt_constant
|
30
30
|
|
31
|
-
def initialize(swt_widget
|
31
|
+
def initialize(swt_widget:nil, swt_display:nil, swt_listener:, widget_add_listener_method: nil, swt_listener_class: nil, swt_listener_method: nil, event_type: nil, swt_constant: nil, filter: false)
|
32
32
|
@swt_widget = swt_widget
|
33
|
+
@swt_display = swt_display
|
34
|
+
@filter = filter
|
33
35
|
@swt_listener = swt_listener
|
34
36
|
@widget_add_listener_method = widget_add_listener_method
|
35
37
|
@swt_listener_class = swt_listener_class
|
@@ -42,14 +44,21 @@ module Glimmer
|
|
42
44
|
@widget_add_listener_method.sub('add', 'remove')
|
43
45
|
end
|
44
46
|
|
45
|
-
def
|
46
|
-
|
47
|
-
if @
|
47
|
+
def deregister
|
48
|
+
return if @swt_widget&.is_disposed || @swt_display&.is_disposed
|
49
|
+
if @swt_display
|
50
|
+
if @filter
|
51
|
+
@swt_display.removeFilter(@event_type, @swt_listener)
|
52
|
+
else
|
53
|
+
@swt_display.removeListener(@event_type, @swt_listener)
|
54
|
+
end
|
55
|
+
elsif @event_type
|
48
56
|
@swt_widget.removeListener(@event_type, @swt_listener)
|
49
57
|
else
|
50
58
|
@swt_widget.send(widget_remove_listener_method, @swt_listener)
|
51
59
|
end
|
52
60
|
end
|
61
|
+
alias unregister deregister # TODO consider dropping unregister (and in Observer too)
|
53
62
|
end
|
54
63
|
end
|
55
64
|
end
|