Implement on_document_changed action

This commit is contained in:
oguzhankoral
2023-07-14 11:46:55 +03:00
parent 9459362a3b
commit e1de48f831
2 changed files with 23 additions and 1 deletions
@@ -1,6 +1,7 @@
# frozen_string_literal: true
require_relative 'event_action'
require_relative 'on_document_changed'
require_relative '../load_sketchup_model'
require_relative '../collect_preferences'
@@ -25,7 +26,8 @@ module SpeckleConnector
# Action to let UI to render itself with new preferences state
# TODO: Later UI should be updated if any stream is invalid after
# we collected speckle_entities appropriately
CollectPreferences.update_state(new_state, {})
# new_state = CollectPreferences.update_state(new_state, nil, {})
OnDocumentChanged.update_state(new_state)
end
end
@@ -0,0 +1,20 @@
# frozen_string_literal: true
module SpeckleConnector
module Actions
# Triggers whenever document has changed.
class OnDocumentChanged < Action
# @param state [States::State] the current state of the {App::SpeckleConnectorApp}
# @return [States::State] the new updated state object
def self.update_state(state)
document_info = {
location: state.sketchup_state.sketchup_model.path,
name: state.sketchup_state.sketchup_model.name,
id: state.sketchup_state.sketchup_model.guid
}
js_command = "baseBinding.emit('documentChanged', #{JSON.unparse(document_info.to_json)})"
state.with_add_queue_js_command('getDocumentInfo', js_command)
end
end
end
end