Class: Glimmer::LibUI::ControlProxy::MenuItemProxy::QuitMenuItemProxy

Inherits:
Glimmer::LibUI::ControlProxy::MenuItemProxy show all
Defined in:
lib/glimmer/libui/control_proxy/menu_item_proxy/quit_menu_item_proxy.rb

Overview

Proxy for LibUI quit menu item object

Follows the Proxy Design Pattern

Constant Summary

Constants inherited from Glimmer::LibUI::ControlProxy

BOOLEAN_PROPERTIES, KEYWORD_ALIASES, STRING_PROPERTIES, TransformProxy

Instance Attribute Summary

Attributes inherited from Glimmer::LibUI::ControlProxy

#args, #block, #content_added, #custom_control, #keyword, #libui, #options, #parent_custom_control, #parent_proxy, #slot

Instance Method Summary collapse

Methods inherited from Glimmer::LibUI::ControlProxy::MenuItemProxy

#libui_api_keyword

Methods inherited from Glimmer::LibUI::ControlProxy

#append_properties, #append_property, #bind_content, constant_symbol, #content, control_proxies, control_proxy_class, create, #custom_listener_name_aliases, #custom_listener_names, #default_destroy, #deregister_all_custom_listeners, #deregister_custom_listeners, descendant_keyword_constant_map, #destroy_child, #enabled, exists?, #handle_custom_listener, #has_custom_listener?, image_proxies, #initialize, keyword, #libui_api_keyword, #listeners, #listeners_for, main_window_proxy, map_descendant_keyword_constants_for, menu_proxies, #method_missing, new_control, #notify_custom_listeners, #post_add_content, #post_initialize_child, reset_descendant_keyword_constant_map, #respond_to?, #respond_to_libui?, #send_to_libui, #visible, #window_proxy

Methods included from DataBindable

#data_bind, #data_bind_read, #data_bind_write, #data_binding_model_attribute_observer_registrations

Methods included from Parent

#children, #post_initialize_child

Constructor Details

This class inherits a constructor from Glimmer::LibUI::ControlProxy

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Glimmer::LibUI::ControlProxy

Instance Method Details

#can_handle_listener?(listener_name) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/glimmer/libui/control_proxy/menu_item_proxy/quit_menu_item_proxy.rb', line 32

def can_handle_listener?(listener_name)
  listener_name == 'on_clicked' || super
end

#destroyObject



59
60
61
62
# File 'lib/glimmer/libui/control_proxy/menu_item_proxy/quit_menu_item_proxy.rb', line 59

def destroy
  @on_clicked_listeners&.clear
  super
end

#handle_listener(listener_name, &listener) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/glimmer/libui/control_proxy/menu_item_proxy/quit_menu_item_proxy.rb', line 36

def handle_listener(listener_name, &listener)
  if listener_name == 'on_clicked'
    @on_clicked_listeners ||= []
    @on_clicked_listeners << listener
    @default_behavior_listener ||= Proc.new do
      return_value = nil
      @on_clicked_listeners.each do |l|
        return_value = l.call(self)
        break if return_value.is_a?(Numeric)
      end
      if return_value.is_a?(Numeric)
        return_value
      else
        ControlProxy.main_window_proxy&.destroy
        ::LibUI.quit
        0
      end
    end.tap do |default_behavior_listener|
      ::LibUI.on_should_quit(&default_behavior_listener)
    end
  end
end