Class: Glimmer::SWT::ShellProxy

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

Direct Known Subclasses

LatestShellProxy, MakeShiftShellProxy

Constant Summary collapse

STYLE =
<<~CSS
  html {
    width: 100%;
    height: 100%;
  }
  body {
    width: 100%;
    height: 100%;
    margin: 0;
  }
  .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

Instance Attribute Summary collapse

Attributes inherited from WidgetProxy

#args, #background, #children, #disposed?, #enabled, #focus, #font, #foreground, #menu, #menu_requested, #parent, #path, #rendered

Instance Method Summary collapse

Methods inherited from CompositeProxy

#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, #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_observation_request, #has_style?, #id, #id=, #listener_dom_element, #listener_path, 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_add_content, #post_dispose_child, #post_initialize_child, #property_type_converters, #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_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.



47
48
49
50
51
52
53
54
55
56
# File 'lib/glimmer/swt/shell_proxy.rb', line 47

def initialize(args)
  @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.



42
43
44
# File 'lib/glimmer/swt/shell_proxy.rb', line 42

def menu_bar
  @menu_bar
end

#minimum_sizeObject

TODO consider renaming to ShellProxy to match SWT API



41
42
43
# File 'lib/glimmer/swt/shell_proxy.rb', line 41

def minimum_size
  @minimum_size
end

Instance Method Details

#closeObject



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

def close
  DisplayProxy.instance.shells.delete(self)
  dom_element.remove
  @open = false
end

#domObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/glimmer/swt/shell_proxy.rb', line 93

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



58
59
60
# File 'lib/glimmer/swt/shell_proxy.rb', line 58

def element
  'div'
end

#hideObject



131
132
133
134
# File 'lib/glimmer/swt/shell_proxy.rb', line 131

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

#open(async: true) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/glimmer/swt/shell_proxy.rb', line 116

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
    end
  end
  if async
    DisplayProxy.instance.async_exec(&work)
  else
    work.call
  end
end

#open?Boolean

Returns:

  • (Boolean)


142
143
144
# File 'lib/glimmer/swt/shell_proxy.rb', line 142

def open?
  @open
end

#parent_pathObject



62
63
64
# File 'lib/glimmer/swt/shell_proxy.rb', line 62

def parent_path
  'body'
end

#style_dom_cssObject



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/glimmer/swt/shell_proxy.rb', line 81

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

#textObject



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

def text
  $document.title
end

#text=(value) ⇒ Object



70
71
72
# File 'lib/glimmer/swt/shell_proxy.rb', line 70

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