Skip to content

Commit

Permalink
bug on addChild
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyan11 committed Aug 1, 2024
1 parent 69dab66 commit 840f961
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 11 deletions.
46 changes: 44 additions & 2 deletions src/Pyramid-Bloc/PyramidBlocPlugin.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,47 @@ PyramidBlocPlugin class >> visibility [
^ property
]

{ #category : #accessing }
PyramidBlocPlugin class >> visibility2 [

| property |
property := PyramidProperty new
name: 'Visibility2';
command: PyramidVisibilityCommand new;
inputPresenterClass: PyramidMagicButtonsInputPresenter;
yourself.
property inputPresenterModel
addButtonModel: (PyramidMagicButtonModel new
icon: (Smalltalk ui icons iconNamed: #windowMaximize);
helpSelected: 'The object is visible.';
helpNotSelected: 'Set the value to visible.';
label: 'Visible';
inputValue: [ BlVisibility visible ];
inputValidation: [ :value | value isVisible ];
yourself);
addButtonModel: (PyramidMagicButtonModel new
icon: (Smalltalk ui icons iconNamed: #windowMaximize);
helpSelected:
'The object is hidden. (Still computed for the layout)';
helpNotSelected:
'Set the value to hidden. (Still computed for the layout)';
label: 'Hidden';
inputValue: [ BlVisibility hidden ];
inputValidation: [ :value |
value isHidden and: [ value isGone not ] ];
yourself);
addButtonModel: (PyramidMagicButtonModel new
icon: (Smalltalk ui icons iconNamed: #windowMaximize);
helpSelected: 'The object is gone. (Not computed for the layout)';
helpNotSelected:
'Set the value to gone. (Not computed for the layout)';
label: 'Gone';
inputValue: [ BlVisibility gone ];
inputValidation: [ :value | value isGone ];
yourself).
^ property
]

{ #category : #accessing }
PyramidBlocPlugin class >> zIndex [

Expand Down Expand Up @@ -192,13 +233,14 @@ PyramidBlocPlugin >> groupMenuBlockSingle [
PyramidBlocPlugin >> initialize [

super initialize.

groupCommand := PyramidGroupCommand new.

propertiesManager := PyramidPropertiesManagerForSelection new.

propertiesManager addProperty: self class elementId.
propertiesManager addProperty: self class visibility.
propertiesManager addProperty: self class visibility2.
propertiesManager addProperty: self class zIndex.
propertiesManager addProperty: self class clipChildren.
propertiesManager addProperty: self class geometry.
Expand Down
21 changes: 21 additions & 0 deletions src/Pyramid-Bloc/PyramidElementsManipulationHelper.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ PyramidElementsManipulationHelper class >> accumulateParentsOf: aCollectionOfBlE
self accumulateParentsOf: nextCollection in: result
]

{ #category : #'as yet unclassified' }
PyramidElementsManipulationHelper class >> countElementsIn: aCollection [

| result |
aCollection ifEmpty: [ ^ 0 ].
result := aCollection size.
aCollection do: [ :each |
result := result + (self recursiveCountElementsIn: each) ].
^ result
]

{ #category : #'as yet unclassified' }
PyramidElementsManipulationHelper class >> flattenChildrenOfCollection: aCollection [
"Consider:
Expand Down Expand Up @@ -79,3 +90,13 @@ PyramidElementsManipulationHelper class >> onlyParents: aCollectionOfBlElement [
self accumulateParentsOf: aCollectionOfBlElement in: result.
^ result asArray
]

{ #category : #'as yet unclassified' }
PyramidElementsManipulationHelper class >> recursiveCountElementsIn: aBlElement [

| result |
aBlElement childrenCount = 0 ifTrue: [ ^ 0 ].
result := aBlElement childrenCount.
aBlElement childrenDo: [ :each | result := result + (self recursiveCountElementsIn: each) ].
^ result
]
32 changes: 27 additions & 5 deletions src/Pyramid-Bloc/PyramidNavigationTreePresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Class {
'navigationModel',
'treeTable',
'editor',
'shouldUpdateSelection'
'shouldUpdateSelection',
'previousNumberOfElement'
],
#category : #'Pyramid-Bloc-plugin-navigation'
}
Expand Down Expand Up @@ -127,6 +128,18 @@ PyramidNavigationTreePresenter >> navigationModel: anObject [
self treeTable expandAll ]
]

{ #category : #accessing }
PyramidNavigationTreePresenter >> previousNumberOfElement [

^ previousNumberOfElement
]

{ #category : #accessing }
PyramidNavigationTreePresenter >> previousNumberOfElement: anObject [

previousNumberOfElement := anObject
]

{ #category : #api }
PyramidNavigationTreePresenter >> roots: aCollection [

Expand Down Expand Up @@ -154,14 +167,23 @@ PyramidNavigationTreePresenter >> treeTable [
{ #category : #'as yet unclassified' }
PyramidNavigationTreePresenter >> updateRoots [

| currentTreeRoots roots parent shouldOrder |
| currentTreeRoots roots parent shouldOrder calculatedNumberOfElement |
self shouldUpdateSelection: false.

roots := self editor projectModel firstLevelElements asArray.
currentTreeRoots := self treeTable roots.

(roots size = currentTreeRoots size and: [ roots includesAll: currentTreeRoots ] )ifTrue: [ self shouldUpdateSelection: true. ^ self ].


(roots size = currentTreeRoots size and: [
(roots includesAll: currentTreeRoots) and: [
calculatedNumberOfElement := self editor projectModel
numberOfElements.
calculatedNumberOfElement = self previousNumberOfElement ] ])
ifTrue: [
self shouldUpdateSelection: true.
^ self ].

self previousNumberOfElement: calculatedNumberOfElement.

parent := nil.

"If roots all have the same parent then it should be ordered by the parent children order."
Expand Down
7 changes: 7 additions & 0 deletions src/Pyramid-Bloc/PyramidProjectModel.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ PyramidProjectModel >> allElements [
^ PyramidElementsManipulationHelper flattenChildrenOfCollection:
self firstLevelElements
]

{ #category : #'*Pyramid-Bloc' }
PyramidProjectModel >> numberOfElements [

^ PyramidElementsManipulationHelper countElementsIn:
self firstLevelElements.
]
36 changes: 36 additions & 0 deletions src/Pyramid-Tests/PyramidElementsManipulationHelperTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,42 @@ D1 -> D2 -> D3.

]

{ #category : #'as yet unclassified' }
PyramidElementsManipulationHelperTest >> makeNestedElement: aNumber [

| origin current |
origin := current := BlElement new.
2 to: aNumber do: [ :i |
| temp |
temp := BlElement new.
current addChild: temp.
current := temp ].
^ origin
]

{ #category : #tests }
PyramidElementsManipulationHelperTest >> testCountElement [
"selection := {A1 . B1 . B2 . C1 . C3}.
PyramidElementsManipulationHelper onlyParents: selection
returns: { A1 . B1 . C1 }"

self
assert: (PyramidElementsManipulationHelper countElementsIn: { })
equals: 0.
self
assert: (PyramidElementsManipulationHelper countElementsIn:
{ (self makeNestedElement: 1) })
equals: 1.
self
assert: (PyramidElementsManipulationHelper countElementsIn:
{ (self makeNestedElement: 10) })
equals: 10.
self
assert: (PyramidElementsManipulationHelper countElementsIn:
{ (self makeNestedElement: 10) . (self makeNestedElement: 10) . (self makeNestedElement: 10) })
equals: 30
]

{ #category : #tests }
PyramidElementsManipulationHelperTest >> testFlattenChildrenOfCollection [

Expand Down
8 changes: 4 additions & 4 deletions src/Pyramid/PyramidProjectModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ PyramidProjectModel >> firstLevelElements [
{ #category : #'as yet unclassified' }
PyramidProjectModel >> informElementsChanged [

self announce: (PyramidElementsChangedEvent new
firstLevelElements: self firstLevelElements;
selection: self selection;
yourself)
self announce: (PyramidElementsChangedEvent new
firstLevelElements: self firstLevelElements;
selection: self selection;
yourself)
]

{ #category : #'as yet unclassified' }
Expand Down

0 comments on commit 840f961

Please sign in to comment.