From 6dae2ca63fd2d32bded080191281eac58ae1471d Mon Sep 17 00:00:00 2001 From: DEMAREY Christophe Date: Fri, 5 Jan 2024 16:11:24 +0100 Subject: [PATCH] Fix pharo image version when absent --- .../PhLImagesPresenter.class.st | 14 +++++ .../PhLPharoVersionChooserPresenter.class.st | 63 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 src/PharoLauncher-Spec2/PhLPharoVersionChooserPresenter.class.st diff --git a/src/PharoLauncher-Spec2/PhLImagesPresenter.class.st b/src/PharoLauncher-Spec2/PhLImagesPresenter.class.st index 3e0d8582..785ff3d5 100644 --- a/src/PharoLauncher-Spec2/PhLImagesPresenter.class.st +++ b/src/PharoLauncher-Spec2/PhLImagesPresenter.class.st @@ -187,6 +187,7 @@ PhLImagesPresenter >> connectPresenters [ imageTable transmitDo: [ :image | self + ensurePharoVersion; refreshLaunchConfigurationList; updateToolbarCommandsAvailability ]. @@ -233,6 +234,19 @@ PhLImagesPresenter >> ensure: aBoolean [ ifFalse: [ PhLCommandError signal ] ] +{ #category : #computing } +PhLImagesPresenter >> ensurePharoVersion [ + | image | + image := self selectedImages first. + [ image ensurePharoVersion ] + on: PhLImageVersionFileNotFound + do: [ | presenter | + presenter := PhLPharoVersionChooserPresenter new. + presenter openModal. + image versionFile + writeStreamDo: [ :stream | stream nextPutAll: presenter version ] ] +] + { #category : #private } PhLImagesPresenter >> filter: regexMatcher [ diff --git a/src/PharoLauncher-Spec2/PhLPharoVersionChooserPresenter.class.st b/src/PharoLauncher-Spec2/PhLPharoVersionChooserPresenter.class.st new file mode 100644 index 00000000..b3a13503 --- /dev/null +++ b/src/PharoLauncher-Spec2/PhLPharoVersionChooserPresenter.class.st @@ -0,0 +1,63 @@ +" +I'm a simple presenter to fix the version of a Pharo image when no version file exists. +" +Class { + #name : #PhLPharoVersionChooserPresenter, + #superclass : #SpPresenterWithModel, + #traits : 'TPhLInteractionTrait', + #classTraits : 'TPhLInteractionTrait classTrait', + #instVars : [ + 'versionTable' + ], + #category : #'PharoLauncher-Spec2' +} + +{ #category : #examples } +PhLPharoVersionChooserPresenter class >> example [ + + ^ self new + openDialog; + yourself +] + +{ #category : #layout } +PhLPharoVersionChooserPresenter >> defaultLayout [ + ^ SpBoxLayout newHorizontal + add: versionTable; + yourself +] + +{ #category : #initialization } +PhLPharoVersionChooserPresenter >> initializePresenters [ + versionTable := self newTable + addColumn: ((SpStringTableColumn title: 'Pharo version' evaluated: #key) width: 100; yourself); + addColumn: ((SpStringTableColumn + title: 'version string' + evaluated: #value) width: 60; yourself); + showColumnHeaders; + items: self pharoVersions; + yourself +] + +{ #category : #initialization } +PhLPharoVersionChooserPresenter >> initializeWindow: aWindowPresenter [ + + aWindowPresenter + title: 'Choose the Pharo version of the image:'; + initialExtent: 300@300; + centered +] + +{ #category : #accessing } +PhLPharoVersionChooserPresenter >> pharoVersions [ + | maxPharoVersion versions | + maxPharoVersion := 12. + versions := (#(1.2 1.3 1.4) copyWithAll: (2 to: maxPharoVersion)) reversed. + + ^ versions collect: [ :v | 'Pharo ', v asString -> (v * 10) asInteger asString] +] + +{ #category : #versions } +PhLPharoVersionChooserPresenter >> version [ + ^ versionTable selectedItem value +]