Class: Glimmer::SWT::MessageBoxProxy

Inherits:
WidgetProxy show all
Defined in:
lib/glimmer/swt/message_box_proxy.rb

Constant Summary collapse

STYLE =
<<~CSS
  .message-box {
    position: fixed;
    z-index: 1000;
    padding-top: 100px;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgb(0,0,0);
    background-color: rgba(0,0,0,0.4);
    text-align: center;
  }
  .message-box-content .text {
    background: rgb(80, 116, 211);
    color: white;
    padding: 5px;
  }
  .message-box-content .message {
    padding: 20px;
  }
  .message-box-content {
    background-color: #fefefe;
    padding-bottom: 15px;
    border: 1px solid #888;
    display: inline-block;
    min-width: 200px;
  }
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_on_render_blocks, #css_classes, #default_observation_request_to_event_mapping, #dialog_ancestor, #dispose, #dom_element, #effective_observation_request_to_event_mapping, #element, #event_handling_suspended?, #event_listener_proxies, for, #get_data, #handle_javascript_observation_request, #handle_observation_request, #has_style?, #id, #id=, #listener_dom_element, #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, #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, #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(parent, args, block) ⇒ MessageBoxProxy

Returns a new instance of MessageBoxProxy.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/glimmer/swt/message_box_proxy.rb', line 73

def initialize(parent, args, block)
  i = 0
  @parent = parent
  @parent = nil if parent.is_a?(LatestShellProxy)
  @parent ||= DisplayProxy.instance.shells.detect(&:open?) || ShellProxy.new([])
  @args = args
  @block = block
  @children = Set.new
  @enabled = true
  on_widget_selected {
    hide
  }
  DisplayProxy.instance.message_boxes << self
end

Dynamic Method Handling

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

Instance Attribute Details

#messageObject

}



71
72
73
# File 'lib/glimmer/swt/message_box_proxy.rb', line 71

def message
  @message
end

#textObject

}



71
72
73
# File 'lib/glimmer/swt/message_box_proxy.rb', line 71

def text
  @text
end

Instance Method Details

#content(&block) ⇒ Object



120
121
122
# File 'lib/glimmer/swt/message_box_proxy.rb', line 120

def content(&block)
  Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Opal::MessageBoxExpression.new, 'message_box', *@args, &block)
end

#domObject



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/glimmer/swt/message_box_proxy.rb', line 140

def dom
  @dom ||= html {
    div(id: id, class: "modal #{name}") {
      div(class: 'message-box-content') {
        header(class: 'text') {
          "#{text}&nbsp;" # ensure title area occuppied when there is no text by adding non-breaking space (&nbsp;)
        }
        tag(_name: 'p', id: 'message', class: 'message') {
          html_message
        }
        input(type: 'button', class: 'close', autofocus: 'autofocus', value: 'OK')
      }
    }
  }.to_s
end

#hideObject



115
116
117
118
# File 'lib/glimmer/swt/message_box_proxy.rb', line 115

def hide
  dom_element.remove
  @open = false
end

#html_messageObject



93
94
95
# File 'lib/glimmer/swt/message_box_proxy.rb', line 93

def html_message
  message&.gsub("\n", '<br />')
end

#listener_pathObject



128
129
130
# File 'lib/glimmer/swt/message_box_proxy.rb', line 128

def listener_path
  path + ' .close'
end

#observation_request_to_event_mappingObject



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

def observation_request_to_event_mapping
  {
    'on_widget_selected' => {
      event: 'click'
    },
  }
end

#openObject



106
107
108
109
110
111
112
113
# File 'lib/glimmer/swt/message_box_proxy.rb', line 106

def open
  shell.open(async: false) unless shell.open?
  owned_proc = Glimmer::Util::ProcTracker.new(owner: self, invoked_from: :open) {
    parent.post_initialize_child(self)
    @open = true
  }
  DisplayProxy.instance.async_exec(owned_proc)
end

#open?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/glimmer/swt/message_box_proxy.rb', line 102

def open?
  @open
end

#selectorObject



124
125
126
# File 'lib/glimmer/swt/message_box_proxy.rb', line 124

def selector
  super + ' .close'
end