Class: Lich::Common::GUI::TabCommunicator

Inherits:
Object
  • Object
show all
Defined in:
documented/common/gui/tab_communicator.rb

Overview

Handles communication between tabs in the GUI.

This class allows for registering and notifying callbacks related to data changes within the tabs.

See Also:

Instance Method Summary collapse

Constructor Details

#initializeTabCommunicator

Returns a new instance of TabCommunicator.



12
13
14
# File 'documented/common/gui/tab_communicator.rb', line 12

def initialize
  @data_change_callbacks = []
end

Instance Method Details

#clear_callbacksvoid

This method returns an undefined value.

Clears all registered data change callbacks.



51
52
53
# File 'documented/common/gui/tab_communicator.rb', line 51

def clear_callbacks
  @data_change_callbacks.clear
end

#notify_data_changed(change_type = :general, data = {}) ⇒ void

This method returns an undefined value.

Notifies all registered callbacks that data has changed.

Examples:

Notify a general data change

communicator.notify_data_changed(:general, { key: "value" })

Parameters:

  • change_type (Symbol) (defaults to: :general)

    the type of change (default: :general)

  • data (Hash) (defaults to: {})

    the data associated with the change (default: {})



31
32
33
34
35
36
37
38
39
# File 'documented/common/gui/tab_communicator.rb', line 31

def notify_data_changed(change_type = :general, data = {})
  @data_change_callbacks.each do |callback|
    begin
      callback.call(change_type, data)
    rescue StandardError => e
      Lich.log "error: Error in data change callback: #{e.message}"
    end
  end
end

#register_data_change_callback(callback) ⇒ void

This method returns an undefined value.

Registers a callback to be invoked when data changes.

Parameters:

  • callback (Proc)

    the callback to be registered



20
21
22
# File 'documented/common/gui/tab_communicator.rb', line 20

def register_data_change_callback(callback)
  @data_change_callbacks << callback if callback.respond_to?(:call)
end

#unregister_data_change_callback(callback) ⇒ void

This method returns an undefined value.

Unregisters a previously registered data change callback.

Parameters:

  • callback (Proc)

    the callback to be unregistered



45
46
47
# File 'documented/common/gui/tab_communicator.rb', line 45

def unregister_data_change_callback(callback)
  @data_change_callbacks.delete(callback)
end