Class: Glimmer::SWT::ShellProxy

Inherits:
CompositeProxy show all
Defined in:
lib/glimmer/swt/shell_proxy.rb

Constant Summary collapse

STYLE =
<<~CSS
  html {
    width: 100%;
    height: 100%;
  }
  body {
    width: 100%;
    height: 100%;
    margin: 0;
  }
  * {
    cursor: inherit;
  }
  .shell {
    height: 100%;
    margin: 0;
  }
  .shell iframe {
    width: 100%;
    height: 100%;
  }
  .shell .dialog-overlay {
    position: fixed;
    z-index: 10;
    padding-top: 100px;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.4);
  }
CSS
WIDTH_MIN =
130
HEIGHT_MIN =
0

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 CompositeProxy

#background_image, #background_image=, #default_layout, #get_layout, #layout=, #layout​, #pack

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, #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_request_to_event_mapping, #observation_requests, #parent_dom_element, #parents, #post_dispose_child, #post_initialize_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, #skip_content_on_render_blocks?, #style_element, #suspend_event_handling, #swt_data, #swt_widget, underscored_widget_name, widget_class, widget_exists?, widget_handling_listener, #widget_property_listener_installers

Methods included from PropertyOwner

#attribute_getter, #attribute_setter, #get_attribute, #set_attribute

Constructor Details

#initialize(args) ⇒ ShellProxy

Returns a new instance of ShellProxy.



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/glimmer/swt/shell_proxy.rb', line 71

def initialize(args)
  # TODO set parent
  @args = args
  @children = []
  render # TODO attach to specific element
  @layout = FillLayoutProxy.new(self, [])
  @layout.margin_width = 0
  @layout.margin_height = 0
  self.minimum_size = Point.new(WIDTH_MIN, HEIGHT_MIN)
  DisplayProxy.instance.shells << self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Glimmer::SWT::WidgetProxy

Instance Attribute Details

Returns the value of attribute menu_bar.



66
67
68
# File 'lib/glimmer/swt/shell_proxy.rb', line 66

def menu_bar
  @menu_bar
end

#minimum_sizeObject

TODO consider renaming to ShellProxy to match SWT API



65
66
67
# File 'lib/glimmer/swt/shell_proxy.rb', line 65

def minimum_size
  @minimum_size
end

Instance Method Details

#closeObject



199
200
201
202
203
204
# File 'lib/glimmer/swt/shell_proxy.rb', line 199

def close
  DisplayProxy.instance.shells.delete(self)
  dom_element.remove
  @open = false
  listeners_for('swt_close').each {|listener| listener.call(Event.new(widget: self))}
end

#domObject



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/glimmer/swt/shell_proxy.rb', line 154

def dom
  i = 0
  body_id = id
  body_class = ([name, 'hide'] + css_classes.to_a).join(' ')
  @dom ||= html {
    div(id: body_id, class: body_class) {
      # TODO consider supporting the idea of dynamic CSS building on close of shell that adds only as much CSS as needed for widgets that were mentioned
      style(class: 'common-style') {
        style_dom_css
      }
      [LayoutProxy, WidgetProxy].map(&:descendants).reduce(:+).each do |style_class|
        if style_class.constants.include?('STYLE')
          style(class: "#{style_class.name.split(':').last.underscore.gsub('_', '-').sub(/-proxy$/, '')}-style") {
            style_class::STYLE
          }
        end
      end
      div(class: 'dialog-overlay hide') {
      }
    }
  }.to_s
end

#elementObject



87
88
89
# File 'lib/glimmer/swt/shell_proxy.rb', line 87

def element
  'div'
end

#favicon_dom_elementObject



121
122
123
# File 'lib/glimmer/swt/shell_proxy.rb', line 121

def favicon_dom_element
  Document.find('link[rel=icon]')
end

#handle_observation_request(keyword, original_event_listener) ⇒ Object



132
133
134
135
136
137
138
139
140
# File 'lib/glimmer/swt/shell_proxy.rb', line 132

def handle_observation_request(keyword, original_event_listener)
  case keyword
  when 'on_swt_show', 'on_swt_close', 'on_shell_closed'
    keyword = 'on_swt_close' if keyword == 'on_shell_closed'
    listeners_for(keyword.sub(/^on_/, '')) << original_event_listener.to_proc
  else
    super(keyword, original_event_listener)
  end
end

#hideObject



194
195
196
197
# File 'lib/glimmer/swt/shell_proxy.rb', line 194

def hide
  dom_element.add_class('hide')
  @open = false
end

#imageObject

favicon



104
105
106
# File 'lib/glimmer/swt/shell_proxy.rb', line 104

def image
  @image
end

#image=(value) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/glimmer/swt/shell_proxy.rb', line 108

def image=(value)
  @image = value
  # TODO consider moving this code to favicon_dom_element
  if favicon_dom_element.empty?
    favicon_element = Element.new(:link)
    favicon_element.attr('rel', 'icon')
    Document.find('head').append(favicon_element)
  else
    favicon_element = favicon_dom_element
  end
  favicon_element.attr('href', image)
end

#open(async: true) ⇒ Object Also known as: show



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/glimmer/swt/shell_proxy.rb', line 177

def open(async: true)
  work = lambda do
    unless @open
      DisplayProxy.instance.shells.select(&:open?).reject {|s| s == self}.map(&:hide)
      dom_element.remove_class('hide')
      @open = true
      listeners_for('swt_show').each {|listener| listener.call(Event.new(widget: self))}
    end
  end
  if async
    DisplayProxy.instance.async_exec(&work)
  else
    work.call
  end
end

#open?Boolean

Returns:

  • (Boolean)


206
207
208
# File 'lib/glimmer/swt/shell_proxy.rb', line 206

def open?
  @open
end

#parent_pathObject



91
92
93
# File 'lib/glimmer/swt/shell_proxy.rb', line 91

def parent_path
  'body'
end

#post_add_contentObject



83
84
85
# File 'lib/glimmer/swt/shell_proxy.rb', line 83

def post_add_content
  `$( document ).tooltip()`
end

#style_dom_cssObject



142
143
144
145
146
147
148
149
150
151
152
# File 'lib/glimmer/swt/shell_proxy.rb', line 142

def style_dom_css
  <<~CSS
    .hide {
      display: none !important;
    }
    .selected {
      background: rgb(80, 116, 211);
      color: white;
    }
  CSS
end

#textObject



95
96
97
# File 'lib/glimmer/swt/shell_proxy.rb', line 95

def text
  $document.title
end

#text=(value) ⇒ Object



99
100
101
# File 'lib/glimmer/swt/shell_proxy.rb', line 99

def text=(value)
  Document.title = value
end

#visibleObject Also known as: visible?



210
211
212
# File 'lib/glimmer/swt/shell_proxy.rb', line 210

def visible
  @open
end

#visible=(value) ⇒ Object



215
216
217
218
219
220
221
# File 'lib/glimmer/swt/shell_proxy.rb', line 215

def visible=(value)
  if value
    show(async: false)
  else
    hide
  end
end