Skip to content

Commit

Permalink
Find existing diagramElement before creating one
Browse files Browse the repository at this point in the history
  • Loading branch information
JanBliznicenko committed Nov 23, 2024
1 parent 231d511 commit e1c4602
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ OPAbstractDiagramControllerTest >> setUp [

super setUp.
controller model: model.
controller diagramElement: OPDiagram new.
controller canvasPresenter: (OPCanvasPresenter new
canvas: RSCanvas new;
yourself)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ OPAbstractElementControllerTest >> setUp [
diagramController canvasPresenter: (OPCanvasPresenter new
canvas: RSCanvas new;
yourself).
diagramController diagramElement: OPDiagram new.
self setUpCreationTarget
]

Expand Down
6 changes: 6 additions & 0 deletions repository/OpenPonk-Core/OPController.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ OPController >> descriptionName [
yourself
]

{ #category : 'accessing' }
OPController >> diagram [

^ self diagramController diagram
]

{ #category : 'accessing' }
OPController >> diagramController [
^ diagramController
Expand Down
4 changes: 1 addition & 3 deletions repository/OpenPonk-Core/OPDiagramController.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,6 @@ OPDiagramController >> deselectAll [
{ #category : 'accessing' }
OPDiagramController >> diagram [

self
deprecated: 'Use diagramElement instead'
transformWith: '`@receiver diagram ' -> '`@receiver diagramElement '.
^ self diagramElement
]

Expand Down Expand Up @@ -534,6 +531,7 @@ OPDiagramController >> nameOfTypeForModel: aModel [

{ #category : 'controllers management' }
OPDiagramController >> newControllerFor: aModel [

^ controllerFactory newControllerFor: aModel
]

Expand Down
20 changes: 20 additions & 0 deletions repository/OpenPonk-Core/OPDiagramElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ OPDiagramElement >> addedByMouseClickTo: aPoint [

]

{ #category : 'enumerating' }
OPDiagramElement >> allOwnedElements [

^ self ownedElements
,
(self ownedElements flatCollect: [ :each | each allOwnedElements ])
]

{ #category : 'enumerating' }
OPDiagramElement >> allOwnedShapesPositionableByUser [

Expand Down Expand Up @@ -194,6 +202,18 @@ OPDiagramElement >> createOwnedElementsWithoutController [

]

{ #category : 'accessing' }
OPDiagramElement >> diagramElementOfType: aType withModelElement: anElement ifFound: aFoundBlock [

((self isKindOf: aType) and: [ modelElements includes: anElement ])
ifTrue: [ ^ aFoundBlock cull: self ].
ownedElements do: [ :each |
each
diagramElementOfType: aType
withModelElement: anElement
ifFound: [ :found | ^ aFoundBlock cull: found ] ]
]

{ #category : 'testing' }
OPDiagramElement >> exists [

Expand Down
7 changes: 6 additions & 1 deletion repository/OpenPonk-Core/OPElementController.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ OPElementController >> ensureDiagramElement [

self diagramElement
ifExists: [ self linkDiagramElementToModel ]
else: [ self createDiagramElement ].
else: [
self diagram
diagramElementOfType: self diagramElementClass
withModelElement: self model
ifFound: [ :found | ^ self diagramElement: found ].
self createDiagramElement ].
^ self diagramElement
]

Expand Down
1 change: 1 addition & 0 deletions repository/OpenPonk-Spec/OPDiagramExplorer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ OPDiagramExplorer >> showAllElements [

{ #category : 'actions' }
OPDiagramExplorer >> showDependentFor: aModelObject [

self showElements: (self dependentFor: aModelObject)
]

Expand Down

0 comments on commit e1c4602

Please sign in to comment.