From f7fa5141e740c370e8b14d2b4e610b85880ca4e9 Mon Sep 17 00:00:00 2001 From: Yann Le Goff Date: Tue, 30 Sep 2025 10:34:56 +0200 Subject: [PATCH 1/2] Add 2 code presenter for all elements and for selection --- .../PyramidSaveModelVerifier.class.st | 6 +- .../PyramidShowCodePlugin.class.st | 147 ++++++++++++++++++ 2 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 src/Pyramid-Bloc/PyramidShowCodePlugin.class.st diff --git a/src/Pyramid-Bloc/PyramidSaveModelVerifier.class.st b/src/Pyramid-Bloc/PyramidSaveModelVerifier.class.st index 50b6bbbd..6374cc47 100644 --- a/src/Pyramid-Bloc/PyramidSaveModelVerifier.class.st +++ b/src/Pyramid-Bloc/PyramidSaveModelVerifier.class.st @@ -47,10 +47,10 @@ PyramidSaveModelVerifier class >> classPackageIsEqual [ PyramidSaveModelVerifier class >> methodIsValid [ ^ self new - verifyBlock: [ :model | model savingMethodName isValidSelector ]; + verifyBlock: [ :model | + OCScanner isSelector: model savingMethodName ]; showBlock: [ :view | view showMethodIsNotValidError ]; - yourself. - + yourself ] { #category : #constructor } diff --git a/src/Pyramid-Bloc/PyramidShowCodePlugin.class.st b/src/Pyramid-Bloc/PyramidShowCodePlugin.class.st new file mode 100644 index 00000000..3093f8bd --- /dev/null +++ b/src/Pyramid-Bloc/PyramidShowCodePlugin.class.st @@ -0,0 +1,147 @@ +Class { + #name : #PyramidShowCodePlugin, + #superclass : #Object, + #traits : 'TPyramidPlugin', + #classTraits : 'TPyramidPlugin classTrait', + #instVars : [ + 'codePresenterForAll', + 'codePresenterForSelection', + 'projectModel' + ], + #category : #'Pyramid-Bloc-plugin-showcode' +} + +{ #category : #adding } +PyramidShowCodePlugin >> addPanelsOn: aPyramidSimpleWindow [ + + aPyramidSimpleWindow at: #tabLeft addItem: [ :builder | + builder + makeTab: self codePresenterForAll + label: 'Code for all' + icon: (Smalltalk ui icons iconNamed: #page) + order: 5 ]. + aPyramidSimpleWindow at: #tabRight addItem: [ :builder | + builder + makeTab: self codePresenterForSelection + label: 'Code for selection' + icon: (Smalltalk ui icons iconNamed: #page) + order: 999 ] +] + +{ #category : #accessing } +PyramidShowCodePlugin >> codePresenterForAll [ + + ^ codePresenterForAll +] + +{ #category : #accessing } +PyramidShowCodePlugin >> codePresenterForSelection [ + + ^ codePresenterForSelection +] + +{ #category : #connecting } +PyramidShowCodePlugin >> connectOn: aPyramidEditor [ + + projectModel := aPyramidEditor projectModel. + aPyramidEditor projectModel announcer + when: PyramidElementsChangedEvent + do: [ :evt | self elementsChanged: evt ] + for: self. + aPyramidEditor projectModel announcer + when: PyramidFirstLevelElementsChangedEvent + do: [ :evt | self firstLevelElementsChanged: evt ] + for: self. + aPyramidEditor projectModel announcer + when: PyramidSelectionChangedEvent + do: [ :evt | self selectionChanged: evt ] + for: self +] + +{ #category : #'as yet unclassified' } +PyramidShowCodePlugin >> elementsChanged: aPyramidElementsChangedEvent [ + + self firstLevelElementsChanged: aPyramidElementsChangedEvent. + self selectionChanged: aPyramidElementsChangedEvent +] + +{ #category : #'as yet unclassified' } +PyramidShowCodePlugin >> firstLevelElementsChanged: aPyramidFirstLevelElementsChangedEvent [ + + self codePresenterForAll text: (Stash new serialize: + aPyramidFirstLevelElementsChangedEvent firstLevelElements) +] + +{ #category : #initialization } +PyramidShowCodePlugin >> initialize [ + + super initialize. + codePresenterForAll := SpCodePresenter new + beForScripting; + whenSubmitDo: [ :text | + self validateCodeForAll: text ]; + yourself. + codePresenterForSelection := SpCodePresenter new + beForScripting; + whenSubmitDo: [ :text | + self validateCodeForSelection: text ]; + yourself +] + +{ #category : #accessing } +PyramidShowCodePlugin >> projectModel [ + + ^ projectModel +] + +{ #category : #'event handling' } +PyramidShowCodePlugin >> selectionChanged: aPyramidSelectionChangedEvent [ + + self codePresenterForSelection text: ''. + aPyramidSelectionChangedEvent selection ifEmpty: [ + self codePresenterForSelection text: '"Select one element."'. + ^ self ]. + aPyramidSelectionChangedEvent selection size > 2 ifTrue: [ + self codePresenterForSelection text: '"Select only one element."'. + ^ self ]. + self codePresenterForSelection text: (Stash new serialize: + aPyramidSelectionChangedEvent selection first) +] + +{ #category : #'as yet unclassified' } +PyramidShowCodePlugin >> validateCodeForAll: aString [ + + | collection | + collection := Stash new materialize: aString. + collection isCollection ifFalse: [ + ^ self inform: 'Could not serialize: The code is not a collection.' ]. + (collection allSatisfy: [ :each | each isKindOf: BlElement ]) + ifFalse: [ + ^ self inform: + 'Could not serialize: Not BlElement found in the code.' ]. + self projectModel firstLevelElements replaceAll: collection. + self projectModel updateSelection +] + +{ #category : #'as yet unclassified' } +PyramidShowCodePlugin >> validateCodeForSelection: aString [ + + | newElement currentSelection | + newElement := Stash new materialize: aString. + (newElement isKindOf: BlElement) ifFalse: [ + ^ self inform: 'Could not serialize: The code is not a BlElement.' ]. + self projectModel selection size = 1 ifFalse: [ + ^ self inform: + 'Could not serialize: The selection should only contains one element.' ]. + currentSelection := self projectModel selection first. + (self projectModel firstLevelElements includes: currentSelection) + ifTrue: [ + self projectModel firstLevelElements replaceAll: + (self projectModel firstLevelElements asArray + copyReplaceAll: { currentSelection } + with: { newElement }) ]. + currentSelection parent ifNotNil: [ :p | + p replaceChild: currentSelection with: newElement ]. + + self projectModel selection replaceAll: { newElement } +] From ea1894560d06b640fa19dbdf20be6093add9d882 Mon Sep 17 00:00:00 2001 From: Yann Le Goff Date: Tue, 30 Sep 2025 10:43:21 +0200 Subject: [PATCH 2/2] Fix OCScanner for Pharo12 --- src/Pyramid-Bloc/PyramidSaveModelVerifier.class.st | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Pyramid-Bloc/PyramidSaveModelVerifier.class.st b/src/Pyramid-Bloc/PyramidSaveModelVerifier.class.st index 6374cc47..d8425326 100644 --- a/src/Pyramid-Bloc/PyramidSaveModelVerifier.class.st +++ b/src/Pyramid-Bloc/PyramidSaveModelVerifier.class.st @@ -47,10 +47,9 @@ PyramidSaveModelVerifier class >> classPackageIsEqual [ PyramidSaveModelVerifier class >> methodIsValid [ ^ self new - verifyBlock: [ :model | - OCScanner isSelector: model savingMethodName ]; + verifyBlock: [ :model | model savingMethodName isValidSelector ]; showBlock: [ :view | view showMethodIsNotValidError ]; - yourself + yourself. ] { #category : #constructor }