diff --git a/src/PharoLauncher-Core/PhLImage.class.st b/src/PharoLauncher-Core/PhLImage.class.st index 1ae0964c..7dc36449 100644 --- a/src/PharoLauncher-Core/PhLImage.class.st +++ b/src/PharoLauncher-Core/PhLImage.class.st @@ -118,6 +118,11 @@ PhLImage class >> isSubclassForLocation: imageFileReference [ ^ versionFile exists and: [ versionFile contents beginsWith: self versionPrefix ] ] +{ #category : #validating } +PhLImage class >> isValidName: anImageName [ + ^ anImageName isNotEmpty and: [ (anImageName includesAny: #/\) not ] +] + { #category : #'instance creation' } PhLImage class >> location: imageFileReference [ | instance | diff --git a/src/PharoLauncher-Spec2/PhLImageCreationPresenter.class.st b/src/PharoLauncher-Spec2/PhLImageCreationPresenter.class.st index 47163510..7a9f8f69 100644 --- a/src/PharoLauncher-Spec2/PhLImageCreationPresenter.class.st +++ b/src/PharoLauncher-Spec2/PhLImageCreationPresenter.class.st @@ -13,14 +13,14 @@ Class { #classTraits : 'TPhLInteractionTrait classTrait', #instVars : [ 'reservedImagesNamesCache', - 'isNameOk', 'imageName', 'createButton', 'initScriptText', 'initScript', 'editInitScriptButton', 'descriptionText', - 'imageNameCheck' + 'imageNameCheck', + 'isNameValid' ], #category : #'PharoLauncher-Spec2' } @@ -66,12 +66,13 @@ PhLImageCreationPresenter >> checkNewName: name [ I use a variable to know the state during the last validation." | isValid | - isValid := name isEmpty or: [ reservedImagesNamesCache ifNotNil: [ reservedImagesNamesCache includes: name asLowercase ] ]. + isValid := (PhLImage isValidName: name) + and: [ reservedImagesNamesCache ifNotNil: [ (reservedImagesNamesCache includes: name asLowercase) not ] ]. "Image already in the right state. We skip." - isNameOk = isValid ifTrue: [ ^ self ]. + isNameValid = isValid ifTrue: [ ^ self ]. - (isNameOk := isValid) ifTrue: [ self showNameError ] ifFalse: [ self showNameOk ] + (isNameValid := isValid ) ifTrue: [ self showNameOk ] ifFalse: [ self showNameError ] ] { #category : #closing } @@ -175,6 +176,11 @@ PhLImageCreationPresenter >> initializePresenters [ createButton disable ] +{ #category : #testing } +PhLImageCreationPresenter >> isNameValid [ + ^ isNameValid +] + { #category : #initialization } PhLImageCreationPresenter >> modelChanged [ @@ -190,6 +196,11 @@ PhLImageCreationPresenter >> noInitializationScriptItem [ ^ (FileSystem memory root / 'No initialization script') ensureCreateFile ] +{ #category : #accessing } +PhLImageCreationPresenter >> okIcon [ + ^ self application iconNamed: #smallOk +] + { #category : #action } PhLImageCreationPresenter >> openScriptPresenter [ @@ -220,7 +231,7 @@ PhLImageCreationPresenter >> showNameOk [ self ifValidTemplate: [ createButton enable ]. imageNameCheck - image: (self application iconNamed: #smallOk); + image: self okIcon; help: 'Image name is valid!' ] diff --git a/src/PharoLauncher-Spec2/PharoLauncherApplication.class.st b/src/PharoLauncher-Spec2/PharoLauncherApplication.class.st index 9af3d05d..ba8792da 100644 --- a/src/PharoLauncher-Spec2/PharoLauncherApplication.class.st +++ b/src/PharoLauncher-Spec2/PharoLauncherApplication.class.st @@ -305,6 +305,7 @@ PharoLauncherApplication >> scriptsDirectory: aFileReference [ { #category : #ui } PharoLauncherApplication >> shouldUpdateTemplateSources [ + ^ self newConfirm title: 'Update'; label: 'Update available for Pharo Launcher templates sources!'; diff --git a/src/PharoLauncher-Tests-Core/PhLImageTest.class.st b/src/PharoLauncher-Tests-Core/PhLImageTest.class.st index d299c8f7..e28c6eb4 100644 --- a/src/PharoLauncher-Tests-Core/PhLImageTest.class.st +++ b/src/PharoLauncher-Tests-Core/PhLImageTest.class.st @@ -157,6 +157,21 @@ PhLImageTest >> testDescriptionIsSetWhenNoDescriptionInMetadataButDescriptionFil equals: desc. ] +{ #category : #tests } +PhLImageTest >> testImageNameIsNotValidWhenContainingFileSeparator [ + + self deny: (PhLImage isValidName: 'fo/o'). + self deny: (PhLImage isValidName: '123\4'). +] + +{ #category : #tests } +PhLImageTest >> testImageNameIsValidWithLettersAndNumbers [ + + self assert: (PhLImage isValidName: 'foo'). + self assert: (PhLImage isValidName: '1234'). + self assert: (PhLImage isValidName: 'Fo23') +] + { #category : #tests } PhLImageTest >> testPhLImageSerialization [ | stonString | diff --git a/src/PharoLauncher-Tests-SpecUI/PhLImageCreationPresenterTest.class.st b/src/PharoLauncher-Tests-SpecUI/PhLImageCreationPresenterTest.class.st index 4a0447b4..5c6b3629 100644 --- a/src/PharoLauncher-Tests-SpecUI/PhLImageCreationPresenterTest.class.st +++ b/src/PharoLauncher-Tests-SpecUI/PhLImageCreationPresenterTest.class.st @@ -17,6 +17,22 @@ PhLImageCreationPresenterTest >> setUp [ yourself) ] +{ #category : #tests } +PhLImageCreationPresenterTest >> testImageNameIsNotValidWhenContainingFileSeparator [ + + presenter checkNewName: 'foo/'. + + self deny: presenter isNameValid. +] + +{ #category : #tests } +PhLImageCreationPresenterTest >> testImageNameIsValid [ + + presenter checkNewName: 'nonExistingImageName'. + + self assert: presenter isNameValid. +] + { #category : #tests } PhLImageCreationPresenterTest >> testInitializationScriptListUpdatedWhenScriptPresenterDoChange [ | scriptPresenter |