diff --git a/README.md b/README.md index 8baa9869..79a5bd75 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ element editWithPyramid. space editWithPyramid. ``` -You can edit in Pyramid an opened BlSpace with `F12` keyboard shortcut, for that open a BlElement with `openInNewSpaceWithPyramidShortcut`. +You can edit in Pyramid all opened BlSpace with `F12` keyboard shortcut, this feature can be disable in the settings. ## Plugins diff --git a/src/Pyramid-Bloc/PyramidContextMenuPlugin.class.st b/src/Pyramid-Bloc/PyramidContextMenuPlugin.class.st index e259496a..4d8955d3 100644 --- a/src/Pyramid-Bloc/PyramidContextMenuPlugin.class.st +++ b/src/Pyramid-Bloc/PyramidContextMenuPlugin.class.st @@ -12,8 +12,10 @@ Class { { #category : #'class initialization' } PyramidContextMenuPlugin class >> initialize [ - self flag:'labordep: Why remove before add ?'. + "Remove the plugin in case of already install (reset)" PyramidPluginManager uniqueInstance removePlugin: self. + + "Add the plugin" PyramidPluginManager uniqueInstance addPlugin: self ] diff --git a/src/Pyramid/PyramidEditOnRunningSystemSettings.class.st b/src/Pyramid-Bloc/PyramidEditOnRunningSystemSettings.class.st similarity index 81% rename from src/Pyramid/PyramidEditOnRunningSystemSettings.class.st rename to src/Pyramid-Bloc/PyramidEditOnRunningSystemSettings.class.st index cf6444db..eab68240 100644 --- a/src/Pyramid/PyramidEditOnRunningSystemSettings.class.st +++ b/src/Pyramid-Bloc/PyramidEditOnRunningSystemSettings.class.st @@ -1,7 +1,7 @@ Class { #name : #PyramidEditOnRunningSystemSettings, #superclass : #Object, - #category : #'Pyramid-plugin-edit-on-running' + #category : #'Pyramid-Bloc-plugin-edit-on-running' } { #category : #dialog } @@ -9,7 +9,7 @@ PyramidEditOnRunningSystemSettings class >> canEditDialog: aBuilder [ ^ self theme newRowIn: self for: { "Default shortcut is F12 because it is usually use to enter dev mode in webbrowsers" - self theme buttonLabelForText: 'with shortcut: F12' translated. + self theme buttonLabelForText: 'with key shortcut: F12' translated. } ] @@ -31,10 +31,10 @@ PyramidEditOnRunningSystemSettings class >> editOnRunningSettingOn: aBuilder [ (aBuilder setting: #editOnRunning) parent: #pyramid; - label: '(Not working) Can edit opened BlSpaces'; + label: 'Can edit Bloc opened windows'; target: self; dialog: [self canEditDialog: aBuilder]; - description: 'Setup availability to edit opened BlSpace in a Pyramid window. + description: 'Setup availability to edit opened BlSpace window in Pyramid editor. Press the required shortcut key(s) on a focused BlSpace window to edit it in Pyramid.' ] diff --git a/src/Pyramid-Bloc/PyramidPluginEditOnRunning.class.st b/src/Pyramid-Bloc/PyramidPluginEditOnRunning.class.st new file mode 100644 index 00000000..a2d5baa1 --- /dev/null +++ b/src/Pyramid-Bloc/PyramidPluginEditOnRunning.class.st @@ -0,0 +1,171 @@ +Class { + #name : #PyramidPluginEditOnRunning, + #superclass : #Object, + #traits : 'TPyramidPlugin', + #classTraits : 'TPyramidPlugin classTrait', + #instVars : [ + 'editOnRunning' + ], + #classInstVars : [ + 'editOnRunning', + 'spaceIds', + 'shortcut', + 'shortcutFork', + 'keyCombination' + ], + #category : #'Pyramid-Bloc-plugin-edit-on-running' +} + +{ #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 +] + +{ #category : #testing } +PyramidPluginEditOnRunning class >> canEditSpace: aSpace [ + + aSpace ifNil:[ ^ false ]. + + "Not edit the editor space or already edited to prevent cycling" + aSpace userData at: #pyramid_isEditor ifPresent:[ ^ false ]. + aSpace userData at: #pyramid_isOnEdition ifPresent:[ ^ false ]. + + ^ true +] + +{ #category : #initialization } +PyramidPluginEditOnRunning class >> cleanUp: anObject [ + + "do nothing" +] + +{ #category : #private } +PyramidPluginEditOnRunning class >> doShortcutAction: anEvent [ + + | space editor whenClosedDo | + + self flag:'labordep: this is a temporary processing because this fork is due to a Bloc opened issue'. + (shortcutFork notNil and:[ shortcutFork isTerminated not ]) ifTrue:[ ^ self ]. + + shortcutFork := [ + + self editOnRunning ifTrue:[ + space := anEvent source space. + (self canEditSpace: space) ifTrue:[ + editor := space editWithPyramid. + whenClosedDo := editor window whenClosedDo. + editor window whenClosedDo: [ whenClosedDo value ]. + ]. + ]. + + ] forkAt: Processor userBackgroundPriority named: 'Pyramid edit-on-running plugin shortcut' +] + +{ #category : #accessing } +PyramidPluginEditOnRunning class >> editOnRunning [ + + ^ editOnRunning ifNil: [ editOnRunning := true ] +] + +{ #category : #accessing } +PyramidPluginEditOnRunning class >> editOnRunning: aBoolean [ + + editOnRunning := aBoolean +] + +{ #category : #initialization } +PyramidPluginEditOnRunning class >> install [ + "Do some stuff here when the plugin used class oriented behavior" + + self installBlUniverseListeners. + +] + +{ #category : #'universe management' } +PyramidPluginEditOnRunning class >> installBlUniverseListeners [ + + Beacon instance + when: BlParallelUniverseOpenSpaceRequestSignal + send: #receiveBlParallelUniverseHostSpaceSignal: + to: self +] + +{ #category : #accessing } +PyramidPluginEditOnRunning class >> keyCombination [ + + ^ keyCombination ifNil: [ + 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 } +PyramidPluginEditOnRunning class >> shortcut [ + + ^ shortcut ifNil: [ + shortcut := BlShortcutWithAction new + name: 'Pyramid edition shortcut'; + combination: self keyCombination; + 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 +] + +{ #category : #adding } +PyramidPluginEditOnRunning >> addPanelsOn: aPyramidSimpleWindow [ + + "do nothing" +] + +{ #category : #actions } +PyramidPluginEditOnRunning >> configureBuilder: aPyramidEditorBuilder [ + + "do nothing" +] + +{ #category : #connecting } +PyramidPluginEditOnRunning >> connectOn: aPyramidEditor [ + + "do nothing" +] diff --git a/src/Pyramid-Bloc/PyramidSavePlugin.class.st b/src/Pyramid-Bloc/PyramidSavePlugin.class.st index 7c7ee66f..0516fdea 100644 --- a/src/Pyramid-Bloc/PyramidSavePlugin.class.st +++ b/src/Pyramid-Bloc/PyramidSavePlugin.class.st @@ -19,7 +19,7 @@ Class { PyramidSavePlugin class >> openOn: aCollectionOfBlElement saveModel: aSaveModel [ | editor savePlugin | - editor := PyramidEditorBuilder makeEditor. + editor := PyramidEditor buildEditor. savePlugin := editor plugins select: [ :each | each class = self ]. savePlugin size = 1 ifFalse: [ Error signal: @@ -27,7 +27,7 @@ PyramidSavePlugin class >> openOn: aCollectionOfBlElement saveModel: aSaveModel savePlugin := savePlugin asArray first. editor projectModel roots addAll: aCollectionOfBlElement. savePlugin openOn: aSaveModel. - editor window open + editor open ] { #category : #adding } diff --git a/src/Pyramid-Bloc/PyramidSpaceBuilder.class.st b/src/Pyramid-Bloc/PyramidSpaceBuilder.class.st index 271dbe6f..edfb5595 100644 --- a/src/Pyramid-Bloc/PyramidSpaceBuilder.class.st +++ b/src/Pyramid-Bloc/PyramidSpaceBuilder.class.st @@ -89,6 +89,7 @@ PyramidSpaceBuilder >> addOverlayNamed: aString [ PyramidSpaceBuilder >> build [ self space: BlSpace new. + self space userData at: #pyramid_isEditor put: true. self overlays ifEmpty: [ ^ self space ]. diff --git a/src/Pyramid-Bloc/PyramidVisualPystonForCly.class.st b/src/Pyramid-Bloc/PyramidVisualPystonForCly.class.st index 633247a9..f5b4eb74 100644 --- a/src/Pyramid-Bloc/PyramidVisualPystonForCly.class.st +++ b/src/Pyramid-Bloc/PyramidVisualPystonForCly.class.st @@ -99,8 +99,10 @@ PyramidVisualPystonForCly >> build [ { #category : #'as yet unclassified' } PyramidVisualPystonForCly >> buttonEditor [ - ^ self buttonLabel: 'Edit' help: 'Open the design in Pyramid' action: [ self openEditor ]. - + ^ self + buttonLabel: 'Edit' + help: 'Edit this design in Pyramid' + action: [ self openEditor ] ] { #category : #'as yet unclassified' } @@ -123,10 +125,9 @@ PyramidVisualPystonForCly >> buttonLabel: aLabel help: aString action: aBlock [ PyramidVisualPystonForCly >> buttonOpen [ ^ self - buttonLabel: 'Open in new Space' - help: 'Open this design in a new BlSpace' + buttonLabel: 'Open' + help: 'Open this design in a window' action: [ self openInNewSpace ] - ] { #category : #initialization } @@ -200,7 +201,7 @@ PyramidVisualPystonForCly >> openInNewSpace [ elements isCollection ifFalse: [ elements := { elements } ]. elements ifEmpty: [ ^ self ]. - space := elements first openInNewSpaceWithPyramidShortcut. + space := elements first openInNewSpace. space root addChildren: elements allButFirst ] diff --git a/src/Pyramid-IDE/PyramidWorld.class.st b/src/Pyramid-IDE/PyramidWorld.class.st index ca8cc1b3..6f0b40c1 100644 --- a/src/Pyramid-IDE/PyramidWorld.class.st +++ b/src/Pyramid-IDE/PyramidWorld.class.st @@ -17,7 +17,9 @@ PyramidWorld class >> displayLoadedPlugins [ "Statistics" stream nextPutAll: (e pluginClasses size) asString; - nextPutAll: ' loaded plugin(s).'; + nextPutAll: ' loaded / '; + nextPutAll: (PyramidPluginManager imagePluginClasses size) asString; + nextPutAll: ' available plugin(s)'; cr; cr. "Details" @@ -161,7 +163,7 @@ PyramidWorld class >> startBrowseSources [ { #category : #actions } PyramidWorld class >> startNewDesign [ - PyramidPluginManager uniqueInstance makeEditor window open + PyramidEditor open ] { #category : #actions } diff --git a/src/Pyramid-Tests/PyramidEditorTest.class.st b/src/Pyramid-Tests/PyramidEditorTest.class.st index 30d6ced1..e21904e9 100644 --- a/src/Pyramid-Tests/PyramidEditorTest.class.st +++ b/src/Pyramid-Tests/PyramidEditorTest.class.st @@ -22,7 +22,7 @@ PyramidEditorTest >> openFromBlSpace [ self assert: (editor projectModel roots includes: element). self deny: (space root children includes: element). - editor window close. + editor close. (Duration milliSeconds: 10) wait. self assert: editor window isClosed. @@ -34,14 +34,16 @@ PyramidEditorTest >> openFromBlSpace [ PyramidEditorTest >> openNewEditor [ | editor spec | - editor := PyramidPluginManager uniqueInstance makeEditor. - spec := editor window open. + editor := PyramidEditor buildEditor. + editor open. + + spec := editor window spec. (Duration milliSeconds: 10) wait. self currentWorld doOneCycle. self assert: editor window isOpen. self assert: spec window isInWorld. - editor window close. + editor close. (Duration milliSeconds: 10) wait. self currentWorld doOneCycle. self assert: editor window isClosed. diff --git a/src/Pyramid-Tests/PyramidPluginEditOnRunningTest.class.st b/src/Pyramid-Tests/PyramidPluginEditOnRunningTest.class.st index 7b6f078f..1b3b646f 100644 --- a/src/Pyramid-Tests/PyramidPluginEditOnRunningTest.class.st +++ b/src/Pyramid-Tests/PyramidPluginEditOnRunningTest.class.st @@ -10,11 +10,24 @@ Class { #category : #'Pyramid-Tests-cases-plugin-edit-on-running' } +{ #category : #utils } +PyramidPluginEditOnRunningTest >> closeSpace: aSpace [ + + aSpace when: BlSpaceShownEvent doOnce: [ :event | + BlSpace pulseUntilEmptyTaskQueue: aSpace timeout: 200 milliSeconds. + aSpace close ]. +] + { #category : #tests } PyramidPluginEditOnRunningTest >> setUp [ super setUp. + + "Preserve user settings" setting := PyramidPluginEditOnRunning editOnRunning. + + PyramidPluginEditOnRunning uninstall. + PyramidPluginEditOnRunning install. ] { #category : #tests } @@ -24,6 +37,38 @@ PyramidPluginEditOnRunningTest >> tearDown [ super tearDown. ] +{ #category : #tests } +PyramidPluginEditOnRunningTest >> testBlSpaceShortcutAddAndRemove [ + | 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. +] + +{ #category : #tests } +PyramidPluginEditOnRunningTest >> testCannotEditTheEditor [ + | space editor | + + PyramidPluginEditOnRunning editOnRunning: true. + + editor := PyramidEditor buildEditor. + "get the space of the editor" + space := (editor getPlugin: 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)). +] + { #category : #tests } PyramidPluginEditOnRunningTest >> testEditOnRunning [ @@ -40,3 +85,24 @@ PyramidPluginEditOnRunningTest >> testInitializePlugin [ self assert: (PyramidPluginManager uniqueInstance isPluginInstalled: PyramidPluginEditOnRunning) ] + +{ #category : #tests } +PyramidPluginEditOnRunningTest >> testKeyCombination [ + + self assert: (PyramidPluginEditOnRunning keyCombination isKindOf: BlKeyCombination) + +] + +{ #category : #tests } +PyramidPluginEditOnRunningTest >> testShortcut [ + + self assert: (PyramidPluginEditOnRunning shortcut isKindOf: BlShortcutWithAction). + +] + +{ #category : #tests } +PyramidPluginEditOnRunningTest >> testSpaceIds [ + + self assert: PyramidPluginEditOnRunning spaceIds isEmpty. + +] diff --git a/src/Pyramid-Tests/PyramidPluginManagerTest.class.st b/src/Pyramid-Tests/PyramidPluginManagerTest.class.st new file mode 100644 index 00000000..4cde2cd5 --- /dev/null +++ b/src/Pyramid-Tests/PyramidPluginManagerTest.class.st @@ -0,0 +1,29 @@ +" +A PyramidPluginManagerTest is a test class for testing the behavior of PyramidPluginManager +" +Class { + #name : #PyramidPluginManagerTest, + #superclass : #TestCase, + #category : #'Pyramid-Tests-core' +} + +{ #category : #tests } +PyramidPluginManagerTest >> testIsPluginInstalled [ + + "Test incorrect values" + | pluginClasses | + self deny: (PyramidPluginManager uniqueInstance isPluginInstalled: nil). + + "Test if all plugins are installed" + pluginClasses := PyramidPluginManager imagePluginClasses. + self assert: pluginClasses notEmpty. + pluginClasses do:[ :c | + self assert: (PyramidPluginManager uniqueInstance isPluginInstalled: c). + ]. +] + +{ #category : #tests } +PyramidPluginManagerTest >> testUniqueInstance [ + + self assert: PyramidPluginManager uniqueInstance class equals: PyramidPluginManager. +] diff --git a/src/Pyramid/BlElement.extension.st b/src/Pyramid/BlElement.extension.st index 7b83e087..43d311ed 100644 --- a/src/Pyramid/BlElement.extension.st +++ b/src/Pyramid/BlElement.extension.st @@ -4,7 +4,9 @@ Extension { #name : #BlElement } BlElement >> editWithPyramid [ | editor oldParent | - editor := PyramidPluginManager uniqueInstance makeEditor. + editor := PyramidEditor buildEditor. + + self flag:'labordep: the code below is too complicated, we need to have a more simple API to edit a BlElement, for example editElement:'. oldParent := self parent. self hasParent ifTrue: [ oldParent removeChild: self ]. @@ -14,23 +16,3 @@ BlElement >> editWithPyramid [ editor window open. ^ editor ] - -{ #category : #'*Pyramid' } -BlElement >> openInNewSpaceWithPyramidShortcut [ - - | space isEdit | - space := self openInNewSpace. - isEdit := false. - space when: BlKeyDownEvent do: [ :evt | - | editor whenClosedDo | - isEdit ifFalse: [ - evt key = KeyboardKey F12 ifTrue: [ - isEdit := true. - editor := space editWithPyramid. - whenClosedDo := editor window whenClosedDo. - editor window whenClosedDo: [ - whenClosedDo value. - isEdit := false ] ] ] ]. - - ^ space -] diff --git a/src/Pyramid/BlSpace.extension.st b/src/Pyramid/BlSpace.extension.st index 7987a743..232dea53 100644 --- a/src/Pyramid/BlSpace.extension.st +++ b/src/Pyramid/BlSpace.extension.st @@ -9,9 +9,13 @@ BlSpace >> editWithPyramid [ spacePlaceholder addChildren: PyramidLogo logoOpenInPyramid materializeAsBlElement. "Open editor" - editor := PyramidPluginManager uniqueInstance makeEditor. + editor := PyramidEditor buildEditor. editor window open. + self flag:'labordep: the code below is too complicated, we need to have a more simple API to edit a BlSpace, for example editSpace:'. + + self userData at: #pyramid_isOnEdition put: true. + "Remove all blElement of the application root to be replaced by the image" elements := self root children asArray copy. self root removeChildren. @@ -26,7 +30,8 @@ BlSpace >> editWithPyramid [ each hasParent ifTrue: [ each parent removeChild: each ] ]. editor projectModel roots removeAll. self root removeChildren. - self root addChildren: pyramidRoots ]. + self root addChildren: pyramidRoots. + self userData removeKey: #pyramid_isOnEdition. ]. ^ editor ] diff --git a/src/Pyramid/PyramidEditor.class.st b/src/Pyramid/PyramidEditor.class.st index 56a2c0f4..5c749c6b 100644 --- a/src/Pyramid/PyramidEditor.class.st +++ b/src/Pyramid/PyramidEditor.class.st @@ -10,6 +10,33 @@ Class { #category : #'Pyramid-core' } +{ #category : #private } +PyramidEditor class >> buildEditor [ + + ^ PyramidPluginManager uniqueInstance buildEditor +] + +{ #category : #'instance creation' } +PyramidEditor class >> open [ +