glimmer-dsl-swt 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/VERSION +1 -1
- data/lib/glimmer/swt/shell_proxy.rb +5 -1
- data/lib/glimmer/swt/table_column_proxy.rb +5 -1
- data/lib/glimmer/swt/table_proxy.rb +122 -52
- data/lib/glimmer/swt/widget_proxy.rb +1 -1
- data/lib/glimmer/ui/custom_widget.rb +10 -10
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce119763646f3e3ccc0211534317572ed02c5d21b9820387dec34d83b714e50f
|
4
|
+
data.tar.gz: 1c4486c574ab3e8d30957133b9aab200dcfbdea10ea1c4aa0279a4991f80a0dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cea6c2e7ac8920d4ae87e447f08c7a622fc8851827b76160dc07b36d8c725911bf94a772aa5f47e43465a24961f7dc38b1d974a164ec3704d159dee61deb7712
|
7
|
+
data.tar.gz: 8efbb95213218c052cbcc8165dc2305c41f26a42f1a374ba05fd9b5912c3a79bfbb99522a524c8cc0fa88b128c471ab22e03fb75a750b7dd31708617b4c6b4cf
|
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 /> Glimmer DSL for SWT 0.3.
|
1
|
+
# <img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 /> Glimmer DSL for SWT 0.3.1 (Desktop GUI)
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/glimmer-dsl-swt.svg)](http://badge.fury.io/rb/glimmer-dsl-swt)
|
3
3
|
[![Travis CI](https://travis-ci.com/AndyObtiva/glimmer-dsl-swt.svg?branch=master)](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-swt)
|
4
4
|
[![Coverage Status](https://coveralls.io/repos/github/AndyObtiva/glimmer-dsl-swt/badge.svg?branch=master)](https://coveralls.io/github/AndyObtiva/glimmer-dsl-swt?branch=master)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
@@ -130,7 +130,11 @@ module Glimmer
|
|
130
130
|
# This method is not needed except in rare circumstances where there is a need to start the SWT Event Loop before opening the shell.
|
131
131
|
def start_event_loop
|
132
132
|
until @swt_widget.isDisposed
|
133
|
-
|
133
|
+
begin
|
134
|
+
@display.sleep unless @display.readAndDispatch
|
135
|
+
rescue => e
|
136
|
+
Glimmer::Config.logger&.debug e.full_message
|
137
|
+
end
|
134
138
|
end
|
135
139
|
end
|
136
140
|
|
@@ -3,7 +3,7 @@ require 'glimmer/swt/widget_proxy'
|
|
3
3
|
module Glimmer
|
4
4
|
module SWT
|
5
5
|
class TableColumnProxy < Glimmer::SWT::WidgetProxy
|
6
|
-
attr_reader :no_sort, :sort_property
|
6
|
+
attr_reader :no_sort, :sort_property, :editor
|
7
7
|
alias no_sort? no_sort
|
8
8
|
attr_accessor :sort_block, :sort_by_block
|
9
9
|
|
@@ -19,6 +19,10 @@ module Glimmer
|
|
19
19
|
@sort_property = args unless args.empty?
|
20
20
|
end
|
21
21
|
|
22
|
+
def editor=(args)
|
23
|
+
@editor = args
|
24
|
+
end
|
25
|
+
|
22
26
|
end
|
23
27
|
end
|
24
28
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require 'glimmer/swt/widget_proxy'
|
2
2
|
|
3
3
|
module Glimmer
|
4
4
|
module SWT
|
@@ -23,8 +23,8 @@ module Glimmer
|
|
23
23
|
def find_table_item_and_column_index
|
24
24
|
{}.tap do |result|
|
25
25
|
if respond_to?(:x) && respond_to?(:y)
|
26
|
-
result[:table_item] = widget.
|
27
|
-
result[:column_index] = widget.
|
26
|
+
result[:table_item] = widget.items.detect do |ti|
|
27
|
+
result[:column_index] = widget.column_count.times.to_a.detect do |ci|
|
28
28
|
ti.getBounds(ci).contains(x, y)
|
29
29
|
end
|
30
30
|
end
|
@@ -33,7 +33,61 @@ module Glimmer
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
|
36
|
+
class << self
|
37
|
+
def editors
|
38
|
+
@editors ||= {
|
39
|
+
text: {
|
40
|
+
widget_value_property: :text,
|
41
|
+
editor_gui: lambda do |args, model, property, table_proxy|
|
42
|
+
table_proxy.table_editor.minimumHeight = 20
|
43
|
+
table_editor_widget_proxy = text(*args) {
|
44
|
+
text model.send(property)
|
45
|
+
focus true
|
46
|
+
on_focus_lost {
|
47
|
+
table_proxy.finish_edit!
|
48
|
+
}
|
49
|
+
on_key_pressed { |key_event|
|
50
|
+
if key_event.keyCode == swt(:cr)
|
51
|
+
table_proxy.finish_edit!
|
52
|
+
elsif key_event.keyCode == swt(:esc)
|
53
|
+
table_proxy.cancel_edit!
|
54
|
+
end
|
55
|
+
}
|
56
|
+
}
|
57
|
+
table_editor_widget_proxy.swt_widget.selectAll
|
58
|
+
table_editor_widget_proxy
|
59
|
+
end,
|
60
|
+
},
|
61
|
+
combo: {
|
62
|
+
widget_value_property: :text,
|
63
|
+
editor_gui: lambda do |args, model, property, table_proxy|
|
64
|
+
table_proxy.table_editor.minimumHeight = 25
|
65
|
+
table_editor_widget_proxy = combo(*args) {
|
66
|
+
items model.send("#{property}_options")
|
67
|
+
text model.send(property)
|
68
|
+
focus true
|
69
|
+
on_focus_lost {
|
70
|
+
table_proxy.finish_edit!
|
71
|
+
}
|
72
|
+
on_key_pressed { |key_event|
|
73
|
+
if key_event.keyCode == swt(:cr)
|
74
|
+
table_proxy.finish_edit!
|
75
|
+
elsif key_event.keyCode == swt(:esc)
|
76
|
+
table_proxy.cancel_edit!
|
77
|
+
end
|
78
|
+
}
|
79
|
+
on_widget_selected {
|
80
|
+
table_proxy.finish_edit!
|
81
|
+
}
|
82
|
+
}
|
83
|
+
table_editor_widget_proxy
|
84
|
+
end,
|
85
|
+
}
|
86
|
+
}
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
attr_reader :table_editor, :table_editor_text_proxy, :table_editor_widget_proxy, :sort_property, :sort_direction, :sort_block, :sort_type, :sort_by_block, :additional_sort_properties, :editor
|
37
91
|
attr_accessor :column_properties
|
38
92
|
|
39
93
|
def initialize(underscored_widget_name, parent, args)
|
@@ -46,7 +100,7 @@ module Glimmer
|
|
46
100
|
|
47
101
|
def model_binding
|
48
102
|
swt_widget.data
|
49
|
-
end
|
103
|
+
end
|
50
104
|
|
51
105
|
def sort_by_column(table_column_proxy)
|
52
106
|
index = swt_widget.columns.to_a.index(table_column_proxy.swt_widget)
|
@@ -100,6 +154,10 @@ module Glimmer
|
|
100
154
|
@additional_sort_properties = args unless args.empty?
|
101
155
|
end
|
102
156
|
|
157
|
+
def editor=(args)
|
158
|
+
@editor = args
|
159
|
+
end
|
160
|
+
|
103
161
|
def sort
|
104
162
|
return unless sort_property && (sort_type || sort_block || sort_by_block)
|
105
163
|
array = model_binding.evaluate_property
|
@@ -152,6 +210,14 @@ module Glimmer
|
|
152
210
|
})
|
153
211
|
end
|
154
212
|
|
213
|
+
def post_initialize_child(table_column_proxy)
|
214
|
+
table_column_proxies << table_column_proxy
|
215
|
+
end
|
216
|
+
|
217
|
+
def table_column_proxies
|
218
|
+
@table_column_proxies ||= []
|
219
|
+
end
|
220
|
+
|
155
221
|
# Indicates if table is in edit mode, thus displaying a text widget for a table item cell
|
156
222
|
def edit_mode?
|
157
223
|
!!@edit_mode
|
@@ -177,58 +243,62 @@ module Glimmer
|
|
177
243
|
|
178
244
|
def edit_table_item(table_item, column_index, before_write: nil, after_write: nil, after_cancel: nil)
|
179
245
|
return if table_item.nil?
|
246
|
+
model = table_item.data
|
247
|
+
property = column_properties[column_index]
|
180
248
|
@cancel_edit&.call if @edit_mode
|
249
|
+
action_taken = false
|
181
250
|
@edit_mode = true
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
251
|
+
|
252
|
+
editor_config = table_column_proxies[column_index].editor || editor
|
253
|
+
editor_config = editor_config.to_a
|
254
|
+
editor_widget_options = editor_config.last.is_a?(Hash) ? editor_config.last : {}
|
255
|
+
editor_widget_arg_last_index = editor_config.last.is_a?(Hash) ? -2 : -1
|
256
|
+
editor_widget = editor_config[0] || :text
|
257
|
+
editor_widget_args = editor_config[1..editor_widget_arg_last_index]
|
258
|
+
model_editing_property = editor_widget_options[:property] || property
|
259
|
+
widget_value_property = TableProxy::editors[editor_widget][:widget_value_property]
|
260
|
+
|
261
|
+
@cancel_edit = lambda do |event=nil|
|
262
|
+
@cancel_in_progress = true
|
263
|
+
@table_editor_widget_proxy&.swt_widget&.dispose
|
264
|
+
@table_editor_widget_proxy = nil
|
265
|
+
after_cancel&.call
|
266
|
+
@edit_in_progress = false
|
267
|
+
@cancel_in_progress = false
|
268
|
+
@cancel_edit = nil
|
269
|
+
@edit_mode = false
|
270
|
+
end
|
271
|
+
|
272
|
+
@finish_edit = lambda do |event=nil|
|
273
|
+
new_value = @table_editor_widget_proxy&.swt_widget&.send(widget_value_property)
|
274
|
+
if table_item.isDisposed
|
275
|
+
@cancel_edit.call
|
276
|
+
elsif new_value && !action_taken && !@edit_in_progress && !@cancel_in_progress
|
277
|
+
action_taken = true
|
278
|
+
@edit_in_progress = true
|
279
|
+
if new_value == model.send(model_editing_property)
|
280
|
+
@cancel_edit.call
|
281
|
+
else
|
282
|
+
before_write&.call
|
283
|
+
model.send("#{model_editing_property}=", new_value) # makes table update itself, so must search for selected table item again
|
284
|
+
# Table refresh happens here because of model update triggering observers, so must retrieve table item again
|
285
|
+
edited_table_item = search { |ti| ti.getData == model }.first
|
286
|
+
swt_widget.showItem(edited_table_item)
|
287
|
+
@table_editor_widget_proxy&.swt_widget&.dispose
|
288
|
+
@table_editor_widget_proxy = nil
|
289
|
+
after_write&.call(edited_table_item)
|
192
290
|
@edit_in_progress = false
|
193
|
-
@cancel_in_progress = false
|
194
|
-
@cancel_edit = nil
|
195
|
-
@edit_mode = false
|
196
|
-
end
|
197
|
-
@finish_edit = lambda do |event=nil|
|
198
|
-
if table_item.isDisposed
|
199
|
-
@cancel_edit.call
|
200
|
-
elsif !action_taken && !@edit_in_progress && !@cancel_in_progress
|
201
|
-
action_taken = true
|
202
|
-
@edit_in_progress = true
|
203
|
-
new_text = @table_editor_text_proxy.swt_widget.getText
|
204
|
-
if new_text == table_item.getText(column_index)
|
205
|
-
@cancel_edit.call
|
206
|
-
else
|
207
|
-
before_write&.call
|
208
|
-
table_item.setText(column_index, new_text)
|
209
|
-
model = table_item.getData
|
210
|
-
model.send("#{column_properties[column_index]}=", new_text) # makes table update itself, so must search for selected table item again
|
211
|
-
edited_table_item = search { |ti| ti.getData == model }.first
|
212
|
-
swt_widget.showItem(edited_table_item)
|
213
|
-
@table_editor_text_proxy&.swt_widget&.dispose
|
214
|
-
@table_editor_text_proxy = nil
|
215
|
-
after_write&.call(edited_table_item)
|
216
|
-
@edit_in_progress = false
|
217
|
-
end
|
218
|
-
end
|
219
291
|
end
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
@cancel_edit.call
|
226
|
-
end
|
227
|
-
}
|
228
|
-
}
|
229
|
-
@table_editor_text_proxy.swt_widget.selectAll
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
content {
|
296
|
+
@table_editor_widget_proxy = @table_editor_text_proxy = TableProxy::editors[editor_widget][:editor_gui].call(editor_widget_args, model, model_editing_property, self)
|
230
297
|
}
|
231
|
-
@table_editor.setEditor(@
|
298
|
+
@table_editor.setEditor(@table_editor_widget_proxy.swt_widget, table_item, column_index)
|
299
|
+
rescue => e
|
300
|
+
Glimmer::Config.logger&.error e.full_message
|
301
|
+
raise e
|
232
302
|
end
|
233
303
|
|
234
304
|
def add_listener(underscored_listener_name, &block)
|
@@ -271,7 +271,7 @@ module Glimmer
|
|
271
271
|
return nil
|
272
272
|
end
|
273
273
|
swt_widget_class
|
274
|
-
rescue NameError => e
|
274
|
+
rescue SyntaxError, NameError => e
|
275
275
|
Glimmer::Config.logger&.debug e.full_message
|
276
276
|
# Glimmer::Config.logger&.debug("#{e.message}\n#{e.backtrace.join("\n")}")
|
277
277
|
nil
|
@@ -138,12 +138,8 @@ module Glimmer
|
|
138
138
|
@swt_widget = @body_root.swt_widget
|
139
139
|
end
|
140
140
|
|
141
|
-
# Subclasses may override to perform post initialization work on an added child
|
142
|
-
def post_initialize_child(child)
|
143
|
-
body_root.post_initialize_child(child)
|
144
|
-
end
|
145
|
-
|
146
141
|
def can_handle_observation_request?(observation_request)
|
142
|
+
observation_request = observation_request.to_s
|
147
143
|
result = false
|
148
144
|
if observation_request.start_with?('on_updated_')
|
149
145
|
property = observation_request.sub(/^on_updated_/, '')
|
@@ -153,6 +149,7 @@ module Glimmer
|
|
153
149
|
end
|
154
150
|
|
155
151
|
def handle_observation_request(observation_request, &block)
|
152
|
+
observation_request = observation_request.to_s
|
156
153
|
if observation_request.start_with?('on_updated_')
|
157
154
|
property = observation_request.sub(/^on_updated_/, '') # TODO look into eliminating duplication from above
|
158
155
|
add_observer(DataBinding::Observer.proc(&block), property) if can_add_observer?(property)
|
@@ -188,7 +185,9 @@ module Glimmer
|
|
188
185
|
|
189
186
|
# This method ensures it has an instance method not coming from Glimmer DSL
|
190
187
|
def has_instance_method?(method_name)
|
191
|
-
respond_to?(method_name) &&
|
188
|
+
respond_to?(method_name) &&
|
189
|
+
!method(method_name)&.source_location&.first&.include?('glimmer/dsl/engine.rb') &&
|
190
|
+
!method(method_name)&.source_location&.first&.include?('glimmer/swt/widget_proxy.rb')
|
192
191
|
end
|
193
192
|
|
194
193
|
def get_attribute(attribute_name)
|
@@ -229,13 +228,14 @@ module Glimmer
|
|
229
228
|
end
|
230
229
|
end
|
231
230
|
|
232
|
-
def dispose
|
233
|
-
body_root.dispose
|
234
|
-
end
|
235
|
-
|
236
231
|
def method_missing(method, *args, &block)
|
237
232
|
body_root.send(method, *args, &block)
|
238
233
|
end
|
234
|
+
|
235
|
+
def respond_to?(method, *args, &block)
|
236
|
+
super or
|
237
|
+
body_root.respond_to?(method, *args, &block)
|
238
|
+
end
|
239
239
|
|
240
240
|
private
|
241
241
|
|
metadata
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glimmer-dsl-swt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AndyMaleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
15
15
|
requirements:
|
16
16
|
- - "~>"
|
17
17
|
- !ruby/object:Gem::Version
|
18
|
-
version: 0.9.
|
18
|
+
version: 0.9.5
|
19
19
|
name: glimmer
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
@@ -23,7 +23,7 @@ dependencies:
|
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.9.
|
26
|
+
version: 0.9.5
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
29
29
|
requirements:
|