Class: RuboCop::Cop::SketchupRequirements::ObserversStartOperation
- Inherits:
-
SketchUp::Cop
- Object
- SketchUp::WorkaroundCop
- SketchUp::Cop
- RuboCop::Cop::SketchupRequirements::ObserversStartOperation
- Includes:
- RangeHelp, SketchUp::NoCommentDisable
- Defined in:
- lib/rubocop/sketchup/cop/requirements/observers_start_operation.rb
Overview
Observers that perform model changes must create transparent operations to ensure the user can easily undo.
An important part of SketchUp’s user experience is to be able to easily undo any modification to the model. This is important to prevent accidental loss of work.
If you for example have an observer that assigns a material to new faces then the user would still expect to undo this in a single operation.
To achieve this, set the fourth argument in ‘model.start_operation` to `true` in order to chain your observer operation to the previous operation.
Constant Summary collapse
- MSG =
'Observers should create transparent operations.'
- OBSERVER_METHODS =
%i[ onActivateModel onNewModel onOpenModel onQuit onUnloadExtension onComponentInstanceAdded onComponentInstanceRemoved onComponentAdded onComponentPropertiesChanged onComponentRemoved onComponentTypeChanged onTextChanged onActiveSectionPlaneChanged onElementAdded onElementModified onElementRemoved onEraseEntities onChangeEntity onEraseEntity onClose onOpen onCurrentLayerChanged onLayerAdded onLayerChanged onLayerRemoved onRemoveAllLayers onMaterialAdd onMaterialChange onMaterialRefChange onMaterialRemove onMaterialSetCurrent onMaterialUndoRedo onActivePathChanged onAfterComponentSaveAs onBeforeComponentSaveAs onDeleteModel onEraseAll onExplode onPidChanged onPlaceComponent onPostSaveModel onPreSaveModel onSaveModel onTransactionAbort onTransactionCommit onTransactionEmpty onTransactionRedo onTransactionStart onTransactionUndo onOptionsProviderChanged onContentsModified onElementAdded onElementRemoved onRenderingOptionsChanged onSelectionAdded onSelectionBulkChange onSelectionCleared onSelectionRemoved onShadowInfoChanged onActiveToolChanged onToolStateChanged onViewChanged ].freeze
Constants inherited from SketchUp::Cop
SketchUp::Cop::SKETCHUP_DEPARTMENT_SEVERITY
Constants included from SketchUp::Config
SketchUp::Config::DEFAULT_CONFIGURATION
Instance Method Summary collapse
Methods inherited from SketchUp::Cop
Instance Method Details
#on_def(node) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/rubocop/sketchup/cop/requirements/observers_start_operation.rb', line 124 def on_def(node) return unless observer_event?(node) operations = start_operation(node) operations.each { |operation| _name, _disable_ui, _next_tr, transparent = operation.arguments next unless transparent.nil? || transparent.falsey_literal? location = operation_location(operation) add_offense(operation, location: location) } end |