From 68f04c69ab203b6080b14eed56311e419608b619 Mon Sep 17 00:00:00 2001 From: Yann Le Goff Date: Tue, 29 Oct 2024 10:30:54 +0100 Subject: [PATCH 1/2] Fix Beacon event by adding a new type of breakpoints --- src/Pyramid-Bloc/PyramidBreakpoint.class.st | 50 +++++++++++++ .../PyramidPluginEditOnRunning.class.st | 70 ++++++++----------- .../PyramidPluginEditOnRunningTest.class.st | 32 ++++----- 3 files changed, 90 insertions(+), 62 deletions(-) create mode 100644 src/Pyramid-Bloc/PyramidBreakpoint.class.st diff --git a/src/Pyramid-Bloc/PyramidBreakpoint.class.st b/src/Pyramid-Bloc/PyramidBreakpoint.class.st new file mode 100644 index 00000000..f251f990 --- /dev/null +++ b/src/Pyramid-Bloc/PyramidBreakpoint.class.st @@ -0,0 +1,50 @@ +Class { + #name : #PyramidBreakpoint, + #superclass : #Breakpoint, + #instVars : [ + 'whenHitDo' + ], + #category : #'Pyramid-Bloc-plugin-edit-on-running' +} + +{ #category : #accessing } +PyramidBreakpoint class >> removeBreakpoint: aBreakpoint [ + + "Do nothing" +] + +{ #category : #api } +PyramidBreakpoint >> breakInContext: aContext node: aNode [ + + self class notifyBreakpointHit: self inContext: aContext node: aNode. + self isEnabled ifFalse: [ ^ self ]. + self onCount ifTrue: [ + self increaseCount = self breakOnCount ifFalse: [ ^ self ] ]. + self once ifTrue: [ self disable ]. + self whenHitDo value: aContext. +] + +{ #category : #initialization } +PyramidBreakpoint >> initialize [ + + super initialize. + whenHitDo := [ :c | ] +] + +{ #category : #testing } +PyramidBreakpoint >> isInstalled [ + + ^ self link methods isNotEmpty +] + +{ #category : #accessing } +PyramidBreakpoint >> whenHitDo [ + + ^ whenHitDo +] + +{ #category : #accessing } +PyramidBreakpoint >> whenHitDo: anObject [ + + whenHitDo := anObject +] diff --git a/src/Pyramid-Bloc/PyramidPluginEditOnRunning.class.st b/src/Pyramid-Bloc/PyramidPluginEditOnRunning.class.st index 0200d305..0f63398f 100644 --- a/src/Pyramid-Bloc/PyramidPluginEditOnRunning.class.st +++ b/src/Pyramid-Bloc/PyramidPluginEditOnRunning.class.st @@ -11,7 +11,8 @@ Class { 'spaceIds', 'shortcut', 'shortcutFork', - 'keyCombination' + 'keyCombination', + 'breakpoint' ], #category : #'Pyramid-Bloc-plugin-edit-on-running' } @@ -19,11 +20,13 @@ Class { { #category : #private } PyramidPluginEditOnRunning class >> addShortcutInSpace: aSpace [ - (self canEditSpace: aSpace) ifFalse:[ ^ self ]. - (self spaceIds includes: aSpace id) ifTrue:[ ^ self ]. - - self spaceIds add: aSpace id. - aSpace root addShortcut: self shortcut + (self canEditSpace: aSpace) ifFalse: [ ^ self ]. + aSpace root addShortcut: self shortcut +] + +{ #category : #initialization } +PyramidPluginEditOnRunning class >> breakpoint [ + ^ breakpoint ] { #category : #testing } @@ -78,19 +81,28 @@ PyramidPluginEditOnRunning class >> editOnRunning: aBoolean [ { #category : #initialization } PyramidPluginEditOnRunning class >> install [ - "Do some stuff here when the plugin used class oriented behavior" - - self installBlUniverseListeners. - + + self isBreakpointInstall ifTrue: [ ^ self ]. + self installBreakpoint. ] { #category : #'universe management' } -PyramidPluginEditOnRunning class >> installBlUniverseListeners [ +PyramidPluginEditOnRunning class >> installBreakpoint [ - Beacon instance - when: BlParallelUniverseOpenSpaceRequestSignal - send: #receiveBlParallelUniverseHostSpaceSignal: - to: self + | node | + node := (BlParallelUniverse methodNamed: #openSpace:) ast. + + breakpoint := PyramidBreakpoint new. + breakpoint node: node. + breakpoint whenHitDo: [ :context | self addShortcutInSpace: context arguments first ]. + breakpoint install +] + +{ #category : #initialization } +PyramidPluginEditOnRunning class >> isBreakpointInstall [ + + self breakpoint ifNil: [ ^ false ]. + ^ self breakpoint isInstalled ] { #category : #accessing } @@ -100,19 +112,11 @@ PyramidPluginEditOnRunning class >> keyCombination [ keyCombination := (BlKeyCombination builder key: KeyboardKey F12) build ] ] -{ #category : #'universe management' } -PyramidPluginEditOnRunning class >> receiveBlParallelUniverseHostSpaceSignal: anEvent [ - - BlSpace spaceWithId: anEvent spaceId do: [ :e | self addShortcutInSpace: e ] -] - { #category : #private } PyramidPluginEditOnRunning class >> removeShortcutInSpace: aSpace [ aSpace ifNil: [ ^ self ]. - aSpace root removeShortcut: self shortcut. - self spaceIds remove: aSpace id. ] { #category : #accessing } @@ -125,27 +129,9 @@ PyramidPluginEditOnRunning class >> shortcut [ action: [ :event | self doShortcutAction: event ] ] ] -{ #category : #accessing } -PyramidPluginEditOnRunning class >> spaceIds [ - - ^ spaceIds ifNil: [ spaceIds := Set new ] -] - { #category : #initialization } PyramidPluginEditOnRunning class >> uninstall [ "Undo some stuff here when the plugin used class oriented behavior" - - self uninstallBlUniverseListeners. - - self spaceIds do:[ :id | BlSpace spaceWithId: id do: [ :e | self removeShortcutInSpace: e ] ]. - self spaceIds removeAll. - shortcutFork ifNotNil: [ shortcutFork terminate. shortcutFork := nil ]. - shortcut := nil. - keyCombination := nil. -] - -{ #category : #'universe management' } -PyramidPluginEditOnRunning class >> uninstallBlUniverseListeners [ - Beacon instance unsubscribe: self + self breakpoint ifNotNil: [ :b | b remove ] ] diff --git a/src/Pyramid-Tests/PyramidPluginEditOnRunningTest.class.st b/src/Pyramid-Tests/PyramidPluginEditOnRunningTest.class.st index b9c209b8..8eb964c0 100644 --- a/src/Pyramid-Tests/PyramidPluginEditOnRunningTest.class.st +++ b/src/Pyramid-Tests/PyramidPluginEditOnRunningTest.class.st @@ -13,9 +13,9 @@ Class { { #category : #utils } PyramidPluginEditOnRunningTest >> closeSpace: aSpace [ - aSpace when: BlSpaceShownEvent doOnce: [ :event | + aSpace addEventHandlerOn: BlSpaceShownEvent doOnce: [ :event | BlSpace pulseUntilEmptyTaskQueue: aSpace timeout: 200 milliSeconds. - aSpace close ]. + aSpace close ] ] { #category : #tests } @@ -42,19 +42,19 @@ PyramidPluginEditOnRunningTest >> tearDown [ { #category : #tests } PyramidPluginEditOnRunningTest >> testBlSpaceShortcutAddAndRemove [ - | space | + | space | PyramidPluginEditOnRunning editOnRunning: true. - + space := BlSpace new. - self deny: (PyramidPluginEditOnRunning spaceIds includes: space id). - self deny: (space root shortcuts includes: (PyramidPluginEditOnRunning shortcut)). - - space show. - self assert: (PyramidPluginEditOnRunning spaceIds includes: space id). - self assert: (space root shortcuts includes: (PyramidPluginEditOnRunning shortcut)). - - self closeSpace: space. + self deny: + (space root shortcuts includes: PyramidPluginEditOnRunning shortcut). + + space show. + self assert: + (space root shortcuts includes: PyramidPluginEditOnRunning shortcut). + + self closeSpace: space ] { #category : #tests } @@ -68,7 +68,6 @@ PyramidPluginEditOnRunningTest >> testCannotEditTheEditor [ space := (editor findPlugin: PyramidSpacePlugin) builder space. "check than the shortcut is not installed" - self deny: (PyramidPluginEditOnRunning spaceIds includes: space id). self deny: (space root shortcuts includes: PyramidPluginEditOnRunning shortcut) ] @@ -103,10 +102,3 @@ PyramidPluginEditOnRunningTest >> testShortcut [ self assert: (PyramidPluginEditOnRunning shortcut isKindOf: BlShortcutWithAction). ] - -{ #category : #tests } -PyramidPluginEditOnRunningTest >> testSpaceIds [ - - self assert: PyramidPluginEditOnRunning spaceIds isEmpty. - -] From b74efa5e6e69b5d676b5c8fa9b551e61a0dd15b1 Mon Sep 17 00:00:00 2001 From: Yann Le Goff Date: Tue, 29 Oct 2024 10:41:57 +0100 Subject: [PATCH 2/2] update event name for space testing --- src/Pyramid-Bloc/PyramidSpacePlugin.class.st | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Pyramid-Bloc/PyramidSpacePlugin.class.st b/src/Pyramid-Bloc/PyramidSpacePlugin.class.st index 8a92b424..ac658044 100644 --- a/src/Pyramid-Bloc/PyramidSpacePlugin.class.st +++ b/src/Pyramid-Bloc/PyramidSpacePlugin.class.st @@ -40,7 +40,8 @@ PyramidSpacePlugin >> initialize [ builder := PyramidSpaceBuilder defaultEditorBuilder. morphicPresenter := SpMorphPresenter new. resetSpaceButton := SpButtonPresenter new - icon: (Smalltalk ui icons iconNamed: #smallUpdate); + icon: + (Smalltalk ui icons iconNamed: #smallUpdate); action: [ self resetSpace ]; help: 'Refresh space in case of an issue'; yourself @@ -61,9 +62,8 @@ PyramidSpacePlugin >> makePresenterWithBlSpace: aBlSpace [ aBlSpace host: host. aBlSpace addEventHandler: (BlEventHandler - on: BlSpaceDestroyedEvent - do: [ :evt | - self updateMorphInCaseOfFaillure: morph ]). + on: BlSpaceClosedEvent + do: [ :evt | self updateMorphInCaseOfFaillure: morph ]). self morphicPresenter morph: morph. self morphicPresenter whenDisplayDo: [ aBlSpace show ]