Module: SKUI::ControlManager Abstract

Included in:
Container, Window
Defined in:
src/SKUI/control_manager.rb

Overview

This module is abstract.

‘Container` and `Window` implements this.

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#controlsObject (readonly)

Since:

  • 1.0.0



7
8
9
# File 'src/SKUI/control_manager.rb', line 7

def controls
  @controls
end

Instance Method Details

#add_control(control) ⇒ Boolean

Returns ‘True` if the webdialog was open and the control added.

Parameters:

Returns:

  • (Boolean)

    ‘True` if the webdialog was open and the control added.

Since:

  • 1.0.0



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'src/SKUI/control_manager.rb', line 19

def add_control( control )
  unless control.is_a?( Control )
    raise( ArgumentError, 'Expected Control' )
  end
  if control.parent
    raise( ArgumentError, 'Control already has a parent' )
  end
  # Add to Ruby DOM tree
  @controls << control
  control.parent = self
  control.window = self.window
  # Add to Webdialog
  if self.window && self.window.visible?
    self.window.bridge.add_control( control )
    if control.is_a?(ControlManager)
      self.window.bridge.add_container( control )
    end
    return true
  end
  false
end

#find_control_by_name(name) ⇒ Control, Nil Also known as: []

Parameters:

  • name (Symbol)

Returns:

Since:

  • 1.0.0



61
62
63
64
65
66
67
68
69
70
# File 'src/SKUI/control_manager.rb', line 61

def find_control_by_name( name )
  for control in @controls
    return control if control.name == name
    if control.is_a?( ControlManager )
      result = control.find_control_by_name( name )
      return result if result
    end
  end
  nil
end

#find_control_by_ui_id(ui_id) ⇒ Control, Nil

Parameters:

  • ui_id (String)

Returns:

Since:

  • 1.0.0



45
46
47
48
49
50
51
52
53
54
55
# File 'src/SKUI/control_manager.rb', line 45

def find_control_by_ui_id( ui_id )
  return self if self.ui_id == ui_id
  for control in @controls
    return control if control.ui_id == ui_id
    if control.is_a?( ControlManager )
      result = control.find_control_by_ui_id( ui_id )
      return result if result
    end
  end
  nil
end

#initializeObject

Since:

  • 1.0.0



10
11
12
13
# File 'src/SKUI/control_manager.rb', line 10

def initialize
  super()
  @controls = []
end

#releaseNil

Returns:

  • (Nil)

See Also:

Since:

  • 1.0.0



76
77
78
79
80
81
82
# File 'src/SKUI/control_manager.rb', line 76

def release
  for control in @controls
    remove_control( control )
  end
  @controls.clear
  super
end

#remove_control(control) ⇒ Boolean

Returns ‘True` if the webdialog was open and the control removed.

Parameters:

Returns:

  • (Boolean)

    ‘True` if the webdialog was open and the control removed.

Raises:

  • (ArgumentError)

Since:

  • 1.0.0



88
89
90
91
92
93
94
95
96
97
98
99
# File 'src/SKUI/control_manager.rb', line 88

def remove_control( control )
  raise( ArgumentError, 'Expected Control' ) unless control.is_a?( Control )
  raise( IndexError, 'Control not found' ) unless controls.include?( control )
  @controls.delete( control )
  control_ui_id = control.ui_id
  control.release
  if self.window && self.window.visible?
    self.window.bridge.call( 'UI.remove_control', control_ui_id )
    return true
  end
  false
end