Class: Glimmer::SWT::MenuItemProxy
Overview
Proxy for org.eclipse.swt.widgets.MenuItem
Follows the Proxy Design Pattern since it’s a proxy for an HTML based menu Follows the Adapter Design Pattern since it’s adapting a Glimmer DSL for SWT widget
Constant Summary
collapse
- STYLE =
<<~CSS
.menu-item.disabled {
background-color: lightgrey;
color: grey;
}
.menu-item.disabled .menu, .menu-item.disabled .menu * {
display: none;
opacity: 0;
}
CSS
Constants inherited
from WidgetProxy
WidgetProxy::DEFAULT_INITIALIZERS, WidgetProxy::JS_KEY_CODE_TO_SWT_KEY_CODE_MAP, WidgetProxy::JS_LOCATION_TO_SWT_KEY_LOCATION_MAP, WidgetProxy::SWT_CURSOR_TO_CSS_CURSOR_MAP
Instance Attribute Summary collapse
Attributes inherited from WidgetProxy
#args, #background, #children, #cursor, #disposed?, #enabled, #focus, #font, #foreground, #menu, #menu_requested, #menu_x, #menu_y, #parent, #path, #rendered
Instance Method Summary
collapse
Methods inherited from WidgetProxy
#add_content_on_render, #add_css_class, #add_css_classes, #add_observer, #apply_property_type_converters, #attach, #build_dom, #can_handle_observation_request?, #clear_css_classes, #content, #content_on_render_blocks, #css_classes, #default_observation_request_to_event_mapping, #dialog_ancestor, #dispose, #dom_element, #effective_observation_request_to_event_mapping, #event_handling_suspended?, #event_listener_proxies, for, #get_data, #handle_javascript_observation_request, #handle_observation_request, #has_style?, #id, #id=, #listener_dom_element, #listener_path, #listeners, #listeners_for, max_id_number_for, max_id_numbers, #method_missing, #name, next_id_number_for, #observation_requests, #parent_dom_element, #parent_path, #parents, #post_add_content, #post_dispose_child, #print, #property_type_converters, #reattach, #remove_all_listeners, #remove_css_class, #remove_css_classes, #remove_event_listener_proxies, #render, reset_max_id_numbers!, #resume_event_handling, #selector, #set_attribute, #set_data, #set_focus, #shell, #style_element, #suspend_event_handling, #swt_data, #swt_widget, underscored_widget_name, widget_class, widget_exists?, widget_handling_listener, #widget_property_listener_installers
#attribute_getter, #attribute_setter, #get_attribute, #set_attribute
Constructor Details
#initialize(parent, args, block) ⇒ MenuItemProxy
Returns a new instance of MenuItemProxy.
46
47
48
49
50
51
52
53
|
# File 'lib/glimmer/swt/menu_item_proxy.rb', line 46
def initialize(parent, args, block)
args.push(:push) if args.empty?
super(parent, args, block)
on_widget_selected {
}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Glimmer::SWT::WidgetProxy
Instance Attribute Details
#accelerator ⇒ Object
TODO consider doing something with it
44
45
46
|
# File 'lib/glimmer/swt/menu_item_proxy.rb', line 44
def accelerator
@accelerator
end
|
Instance Method Details
#cascade? ⇒ Boolean
59
60
61
|
# File 'lib/glimmer/swt/menu_item_proxy.rb', line 59
def cascade?
args.include?(:cascade)
end
|
#check? ⇒ Boolean
71
72
73
|
# File 'lib/glimmer/swt/menu_item_proxy.rb', line 71
def check?
args.include?(:check)
end
|
#div_content ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/glimmer/swt/menu_item_proxy.rb', line 110
def div_content
div_attributes = {}
icon_suffix = check? ? 'check' : 'bullet'
div(div_attributes) {
unless separator? span(class: "menu-item-selection #{"ui-icon ui-icon-#{icon_suffix}" if selection}") {}
span(class: 'ui-menu-icon ui-icon ui-icon-caret-1-e') {} if cascade? && !parent.bar?
span(class: 'menu-item-text') {
@text
}
''
end
}
end
|
#dom ⇒ Object
164
165
166
167
168
169
170
171
|
# File 'lib/glimmer/swt/menu_item_proxy.rb', line 164
def dom
@dom ||= html {
li(id: id, class: "#{name} #{'disabled' unless enabled}") {
div_content
}
}.to_s
end
|
#element ⇒ Object
160
161
162
|
# File 'lib/glimmer/swt/menu_item_proxy.rb', line 160
def element
'li'
end
|
#enabled=(value) ⇒ Object
104
105
106
107
108
|
# File 'lib/glimmer/swt/menu_item_proxy.rb', line 104
def enabled=(value)
@enabled = value
dom_element.toggle_class('disabled', !@enabled)
@enabled
end
|
#observation_request_to_event_mapping ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/glimmer/swt/menu_item_proxy.rb', line 135
def observation_request_to_event_mapping
{
'on_widget_selected' => {
event: 'mouseup',
event_handler: -> (event_listener) {
-> (event) {
if enabled && (push? || radio? || check?)
if check?
self.toggle_selection!
elsif radio? && !selection
parent.children.detect(&:selection)&.selection = false
self.selection = true
end
if !.bar?
remove_event_listener_proxies
.close
end
event_listener.call(event)
end
}
},
},
}
end
|
#post_initialize_child(child) ⇒ Object
55
56
57
|
# File 'lib/glimmer/swt/menu_item_proxy.rb', line 55
def post_initialize_child(child)
@children << child
end
|
#push? ⇒ Boolean
63
64
65
|
# File 'lib/glimmer/swt/menu_item_proxy.rb', line 63
def push?
args.include?(:push)
end
|
#radio? ⇒ Boolean
67
68
69
|
# File 'lib/glimmer/swt/menu_item_proxy.rb', line 67
def radio?
args.include?(:radio)
end
|
125
126
127
128
129
|
# File 'lib/glimmer/swt/menu_item_proxy.rb', line 125
def
= parent
= . until .
end
|
#selection ⇒ Object
89
90
91
|
# File 'lib/glimmer/swt/menu_item_proxy.rb', line 89
def selection
@selection
end
|
#selection=(value) ⇒ Object
93
94
95
96
97
98
|
# File 'lib/glimmer/swt/menu_item_proxy.rb', line 93
def selection=(value)
@selection = value
icon_suffix = check? ? 'check' : 'bullet'
dom_element.find('.menu-item-selection').toggle_class("ui-icon ui-icon-#{icon_suffix}", @selection)
@selection
end
|
#separator? ⇒ Boolean
75
76
77
|
# File 'lib/glimmer/swt/menu_item_proxy.rb', line 75
def separator?
args.include?(:separator)
end
|
#skip_content_on_render_blocks? ⇒ Boolean
131
132
133
|
# File 'lib/glimmer/swt/menu_item_proxy.rb', line 131
def skip_content_on_render_blocks?
true
end
|
#text ⇒ Object
79
80
81
|
# File 'lib/glimmer/swt/menu_item_proxy.rb', line 79
def text
@text
end
|
#text=(value) ⇒ Object
83
84
85
86
87
|
# File 'lib/glimmer/swt/menu_item_proxy.rb', line 83
def text=(value)
@text = value
dom_element.find('.menu-item-text').html(@text)
@text
end
|
#toggle_selection! ⇒ Object
100
101
102
|
# File 'lib/glimmer/swt/menu_item_proxy.rb', line 100
def toggle_selection!
self.selection = !selection
end
|