Class: Lich::Common::GUI::TabCommunicator
- Inherits:
-
Object
- Object
- Lich::Common::GUI::TabCommunicator
- 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.
Instance Method Summary collapse
-
#clear_callbacks ⇒ void
Clears all registered data change callbacks.
-
#initialize ⇒ TabCommunicator
constructor
A new instance of TabCommunicator.
-
#notify_data_changed(change_type = :general, data = {}) ⇒ void
Notifies all registered callbacks that data has changed.
-
#register_data_change_callback(callback) ⇒ void
Registers a callback to be invoked when data changes.
-
#unregister_data_change_callback(callback) ⇒ void
Unregisters a previously registered data change callback.
Constructor Details
#initialize ⇒ TabCommunicator
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_callbacks ⇒ void
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.
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.}" end end end |
#register_data_change_callback(callback) ⇒ void
This method returns an undefined value.
Registers a callback to be invoked when data changes.
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.
45 46 47 |
# File 'documented/common/gui/tab_communicator.rb', line 45 def unregister_data_change_callback(callback) @data_change_callbacks.delete(callback) end |