glimmer-dsl-swt 4.17.10.6 → 4.18.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +39 -0
- data/LICENSE.txt +1 -1
- data/README.md +369 -60
- data/RUBY_VERSION +1 -1
- data/VERSION +1 -1
- data/bin/girb +1 -1
- data/bin/girb_runner.rb +1 -1
- data/bin/glimmer +1 -1
- data/glimmer-dsl-swt.gemspec +54 -34
- data/lib/ext/glimmer.rb +1 -1
- data/lib/ext/glimmer/config.rb +1 -1
- data/lib/glimmer-dsl-swt.rb +2 -1
- data/lib/glimmer/Rakefile +1 -1
- data/lib/glimmer/data_binding/list_selection_binding.rb +1 -1
- data/lib/glimmer/data_binding/observable_widget.rb +1 -1
- data/lib/glimmer/data_binding/shine.rb +1 -1
- data/lib/glimmer/data_binding/table_items_binding.rb +1 -1
- data/lib/glimmer/data_binding/tree_items_binding.rb +1 -1
- data/lib/glimmer/data_binding/widget_binding.rb +1 -1
- data/lib/glimmer/dsl/swt/async_exec_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/bind_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/block_property_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/checkbox_group_selection_data_binding_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/color_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/column_properties_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/cursor_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/custom_widget_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/data_binding_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/dialog_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/directory_dialog_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/display_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/dnd_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/dsl.rb +1 -1
- data/lib/glimmer/dsl/swt/exec_expression.rb +5 -5
- data/lib/glimmer/dsl/swt/expand_item_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/file_dialog_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/font_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/image_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/layout_data_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/layout_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/menu_bar_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/menu_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/message_box_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/observe_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/property_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/rgb_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/rgba_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/shell_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/swt_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/sync_exec_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/tab_item_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/table_items_data_binding_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/tree_items_data_binding_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/tree_properties_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/widget_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/widget_listener_expression.rb +1 -1
- data/lib/glimmer/launcher.rb +1 -1
- data/lib/glimmer/rake_task.rb +1 -1
- data/lib/glimmer/rake_task/list.rb +1 -1
- data/lib/glimmer/rake_task/package.rb +1 -1
- data/lib/glimmer/rake_task/scaffold.rb +1 -1
- data/lib/glimmer/swt/color_proxy.rb +1 -1
- data/lib/glimmer/swt/cursor_proxy.rb +1 -1
- data/lib/glimmer/swt/custom/checkbox_group.rb +1 -1
- data/lib/glimmer/swt/custom/radio_group.rb +1 -1
- data/lib/glimmer/swt/date_time_proxy.rb +1 -1
- data/lib/glimmer/swt/directory_dialog_proxy.rb +1 -1
- data/lib/glimmer/swt/display_proxy.rb +1 -1
- data/lib/glimmer/swt/dnd_proxy.rb +1 -1
- data/lib/glimmer/swt/expand_item_proxy.rb +1 -1
- data/lib/glimmer/swt/file_dialog_proxy.rb +1 -1
- data/lib/glimmer/swt/font_proxy.rb +1 -1
- data/lib/glimmer/swt/image_proxy.rb +12 -11
- data/lib/glimmer/swt/layout_data_proxy.rb +1 -1
- data/lib/glimmer/swt/layout_proxy.rb +8 -4
- data/lib/glimmer/swt/menu_proxy.rb +10 -6
- data/lib/glimmer/swt/message_box_proxy.rb +1 -1
- data/lib/glimmer/swt/packages.rb +1 -1
- data/lib/glimmer/swt/sash_form_proxy.rb +2 -2
- data/lib/glimmer/swt/scrolled_composite_proxy.rb +1 -1
- data/lib/glimmer/swt/shell_proxy.rb +1 -1
- data/lib/glimmer/swt/style_constantizable.rb +9 -5
- data/lib/glimmer/swt/styled_text_proxy.rb +1 -1
- data/lib/glimmer/swt/swt_proxy.rb +1 -1
- data/lib/glimmer/swt/tab_item_proxy.rb +1 -1
- data/lib/glimmer/swt/table_column_proxy.rb +1 -1
- data/lib/glimmer/swt/table_proxy.rb +1 -1
- data/lib/glimmer/swt/tree_proxy.rb +26 -22
- data/lib/glimmer/swt/widget_listener_proxy.rb +1 -1
- data/lib/glimmer/swt/widget_proxy.rb +70 -25
- data/lib/glimmer/ui/custom_shell.rb +1 -1
- data/lib/glimmer/ui/custom_widget.rb +1 -1
- data/lib/glimmer/util/proc_tracker.rb +1 -1
- data/samples/elaborate/contact_manager.rb +1 -1
- data/samples/elaborate/contact_manager/contact.rb +1 -1
- data/samples/elaborate/contact_manager/contact_manager_presenter.rb +1 -1
- data/samples/elaborate/contact_manager/contact_repository.rb +1 -1
- data/samples/elaborate/login.rb +1 -1
- data/samples/elaborate/meta_sample.rb +80 -20
- data/samples/elaborate/tic_tac_toe.rb +2 -2
- data/samples/elaborate/tic_tac_toe/board.rb +1 -1
- data/samples/elaborate/tic_tac_toe/cell.rb +1 -1
- data/samples/elaborate/user_profile.rb +1 -1
- data/samples/hello/hello_browser.rb +3 -1
- data/samples/hello/hello_button.rb +1 -1
- data/samples/hello/hello_checkbox.rb +1 -1
- data/samples/hello/hello_checkbox_group.rb +1 -1
- data/samples/hello/hello_combo.rb +1 -1
- data/samples/hello/hello_computed.rb +10 -4
- data/samples/hello/hello_computed/contact.rb +1 -1
- data/samples/hello/hello_custom_shell.rb +1 -1
- data/samples/hello/hello_custom_widget.rb +1 -1
- data/samples/hello/hello_date_time.rb +1 -1
- data/samples/hello/hello_dialog.rb +78 -0
- data/samples/hello/hello_directory_dialog.rb +1 -1
- data/samples/hello/hello_drag_and_drop.rb +1 -1
- data/samples/hello/hello_expand_bar.rb +1 -1
- data/samples/hello/hello_file_dialog.rb +1 -1
- data/samples/hello/hello_group.rb +1 -1
- data/samples/hello/hello_link.rb +4 -6
- data/samples/hello/hello_list_multi_selection.rb +1 -1
- data/samples/hello/hello_list_single_selection.rb +1 -1
- data/samples/hello/hello_menu_bar.rb +185 -29
- data/samples/hello/hello_message_box.rb +10 -9
- data/samples/hello/hello_pop_up_context_menu.rb +34 -7
- data/samples/hello/hello_radio.rb +1 -1
- data/samples/hello/hello_radio_group.rb +1 -1
- data/samples/hello/hello_sash_form.rb +1 -1
- data/samples/hello/hello_spinner.rb +1 -1
- data/samples/hello/hello_styled_text.rb +1 -1
- data/samples/hello/hello_tab.rb +1 -1
- data/samples/hello/hello_table.rb +1 -1
- data/samples/hello/hello_world.rb +1 -1
- data/vendor/swt/linux/swt.jar +0 -0
- data/vendor/swt/mac/swt.jar +0 -0
- data/vendor/swt/windows/swt.jar +0 -0
- metadata +74 -42
@@ -1,5 +1,5 @@
|
|
1
|
-
# Copyright (c) 2007-
|
2
|
-
#
|
1
|
+
# Copyright (c) 2007-2021 Andy Maleh
|
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
|
@@ -59,7 +59,7 @@ module Glimmer
|
|
59
59
|
observer.call(@swt_widget.getSelection)
|
60
60
|
}
|
61
61
|
end
|
62
|
-
},
|
62
|
+
},
|
63
63
|
})
|
64
64
|
end
|
65
65
|
|
@@ -85,24 +85,28 @@ module Glimmer
|
|
85
85
|
@edit_in_progress = false
|
86
86
|
}
|
87
87
|
action = lambda { |event|
|
88
|
-
|
89
|
-
action_taken
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
88
|
+
begin
|
89
|
+
if !action_taken && !@edit_in_progress
|
90
|
+
action_taken = true
|
91
|
+
@edit_in_progress = true
|
92
|
+
new_text = @tree_editor_text_proxy.swt_widget.getText
|
93
|
+
if new_text == tree_item.getText
|
94
|
+
cancel.call
|
95
|
+
else
|
96
|
+
before_write&.call
|
97
|
+
tree_item.setText(new_text)
|
98
|
+
model = tree_item.getData
|
99
|
+
model.send("#{tree_properties[:text]}=", new_text) # makes tree update itself, so must search for selected tree item again
|
100
|
+
edited_tree_item = depth_first_search { |ti| ti.getData == model }.first
|
101
|
+
swt_widget.showItem(edited_tree_item)
|
102
|
+
@tree_editor_text_proxy.swt_widget.dispose
|
103
|
+
@tree_editor_text_proxy = nil
|
104
|
+
after_write&.call(edited_tree_item)
|
105
|
+
@edit_in_progress = false
|
106
|
+
end
|
105
107
|
end
|
108
|
+
rescue => e
|
109
|
+
Glimmer::Config.logger.error {"Error encountered while editing tree item!\n#{e.full_message}"}
|
106
110
|
end
|
107
111
|
}
|
108
112
|
on_focus_lost(&action)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2007-
|
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
|
@@ -69,7 +69,7 @@ module Glimmer
|
|
69
69
|
}
|
70
70
|
|
71
71
|
DEFAULT_INITIALIZERS = {
|
72
|
-
|
72
|
+
composite: lambda do |composite|
|
73
73
|
if composite.get_layout.nil?
|
74
74
|
layout = GridLayout.new
|
75
75
|
layout.marginWidth = 15
|
@@ -77,18 +77,18 @@ module Glimmer
|
|
77
77
|
composite.layout = layout
|
78
78
|
end
|
79
79
|
end,
|
80
|
-
|
80
|
+
scrolled_composite: lambda do |scrolled_composite|
|
81
81
|
scrolled_composite.expand_horizontal = true
|
82
82
|
scrolled_composite.expand_vertical = true
|
83
83
|
end,
|
84
|
-
|
84
|
+
table: lambda do |table|
|
85
85
|
table.setHeaderVisible(true)
|
86
86
|
table.setLinesVisible(true)
|
87
87
|
end,
|
88
|
-
|
88
|
+
table_column: lambda do |table_column|
|
89
89
|
table_column.setWidth(80)
|
90
90
|
end,
|
91
|
-
|
91
|
+
group: lambda do |group|
|
92
92
|
group.layout = GridLayout.new if group.get_layout.nil?
|
93
93
|
end,
|
94
94
|
}
|
@@ -160,7 +160,7 @@ module Glimmer
|
|
160
160
|
end
|
161
161
|
if @swt_widget&.get_data('proxy').nil?
|
162
162
|
@swt_widget.set_data('proxy', self)
|
163
|
-
DEFAULT_INITIALIZERS[underscored_widget_name]&.call(@swt_widget)
|
163
|
+
DEFAULT_INITIALIZERS[underscored_widget_name.to_s.to_sym]&.call(@swt_widget)
|
164
164
|
@parent_proxy.post_initialize_child(self)
|
165
165
|
end
|
166
166
|
end
|
@@ -202,7 +202,22 @@ module Glimmer
|
|
202
202
|
end
|
203
203
|
end
|
204
204
|
|
205
|
+
def has_attribute_getter?(attribute_getter_name, *args)
|
206
|
+
attribute_getter_name = attribute_getter_name.to_s.underscore
|
207
|
+
return false unless !attribute_getter_name.end_with?('=') && !attribute_getter_name.start_with?('set_')
|
208
|
+
args.empty? && swt_widget.respond_to?(attribute_getter_name)
|
209
|
+
end
|
210
|
+
|
211
|
+
def has_attribute_setter?(attribute_setter_name, *args)
|
212
|
+
attribute_setter_name = attribute_setter_name.to_s
|
213
|
+
underscored_attribute_setter_name = attribute_setter_name.underscore
|
214
|
+
return false unless attribute_setter_name.end_with?('=') || (attribute_setter_name.start_with?('set_') && !args.empty?)
|
215
|
+
attribute_name = underscored_attribute_setter_name.sub(/^set_/, '').sub(/=$/, '')
|
216
|
+
has_attribute?(attribute_name, *args)
|
217
|
+
end
|
218
|
+
|
205
219
|
def has_attribute?(attribute_name, *args)
|
220
|
+
# TODO test that attribute getter responds too
|
206
221
|
widget_custom_attribute = widget_custom_attribute_mapping[attribute_name.to_s]
|
207
222
|
if widget_custom_attribute
|
208
223
|
@swt_widget.respond_to?(widget_custom_attribute[:setter][:name])
|
@@ -212,12 +227,15 @@ module Glimmer
|
|
212
227
|
end
|
213
228
|
|
214
229
|
def set_attribute(attribute_name, *args)
|
230
|
+
# TODO Think about widget subclasses overriding set_attribute to add more attributes vs adding as Ruby attributes directly
|
215
231
|
widget_custom_attribute = widget_custom_attribute_mapping[attribute_name.to_s]
|
232
|
+
apply_property_type_converters(normalized_attribute(attribute_name), args)
|
216
233
|
if widget_custom_attribute
|
217
234
|
widget_custom_attribute[:setter][:invoker].call(@swt_widget, args)
|
218
235
|
elsif @swt_widget.respond_to?(attribute_setter(attribute_name))
|
219
|
-
apply_property_type_converters(attribute_name, args)
|
220
236
|
@swt_widget.send(attribute_setter(attribute_name), *args) unless @swt_widget.send(attribute_getter(attribute_name)) == args.first
|
237
|
+
elsif @swt_widget.respond_to?(ruby_attribute_setter(attribute_name))
|
238
|
+
@swt_widget.send(ruby_attribute_setter(attribute_name), args)
|
221
239
|
else
|
222
240
|
send(ruby_attribute_setter(attribute_name), args)
|
223
241
|
end
|
@@ -233,6 +251,12 @@ module Glimmer
|
|
233
251
|
end
|
234
252
|
elsif @swt_widget.respond_to?(attribute_getter(attribute_name))
|
235
253
|
@swt_widget.send(attribute_getter(attribute_name))
|
254
|
+
elsif @swt_widget.respond_to?(ruby_attribute_getter(attribute_name))
|
255
|
+
@swt_widget.send(ruby_attribute_getter(attribute_name))
|
256
|
+
elsif @swt_widget.respond_to?(attribute_name)
|
257
|
+
@swt_widget.send(attribute_name)
|
258
|
+
elsif respond_to?(ruby_attribute_getter(attribute_name))
|
259
|
+
send(ruby_attribute_getter(attribute_name))
|
236
260
|
else
|
237
261
|
send(attribute_name)
|
238
262
|
end
|
@@ -607,11 +631,16 @@ module Glimmer
|
|
607
631
|
def method_missing(method, *args, &block)
|
608
632
|
if can_handle_observation_request?(method)
|
609
633
|
handle_observation_request(method, &block)
|
634
|
+
elsif has_attribute_setter?(method, *args)
|
635
|
+
set_attribute(method, *args)
|
636
|
+
elsif has_attribute_getter?(method, *args)
|
637
|
+
get_attribute(method, *args)
|
610
638
|
else
|
611
639
|
swt_widget.send(method, *args, &block)
|
612
640
|
end
|
613
641
|
rescue => e
|
614
|
-
Glimmer::Config.logger.debug {"Neither WidgetProxy nor #{swt_widget.class.name} can handle the method ##{method}"}
|
642
|
+
Glimmer::Config.logger.debug { "Neither WidgetProxy nor #{swt_widget.class.name} can handle the method ##{method}" }
|
643
|
+
Glimmer::Config.logger.debug { e.full_message }
|
615
644
|
super
|
616
645
|
# TODO consider get_attribute too
|
617
646
|
end
|
@@ -639,16 +668,26 @@ module Glimmer
|
|
639
668
|
end
|
640
669
|
|
641
670
|
def ruby_attribute_setter(attribute_name)
|
642
|
-
"#{attribute_name}="
|
671
|
+
"#{normalized_attribute(attribute_name)}="
|
643
672
|
end
|
644
673
|
|
645
674
|
def attribute_setter(attribute_name)
|
646
|
-
"set#{attribute_name.
|
675
|
+
"set#{normalized_attribute(attribute_name).camelcase(:upper)}"
|
647
676
|
end
|
648
677
|
|
649
678
|
def attribute_getter(attribute_name)
|
650
|
-
"get#{attribute_name.
|
679
|
+
"get#{normalized_attribute(attribute_name).camelcase(:upper)}"
|
651
680
|
end
|
681
|
+
|
682
|
+
def normalized_attribute(attribute_name)
|
683
|
+
attribute_name = attribute_name.to_s if attribute_name.is_a?(Symbol)
|
684
|
+
attribute_name = attribute_name.underscore unless attribute_name.downcase?
|
685
|
+
attribute_name = attribute_name.sub(/^get_/, '') if attribute_name.start_with?('get_')
|
686
|
+
attribute_name = attribute_name.sub(/^set_/, '') if attribute_name.start_with?('set_')
|
687
|
+
attribute_name = attribute_name.sub(/=$/, '') if attribute_name.end_with?('=')
|
688
|
+
attribute_name
|
689
|
+
end
|
690
|
+
alias ruby_attribute_getter normalized_attribute
|
652
691
|
|
653
692
|
# TODO refactor following methods to eliminate duplication
|
654
693
|
# perhaps consider relying on raising an exception to avoid checking first
|
@@ -799,11 +838,14 @@ module Glimmer
|
|
799
838
|
end
|
800
839
|
# TODO consider detecting type on widget method and automatically invoking right converter (e.g. :to_s for String, :to_i for Integer)
|
801
840
|
@property_type_converters ||= {
|
802
|
-
|
841
|
+
accelerator: lambda { |*value|
|
842
|
+
SWTProxy[*value]
|
843
|
+
},
|
844
|
+
alignment: lambda { |*value|
|
803
845
|
SWTProxy[*value]
|
804
846
|
},
|
805
|
-
:
|
806
|
-
:
|
847
|
+
background: color_converter,
|
848
|
+
background_image: lambda do |*value|
|
807
849
|
image_proxy = ImageProxy.create(*value)
|
808
850
|
|
809
851
|
if image_proxy&.file_path&.end_with?('.gif')
|
@@ -844,7 +886,7 @@ module Glimmer
|
|
844
886
|
|
845
887
|
image_proxy&.swt_image
|
846
888
|
end,
|
847
|
-
:
|
889
|
+
cursor: lambda do |value|
|
848
890
|
cursor_proxy = nil
|
849
891
|
if value.is_a?(CursorProxy)
|
850
892
|
cursor_proxy = value
|
@@ -856,9 +898,9 @@ module Glimmer
|
|
856
898
|
:enabled => lambda do |value|
|
857
899
|
!!value
|
858
900
|
end,
|
859
|
-
:
|
860
|
-
:
|
861
|
-
:
|
901
|
+
foreground: color_converter,
|
902
|
+
link_foreground: color_converter,
|
903
|
+
font: lambda do |value|
|
862
904
|
if value.is_a?(Hash)
|
863
905
|
font_properties = value
|
864
906
|
FontProxy.new(self, font_properties).swt_font
|
@@ -866,21 +908,21 @@ module Glimmer
|
|
866
908
|
value
|
867
909
|
end
|
868
910
|
end,
|
869
|
-
:
|
911
|
+
image: lambda do |*value|
|
870
912
|
ImageProxy.create(*value).swt_image
|
871
913
|
end,
|
872
|
-
:
|
914
|
+
images: lambda do |array|
|
873
915
|
array.to_a.map do |value|
|
874
916
|
ImageProxy.create(value).swt_image
|
875
917
|
end.to_java(Image)
|
876
918
|
end,
|
877
|
-
:
|
919
|
+
items: lambda do |value|
|
878
920
|
value.to_java :string
|
879
921
|
end,
|
880
|
-
:
|
922
|
+
text: lambda do |value|
|
881
923
|
value.to_s
|
882
924
|
end,
|
883
|
-
:
|
925
|
+
transfer: lambda do |value|
|
884
926
|
value = value.first if value.is_a?(Array) && value.size == 1 && value.first.is_a?(Array)
|
885
927
|
transfer_object_extrapolator = lambda do |transfer_name|
|
886
928
|
transfer_type = "#{transfer_name.to_s.camelcase(:upper)}Transfer".to_sym
|
@@ -899,9 +941,12 @@ module Glimmer
|
|
899
941
|
result = result.to_java(Transfer) unless result.is_a?(ArrayJavaProxy)
|
900
942
|
result
|
901
943
|
end,
|
902
|
-
:
|
944
|
+
visible: lambda do |value|
|
903
945
|
!!value
|
904
946
|
end,
|
947
|
+
weights: lambda do |value|
|
948
|
+
value.to_java(:int)
|
949
|
+
end,
|
905
950
|
}
|
906
951
|
end
|
907
952
|
end
|
data/samples/elaborate/login.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'etc'
|
3
|
+
|
1
4
|
class Sample
|
5
|
+
include Glimmer::DataBinding::ObservableModel
|
6
|
+
|
2
7
|
attr_accessor :sample_directory, :file, :selected
|
3
8
|
|
4
9
|
def initialize(file, sample_directory: )
|
@@ -19,12 +24,39 @@ class Sample
|
|
19
24
|
@name
|
20
25
|
end
|
21
26
|
|
22
|
-
def
|
23
|
-
|
27
|
+
def code
|
28
|
+
reset_code! if @code.nil?
|
29
|
+
@code
|
24
30
|
end
|
25
|
-
|
26
|
-
def
|
27
|
-
|
31
|
+
|
32
|
+
def reset_code!
|
33
|
+
@code = File.read(file)
|
34
|
+
notify_observers('code')
|
35
|
+
end
|
36
|
+
|
37
|
+
def editable
|
38
|
+
File.basename(file) != 'meta_sample.rb'
|
39
|
+
end
|
40
|
+
alias launchable editable
|
41
|
+
|
42
|
+
def launch(modified_code)
|
43
|
+
parent_directory = File.basename(File.dirname(file))
|
44
|
+
modified_file_parent_directory = File.join(Etc.getpwuid.dir, '.glimmer', 'samples', parent_directory)
|
45
|
+
launch_file = modified_file = File.join(modified_file_parent_directory, File.basename(file))
|
46
|
+
begin
|
47
|
+
FileUtils.mkdir_p(modified_file_parent_directory)
|
48
|
+
FileUtils.cp_r(file, modified_file_parent_directory)
|
49
|
+
FileUtils.cp_r(file.sub(/\.rb/, ''), modified_file_parent_directory) if File.exist?(file.sub(/\.rb/, ''))
|
50
|
+
File.write(modified_file, modified_code)
|
51
|
+
rescue => e
|
52
|
+
puts 'Error writing sample modifications. Launching original sample.'
|
53
|
+
puts e.full_message
|
54
|
+
launch_file = file # load original file if failed to write changes
|
55
|
+
end
|
56
|
+
load(launch_file)
|
57
|
+
ensure
|
58
|
+
FileUtils.rm_rf(modified_file)
|
59
|
+
FileUtils.rm_rf(modified_file.sub(/\.rb/, ''))
|
28
60
|
end
|
29
61
|
end
|
30
62
|
|
@@ -111,18 +143,25 @@ end
|
|
111
143
|
class MetaSampleApplication
|
112
144
|
include Glimmer
|
113
145
|
|
146
|
+
def initialize
|
147
|
+
selected_sample_directory = SampleDirectory.sample_directories.first
|
148
|
+
selected_sample = selected_sample_directory.samples.first
|
149
|
+
selected_sample_directory.selected_sample_name = selected_sample.name
|
150
|
+
end
|
151
|
+
|
114
152
|
def launch
|
153
|
+
Display.setAppName('Glimmer Meta-Sample')
|
115
154
|
shell {
|
116
155
|
minimum_size 1280, 768
|
117
156
|
text 'Glimmer Meta-Sample (The Sample of Samples)'
|
118
|
-
|
119
|
-
on_swt_show {
|
120
|
-
SampleDirectory.selected_sample = SampleDirectory.all_samples.first
|
121
|
-
}
|
157
|
+
image File.expand_path('../../icons/scaffold_app.png', __dir__)
|
122
158
|
|
123
159
|
sash_form {
|
124
160
|
composite {
|
125
|
-
grid_layout
|
161
|
+
grid_layout(1, false) {
|
162
|
+
margin_width 0
|
163
|
+
margin_height 0
|
164
|
+
}
|
126
165
|
|
127
166
|
expand_bar {
|
128
167
|
layout_data(:fill, :fill, true, true)
|
@@ -131,7 +170,7 @@ class MetaSampleApplication
|
|
131
170
|
SampleDirectory.sample_directories.each { |sample_directory|
|
132
171
|
expand_item {
|
133
172
|
layout_data(:fill, :fill, true, true)
|
134
|
-
text "#{sample_directory.name} Samples"
|
173
|
+
text " #{sample_directory.name} Samples"
|
135
174
|
|
136
175
|
radio_group { |radio_group_proxy|
|
137
176
|
row_layout(:vertical) {
|
@@ -144,22 +183,43 @@ class MetaSampleApplication
|
|
144
183
|
}
|
145
184
|
}
|
146
185
|
|
147
|
-
|
186
|
+
composite {
|
187
|
+
fill_layout
|
148
188
|
layout_data(:fill, :center, true, false) {
|
149
189
|
height_hint 120
|
150
190
|
}
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
191
|
+
|
192
|
+
button {
|
193
|
+
text 'Launch'
|
194
|
+
font height: 30
|
195
|
+
enabled bind(SampleDirectory, 'selected_sample.launchable')
|
196
|
+
|
197
|
+
on_widget_selected {
|
198
|
+
begin
|
199
|
+
SampleDirectory.selected_sample.launch(@code_text.text)
|
200
|
+
rescue StandardError, SyntaxError => launch_error
|
201
|
+
message_box {
|
202
|
+
text 'Error Launching'
|
203
|
+
message launch_error.full_message
|
204
|
+
}.open
|
205
|
+
end
|
206
|
+
}
|
207
|
+
}
|
208
|
+
button {
|
209
|
+
text 'Reset'
|
210
|
+
font height: 30
|
211
|
+
enabled bind(SampleDirectory, 'selected_sample.editable')
|
212
|
+
|
213
|
+
on_widget_selected {
|
214
|
+
SampleDirectory.selected_sample.reset_code!
|
215
|
+
}
|
155
216
|
}
|
156
217
|
}
|
157
218
|
}
|
158
219
|
|
159
|
-
code_text {
|
160
|
-
text bind(SampleDirectory, 'selected_sample.
|
161
|
-
editable
|
162
|
-
caret nil
|
220
|
+
@code_text = code_text {
|
221
|
+
text bind(SampleDirectory, 'selected_sample.code', read_only: true)
|
222
|
+
editable bind(SampleDirectory, 'selected_sample.editable')
|
163
223
|
}
|
164
224
|
|
165
225
|
weights 4, 9
|