diff --git a/speckle_connector/src/actions/events/app_event_action.rb b/speckle_connector/src/actions/events/app_event_action.rb index 2d9dc80..bd5aa5f 100644 --- a/speckle_connector/src/actions/events/app_event_action.rb +++ b/speckle_connector/src/actions/events/app_event_action.rb @@ -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 diff --git a/speckle_connector/src/actions/events/on_document_changed.rb b/speckle_connector/src/actions/events/on_document_changed.rb new file mode 100644 index 0000000..17e1db8 --- /dev/null +++ b/speckle_connector/src/actions/events/on_document_changed.rb @@ -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