From 239d1d4d7da7538eb89b17bfd36107975adb937f Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Tue, 25 Apr 2023 15:55:32 +0200 Subject: [PATCH 01/41] =?UTF-8?q?d=C3=83=C2=A9but=20de=20prototype=20:=20?= =?UTF-8?q?=20encore=20des=20bugs=20=C3=83=C2=A0=20r=C3=83=C2=A9soudre=20e?= =?UTF-8?q?t=20des=20ajustements=20=C3=83=C2=A0=20faire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../INNotebookCellPreviewPresenter.class.st | 64 +++++++++---------- .../INNotebookCodeCellModel.class.st | 18 +++--- .../INNotebookModel.class.st | 16 ++--- .../INNotebookPreviewPresenter.class.st | 12 ++-- .../INNotebookTextCellModel.class.st | 8 ++- .../INNotebookWithPreviewPresenter.class.st | 6 ++ .../Object.extension.st | 19 ++++++ .../RSCanvas.extension.st | 18 ++++++ .../SpRoassalPresenter.extension.st | 21 ++++++ .../SpTextPresenter.extension.st | 23 +++++++ 10 files changed, 145 insertions(+), 60 deletions(-) create mode 100644 src/InteractiveNotebookPresenter/Object.extension.st create mode 100644 src/InteractiveNotebookPresenter/RSCanvas.extension.st create mode 100644 src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st create mode 100644 src/InteractiveNotebookPresenter/SpTextPresenter.extension.st diff --git a/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st index 7092fb5..be0fec2 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st @@ -2,13 +2,19 @@ Class { #name : #INNotebookCellPreviewPresenter, #superclass : #SpPresenter, #instVars : [ - 'textPresenter', + 'presenter', 'cell', 'parent' ], #category : #InteractiveNotebookPresenter } +{ #category : #initialization } +INNotebookCellPreviewPresenter class >> unselectedColor [ + + ^ Smalltalk ui theme backgroundColor +] + { #category : #actions } INNotebookCellPreviewPresenter >> beSelected [ @@ -28,30 +34,19 @@ INNotebookCellPreviewPresenter >> cell: anObject [ cell := anObject ] +{ #category : #'as yet unclassified' } +INNotebookCellPreviewPresenter >> getContentPresenter [ + ^ presenter +] + { #category : #initialization } INNotebookCellPreviewPresenter >> initializeLayout [ self layout: (SpBoxLayout newLeftToRight - add: textPresenter; + add: presenter; yourself) ] -{ #category : #initialization } -INNotebookCellPreviewPresenter >> initializePresenters [ - - textPresenter := self newText - beNotEditable; - yourself. - self whenDisplayDo: [ - self updateHeight. - textPresenter withAdapterDo: [ :a | - UIManager default defer: [ - a widget backgroundColor: self unselectedColor ] ] ]. - self initializeLayout. - textPresenter eventHandler whenMouseDownDo: [ :anEvent | - self selectMe ] -] - { #category : #initialization } INNotebookCellPreviewPresenter >> morphFor: aPresenter from: aMorph [ @@ -75,8 +70,7 @@ INNotebookCellPreviewPresenter >> parent: anObject [ { #category : #actions } INNotebookCellPreviewPresenter >> select [ - textPresenter withAdapterDo: [ :a | - a widget backgroundColor: (Color fromHexString: '77A8C8') ] + presenter selectNotebookPresenter ] { #category : #actions } @@ -92,31 +86,35 @@ INNotebookCellPreviewPresenter >> selectMe [ cell ifNotNil: [ :c | c selectAndScrollToMe ] ] +{ #category : #initialization } +INNotebookCellPreviewPresenter >> setContentPresenter: aPresenter [ + + presenter := aPresenter. + self whenDisplayDo: [ + self updateHeight. + "presenter withAdapterDo: [ :a | + UIManager default defer: [ + a widget backgroundColor: self unselectedColor ] ]" ]. + self initializeLayout. + presenter eventHandler whenMouseDownDo: [ :anEvent | + self selectMe ] +] + { #category : #accessing } INNotebookCellPreviewPresenter >> text: aString [ - textPresenter text: aString + presenter text: aString ] { #category : #actions } INNotebookCellPreviewPresenter >> unselected [ - textPresenter withAdapterDo: [ :a | a widget backgroundColor: self unselectedColor ] -] - -{ #category : #initialization } -INNotebookCellPreviewPresenter >> unselectedColor [ - - ^ Smalltalk ui theme backgroundColor + presenter unselectedNotebookPresenter ] { #category : #initialization } INNotebookCellPreviewPresenter >> updateHeight [ UIManager default defer: [ - textPresenter withAdapterDo: [ :a | - a widget defer: [ - a widget scrollPane textArea withoutSelectionBar. - self withAdapterDo: [ :b | - b widget height: a widget scrollPane textArea height ] ] ] ] + presenter updateNotebookPresenterHeight ] ] diff --git a/src/InteractiveNotebookPresenter/INNotebookCodeCellModel.class.st b/src/InteractiveNotebookPresenter/INNotebookCodeCellModel.class.st index f56d412..d4d3a36 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCodeCellModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCodeCellModel.class.st @@ -4,6 +4,14 @@ Class { #category : #InteractiveNotebookPresenter } +{ #category : #printing } +INNotebookCodeCellModel >> getContentwithContext: aContext [ + ^self class compiler + compilationContext: aContext; + source: text; + evaluate +] + { #category : #helpers } INNotebookCodeCellModel >> presenterClass [ @@ -12,15 +20,7 @@ INNotebookCodeCellModel >> presenterClass [ { #category : #printing } INNotebookCodeCellModel >> printContentIn: aStream withContext: aContext [ - - aContext bindings add: - (AdditionalBinding key: 'stream' value: aStream). - aContext bindings add: (AdditionalBinding - key: 'printer' - value: (INReportCollectionPrinter new - stream: aStream; - yourself)). - self class compiler + ^self class compiler compilationContext: aContext; source: text; evaluate diff --git a/src/InteractiveNotebookPresenter/INNotebookModel.class.st b/src/InteractiveNotebookPresenter/INNotebookModel.class.st index 4cddd02..88763b2 100644 --- a/src/InteractiveNotebookPresenter/INNotebookModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookModel.class.st @@ -82,20 +82,12 @@ INNotebookModel >> executeAllCells [ { #category : #actions } INNotebookModel >> executeAllCellsAsTextCollection [ - | textCollection | + | collection | self initializeContext. - generatedDocument := String streamContents: [ :p | - textCollection := cellList collect: [ :cell | - | str | - str := String streamContents: [ :s | - cell - printContentIn: s - withContext: context ]. - p nextPutAll: str. - p nextPut: Character cr. - str ] ]. - ^ textCollection + collection := cellList collect: [ :cell | + cell getContentwithContext: context ]. + ^ collection ] { #category : #export } diff --git a/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st index a5f2752..971e868 100644 --- a/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st @@ -80,12 +80,14 @@ INNotebookPreviewPresenter >> initializePresenters [ ] { #category : #actions } -INNotebookPreviewPresenter >> newPreviewCellWith: aString [ - - ^ (self instantiate: INNotebookCellPreviewPresenter) - text: aString; +INNotebookPreviewPresenter >> newPreviewCellWith: anObject [ + | pCell | + pCell := (self instantiate: INNotebookCellPreviewPresenter) + setContentPresenter: (anObject createContentPreviewPresenter); parent: self; - yourself + yourself. + anObject addContentToPreviewPresenter: pCell getContentPresenter. + ^ pCell ] { #category : #initialization } diff --git a/src/InteractiveNotebookPresenter/INNotebookTextCellModel.class.st b/src/InteractiveNotebookPresenter/INNotebookTextCellModel.class.st index 74e4a28..2af074d 100644 --- a/src/InteractiveNotebookPresenter/INNotebookTextCellModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookTextCellModel.class.st @@ -4,6 +4,12 @@ Class { #category : #InteractiveNotebookPresenter } +{ #category : #printing } +INNotebookTextCellModel >> getContentwithContext: aContext [ + + ^ text +] + { #category : #helpers } INNotebookTextCellModel >> presenterClass [ @@ -13,5 +19,5 @@ INNotebookTextCellModel >> presenterClass [ { #category : #printing } INNotebookTextCellModel >> printContentIn: aStream withContext: aContext [ - aStream nextPutAll: text + ^ text ] diff --git a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st index 68c85e6..dc73336 100644 --- a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st @@ -243,6 +243,12 @@ INNotebookWithPreviewPresenter >> setModelBeforeInitialization: aModel [ super setModelBeforeInitialization: aModel ] +{ #category : #initialization } +INNotebookWithPreviewPresenter >> updateHeight [ +"je pense que ça ne devrait pas être appelé ici, au moins avec une méthode vide y'a pas de bug" + previewOpened ifTrue: [ notebookPreview updateHeight ] +] + { #category : #initialization } INNotebookWithPreviewPresenter >> updateModelCells [ diff --git a/src/InteractiveNotebookPresenter/Object.extension.st b/src/InteractiveNotebookPresenter/Object.extension.st new file mode 100644 index 0000000..1f89df9 --- /dev/null +++ b/src/InteractiveNotebookPresenter/Object.extension.st @@ -0,0 +1,19 @@ +Extension { #name : #Object } + +{ #category : #'*InteractiveNotebookPresenter' } +Object >> addContentToPreviewPresenter: aPresenter [ + aPresenter text: self asString +] + +{ #category : #'*InteractiveNotebookPresenter' } +Object >> createContentPreviewPresenter [ + | textPresenter | + textPresenter := SpTextPresenter new. + textPresenter beNotEditable. + ^ textPresenter +] + +{ #category : #'*InteractiveNotebookPresenter' } +Object >> generateMicrodown [ + ^ self asString +] diff --git a/src/InteractiveNotebookPresenter/RSCanvas.extension.st b/src/InteractiveNotebookPresenter/RSCanvas.extension.st new file mode 100644 index 0000000..86e13ff --- /dev/null +++ b/src/InteractiveNotebookPresenter/RSCanvas.extension.st @@ -0,0 +1,18 @@ +Extension { #name : #RSCanvas } + +{ #category : #'*InteractiveNotebookPresenter' } +RSCanvas >> addContentToPreviewPresenter: aPresenter [ + aPresenter canvas: self +] + +{ #category : #'*InteractiveNotebookPresenter' } +RSCanvas >> createContentPreviewPresenter [ + | rPresenter | + rPresenter := SpRoassalPresenter new. + ^ rPresenter +] + +{ #category : #'*InteractiveNotebookPresenter' } +RSCanvas >> generateMicrodown [ + ^ 'plus tard hehe' +] diff --git a/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st b/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st new file mode 100644 index 0000000..fba1071 --- /dev/null +++ b/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st @@ -0,0 +1,21 @@ +Extension { #name : #SpRoassalPresenter } + +{ #category : #'*InteractiveNotebookPresenter' } +SpRoassalPresenter >> selectNotebookPresenter [ + + "todo" +] + +{ #category : #'*InteractiveNotebookPresenter' } +SpRoassalPresenter >> unselectedNotebookPresenter [ + + "todo" +] + +{ #category : #'*InteractiveNotebookPresenter' } +SpRoassalPresenter >> updateNotebookPresenterHeight [ + + self owner withAdapterDo: [ :a | + a widget defer: [ a widget height: 350 ]. + self canvas zoomToFit ] +] diff --git a/src/InteractiveNotebookPresenter/SpTextPresenter.extension.st b/src/InteractiveNotebookPresenter/SpTextPresenter.extension.st new file mode 100644 index 0000000..3b7bbd7 --- /dev/null +++ b/src/InteractiveNotebookPresenter/SpTextPresenter.extension.st @@ -0,0 +1,23 @@ +Extension { #name : #SpTextPresenter } + +{ #category : #'*InteractiveNotebookPresenter' } +SpTextPresenter >> selectNotebookPresenter [ + + self withAdapterDo: [ :a | + a widget backgroundColor: (Color fromHexString: '77A8C8') ] +] + +{ #category : #'*InteractiveNotebookPresenter' } +SpTextPresenter >> unselectedNotebookPresenter [ + + self withAdapterDo: [ :a | a widget backgroundColor: INNotebookCellPreviewPresenter unselectedColor ] +] + +{ #category : #'*InteractiveNotebookPresenter' } +SpTextPresenter >> updateNotebookPresenterHeight [ + self withAdapterDo: [ :a | + a widget defer: [ + a widget scrollPane textArea withoutSelectionBar. + self owner withAdapterDo: [ :b | + b widget height: a widget scrollPane textArea height ] ] ] +] From 6cf4522f0668b6f27f7250b291f6e9be185fd7f4 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Wed, 26 Apr 2023 16:46:07 +0200 Subject: [PATCH 02/41] methods to print MooseGroup results, more tries to make Roassal visualizations work --- .../INNotebookWithPreviewPresenter.class.st | 3 +- .../MooseGroup.extension.st | 19 ++++++++++ .../RSCanvas.extension.st | 2 +- .../SpMorphPresenter.extension.st | 18 ++++++++++ .../SpRoassalPresenter.extension.st | 36 +++++++++++++++++-- 5 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 src/InteractiveNotebookPresenter/MooseGroup.extension.st create mode 100644 src/InteractiveNotebookPresenter/SpMorphPresenter.extension.st diff --git a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st index dc73336..39bd1a4 100644 --- a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st @@ -245,7 +245,8 @@ INNotebookWithPreviewPresenter >> setModelBeforeInitialization: aModel [ { #category : #initialization } INNotebookWithPreviewPresenter >> updateHeight [ -"je pense que ça ne devrait pas être appelé ici, au moins avec une méthode vide y'a pas de bug" +"je ne sais pas si ça devrait être appelé ici, au moins avec une méthode y'a pas de bug" + notebook updateHeight. previewOpened ifTrue: [ notebookPreview updateHeight ] ] diff --git a/src/InteractiveNotebookPresenter/MooseGroup.extension.st b/src/InteractiveNotebookPresenter/MooseGroup.extension.st new file mode 100644 index 0000000..9d789bc --- /dev/null +++ b/src/InteractiveNotebookPresenter/MooseGroup.extension.st @@ -0,0 +1,19 @@ +Extension { #name : #MooseGroup } + +{ #category : #'*InteractiveNotebookPresenter' } +MooseGroup >> addContentToPreviewPresenter: aPresenter [ + + aPresenter text: (String streamContents: [ :s | + self collect: [ :e | + s nextPutAll: '- '. + s nextPutAll: e mooseName. + s nextPut: Character cr ] ]) +] + +{ #category : #'*InteractiveNotebookPresenter' } +MooseGroup >> createContentPreviewPresenter [ + | textPresenter | + textPresenter := SpTextPresenter new. + textPresenter beNotEditable. + ^ textPresenter +] diff --git a/src/InteractiveNotebookPresenter/RSCanvas.extension.st b/src/InteractiveNotebookPresenter/RSCanvas.extension.st index 86e13ff..672b3f7 100644 --- a/src/InteractiveNotebookPresenter/RSCanvas.extension.st +++ b/src/InteractiveNotebookPresenter/RSCanvas.extension.st @@ -2,7 +2,7 @@ Extension { #name : #RSCanvas } { #category : #'*InteractiveNotebookPresenter' } RSCanvas >> addContentToPreviewPresenter: aPresenter [ - aPresenter canvas: self + aPresenter canvas: self canvas ] { #category : #'*InteractiveNotebookPresenter' } diff --git a/src/InteractiveNotebookPresenter/SpMorphPresenter.extension.st b/src/InteractiveNotebookPresenter/SpMorphPresenter.extension.st new file mode 100644 index 0000000..9c7af25 --- /dev/null +++ b/src/InteractiveNotebookPresenter/SpMorphPresenter.extension.st @@ -0,0 +1,18 @@ +Extension { #name : #SpMorphPresenter } + +{ #category : #'*InteractiveNotebookPresenter' } +SpMorphPresenter >> selectNotebookPresenter [ + "todo" +] + +{ #category : #'*InteractiveNotebookPresenter' } +SpMorphPresenter >> unselectedNotebookPresenter [ + "todo" +] + +{ #category : #'*InteractiveNotebookPresenter' } +SpMorphPresenter >> updateNotebookPresenterHeight [ + self owner withAdapterDo: [ :a | + a widget defer: [ a widget height: 350 ]. + self morph zoomToFit ] +] diff --git a/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st b/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st index fba1071..7c81873 100644 --- a/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st +++ b/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st @@ -1,5 +1,26 @@ Extension { #name : #SpRoassalPresenter } +{ #category : #'*InteractiveNotebookPresenter' } +SpRoassalPresenter >> calculateNewCenter [ + | x y | + x := self canvas extent x. + y := self canvas extent y. + ^ x / 2 @ y / 2 +] + +{ #category : #'*InteractiveNotebookPresenter' } +SpRoassalPresenter >> calculateNewScale [ + + | xw yw xc yc | + xw := self owner withAdapterDo: [ :a | a widget height ]. + xc := self canvas extent x. + yw := self owner withAdapterDo: [ :a | a widget width ]. + yc := self canvas extent y. + ^ xc - xw > (yc - yw) + ifTrue: [ xw / xc ] + ifFalse: [ yw / yc ] +] + { #category : #'*InteractiveNotebookPresenter' } SpRoassalPresenter >> selectNotebookPresenter [ @@ -15,7 +36,18 @@ SpRoassalPresenter >> unselectedNotebookPresenter [ { #category : #'*InteractiveNotebookPresenter' } SpRoassalPresenter >> updateNotebookPresenterHeight [ + | rect | self owner withAdapterDo: [ :a | - a widget defer: [ a widget height: 350 ]. - self canvas zoomToFit ] + a widget defer: [ a widget height: 350 ] ]. + self canvas camera zoomToFit: self canvas extent * 0.9 + "self canvas camera scale: self calculateNewScale. + self canvas camera position: self calculateNewCenter." + + "rect := RSCoordinates new visibleRectangleFor: self canvas camera. + ""rect := Rectangle + origin: 0 - a widget height @ 0 - a widget width + corner: a widget height @ a widget width."" + self canvas camera + zoomToFit: (a widget height @ a widget width) * 1.3 + rectangle: rect." ] From d0293f203f24fff653225787e6abfbd99739348f Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Thu, 27 Apr 2023 10:40:24 +0200 Subject: [PATCH 03/41] light refactoring --- src/InteractiveNotebookPresenter/INNotebookModel.class.st | 2 +- .../INNotebookWithPreviewPresenter.class.st | 2 +- .../SpRoassalPresenter.extension.st | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookModel.class.st b/src/InteractiveNotebookPresenter/INNotebookModel.class.st index 88763b2..5d358da 100644 --- a/src/InteractiveNotebookPresenter/INNotebookModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookModel.class.st @@ -80,7 +80,7 @@ INNotebookModel >> executeAllCells [ ] { #category : #actions } -INNotebookModel >> executeAllCellsAsTextCollection [ +INNotebookModel >> executeAllCellsAsCollection [ | collection | self initializeContext. diff --git a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st index 39bd1a4..42c9e0d 100644 --- a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st @@ -219,7 +219,7 @@ INNotebookWithPreviewPresenter >> preview [ notebookPreview updateWithStringCollection: - self model executeAllCellsAsTextCollection + self model executeAllCellsAsCollection andCells: notebook cellList ] diff --git a/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st b/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st index 7c81873..e346470 100644 --- a/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st +++ b/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st @@ -37,9 +37,8 @@ SpRoassalPresenter >> unselectedNotebookPresenter [ SpRoassalPresenter >> updateNotebookPresenterHeight [ | rect | - self owner withAdapterDo: [ :a | - a widget defer: [ a widget height: 350 ] ]. - self canvas camera zoomToFit: self canvas extent * 0.9 + self owner withAdapterDo: [ :a | a widget height: 350. self canvas camera zoomToFit: self canvas extent * 0.9. ]. + "self canvas camera scale: self calculateNewScale. self canvas camera position: self calculateNewCenter." From 4e3c50399edee90ff1f5f8a3cb3fa97adf20058d Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Thu, 27 Apr 2023 13:55:28 +0200 Subject: [PATCH 04/41] needToUpdate value updated and used before preview --- .../INNotebookAbstractCellModel.class.st | 10 ++++++++++ .../INNotebookAbstractCellPresenter.class.st | 6 ++++++ .../INNotebookCodeCellPresenter.class.st | 7 ++++--- .../INNotebookEditorPresenter.class.st | 1 - .../INNotebookModel.class.st | 12 ++++++++++++ .../INNotebookTextCellPresenter.class.st | 5 +++-- .../INNotebookWithPreviewPresenter.class.st | 4 +++- 7 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st b/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st index ef2377e..9573e0b 100644 --- a/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st @@ -15,6 +15,16 @@ INNotebookAbstractCellModel >> initialize [ text := String empty ] +{ #category : #accessing } +INNotebookAbstractCellModel >> model [ + ^ model +] + +{ #category : #accessing } +INNotebookAbstractCellModel >> model: aModel [ + model := aModel +] + { #category : #helpers } INNotebookAbstractCellModel >> presenterClass [ diff --git a/src/InteractiveNotebookPresenter/INNotebookAbstractCellPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookAbstractCellPresenter.class.st index 5f15b21..81163c7 100644 --- a/src/InteractiveNotebookPresenter/INNotebookAbstractCellPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookAbstractCellPresenter.class.st @@ -179,6 +179,12 @@ INNotebookAbstractCellPresenter >> moveUp [ notebook moveUp: self ] +{ #category : #accessing } +INNotebookAbstractCellPresenter >> needToUpdateModel [ + notebook model needToUpdate: true. + +] + { #category : #accessing } INNotebookAbstractCellPresenter >> notebook [ diff --git a/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st index ebd74e1..3a1a461 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st @@ -20,8 +20,9 @@ INNotebookCodeCellPresenter >> beCode [ { #category : #api } INNotebookCodeCellPresenter >> beText [ - - notebook transformToTextCell: self + + notebook transformToTextCell: self. + self needToUpdateModel ] { #category : #initialization } @@ -33,7 +34,7 @@ INNotebookCodeCellPresenter >> initializePresenters [ beForScripting; placeholder: notebook codeCellPlaceholder; yourself. - cell whenTextChangedDo: [ self updateHeight ]. + cell whenTextChangedDo: [ self updateHeight. self needToUpdateModel ]. self interactionModel: notebook interactionModel. icon := self newButton diff --git a/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st index c6b25ef..c0362e2 100644 --- a/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st @@ -8,7 +8,6 @@ Class { 'selectedCell', 'interactionModel', 'headerSep', - 'mooseModel', 'cellLayout', 'browser', 'codeCellPlaceholder' diff --git a/src/InteractiveNotebookPresenter/INNotebookModel.class.st b/src/InteractiveNotebookPresenter/INNotebookModel.class.st index 5d358da..6cd590b 100644 --- a/src/InteractiveNotebookPresenter/INNotebookModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookModel.class.st @@ -32,6 +32,7 @@ INNotebookModel >> addCell: aCell [ { #category : #initialization } INNotebookModel >> addTextCell [ + needToUpdate := true. ^ self addCell: INNotebookTextCellModel new ] @@ -87,6 +88,7 @@ INNotebookModel >> executeAllCellsAsCollection [ collection := cellList collect: [ :cell | cell getContentwithContext: context ]. + needToUpdate := false. ^ collection ] @@ -177,3 +179,13 @@ INNotebookModel >> name [ ^ fileName ifNil: [ 'new *' ] ] + +{ #category : #accessing } +INNotebookModel >> needToUpdate [ + ^ needToUpdate +] + +{ #category : #accessing } +INNotebookModel >> needToUpdate: aBoolean [ + needToUpdate := aBoolean +] diff --git a/src/InteractiveNotebookPresenter/INNotebookTextCellPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookTextCellPresenter.class.st index 8d1bfa8..94a3897 100644 --- a/src/InteractiveNotebookPresenter/INNotebookTextCellPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookTextCellPresenter.class.st @@ -15,7 +15,8 @@ INNotebookTextCellPresenter >> asModelCell [ { #category : #api } INNotebookTextCellPresenter >> beCode [ - notebook transformToCodeCell: self + notebook transformToCodeCell: self. + self needToUpdateModel ] { #category : #api } @@ -29,7 +30,7 @@ INNotebookTextCellPresenter >> initializePresenters [ super initializePresenters. cell := self newText. - cell whenTextChangedDo: [ self updateHeight ]. + cell whenTextChangedDo: [ self updateHeight. self needToUpdateModel ]. icon := self newButton label: 'Mic'; action: [ notebook transformToCodeCell: self ]; diff --git a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st index 42c9e0d..ad90c9d 100644 --- a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st @@ -59,7 +59,8 @@ INNotebookWithPreviewPresenter class >> title [ { #category : #actions } INNotebookWithPreviewPresenter >> addTextCell [ - notebook addTextCell + notebook addTextCell. + self announcingObject value needToUpdate: true. ] { #category : #actions } @@ -215,6 +216,7 @@ INNotebookWithPreviewPresenter >> openPreview [ INNotebookWithPreviewPresenter >> preview [ self openPreview. + self announcingObject value needToUpdate ifFalse: [ ^ self ]. self updateModelCells. notebookPreview From 6370892b26c63644d9e3dbe709b28dc9c7f2b192 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Thu, 27 Apr 2023 16:45:22 +0200 Subject: [PATCH 05/41] CellModels have needToUpdate attribute, cells and preview cells are recompiled only if needed --- .../INNotebookAbstractCellModel.class.st | 31 ++++++++++++++++++- .../INNotebookAbstractCellPresenter.class.st | 4 +-- .../INNotebookCodeCellModel.class.st | 20 +++++++++--- .../INNotebookCodeCellPresenter.class.st | 2 +- .../INNotebookEditorPresenter.class.st | 14 +++++++-- .../INNotebookModel.class.st | 4 ++- .../INNotebookPreviewPresenter.class.st | 12 ++++--- .../INNotebookTextCellModel.class.st | 11 +++++++ .../INNotebookTextCellPresenter.class.st | 2 +- .../INNotebookWithPreviewPresenter.class.st | 4 +-- 10 files changed, 86 insertions(+), 18 deletions(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st b/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st index 9573e0b..7538a1e 100644 --- a/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st @@ -3,15 +3,33 @@ Class { #superclass : #Object, #instVars : [ 'text', - 'model' + 'model', + 'needToUpdate' ], #category : #InteractiveNotebookPresenter } +{ #category : #'as yet unclassified' } +INNotebookAbstractCellModel >> beCodeModel [ + ^ self subclassResponsibility +] + +{ #category : #'as yet unclassified' } +INNotebookAbstractCellModel >> beTextModel [ + ^ self subclassResponsibility +] + +{ #category : #printing } +INNotebookAbstractCellModel >> getContentwithContext: aContext [ + + ^ self subclassResponsibility +] + { #category : #initialization } INNotebookAbstractCellModel >> initialize [ super initialize. + needToUpdate := true. text := String empty ] @@ -25,6 +43,16 @@ INNotebookAbstractCellModel >> model: aModel [ model := aModel ] +{ #category : #accessing } +INNotebookAbstractCellModel >> needToUpdate [ + ^ needToUpdate +] + +{ #category : #accessing } +INNotebookAbstractCellModel >> needToUpdate: aBoolean [ + needToUpdate := aBoolean +] + { #category : #helpers } INNotebookAbstractCellModel >> presenterClass [ @@ -46,5 +74,6 @@ INNotebookAbstractCellModel >> text [ { #category : #accessing } INNotebookAbstractCellModel >> text: anObject [ + (text equalsTo: anObject) ifFalse: [ self needToUpdate: true ]. text := anObject ] diff --git a/src/InteractiveNotebookPresenter/INNotebookAbstractCellPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookAbstractCellPresenter.class.st index 81163c7..9c7d329 100644 --- a/src/InteractiveNotebookPresenter/INNotebookAbstractCellPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookAbstractCellPresenter.class.st @@ -1,6 +1,6 @@ Class { #name : #INNotebookAbstractCellPresenter, - #superclass : #SpPresenter, + #superclass : #SpPresenterWithModel, #instVars : [ 'cell', 'icon', @@ -181,7 +181,7 @@ INNotebookAbstractCellPresenter >> moveUp [ { #category : #accessing } INNotebookAbstractCellPresenter >> needToUpdateModel [ - notebook model needToUpdate: true. + self model needToUpdate: true. ] diff --git a/src/InteractiveNotebookPresenter/INNotebookCodeCellModel.class.st b/src/InteractiveNotebookPresenter/INNotebookCodeCellModel.class.st index d4d3a36..3fb05ea 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCodeCellModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCodeCellModel.class.st @@ -4,12 +4,24 @@ Class { #category : #InteractiveNotebookPresenter } +{ #category : #'as yet unclassified' } +INNotebookCodeCellModel >> beCodeModel [ + ^ self +] + +{ #category : #'as yet unclassified' } +INNotebookCodeCellModel >> beTextModel [ + "no need to add the text of the current model in the new model, it will be compiled anyway in the next preview" + ^ INNotebookTextCellModel new +] + { #category : #printing } INNotebookCodeCellModel >> getContentwithContext: aContext [ - ^self class compiler - compilationContext: aContext; - source: text; - evaluate + + ^ self class compiler + compilationContext: aContext; + source: text; + evaluate ] { #category : #helpers } diff --git a/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st index 3a1a461..55d85af 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st @@ -34,7 +34,7 @@ INNotebookCodeCellPresenter >> initializePresenters [ beForScripting; placeholder: notebook codeCellPlaceholder; yourself. - cell whenTextChangedDo: [ self updateHeight. self needToUpdateModel ]. + cell whenTextChangedDo: [ self updateHeight ]. self interactionModel: notebook interactionModel. icon := self newButton diff --git a/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st index c0362e2..887ed09 100644 --- a/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st @@ -62,7 +62,7 @@ INNotebookEditorPresenter >> addTextCellBefore: aCell [ { #category : #accessing } INNotebookEditorPresenter >> allModelCells [ - ^ cellList asOrderedCollection collect: [ :cell | cell asModelCell ] + ^ cellList asOrderedCollection collect: [ :cell | cell model ] ] { #category : #accessing } @@ -196,13 +196,17 @@ INNotebookEditorPresenter >> newCodeCell [ ^ (self instantiate: INNotebookCodeCellPresenter on: self) notebook: self; + model: INNotebookCodeCellModel new; yourself ] { #category : #initialization } INNotebookEditorPresenter >> newTextCell [ - ^ (self instantiate: INNotebookTextCellPresenter) notebook: self + ^ (self instantiate: INNotebookTextCellPresenter) + notebook: self; + model: INNotebookTextCellModel new; + yourself ] { #category : #adding } @@ -285,6 +289,7 @@ INNotebookEditorPresenter >> updateAll [ cellList := LinkedList new. self model cellList do: [ :c | cellList add: ((self instantiate: c presenterClass) + model: c; notebook: self; text: c text; yourself) ]. @@ -300,6 +305,11 @@ INNotebookEditorPresenter >> updateHeight [ cellList do: [ :c | c updateHeight ] ] +{ #category : #removing } +INNotebookEditorPresenter >> updateModelCells [ + cellList do: [ :cell | cell model text: cell text ] +] + { #category : #initialization } INNotebookEditorPresenter >> updatePresenter [ diff --git a/src/InteractiveNotebookPresenter/INNotebookModel.class.st b/src/InteractiveNotebookPresenter/INNotebookModel.class.st index 6cd590b..19b0b80 100644 --- a/src/InteractiveNotebookPresenter/INNotebookModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookModel.class.st @@ -87,7 +87,9 @@ INNotebookModel >> executeAllCellsAsCollection [ self initializeContext. collection := cellList collect: [ :cell | - cell getContentwithContext: context ]. + cell needToUpdate + ifTrue: [ cell getContentwithContext: context ] + ifFalse: [ nil ] ]. needToUpdate := false. ^ collection ] diff --git a/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st index 971e868..eba24f5 100644 --- a/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st @@ -142,12 +142,16 @@ INNotebookPreviewPresenter >> updateWithStringCollection: aCollection andCells: | col | col := OrderedCollection new. - aCollection withIndexDo: [ :e :i | + aCollection withIndexDo: [ :obj :i | | cell pCell | cell := cells at: i. - pCell := self newPreviewCellWith: (aCollection at: i). - pCell cell: cell. - cell previewCell: pCell. + cell model needToUpdate + ifTrue: [ + pCell := self newPreviewCellWith: obj. + pCell cell: cell. + cell previewCell: pCell. + cell model needToUpdate: false ] + ifFalse: [ pCell := cell previewCell ]. col add: pCell ]. previewCells := col. self relayout diff --git a/src/InteractiveNotebookPresenter/INNotebookTextCellModel.class.st b/src/InteractiveNotebookPresenter/INNotebookTextCellModel.class.st index 2af074d..6d7a9b9 100644 --- a/src/InteractiveNotebookPresenter/INNotebookTextCellModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookTextCellModel.class.st @@ -4,6 +4,17 @@ Class { #category : #InteractiveNotebookPresenter } +{ #category : #'as yet unclassified' } +INNotebookTextCellModel >> beCodeModel [ + "no need to add the text in the current model, it will be compiled anyway in the next preview" + ^ INNotebookCodeCellModel new +] + +{ #category : #'as yet unclassified' } +INNotebookTextCellModel >> beTextModel [ + ^ self +] + { #category : #printing } INNotebookTextCellModel >> getContentwithContext: aContext [ diff --git a/src/InteractiveNotebookPresenter/INNotebookTextCellPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookTextCellPresenter.class.st index 94a3897..73a2143 100644 --- a/src/InteractiveNotebookPresenter/INNotebookTextCellPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookTextCellPresenter.class.st @@ -30,7 +30,7 @@ INNotebookTextCellPresenter >> initializePresenters [ super initializePresenters. cell := self newText. - cell whenTextChangedDo: [ self updateHeight. self needToUpdateModel ]. + cell whenTextChangedDo: [ self updateHeight ]. icon := self newButton label: 'Mic'; action: [ notebook transformToCodeCell: self ]; diff --git a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st index ad90c9d..130aa25 100644 --- a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st @@ -216,7 +216,6 @@ INNotebookWithPreviewPresenter >> openPreview [ INNotebookWithPreviewPresenter >> preview [ self openPreview. - self announcingObject value needToUpdate ifFalse: [ ^ self ]. self updateModelCells. notebookPreview @@ -254,7 +253,8 @@ INNotebookWithPreviewPresenter >> updateHeight [ { #category : #initialization } INNotebookWithPreviewPresenter >> updateModelCells [ - + + notebook updateModelCells. self model cellList: notebook allModelCells. ] From 88af57a442b6add9958779d9ce719d4c8fab9f49 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Thu, 27 Apr 2023 16:49:45 +0200 Subject: [PATCH 06/41] remove MooseGroup extension for Pharo compatibility --- .../MooseGroup.extension.st | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 src/InteractiveNotebookPresenter/MooseGroup.extension.st diff --git a/src/InteractiveNotebookPresenter/MooseGroup.extension.st b/src/InteractiveNotebookPresenter/MooseGroup.extension.st deleted file mode 100644 index 9d789bc..0000000 --- a/src/InteractiveNotebookPresenter/MooseGroup.extension.st +++ /dev/null @@ -1,19 +0,0 @@ -Extension { #name : #MooseGroup } - -{ #category : #'*InteractiveNotebookPresenter' } -MooseGroup >> addContentToPreviewPresenter: aPresenter [ - - aPresenter text: (String streamContents: [ :s | - self collect: [ :e | - s nextPutAll: '- '. - s nextPutAll: e mooseName. - s nextPut: Character cr ] ]) -] - -{ #category : #'*InteractiveNotebookPresenter' } -MooseGroup >> createContentPreviewPresenter [ - | textPresenter | - textPresenter := SpTextPresenter new. - textPresenter beNotEditable. - ^ textPresenter -] From e4eac94fa522af79fbd1c7163ef7a0fc9e93bb82 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Fri, 28 Apr 2023 11:22:04 +0200 Subject: [PATCH 07/41] fix equalsTo: -> = --- .../INNotebookAbstractCellModel.class.st | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st b/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st index 7538a1e..b8b3b28 100644 --- a/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st @@ -74,6 +74,6 @@ INNotebookAbstractCellModel >> text [ { #category : #accessing } INNotebookAbstractCellModel >> text: anObject [ - (text equalsTo: anObject) ifFalse: [ self needToUpdate: true ]. + (text = anObject) ifFalse: [ self needToUpdate: true ]. text := anObject ] From db0c0e83d01244f468a8b00c2a37917aa7cf439c Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Tue, 2 May 2023 11:04:41 +0200 Subject: [PATCH 08/41] cleaning : removing unused adding methods, and needToUpdate instance variable of model + references --- .../INNotebookAbstractCellPresenter.class.st | 1 - .../INNotebookEditorPresenter.class.st | 26 ------------------- .../INNotebookModel.class.st | 18 ------------- .../INNotebookWithPreviewPresenter.class.st | 7 ----- 4 files changed, 52 deletions(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookAbstractCellPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookAbstractCellPresenter.class.st index 9c7d329..7842558 100644 --- a/src/InteractiveNotebookPresenter/INNotebookAbstractCellPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookAbstractCellPresenter.class.st @@ -283,7 +283,6 @@ INNotebookAbstractCellPresenter >> unselectedColor [ { #category : #initialization } INNotebookAbstractCellPresenter >> updateHeight [ - UIManager default defer: [ notebook headerSep withAdapterDo: [ :a | cell withAdapterDo: [ :b | diff --git a/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st index 887ed09..30e62ec 100644 --- a/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st @@ -15,32 +15,6 @@ Class { #category : #InteractiveNotebookPresenter } -{ #category : #adding } -INNotebookEditorPresenter >> add: aCell [ - - self layout add: aCell expand: false. - aCell announceDisplayed. - lastCellAdded takeKeyboardFocus -] - -{ #category : #adding } -INNotebookEditorPresenter >> addCodeCell [ - - lastCellAdded := self newCodeCell. - cellList addLast: lastCellAdded. - selectedCell := lastCellAdded. - self relayout -] - -{ #category : #adding } -INNotebookEditorPresenter >> addTextCell [ - - lastCellAdded := self newTextCell. - cellList addLast: lastCellAdded. - selectedCell := lastCellAdded. - self relayout -] - { #category : #initialization } INNotebookEditorPresenter >> addTextCellAfter: aCell [ diff --git a/src/InteractiveNotebookPresenter/INNotebookModel.class.st b/src/InteractiveNotebookPresenter/INNotebookModel.class.st index 19b0b80..cdc24ed 100644 --- a/src/InteractiveNotebookPresenter/INNotebookModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookModel.class.st @@ -3,7 +3,6 @@ Class { #superclass : #Object, #instVars : [ 'textEditedSource', - 'needToUpdate', 'micDocument', 'cellList', 'context', @@ -31,8 +30,6 @@ INNotebookModel >> addCell: aCell [ { #category : #initialization } INNotebookModel >> addTextCell [ - - needToUpdate := true. ^ self addCell: INNotebookTextCellModel new ] @@ -57,7 +54,6 @@ INNotebookModel >> cellList [ { #category : #accessing } INNotebookModel >> cellList: anOrderedCollection [ - needToUpdate := true. cellList := anOrderedCollection ] @@ -70,13 +66,11 @@ INNotebookModel >> context [ { #category : #actions } INNotebookModel >> executeAllCells [ - needToUpdate ifFalse: [ ^ generatedDocument ]. generatedDocument := String streamContents: [ :s | self initializeContextWithStream: s. cellList do: [ :cell | cell printContentIn: s withContext: context. s nextPut: Character cr ] ]. - needToUpdate := false. ^ generatedDocument ] @@ -90,7 +84,6 @@ INNotebookModel >> executeAllCellsAsCollection [ cell needToUpdate ifTrue: [ cell getContentwithContext: context ] ifFalse: [ nil ] ]. - needToUpdate := false. ^ collection ] @@ -149,7 +142,6 @@ INNotebookModel >> importCellsFrom: aFileReference [ INNotebookModel >> initialize [ super initialize. - needToUpdate := true. cellList := OrderedCollection new. additionalBindings := Dictionary new ] @@ -181,13 +173,3 @@ INNotebookModel >> name [ ^ fileName ifNil: [ 'new *' ] ] - -{ #category : #accessing } -INNotebookModel >> needToUpdate [ - ^ needToUpdate -] - -{ #category : #accessing } -INNotebookModel >> needToUpdate: aBoolean [ - needToUpdate := aBoolean -] diff --git a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st index 130aa25..e565466 100644 --- a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st @@ -56,13 +56,6 @@ INNotebookWithPreviewPresenter class >> title [ ^ 'Notebook' ] -{ #category : #actions } -INNotebookWithPreviewPresenter >> addTextCell [ - - notebook addTextCell. - self announcingObject value needToUpdate: true. -] - { #category : #actions } INNotebookWithPreviewPresenter >> chooseTextFile: messageString extensions: stringCollection path: defaultName [ ^UIManager default From 44468887bd4859868e88243773cd6e7e3922bd8e Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Tue, 2 May 2023 11:35:03 +0200 Subject: [PATCH 09/41] remove wrong menu item --- .../INNotebookPresenter.class.st | 1 - .../INNotebookWithPreviewPresenter.class.st | 34 ------------------- 2 files changed, 35 deletions(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookPresenter.class.st index 86d6b03..698697b 100644 --- a/src/InteractiveNotebookPresenter/INNotebookPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookPresenter.class.st @@ -38,7 +38,6 @@ INNotebookPresenter class >> menuItem [ { #category : #'instance creation' } INNotebookPresenter class >> open [ - ^ self new open; yourself diff --git a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st index e565466..ca95447 100644 --- a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st @@ -10,46 +10,12 @@ Class { #category : #InteractiveNotebookPresenter } -{ #category : #help } -INNotebookWithPreviewPresenter class >> helpMessage [ - - ^ 'Open the interactive notebook' -] - -{ #category : #'world menu' } -INNotebookWithPreviewPresenter class >> menuCommandOn: aBuilder [ - - - - (aBuilder item: #Reporter) - parent: #Moose; - label: self title; - icon: (self iconNamed: #smallExport); - order: 6; - help: self helpMessage; - action: [ self open ] -] - -{ #category : #'world menu' } -INNotebookWithPreviewPresenter class >> menuItem [ - - ^ #reporteBuilder -] - { #category : #'instance creation' } INNotebookWithPreviewPresenter class >> newModel [ ^ INNotebookModel new ] -{ #category : #'instance creation' } -INNotebookWithPreviewPresenter class >> open [ - - ^ (self on: self newModel) - open; - yourself -] - { #category : #specs } INNotebookWithPreviewPresenter class >> title [ From 07ff4c09207fd65636dffd8bf3e4a472763f1a94 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Tue, 2 May 2023 15:00:38 +0200 Subject: [PATCH 10/41] removing mooseModel accessor, adding a few class comments --- .../INNotebookCellPreviewPresenter.class.st | 8 ++++++++ .../INNotebookEditorPresenter.class.st | 11 +++++------ .../INNotebookModel.class.st | 7 +++++++ .../INNotebookPresenter.class.st | 5 +++++ .../INNotebookWithPreviewPresenter.class.st | 7 +++++++ 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st index be0fec2..b4b07e5 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st @@ -1,3 +1,11 @@ +" +I am a preview cell of a notebook page. +I display the compiled content of a cell, either in Microdown if I represent a text cell, or using different types of presenters for a code cell, depending on the class of the final compiled result of the cell. + +Using class extensions, the object resulting of the compilation of a cell provides me an appropriate presenter to display itself (using the extension method `createContentPreviewPresenter`). I can add this object to the created presenter (using the extension method `addContentToPreviewPresenter: anObject`). + +Those presenters also use extension methods : `selectNotebookPresenter`, `unselectedNotebookPresenter` and `updateNotebookPresenterHeight`. +" Class { #name : #INNotebookCellPreviewPresenter, #superclass : #SpPresenter, diff --git a/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st index 30e62ec..8135448 100644 --- a/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st @@ -1,3 +1,8 @@ +" +I am the editor panel for a notebook page. + +I allow the user to add cells before or after a cell, to transform a text cell into a code cell and vice versa, or to move up or down a cell. +" Class { #name : #INNotebookEditorPresenter, #superclass : #SpPresenter, @@ -137,12 +142,6 @@ INNotebookEditorPresenter >> model [ ^ self owner model ] -{ #category : #accessing } -INNotebookEditorPresenter >> mooseModel [ - - ^ self owner mooseModel -] - { #category : #removing } INNotebookEditorPresenter >> moveDown: aCell [ diff --git a/src/InteractiveNotebookPresenter/INNotebookModel.class.st b/src/InteractiveNotebookPresenter/INNotebookModel.class.st index cdc24ed..b2330ba 100644 --- a/src/InteractiveNotebookPresenter/INNotebookModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookModel.class.st @@ -1,3 +1,10 @@ +" +I am the model of a notebook page (each notebook tab owns a different model). + +I am responsible of the execution of each text and code cell when building a preview. +I also manage the context of the cells (the bindings allowing the user to use previously defined variables in the following cells). +Finally, I am responsible of the generation of the document to export (in Markdown, HTML, or STON). +" Class { #name : #INNotebookModel, #superclass : #Object, diff --git a/src/InteractiveNotebookPresenter/INNotebookPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookPresenter.class.st index 698697b..95764e6 100644 --- a/src/InteractiveNotebookPresenter/INNotebookPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookPresenter.class.st @@ -1,3 +1,8 @@ +" +I am the main presenter window for the Notebook. + +I am able to create new notebook tabs (each tab is an editable notebook with its own cells), and I can also import or export a notebook to various file formats. +" Class { #name : #INNotebookPresenter, #superclass : #SpPresenter, diff --git a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st index ca95447..143d2c2 100644 --- a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st @@ -1,3 +1,10 @@ +" +I am a notebook page (a tab of the main notebook window), containing an editor page and a preview page. + +I own an instance of INNotebookModel that I use to produce a document to export or to execute the cells to create the preview of the notebook. + + +" Class { #name : #INNotebookWithPreviewPresenter, #superclass : #SpPresenterWithModel, From 8b7d09090fc75749655d078d158b7e5c4da5a01a Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Tue, 2 May 2023 15:42:28 +0200 Subject: [PATCH 11/41] fix canvas size not setting right --- .../SpRoassalPresenter.extension.st | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st b/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st index e346470..fa5a2e0 100644 --- a/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st +++ b/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st @@ -21,6 +21,18 @@ SpRoassalPresenter >> calculateNewScale [ ifFalse: [ yw / yc ] ] +{ #category : #'*InteractiveNotebookPresenter' } +SpRoassalPresenter >> defaultHeight [ + + ^ 350 +] + +{ #category : #'*InteractiveNotebookPresenter' } +SpRoassalPresenter >> defaultZoom [ + + ^ 0.9 +] + { #category : #'*InteractiveNotebookPresenter' } SpRoassalPresenter >> selectNotebookPresenter [ @@ -36,17 +48,12 @@ SpRoassalPresenter >> unselectedNotebookPresenter [ { #category : #'*InteractiveNotebookPresenter' } SpRoassalPresenter >> updateNotebookPresenterHeight [ - | rect | - self owner withAdapterDo: [ :a | a widget height: 350. self canvas camera zoomToFit: self canvas extent * 0.9. ]. - - "self canvas camera scale: self calculateNewScale. - self canvas camera position: self calculateNewCenter." - - "rect := RSCoordinates new visibleRectangleFor: self canvas camera. - ""rect := Rectangle - origin: 0 - a widget height @ 0 - a widget width - corner: a widget height @ a widget width."" - self canvas camera - zoomToFit: (a widget height @ a widget width) * 1.3 - rectangle: rect." + self owner withAdapterDo: [ :a | + | canvas | + canvas := self currentCanvas. + a widget height: self defaultHeight. + canvas camera + zoomToFit: a widget extent * self defaultZoom + rectangle: canvas encompassingRectangle. + canvas signalUpdate ] ] From 83ac7a8a27fa46e418581bd2ba3dd34a9ec8d9f9 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Tue, 2 May 2023 16:35:15 +0200 Subject: [PATCH 12/41] renaming, cleaning and adding more class comments --- .../INNotebookAbstractCellModel.class.st | 12 +++++- .../INNotebookAbstractCellPresenter.class.st | 39 +++++++++++-------- .../INNotebookCellPreviewPresenter.class.st | 8 ++-- .../INNotebookCodeCellModel.class.st | 4 +- .../INNotebookCodeCellPresenter.class.st | 11 +++--- .../INNotebookPreviewPresenter.class.st | 3 ++ .../INNotebookTextCellModel.class.st | 4 +- .../INNotebookTextCellPresenter.class.st | 9 ++--- .../SpMorphPresenter.extension.st | 18 --------- 9 files changed, 52 insertions(+), 56 deletions(-) delete mode 100644 src/InteractiveNotebookPresenter/SpMorphPresenter.extension.st diff --git a/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st b/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st index b8b3b28..ebc1043 100644 --- a/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st @@ -1,3 +1,11 @@ +" +I am an abstract editor cell model. + +I have an instance variable `needToUpdate` that is set to true if a preview cell was never created for me (i.e. if I was never compiled) or if I was modified after having created a preview cell. +It is set to false otherwise, this way I don't have to be recompiled or to create a new preview cell. + +I am responsible for the compilation of the content in my presenter's text input. +" Class { #name : #INNotebookAbstractCellModel, #superclass : #Object, @@ -9,12 +17,12 @@ Class { #category : #InteractiveNotebookPresenter } -{ #category : #'as yet unclassified' } +{ #category : #converting } INNotebookAbstractCellModel >> beCodeModel [ ^ self subclassResponsibility ] -{ #category : #'as yet unclassified' } +{ #category : #converting } INNotebookAbstractCellModel >> beTextModel [ ^ self subclassResponsibility ] diff --git a/src/InteractiveNotebookPresenter/INNotebookAbstractCellPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookAbstractCellPresenter.class.st index 7842558..eaab787 100644 --- a/src/InteractiveNotebookPresenter/INNotebookAbstractCellPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookAbstractCellPresenter.class.st @@ -1,8 +1,18 @@ +" +I am an abstract editing cell presenter. + +I have a presenter providing a text input (`cellTextInput`) in which the user can type Microdown text or code, depending on the cell type. + +I give to my children buttons allowing to transform themselves from code cell to text cell and vice versa, to add a new text cell before or after the current cell, to move the cell up or down in the notebook, and one to delete the current cell. + + + + +" Class { #name : #INNotebookAbstractCellPresenter, #superclass : #SpPresenterWithModel, #instVars : [ - 'cell', 'icon', 'notebook', 'removeButton', @@ -13,7 +23,8 @@ Class { 'addCellAboveButton', 'moveCellUp', 'moveCellDown', - 'previewCell' + 'previewCell', + 'cellTextInput' ], #category : #InteractiveNotebookPresenter } @@ -53,9 +64,9 @@ INNotebookAbstractCellPresenter >> beUnselected [ ] { #category : #accessing } -INNotebookAbstractCellPresenter >> cell [ +INNotebookAbstractCellPresenter >> cellTextInput [ - ^ cell + ^ cellTextInput ] { #category : #initialization } @@ -84,7 +95,7 @@ INNotebookAbstractCellPresenter >> initializeLayout [ self layout: (SpBoxLayout newLeftToRight add: leftMenuCanvas width: 30; - add: cell; + add: cellTextInput; add: rightMenuCanvas width: 100; yourself) ] @@ -179,12 +190,6 @@ INNotebookAbstractCellPresenter >> moveUp [ notebook moveUp: self ] -{ #category : #accessing } -INNotebookAbstractCellPresenter >> needToUpdateModel [ - self model needToUpdate: true. - -] - { #category : #accessing } INNotebookAbstractCellPresenter >> notebook [ @@ -247,19 +252,19 @@ INNotebookAbstractCellPresenter >> selectedColor [ { #category : #protocol } INNotebookAbstractCellPresenter >> takeKeyboardFocus [ - cell takeKeyboardFocus + cellTextInput takeKeyboardFocus ] { #category : #initialization } INNotebookAbstractCellPresenter >> text [ - ^ cell text + ^ cellTextInput text ] { #category : #initialization } INNotebookAbstractCellPresenter >> text: aText [ - cell text: aText + cellTextInput text: aText ] { #category : #accessing } @@ -285,7 +290,7 @@ INNotebookAbstractCellPresenter >> unselectedColor [ INNotebookAbstractCellPresenter >> updateHeight [ UIManager default defer: [ notebook headerSep withAdapterDo: [ :a | - cell withAdapterDo: [ :b | + cellTextInput withAdapterDo: [ :b | | textMorph height width | textMorph := b widget. textMorph @@ -300,12 +305,12 @@ INNotebookAbstractCellPresenter >> updateHeight [ font: textMorph font; width: width - 182; beWrapped; - updateTextWith: cell text) height. + updateTextWith: cellTextInput text) height. self withAdapterDo: [ :c | c widget height: height + 2 ] ] ] ] ] { #category : #enumerating } INNotebookAbstractCellPresenter >> whenTextChangedDo: aBlock [ - cell whenTextChangedDo: aBlock + cellTextInput whenTextChangedDo: aBlock ] diff --git a/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st index b4b07e5..c9c1eb7 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st @@ -31,15 +31,15 @@ INNotebookCellPreviewPresenter >> beSelected [ ] { #category : #accessing } -INNotebookCellPreviewPresenter >> cell [ +INNotebookCellPreviewPresenter >> cell: anObject [ - ^ cell + cell := anObject ] { #category : #accessing } -INNotebookCellPreviewPresenter >> cell: anObject [ +INNotebookCellPreviewPresenter >> cellTextInput [ - cell := anObject + ^ cell ] { #category : #'as yet unclassified' } diff --git a/src/InteractiveNotebookPresenter/INNotebookCodeCellModel.class.st b/src/InteractiveNotebookPresenter/INNotebookCodeCellModel.class.st index 3fb05ea..a5d9487 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCodeCellModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCodeCellModel.class.st @@ -4,12 +4,12 @@ Class { #category : #InteractiveNotebookPresenter } -{ #category : #'as yet unclassified' } +{ #category : #converting } INNotebookCodeCellModel >> beCodeModel [ ^ self ] -{ #category : #'as yet unclassified' } +{ #category : #converting } INNotebookCodeCellModel >> beTextModel [ "no need to add the text of the current model in the new model, it will be compiled anyway in the next preview" ^ INNotebookTextCellModel new diff --git a/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st index 55d85af..1ec775d 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st @@ -8,7 +8,7 @@ Class { INNotebookCodeCellPresenter >> asModelCell [ ^ INNotebookCodeCellModel new - text: cell text; + text: cellTextInput text; yourself ] @@ -21,20 +21,19 @@ INNotebookCodeCellPresenter >> beCode [ { #category : #api } INNotebookCodeCellPresenter >> beText [ - notebook transformToTextCell: self. - self needToUpdateModel + notebook transformToTextCell: self ] { #category : #initialization } INNotebookCodeCellPresenter >> initializePresenters [ super initializePresenters. - cell := self newCode + cellTextInput := self newCode withoutLineNumbers; beForScripting; placeholder: notebook codeCellPlaceholder; yourself. - cell whenTextChangedDo: [ self updateHeight ]. + cellTextInput whenTextChangedDo: [ self updateHeight ]. self interactionModel: notebook interactionModel. icon := self newButton @@ -54,7 +53,7 @@ INNotebookCodeCellPresenter >> initializePresenters [ { #category : #api } INNotebookCodeCellPresenter >> interactionModel: anEnvironment [ - cell interactionModel: anEnvironment + cellTextInput interactionModel: anEnvironment ] { #category : #accessing } diff --git a/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st index eba24f5..45c6afc 100644 --- a/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st @@ -1,3 +1,6 @@ +" +I am the preview side of a notebook page. I create preview cells to display the result of the compilation of each cell. +" Class { #name : #INNotebookPreviewPresenter, #superclass : #SpPresenter, diff --git a/src/InteractiveNotebookPresenter/INNotebookTextCellModel.class.st b/src/InteractiveNotebookPresenter/INNotebookTextCellModel.class.st index 6d7a9b9..0c14e16 100644 --- a/src/InteractiveNotebookPresenter/INNotebookTextCellModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookTextCellModel.class.st @@ -4,13 +4,13 @@ Class { #category : #InteractiveNotebookPresenter } -{ #category : #'as yet unclassified' } +{ #category : #converting } INNotebookTextCellModel >> beCodeModel [ "no need to add the text in the current model, it will be compiled anyway in the next preview" ^ INNotebookCodeCellModel new ] -{ #category : #'as yet unclassified' } +{ #category : #converting } INNotebookTextCellModel >> beTextModel [ ^ self ] diff --git a/src/InteractiveNotebookPresenter/INNotebookTextCellPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookTextCellPresenter.class.st index 73a2143..04604de 100644 --- a/src/InteractiveNotebookPresenter/INNotebookTextCellPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookTextCellPresenter.class.st @@ -8,15 +8,14 @@ Class { INNotebookTextCellPresenter >> asModelCell [ ^ INNotebookTextCellModel new - text: cell text; + text: cellTextInput text; yourself ] { #category : #api } INNotebookTextCellPresenter >> beCode [ - notebook transformToCodeCell: self. - self needToUpdateModel + notebook transformToCodeCell: self ] { #category : #api } @@ -29,8 +28,8 @@ INNotebookTextCellPresenter >> beText [ INNotebookTextCellPresenter >> initializePresenters [ super initializePresenters. - cell := self newText. - cell whenTextChangedDo: [ self updateHeight ]. + cellTextInput := self newText. + cellTextInput whenTextChangedDo: [ self updateHeight ]. icon := self newButton label: 'Mic'; action: [ notebook transformToCodeCell: self ]; diff --git a/src/InteractiveNotebookPresenter/SpMorphPresenter.extension.st b/src/InteractiveNotebookPresenter/SpMorphPresenter.extension.st deleted file mode 100644 index 9c7af25..0000000 --- a/src/InteractiveNotebookPresenter/SpMorphPresenter.extension.st +++ /dev/null @@ -1,18 +0,0 @@ -Extension { #name : #SpMorphPresenter } - -{ #category : #'*InteractiveNotebookPresenter' } -SpMorphPresenter >> selectNotebookPresenter [ - "todo" -] - -{ #category : #'*InteractiveNotebookPresenter' } -SpMorphPresenter >> unselectedNotebookPresenter [ - "todo" -] - -{ #category : #'*InteractiveNotebookPresenter' } -SpMorphPresenter >> updateNotebookPresenterHeight [ - self owner withAdapterDo: [ :a | - a widget defer: [ a widget height: 350 ]. - self morph zoomToFit ] -] From 6aedddb130ef7fddc8b2e0db1807528842e31ce9 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Wed, 3 May 2023 10:25:38 +0200 Subject: [PATCH 13/41] more renaming and cleaning --- .../INNotebookAbstractCellModel.class.st | 13 ++--------- .../INNotebookCellPreviewPresenter.class.st | 22 +++++++++---------- .../INNotebookEditorPresenter.class.st | 1 - .../INNotebookModel.class.st | 1 - 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st b/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st index ebc1043..3587614 100644 --- a/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st @@ -12,7 +12,8 @@ Class { #instVars : [ 'text', 'model', - 'needToUpdate' + 'needToUpdate', + 'previewCell' ], #category : #InteractiveNotebookPresenter } @@ -41,16 +42,6 @@ INNotebookAbstractCellModel >> initialize [ text := String empty ] -{ #category : #accessing } -INNotebookAbstractCellModel >> model [ - ^ model -] - -{ #category : #accessing } -INNotebookAbstractCellModel >> model: aModel [ - model := aModel -] - { #category : #accessing } INNotebookAbstractCellModel >> needToUpdate [ ^ needToUpdate diff --git a/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st index c9c1eb7..217ac5f 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st @@ -10,9 +10,9 @@ Class { #name : #INNotebookCellPreviewPresenter, #superclass : #SpPresenter, #instVars : [ - 'presenter', 'cell', - 'parent' + 'parent', + 'contentPresenter' ], #category : #InteractiveNotebookPresenter } @@ -42,16 +42,16 @@ INNotebookCellPreviewPresenter >> cellTextInput [ ^ cell ] -{ #category : #'as yet unclassified' } +{ #category : #accessing } INNotebookCellPreviewPresenter >> getContentPresenter [ - ^ presenter + ^ contentPresenter ] { #category : #initialization } INNotebookCellPreviewPresenter >> initializeLayout [ self layout: (SpBoxLayout newLeftToRight - add: presenter; + add: contentPresenter; yourself) ] @@ -78,7 +78,7 @@ INNotebookCellPreviewPresenter >> parent: anObject [ { #category : #actions } INNotebookCellPreviewPresenter >> select [ - presenter selectNotebookPresenter + contentPresenter selectNotebookPresenter ] { #category : #actions } @@ -97,32 +97,32 @@ INNotebookCellPreviewPresenter >> selectMe [ { #category : #initialization } INNotebookCellPreviewPresenter >> setContentPresenter: aPresenter [ - presenter := aPresenter. + contentPresenter := aPresenter. self whenDisplayDo: [ self updateHeight. "presenter withAdapterDo: [ :a | UIManager default defer: [ a widget backgroundColor: self unselectedColor ] ]" ]. self initializeLayout. - presenter eventHandler whenMouseDownDo: [ :anEvent | + contentPresenter eventHandler whenMouseDownDo: [ :anEvent | self selectMe ] ] { #category : #accessing } INNotebookCellPreviewPresenter >> text: aString [ - presenter text: aString + contentPresenter text: aString ] { #category : #actions } INNotebookCellPreviewPresenter >> unselected [ - presenter unselectedNotebookPresenter + contentPresenter unselectedNotebookPresenter ] { #category : #initialization } INNotebookCellPreviewPresenter >> updateHeight [ UIManager default defer: [ - presenter updateNotebookPresenterHeight ] + contentPresenter updateNotebookPresenterHeight ] ] diff --git a/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st index 8135448..d4d7b53 100644 --- a/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st @@ -7,7 +7,6 @@ Class { #name : #INNotebookEditorPresenter, #superclass : #SpPresenter, #instVars : [ - 'menu', 'cellList', 'lastCellAdded', 'selectedCell', diff --git a/src/InteractiveNotebookPresenter/INNotebookModel.class.st b/src/InteractiveNotebookPresenter/INNotebookModel.class.st index b2330ba..ee2365d 100644 --- a/src/InteractiveNotebookPresenter/INNotebookModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookModel.class.st @@ -9,7 +9,6 @@ Class { #name : #INNotebookModel, #superclass : #Object, #instVars : [ - 'textEditedSource', 'micDocument', 'cellList', 'context', From 8294219d7e015686d8b2f6f6c275e10025a4b18f Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Wed, 3 May 2023 10:33:57 +0200 Subject: [PATCH 14/41] final cleaning (for now) --- .../INNotebookAbstractCellModel.class.st | 3 +-- src/InteractiveNotebookPresenter/INNotebookModel.class.st | 4 ++-- .../INNotebookPreviewPresenter.class.st | 8 -------- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st b/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st index 3587614..b4da677 100644 --- a/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st @@ -12,8 +12,7 @@ Class { #instVars : [ 'text', 'model', - 'needToUpdate', - 'previewCell' + 'needToUpdate' ], #category : #InteractiveNotebookPresenter } diff --git a/src/InteractiveNotebookPresenter/INNotebookModel.class.st b/src/InteractiveNotebookPresenter/INNotebookModel.class.st index ee2365d..d404e9e 100644 --- a/src/InteractiveNotebookPresenter/INNotebookModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookModel.class.st @@ -89,8 +89,8 @@ INNotebookModel >> executeAllCellsAsCollection [ collection := cellList collect: [ :cell | cell needToUpdate ifTrue: [ cell getContentwithContext: context ] - ifFalse: [ nil ] ]. - ^ collection + ifFalse: [ nil ] ]. "has to be nil, so the list has the right size" + ^ collection "while still compiling only when necessary" ] { #category : #export } diff --git a/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st index 45c6afc..5cf2a8b 100644 --- a/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st @@ -132,14 +132,6 @@ INNotebookPreviewPresenter >> updateHeight [ previewCells do: [ :c | c updateHeight ] ] -{ #category : #actions } -INNotebookPreviewPresenter >> updateWithStringCollection: aCollection [ - - previewCells := aCollection collect: [ :s | - self newPreviewCellWith: s ]. - self relayout -] - { #category : #actions } INNotebookPreviewPresenter >> updateWithStringCollection: aCollection andCells: cells [ From a629a3754eb38ca6d85d4c5ae16e606a268f0c76 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Wed, 3 May 2023 10:52:23 +0200 Subject: [PATCH 15/41] setting things up for the export functionnality --- .../INNotebookAbstractCellModel.class.st | 16 ++++++++++++++-- .../INNotebookPreviewPresenter.class.st | 1 + .../INNotebookWithPreviewPresenter.class.st | 6 +++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st b/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st index b4da677..1dab866 100644 --- a/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st @@ -11,8 +11,8 @@ Class { #superclass : #Object, #instVars : [ 'text', - 'model', - 'needToUpdate' + 'needToUpdate', + 'previewCell' ], #category : #InteractiveNotebookPresenter } @@ -57,6 +57,18 @@ INNotebookAbstractCellModel >> presenterClass [ self subclassResponsibility ] +{ #category : #accessing } +INNotebookAbstractCellModel >> previewCell [ + + ^ previewCell +] + +{ #category : #accessing } +INNotebookAbstractCellModel >> previewCell: anObject [ + + previewCell := anObject +] + { #category : #printing } INNotebookAbstractCellModel >> printContentIn: aStream withContext: aContext [ diff --git a/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st index 5cf2a8b..0885526 100644 --- a/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st @@ -145,6 +145,7 @@ INNotebookPreviewPresenter >> updateWithStringCollection: aCollection andCells: pCell := self newPreviewCellWith: obj. pCell cell: cell. cell previewCell: pCell. + cell model previewCell: pCell. cell model needToUpdate: false ] ifFalse: [ pCell := cell previewCell ]. col add: pCell ]. diff --git a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st index 143d2c2..4443404 100644 --- a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st @@ -62,7 +62,7 @@ INNotebookWithPreviewPresenter >> codeCellPlaceholder: anObject [ INNotebookWithPreviewPresenter >> exportDocument [ | aFile | - self updateModelCells. + self preview. self model cellList ifEmpty: [ self inform: 'Nothing to export'. ^ self ]. @@ -77,7 +77,7 @@ INNotebookWithPreviewPresenter >> exportDocument [ INNotebookWithPreviewPresenter >> exportToHTML [ | aFile | - self updateModelCells. + self preview. self model cellList ifEmpty: [ self inform: 'Nothing to export'. ^ self ]. @@ -94,7 +94,7 @@ INNotebookWithPreviewPresenter >> exportToHTML [ INNotebookWithPreviewPresenter >> exportToText [ | aFile | - self updateModelCells. + self preview. self model cellList ifEmpty: [ self inform: 'Nothing to export'. ^ self ]. From 551678972239e6d8ec47bb0b74107772c0c2b191 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Wed, 3 May 2023 15:02:40 +0200 Subject: [PATCH 16/41] exporter works with text and roassal canvas --- .../INNotebookCellPreviewPresenter.class.st | 35 ++++++++++------- .../INNotebookModel.class.st | 39 ++++++++----------- .../INNotebookPreviewPresenter.class.st | 4 +- .../Object.extension.st | 5 ++- .../RSCanvas.extension.st | 20 +++++++++- .../SpRoassalPresenter.extension.st | 5 +++ .../SpTextPresenter.extension.st | 5 +++ 7 files changed, 71 insertions(+), 42 deletions(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st index 217ac5f..733838c 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st @@ -43,10 +43,29 @@ INNotebookCellPreviewPresenter >> cellTextInput [ ] { #category : #accessing } -INNotebookCellPreviewPresenter >> getContentPresenter [ +INNotebookCellPreviewPresenter >> contentPresenter [ ^ contentPresenter ] +{ #category : #initialization } +INNotebookCellPreviewPresenter >> contentPresenter: aPresenter [ + + contentPresenter := aPresenter. + self whenDisplayDo: [ + self updateHeight. + "presenter withAdapterDo: [ :a | + UIManager default defer: [ + a widget backgroundColor: self unselectedColor ] ]" ]. + self initializeLayout. + contentPresenter eventHandler whenMouseDownDo: [ :anEvent | + self selectMe ] +] + +{ #category : #accessing } +INNotebookCellPreviewPresenter >> getContent [ + ^ contentPresenter getContent +] + { #category : #initialization } INNotebookCellPreviewPresenter >> initializeLayout [ @@ -94,20 +113,6 @@ INNotebookCellPreviewPresenter >> selectMe [ cell ifNotNil: [ :c | c selectAndScrollToMe ] ] -{ #category : #initialization } -INNotebookCellPreviewPresenter >> setContentPresenter: aPresenter [ - - contentPresenter := aPresenter. - self whenDisplayDo: [ - self updateHeight. - "presenter withAdapterDo: [ :a | - UIManager default defer: [ - a widget backgroundColor: self unselectedColor ] ]" ]. - self initializeLayout. - contentPresenter eventHandler whenMouseDownDo: [ :anEvent | - self selectMe ] -] - { #category : #accessing } INNotebookCellPreviewPresenter >> text: aString [ diff --git a/src/InteractiveNotebookPresenter/INNotebookModel.class.st b/src/InteractiveNotebookPresenter/INNotebookModel.class.st index d404e9e..2b39290 100644 --- a/src/InteractiveNotebookPresenter/INNotebookModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookModel.class.st @@ -12,7 +12,6 @@ Class { 'micDocument', 'cellList', 'context', - 'generatedDocument', 'additionalBindings', 'fileName' ], @@ -69,14 +68,19 @@ INNotebookModel >> context [ ^ context ] -{ #category : #actions } -INNotebookModel >> executeAllCells [ +{ #category : #'as yet unclassified' } +INNotebookModel >> createGeneratedDocumentAt: aFileReference [ - generatedDocument := String streamContents: [ :s | - self initializeContextWithStream: s. - cellList do: [ :cell | - cell printContentIn: s withContext: context. - s nextPut: Character cr ] ]. + | generatedDocument parentReference | + parentReference := aFileReference parent. + generatedDocument := String streamContents: [ :stream | + cellList doWithIndex: [ :cell :index | + stream nextPutAll: + (cell previewCell getContent + generateMicrodownAt: parentReference + withIndex: index). + stream nextPutAll: ' '. + stream nextPut: Character cr ] ]. ^ generatedDocument ] @@ -108,9 +112,11 @@ INNotebookModel >> exportDocumentAt: aFileReference [ INNotebookModel >> exportToHTMLAt: aFileReference [ "This will use the microdown HTML visitor to export the document to HTML. So your document should respect Microdown specs." + aFileReference ifNil: [ ^ self ]. aFileReference writeStreamDo: [ :stream | - stream nextPutAll: (MicHTMLVisitor asHTMLString: self generatedDocument) ] + stream nextPutAll: (MicHTMLVisitor asHTMLString: + (self createGeneratedDocumentAt: aFileReference)) ] ] { #category : #export } @@ -121,19 +127,8 @@ INNotebookModel >> exportToTextAt: aFileReference [ aFileReference ifNil: [ ^ self ]. aFileReference ensureDelete. aFileReference ifNotNil: [ - aFileReference writeStreamDo: [ :s | s << generatedDocument ] ] -] - -{ #category : #accessing } -INNotebookModel >> generatedDocument [ - - ^ generatedDocument -] - -{ #category : #accessing } -INNotebookModel >> generatedDocument: anObject [ - - generatedDocument := anObject. + aFileReference writeStreamDo: [ :s | + s << (self createGeneratedDocumentAt: aFileReference) ] ] ] { #category : #actions } diff --git a/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st index 0885526..a55fbfb 100644 --- a/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st @@ -86,10 +86,10 @@ INNotebookPreviewPresenter >> initializePresenters [ INNotebookPreviewPresenter >> newPreviewCellWith: anObject [ | pCell | pCell := (self instantiate: INNotebookCellPreviewPresenter) - setContentPresenter: (anObject createContentPreviewPresenter); + contentPresenter: (anObject createContentPreviewPresenter); parent: self; yourself. - anObject addContentToPreviewPresenter: pCell getContentPresenter. + anObject addContentToPreviewPresenter: pCell contentPresenter. ^ pCell ] diff --git a/src/InteractiveNotebookPresenter/Object.extension.st b/src/InteractiveNotebookPresenter/Object.extension.st index 1f89df9..7ad2608 100644 --- a/src/InteractiveNotebookPresenter/Object.extension.st +++ b/src/InteractiveNotebookPresenter/Object.extension.st @@ -14,6 +14,9 @@ Object >> createContentPreviewPresenter [ ] { #category : #'*InteractiveNotebookPresenter' } -Object >> generateMicrodown [ +Object >> generateMicrodownAt: aFileReference withIndex: anIndex [ + "Returns a Microdown string to include in the generated document. + This method can have side effects (if an image needs to be included for example, if must first be created). + The file reference is pointing to the directory containing the exported document, and the index is the index of the preview cell in the cell list. Those parameters are used to create a path for the eventual files to create." ^ self asString ] diff --git a/src/InteractiveNotebookPresenter/RSCanvas.extension.st b/src/InteractiveNotebookPresenter/RSCanvas.extension.st index 672b3f7..5f809ba 100644 --- a/src/InteractiveNotebookPresenter/RSCanvas.extension.st +++ b/src/InteractiveNotebookPresenter/RSCanvas.extension.st @@ -5,6 +5,11 @@ RSCanvas >> addContentToPreviewPresenter: aPresenter [ aPresenter canvas: self canvas ] +{ #category : #'*InteractiveNotebookPresenter' } +RSCanvas >> checkForResourcesDirectoryAt: aFileReference [ + ^ (aFileReference / 'notebook_resources') exists +] + { #category : #'*InteractiveNotebookPresenter' } RSCanvas >> createContentPreviewPresenter [ | rPresenter | @@ -13,6 +18,17 @@ RSCanvas >> createContentPreviewPresenter [ ] { #category : #'*InteractiveNotebookPresenter' } -RSCanvas >> generateMicrodown [ - ^ 'plus tard hehe' +RSCanvas >> createResourcesDirectoryAt: aFileReference [ + (aFileReference / 'notebook_resources') createDirectory +] + +{ #category : #'*InteractiveNotebookPresenter' } +RSCanvas >> generateMicrodownAt: aFileReference withIndex: anIndex [ + + (self checkForResourcesDirectoryAt: aFileReference) ifFalse: [ + self createResourcesDirectoryAt: aFileReference ]. + + RSPNGExporter new canvas: self; exportToFile: aFileReference / 'notebook_resources' / ('img' , (anIndex asString) , '.png'). + + ^ '![cell n°', anIndex asString ,'](notebook_resources/img', anIndex asString ,'.png)'. ] diff --git a/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st b/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st index fa5a2e0..4475644 100644 --- a/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st +++ b/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st @@ -33,6 +33,11 @@ SpRoassalPresenter >> defaultZoom [ ^ 0.9 ] +{ #category : #'*InteractiveNotebookPresenter' } +SpRoassalPresenter >> getContent [ + ^ self canvas +] + { #category : #'*InteractiveNotebookPresenter' } SpRoassalPresenter >> selectNotebookPresenter [ diff --git a/src/InteractiveNotebookPresenter/SpTextPresenter.extension.st b/src/InteractiveNotebookPresenter/SpTextPresenter.extension.st index 3b7bbd7..23e9b4a 100644 --- a/src/InteractiveNotebookPresenter/SpTextPresenter.extension.st +++ b/src/InteractiveNotebookPresenter/SpTextPresenter.extension.st @@ -1,5 +1,10 @@ Extension { #name : #SpTextPresenter } +{ #category : #'*InteractiveNotebookPresenter' } +SpTextPresenter >> getContent [ + ^ self text +] + { #category : #'*InteractiveNotebookPresenter' } SpTextPresenter >> selectNotebookPresenter [ From 2a38d093c8e3dfe64266095d3d2e8deedb7b2b95 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Wed, 3 May 2023 16:45:24 +0200 Subject: [PATCH 17/41] fix import export STON --- .../INNotebookAbstractCellModel.class.st | 5 +++++ .../INNotebookAbstractCellPresenter.class.st | 6 ++++++ .../INNotebookCodeCellPresenter.class.st | 6 ------ .../INNotebookEditorPresenter.class.st | 3 +-- src/InteractiveNotebookPresenter/INNotebookModel.class.st | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st b/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st index 1dab866..1208b64 100644 --- a/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st @@ -17,6 +17,11 @@ Class { #category : #InteractiveNotebookPresenter } +{ #category : #ston } +INNotebookAbstractCellModel class >> stonAllInstVarNames [ + ^ super stonAllInstVarNames \ {#needToUpdate. #previewCell } +] + { #category : #converting } INNotebookAbstractCellModel >> beCodeModel [ ^ self subclassResponsibility diff --git a/src/InteractiveNotebookPresenter/INNotebookAbstractCellPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookAbstractCellPresenter.class.st index eaab787..7d4682a 100644 --- a/src/InteractiveNotebookPresenter/INNotebookAbstractCellPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookAbstractCellPresenter.class.st @@ -249,6 +249,12 @@ INNotebookAbstractCellPresenter >> selectedColor [ ^ Color fromHexString: '77A8C8' ] +{ #category : #api } +INNotebookAbstractCellPresenter >> setModelBeforeInitialization: aModel [ + + self notebook: aModel +] + { #category : #protocol } INNotebookAbstractCellPresenter >> takeKeyboardFocus [ diff --git a/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st index 1ec775d..5cb4cba 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st @@ -61,9 +61,3 @@ INNotebookCodeCellPresenter >> notebook: aNoteBook [ notebook := aNoteBook. ] - -{ #category : #api } -INNotebookCodeCellPresenter >> setModelBeforeInitialization: aModel [ - - self notebook: aModel -] diff --git a/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st index d4d7b53..42fe415 100644 --- a/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st @@ -260,9 +260,8 @@ INNotebookEditorPresenter >> updateAll [ cellList := LinkedList new. self model cellList do: [ :c | - cellList add: ((self instantiate: c presenterClass) + cellList add: ((self instantiate: c presenterClass on: self) model: c; - notebook: self; text: c text; yourself) ]. diff --git a/src/InteractiveNotebookPresenter/INNotebookModel.class.st b/src/InteractiveNotebookPresenter/INNotebookModel.class.st index 2b39290..ee57ffe 100644 --- a/src/InteractiveNotebookPresenter/INNotebookModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookModel.class.st @@ -68,7 +68,7 @@ INNotebookModel >> context [ ^ context ] -{ #category : #'as yet unclassified' } +{ #category : #export } INNotebookModel >> createGeneratedDocumentAt: aFileReference [ | generatedDocument parentReference | From 14cf1a97233d9448a03ca298aab620938f3f54f7 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Thu, 4 May 2023 10:38:09 +0200 Subject: [PATCH 18/41] collection custom printing --- .../Collection.extension.st | 28 +++++++++++++++++++ .../INNotebookAbstractCellModel.class.st | 2 +- .../String.extension.st | 6 ++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/InteractiveNotebookPresenter/Collection.extension.st create mode 100644 src/InteractiveNotebookPresenter/String.extension.st diff --git a/src/InteractiveNotebookPresenter/Collection.extension.st b/src/InteractiveNotebookPresenter/Collection.extension.st new file mode 100644 index 0000000..54c2cef --- /dev/null +++ b/src/InteractiveNotebookPresenter/Collection.extension.st @@ -0,0 +1,28 @@ +Extension { #name : #Collection } + +{ #category : #'*InteractiveNotebookPresenter' } +Collection >> addContentToPreviewPresenter: aPresenter [ + + | text | + text := self + ifNotEmpty: [ + String streamContents: [ :s | + self do: [ :el | + s nextPutAll: '- '. + s nextPutAll: el asString. + s nextPut: Character cr ] ] ] + ifEmpty: [ 'Empty collection.' ]. + aPresenter text: text +] + +{ #category : #'*InteractiveNotebookPresenter' } +Collection >> generateMicrodownAt: aFileReference withIndex: anIndex [ + + | text | + text := String streamContents: [ :s | + self do: [ :el | + s nextPutAll: '- '. + s nextPutAll: el asString. + s nextPut: Character cr ] ]. + ^ text +] diff --git a/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st b/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st index 1208b64..44d0524 100644 --- a/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st @@ -19,7 +19,7 @@ Class { { #category : #ston } INNotebookAbstractCellModel class >> stonAllInstVarNames [ - ^ super stonAllInstVarNames \ {#needToUpdate. #previewCell } + ^ super stonAllInstVarNames \ { #needToUpdate. #previewCell } ] { #category : #converting } diff --git a/src/InteractiveNotebookPresenter/String.extension.st b/src/InteractiveNotebookPresenter/String.extension.st new file mode 100644 index 0000000..8571400 --- /dev/null +++ b/src/InteractiveNotebookPresenter/String.extension.st @@ -0,0 +1,6 @@ +Extension { #name : #String } + +{ #category : #'*InteractiveNotebookPresenter' } +String >> addContentToPreviewPresenter: aPresenter [ + aPresenter text: self +] From 9e8838b00368bb6a91f416d8138eb88406bf43c8 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Thu, 4 May 2023 13:44:36 +0200 Subject: [PATCH 19/41] small fixes and tests --- .../INNotebookCodeCellPresenter.class.st | 9 +++++---- .../INNotebookTextCellPresenter.class.st | 5 ++++- .../SpRoassalPresenter.extension.st | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st index 5cb4cba..485ee60 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st @@ -29,10 +29,11 @@ INNotebookCodeCellPresenter >> initializePresenters [ super initializePresenters. cellTextInput := self newCode - withoutLineNumbers; - beForScripting; - placeholder: notebook codeCellPlaceholder; - yourself. + withoutLineNumbers; + withoutScrollBars; + beForScripting; + placeholder: notebook codeCellPlaceholder; + yourself. cellTextInput whenTextChangedDo: [ self updateHeight ]. self interactionModel: notebook interactionModel. diff --git a/src/InteractiveNotebookPresenter/INNotebookTextCellPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookTextCellPresenter.class.st index 04604de..91dd53f 100644 --- a/src/InteractiveNotebookPresenter/INNotebookTextCellPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookTextCellPresenter.class.st @@ -28,7 +28,10 @@ INNotebookTextCellPresenter >> beText [ INNotebookTextCellPresenter >> initializePresenters [ super initializePresenters. - cellTextInput := self newText. + cellTextInput := self + newText + withoutScrollBars; + yourself. cellTextInput whenTextChangedDo: [ self updateHeight ]. icon := self newButton label: 'Mic'; diff --git a/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st b/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st index 4475644..4aa1688 100644 --- a/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st +++ b/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st @@ -24,7 +24,7 @@ SpRoassalPresenter >> calculateNewScale [ { #category : #'*InteractiveNotebookPresenter' } SpRoassalPresenter >> defaultHeight [ - ^ 350 + ^ 500 ] { #category : #'*InteractiveNotebookPresenter' } From e8af5a47002811a8b7fc032182b09dcd9a6ac27d Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Thu, 4 May 2023 15:22:53 +0200 Subject: [PATCH 20/41] unfix fix + fixing string export generation --- .../INNotebookCodeCellPresenter.class.st | 1 - .../INNotebookTextCellPresenter.class.st | 5 +---- src/InteractiveNotebookPresenter/String.extension.st | 6 ++++++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st index 485ee60..b6256e2 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st @@ -30,7 +30,6 @@ INNotebookCodeCellPresenter >> initializePresenters [ super initializePresenters. cellTextInput := self newCode withoutLineNumbers; - withoutScrollBars; beForScripting; placeholder: notebook codeCellPlaceholder; yourself. diff --git a/src/InteractiveNotebookPresenter/INNotebookTextCellPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookTextCellPresenter.class.st index 91dd53f..04604de 100644 --- a/src/InteractiveNotebookPresenter/INNotebookTextCellPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookTextCellPresenter.class.st @@ -28,10 +28,7 @@ INNotebookTextCellPresenter >> beText [ INNotebookTextCellPresenter >> initializePresenters [ super initializePresenters. - cellTextInput := self - newText - withoutScrollBars; - yourself. + cellTextInput := self newText. cellTextInput whenTextChangedDo: [ self updateHeight ]. icon := self newButton label: 'Mic'; diff --git a/src/InteractiveNotebookPresenter/String.extension.st b/src/InteractiveNotebookPresenter/String.extension.st index 8571400..cb27599 100644 --- a/src/InteractiveNotebookPresenter/String.extension.st +++ b/src/InteractiveNotebookPresenter/String.extension.st @@ -4,3 +4,9 @@ Extension { #name : #String } String >> addContentToPreviewPresenter: aPresenter [ aPresenter text: self ] + +{ #category : #'*InteractiveNotebookPresenter' } +String >> generateMicrodownAt: aFileReference withIndex: anIndex [ + + ^ self +] From f1bec6344130378aed5464c534a7968122d29c1c Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Tue, 9 May 2023 11:23:52 +0200 Subject: [PATCH 21/41] first attempt to display inspector like view for notebook --- .../INNotebookCellPreviewPresenter.class.st | 9 ++-- .../INNotebookPreviewPresenter.class.st | 46 +++++++++++++++++-- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st index 733838c..f9d9fe4 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st @@ -97,7 +97,7 @@ INNotebookCellPreviewPresenter >> parent: anObject [ { #category : #actions } INNotebookCellPreviewPresenter >> select [ - contentPresenter selectNotebookPresenter + "contentPresenter selectNotebookPresenter " ] { #category : #actions } @@ -122,12 +122,13 @@ INNotebookCellPreviewPresenter >> text: aString [ { #category : #actions } INNotebookCellPreviewPresenter >> unselected [ - contentPresenter unselectedNotebookPresenter + "contentPresenter unselectedNotebookPresenter " ] { #category : #initialization } INNotebookCellPreviewPresenter >> updateHeight [ - UIManager default defer: [ - contentPresenter updateNotebookPresenterHeight ] + self withAdapterDo: [ :a | "UIManager default defer: [ + contentPresenter updateNotebookPresenterHeight ]" + a widget height: 350 ] ] diff --git a/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st index a55fbfb..1ec2fb9 100644 --- a/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st @@ -34,6 +34,18 @@ INNotebookPreviewPresenter >> close [ browser closePreview ] +{ #category : #'as yet unclassified' } +INNotebookPreviewPresenter >> createInspectorViewFor: anObject [ + + | ctxs presenter | + ctxs := anObject inspectionContexts. + presenter := self newNotebook. + ctxs do: [ :ctx | + ctx evaluator: false. + presenter addPage: (self newPageForContext: ctx andObject: anObject) ]. + ^ presenter +] + { #category : #initialization } INNotebookPreviewPresenter >> initialize [ @@ -82,15 +94,39 @@ INNotebookPreviewPresenter >> initializePresenters [ self initializeLayout ] +{ #category : #actions } +INNotebookPreviewPresenter >> newInspectionForContext: aContext andObject: anObject [ + + ^ StObjectContextPresenter on: (StObjectContextModel new + inspection: self; + inspectedObject: anObject; + context: aContext; + yourself) +] + +{ #category : #actions } +INNotebookPreviewPresenter >> newPageForContext: aContext andObject: anObject [ + + ^ SpNotebookPage new + title: aContext title; + presenterProvider: [ self newInspectionForContext: aContext andObject: anObject ]; + "whenRetrievedDo: [ :presenter | + self keepPresenter: presenter. + self addActivationTo: presenter ];" + yourself +] + { #category : #actions } INNotebookPreviewPresenter >> newPreviewCellWith: anObject [ + | pCell | pCell := (self instantiate: INNotebookCellPreviewPresenter) - contentPresenter: (anObject createContentPreviewPresenter); - parent: self; - yourself. - anObject addContentToPreviewPresenter: pCell contentPresenter. - ^ pCell + contentPresenter: (self createInspectorViewFor: anObject); + parent: self; + yourself. + "contentPresenter: (anObject createContentPreviewPresenter);" + "anObject addContentToPreviewPresenter: pCell contentPresenter." + ^ pCell ] { #category : #initialization } From 45a20c6a9f016d4b2d09e241599c9e9695613e77 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Wed, 10 May 2023 14:56:57 +0200 Subject: [PATCH 22/41] parsing of cells to create bindings (could be better, using one interaction model per code cell would make sure to only give access to variables defined in previous cells) --- .../INNotebookCodeCellModel.class.st | 6 ++++++ .../INNotebookCodeCellPresenter.class.st | 11 ++++++++++- .../INNotebookCodeScriptingInteractionModel.class.st | 7 +++++++ .../INNotebookModel.class.st | 3 ++- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookCodeCellModel.class.st b/src/InteractiveNotebookPresenter/INNotebookCodeCellModel.class.st index a5d9487..da4eae1 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCodeCellModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCodeCellModel.class.st @@ -24,6 +24,12 @@ INNotebookCodeCellModel >> getContentwithContext: aContext [ evaluate ] +{ #category : #compiling } +INNotebookCodeCellModel >> parseContent [ + + ^ RBParser parseExpression: text +] + { #category : #helpers } INNotebookCodeCellModel >> presenterClass [ diff --git a/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st index b6256e2..68d7202 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st @@ -33,7 +33,7 @@ INNotebookCodeCellPresenter >> initializePresenters [ beForScripting; placeholder: notebook codeCellPlaceholder; yourself. - cellTextInput whenTextChangedDo: [ self updateHeight ]. + cellTextInput whenTextChangedDo: [ self updateHeight. self updateBindings. ]. self interactionModel: notebook interactionModel. icon := self newButton @@ -61,3 +61,12 @@ INNotebookCodeCellPresenter >> notebook: aNoteBook [ notebook := aNoteBook. ] + +{ #category : #'as yet unclassified' } +INNotebookCodeCellPresenter >> updateBindings [ + + | parsedContent | + self model text: cellTextInput text. + parsedContent := [ self model parseContent ] on: Exception do: [ ^ self ]. + notebook interactionModel setBindings: parsedContent +] diff --git a/src/InteractiveNotebookPresenter/INNotebookCodeScriptingInteractionModel.class.st b/src/InteractiveNotebookPresenter/INNotebookCodeScriptingInteractionModel.class.st index e60f721..3047545 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCodeScriptingInteractionModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCodeScriptingInteractionModel.class.st @@ -24,3 +24,10 @@ INNotebookCodeScriptingInteractionModel >> receiver: anObject [ receiver := anObject ] + +{ #category : #initialization } +INNotebookCodeScriptingInteractionModel >> setBindings: aASTTree [ + + aASTTree allChildren do: [ :l | + l class = RBAssignmentNode ifTrue: [ self bindingOf: l variable name ] ] +] diff --git a/src/InteractiveNotebookPresenter/INNotebookModel.class.st b/src/InteractiveNotebookPresenter/INNotebookModel.class.st index ee57ffe..5dc9ee2 100644 --- a/src/InteractiveNotebookPresenter/INNotebookModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookModel.class.st @@ -144,7 +144,8 @@ INNotebookModel >> initialize [ super initialize. cellList := OrderedCollection new. - additionalBindings := Dictionary new + additionalBindings := Dictionary new. + self initializeContext ] { #category : #initialization } From 3f24f8edafa165c5ee8554d432172d25de26c840 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Thu, 11 May 2023 11:36:54 +0200 Subject: [PATCH 23/41] removing useless classes and methods --- .../INAbstractReportPrinter.class.st | 35 ---------- .../INReportCollectionPrinter.class.st | 68 ------------------- .../SpRoassalPresenter.extension.st | 21 ------ 3 files changed, 124 deletions(-) delete mode 100644 src/InteractiveNotebookPresenter/INAbstractReportPrinter.class.st delete mode 100644 src/InteractiveNotebookPresenter/INReportCollectionPrinter.class.st diff --git a/src/InteractiveNotebookPresenter/INAbstractReportPrinter.class.st b/src/InteractiveNotebookPresenter/INAbstractReportPrinter.class.st deleted file mode 100644 index 444af61..0000000 --- a/src/InteractiveNotebookPresenter/INAbstractReportPrinter.class.st +++ /dev/null @@ -1,35 +0,0 @@ -Class { - #name : #INAbstractReportPrinter, - #superclass : #Object, - #instVars : [ - 'micBuilder', - 'stream' - ], - #category : #InteractiveNotebookPresenter -} - -{ #category : #printing } -INAbstractReportPrinter >> initialize [ - - super initialize. - micBuilder := Microdown builder. -] - -{ #category : #printing } -INAbstractReportPrinter >> print: aCollection [ - - self shouldBeImplemented -] - -{ #category : #accessing } -INAbstractReportPrinter >> stream [ - - ^ stream -] - -{ #category : #accessing } -INAbstractReportPrinter >> stream: anObject [ - - stream := anObject. - micBuilder setStream: stream -] diff --git a/src/InteractiveNotebookPresenter/INReportCollectionPrinter.class.st b/src/InteractiveNotebookPresenter/INReportCollectionPrinter.class.st deleted file mode 100644 index 9105714..0000000 --- a/src/InteractiveNotebookPresenter/INReportCollectionPrinter.class.st +++ /dev/null @@ -1,68 +0,0 @@ -Class { - #name : #INReportCollectionPrinter, - #superclass : #INAbstractReportPrinter, - #category : #InteractiveNotebookPresenter -} - -{ #category : #printing } -INReportCollectionPrinter >> print: aCollection [ - - aCollection do: [ :e | - micBuilder unorderedListDuring: [ micBuilder item: [micBuilder raw: e mooseName]]. - ] -] - -{ #category : #printing } -INReportCollectionPrinter >> print: aCollection with: aBlock [ - - self sort: aCollection with: aBlock. - aCollection do: [ :e | - e isAssociation - ifTrue: [ self printAssoc: e with: aBlock ] - ifFalse: [ self printElement: e with: aBlock ] ] -] - -{ #category : #printing } -INReportCollectionPrinter >> printAssoc: anAssoc with: aBlock [ - - micBuilder unorderedListDuring: [ - micBuilder item: [ micBuilder raw: (aBlock value: anAssoc key) ]. - micBuilder unorderedListDuring: [ - anAssoc value do: [ :e | - micBuilder item: [ micBuilder raw: (aBlock value: e) ] ] ] ] -] - -{ #category : #printing } -INReportCollectionPrinter >> printElement: aMooseObject with: aBlock [ - - micBuilder unorderedListDuring: [ micBuilder item: [micBuilder raw: (aBlock value: aMooseObject)]] -] - -{ #category : #printing } -INReportCollectionPrinter >> printMooseName: aCollection [ - - self print: aCollection with: [ :e | - e isMooseObject - ifTrue: [ e mooseName ] - ifFalse: [ e ] ] -] - -{ #category : #printing } -INReportCollectionPrinter >> printName: aCollection [ - - self print: aCollection with: [ :e | - e isMooseObject - ifTrue: [ e name ] - ifFalse: [ e ] ] -] - -{ #category : #printing } -INReportCollectionPrinter >> sort: aCollection with: aBlock [ - - | val | - val := [ :a | a ]. - (aCollection allSatisfy: [ :e | e isAssociation ]) ifTrue: [ - val := [ :a | a key ] ]. - aCollection sort: [ :a :b | - (aBlock value: (val value: a)) < (aBlock value: (val value: b)) ] -] diff --git a/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st b/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st index 4aa1688..a5046b0 100644 --- a/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st +++ b/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st @@ -1,26 +1,5 @@ Extension { #name : #SpRoassalPresenter } -{ #category : #'*InteractiveNotebookPresenter' } -SpRoassalPresenter >> calculateNewCenter [ - | x y | - x := self canvas extent x. - y := self canvas extent y. - ^ x / 2 @ y / 2 -] - -{ #category : #'*InteractiveNotebookPresenter' } -SpRoassalPresenter >> calculateNewScale [ - - | xw yw xc yc | - xw := self owner withAdapterDo: [ :a | a widget height ]. - xc := self canvas extent x. - yw := self owner withAdapterDo: [ :a | a widget width ]. - yc := self canvas extent y. - ^ xc - xw > (yc - yw) - ifTrue: [ xw / xc ] - ifFalse: [ yw / yc ] -] - { #category : #'*InteractiveNotebookPresenter' } SpRoassalPresenter >> defaultHeight [ From ad6c4b3a3ddfc1cc7b2c75b0773057d184ced19e Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Thu, 11 May 2023 11:37:50 +0200 Subject: [PATCH 24/41] adding a button to recalculate every cell during preview --- .../INNotebookModel.class.st | 5 +++++ .../INNotebookPresenter.class.st | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookModel.class.st b/src/InteractiveNotebookPresenter/INNotebookModel.class.st index 5dc9ee2..119a40b 100644 --- a/src/InteractiveNotebookPresenter/INNotebookModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookModel.class.st @@ -175,3 +175,8 @@ INNotebookModel >> name [ ^ fileName ifNil: [ 'new *' ] ] + +{ #category : #'as yet unclassified' } +INNotebookModel >> needToUpdateAllCells [ + cellList do: [ :c | c needToUpdate: true ] +] diff --git a/src/InteractiveNotebookPresenter/INNotebookPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookPresenter.class.st index 95764e6..6274cc4 100644 --- a/src/InteractiveNotebookPresenter/INNotebookPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookPresenter.class.st @@ -167,7 +167,7 @@ INNotebookPresenter >> initializeToolbar [ icon: (self iconNamed: #smallLoadProject); action: [ self importMicrodownFile ]; yourself); - addItem: (self newToolbarButton + addItem: (self newToolbarButton label: 'Save...'; icon: (self iconNamed: #smallExport); action: [ self exportDocument ]; @@ -177,6 +177,11 @@ INNotebookPresenter >> initializeToolbar [ icon: (self iconNamed: #smallExport); action: [ self preview ]; yourself); + addItem: (self newToolbarButton + label: 'Preview (recalculated)'; + icon: (self iconNamed: #smallExport); + action: [ self previewReloaded ]; + yourself); addItem: (self newToolbarButton label: 'Export to text'; icon: (self iconNamed: #smallExport); @@ -214,6 +219,12 @@ INNotebookPresenter >> preview [ self currentNotebook preview ] +{ #category : #'as yet unclassified' } +INNotebookPresenter >> previewReloaded [ + self currentNotebook model needToUpdateAllCells. + self preview +] + { #category : #actions } INNotebookPresenter >> reportExported: aFile [ From 777407f5355689a8762abc2e6d471cc0d921dca2 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Thu, 11 May 2023 11:38:15 +0200 Subject: [PATCH 25/41] fixing name of files when exporting --- .../INNotebookModel.class.st | 10 ++++++++-- .../INNotebookWithPreviewPresenter.class.st | 20 ++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookModel.class.st b/src/InteractiveNotebookPresenter/INNotebookModel.class.st index 119a40b..60dd47a 100644 --- a/src/InteractiveNotebookPresenter/INNotebookModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookModel.class.st @@ -18,6 +18,12 @@ Class { #category : #InteractiveNotebookPresenter } +{ #category : #accessing } +INNotebookModel class >> defaultName [ + + ^ 'new *' +] + { #category : #initialization } INNotebookModel class >> initializeWith: aFileReference on: aMooseModel [ @@ -135,7 +141,7 @@ INNotebookModel >> exportToTextAt: aFileReference [ INNotebookModel >> importCellsFrom: aFileReference [ aFileReference ifNil: [ ^ self ]. - fileName := aFileReference basename. + fileName := aFileReference basenameWithoutExtension. cellList := STON fromString: aFileReference contents ] @@ -173,7 +179,7 @@ INNotebookModel >> micDocument [ { #category : #accessing } INNotebookModel >> name [ - ^ fileName ifNil: [ 'new *' ] + ^ fileName ifNil: [ self class defaultName ] ] { #category : #'as yet unclassified' } diff --git a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st index 4443404..6af650f 100644 --- a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st @@ -17,6 +17,12 @@ Class { #category : #InteractiveNotebookPresenter } +{ #category : #specs } +INNotebookWithPreviewPresenter class >> defaultNotebookExportName [ + + ^ 'notebook' +] + { #category : #'instance creation' } INNotebookWithPreviewPresenter class >> newModel [ @@ -69,10 +75,18 @@ INNotebookWithPreviewPresenter >> exportDocument [ aFile := self chooseTextFile: 'Chose export destination' extensions: #( 'ston' ) - path: 'notebook.ston'. + path: self exportFilename , '.ston'. aFile ifNotNil: [ self model exportDocumentAt: aFile ] ] +{ #category : #'as yet unclassified' } +INNotebookWithPreviewPresenter >> exportFilename [ + + ^ self model name = self model class defaultName + ifTrue: [ self class defaultNotebookExportName ] + ifFalse: [ self model name ] +] + { #category : #actions } INNotebookWithPreviewPresenter >> exportToHTML [ @@ -84,7 +98,7 @@ INNotebookWithPreviewPresenter >> exportToHTML [ aFile := self chooseTextFile: 'Chose export destination' extensions: #( 'html' ) - path: 'notebook.html'. + path: self exportFilename , '.html'. aFile ifNil: [ ^ self ]. self model exportToHTMLAt: aFile. self reportExported: aFile @@ -101,7 +115,7 @@ INNotebookWithPreviewPresenter >> exportToText [ aFile := self chooseTextFile: 'Chose export destination' extensions: #( 'md' ) - path: 'mooseNotebook.md'. + path: self exportFilename , '.md'. aFile ifNotNil: [ self model exportToTextAt: aFile ] ] From b588bab1da0d3a6e73225c7bdb14e8001fc08d0c Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Thu, 11 May 2023 11:50:30 +0200 Subject: [PATCH 26/41] moving previewReloaded, and calling it before any export (replacing the call to preview) --- .../INNotebookPresenter.class.st | 3 +-- .../INNotebookWithPreviewPresenter.class.st | 12 +++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookPresenter.class.st index 6274cc4..d18a5d0 100644 --- a/src/InteractiveNotebookPresenter/INNotebookPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookPresenter.class.st @@ -221,8 +221,7 @@ INNotebookPresenter >> preview [ { #category : #'as yet unclassified' } INNotebookPresenter >> previewReloaded [ - self currentNotebook model needToUpdateAllCells. - self preview + self currentNotebook previewReloaded ] { #category : #actions } diff --git a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st index 6af650f..ce3637f 100644 --- a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st @@ -68,7 +68,7 @@ INNotebookWithPreviewPresenter >> codeCellPlaceholder: anObject [ INNotebookWithPreviewPresenter >> exportDocument [ | aFile | - self preview. + self previewReloaded. self model cellList ifEmpty: [ self inform: 'Nothing to export'. ^ self ]. @@ -91,7 +91,7 @@ INNotebookWithPreviewPresenter >> exportFilename [ INNotebookWithPreviewPresenter >> exportToHTML [ | aFile | - self preview. + self previewReloaded. self model cellList ifEmpty: [ self inform: 'Nothing to export'. ^ self ]. @@ -108,7 +108,7 @@ INNotebookWithPreviewPresenter >> exportToHTML [ INNotebookWithPreviewPresenter >> exportToText [ | aFile | - self preview. + self previewReloaded. self model cellList ifEmpty: [ self inform: 'Nothing to export'. ^ self ]. @@ -204,6 +204,12 @@ INNotebookWithPreviewPresenter >> preview [ andCells: notebook cellList ] +{ #category : #'as yet unclassified' } +INNotebookWithPreviewPresenter >> previewReloaded [ + self model needToUpdateAllCells. + self preview +] + { #category : #actions } INNotebookWithPreviewPresenter >> reportExported: aFile [ From efcb102b2d53c3e62e5fbf733d5474ef631f262a Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Fri, 12 May 2023 09:51:24 +0200 Subject: [PATCH 27/41] small fixes on document export to STON --- src/InteractiveNotebookPresenter/INNotebookModel.class.st | 4 ++-- .../INNotebookWithPreviewPresenter.class.st | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookModel.class.st b/src/InteractiveNotebookPresenter/INNotebookModel.class.st index 60dd47a..49e7c12 100644 --- a/src/InteractiveNotebookPresenter/INNotebookModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookModel.class.st @@ -105,12 +105,12 @@ INNotebookModel >> executeAllCellsAsCollection [ { #category : #export } INNotebookModel >> exportDocumentAt: aFileReference [ - "Export the cell list in a ston file." aFileReference ifNil: [ ^ self ]. aFileReference ensureDelete. - aFileReference ifNotNil: [ + aFileReference ifNotNil: [ + fileName := aFileReference basenameWithoutExtension. aFileReference writeStreamDo: [ :s | STON put: cellList onStream: s ] ] ] diff --git a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st index ce3637f..bc54a22 100644 --- a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st @@ -68,7 +68,6 @@ INNotebookWithPreviewPresenter >> codeCellPlaceholder: anObject [ INNotebookWithPreviewPresenter >> exportDocument [ | aFile | - self previewReloaded. self model cellList ifEmpty: [ self inform: 'Nothing to export'. ^ self ]. From b683ae7f0045b7265abb83c307b8e4eae3284124 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Fri, 12 May 2023 14:02:59 +0200 Subject: [PATCH 28/41] added settings windows, allowing to change the view from the default page to the full inspector view --- .../INNotebookPresenter.class.st | 37 ++++++++++- .../INNotebookSettingsPresenter.class.st | 65 +++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 src/InteractiveNotebookPresenter/INNotebookSettingsPresenter.class.st diff --git a/src/InteractiveNotebookPresenter/INNotebookPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookPresenter.class.st index d18a5d0..e7dac67 100644 --- a/src/InteractiveNotebookPresenter/INNotebookPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookPresenter.class.st @@ -10,7 +10,8 @@ Class { 'toolbar', 'mainLayout', 'sep', - 'tabbedPresenter' + 'tabbedPresenter', + 'displayInspectorView' ], #category : #InteractiveNotebookPresenter } @@ -78,6 +79,11 @@ INNotebookPresenter >> addNewTabWithModel: aModel [ tabbedPresenter selectPage: newTab ] +{ #category : #actions } +INNotebookPresenter >> allNotebookPages [ + ^ tabbedPresenter pages collect: [ :p | p activePresenter ] +] + { #category : #actions } INNotebookPresenter >> chooseTextFile: messageString extensions: stringCollection path: defaultName [ ^UIManager default @@ -98,6 +104,18 @@ INNotebookPresenter >> currentNotebook [ ^ tabbedPresenter selectedPage activePresenter ] +{ #category : #accessing } +INNotebookPresenter >> displayInspectorView [ + + ^ displayInspectorView +] + +{ #category : #accessing } +INNotebookPresenter >> displayInspectorView: aBoolean [ + + displayInspectorView := aBoolean +] + { #category : #initialization } INNotebookPresenter >> exportDocument [ @@ -128,6 +146,12 @@ INNotebookPresenter >> importMicrodownFile [ file ifNotNil: [ self updateWithFile: file ] ] +{ #category : #initialization } +INNotebookPresenter >> initialize [ + displayInspectorView := false. + super initialize +] + { #category : #initialization } INNotebookPresenter >> initializeLayout [ @@ -197,6 +221,11 @@ INNotebookPresenter >> initializeToolbar [ icon: (self iconNamed: #add); action: [ self addNewTab ]; yourself); + addItemRight: (self newToolbarButton + label: 'Settings'; + icon: (self iconNamed: #smallConfiguration); + action: [ self openSettings ]; + yourself); yourself ] @@ -213,6 +242,12 @@ INNotebookPresenter >> openPreview [ self currentNotebook openPreview ] +{ #category : #actions } +INNotebookPresenter >> openSettings [ + self allNotebookPages do: [ :n | n model needToUpdateAllCells ]. + INNotebookSettingsPresenter openFor: self +] + { #category : #initialization } INNotebookPresenter >> preview [ diff --git a/src/InteractiveNotebookPresenter/INNotebookSettingsPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookSettingsPresenter.class.st new file mode 100644 index 0000000..1fb844b --- /dev/null +++ b/src/InteractiveNotebookPresenter/INNotebookSettingsPresenter.class.st @@ -0,0 +1,65 @@ +Class { + #name : #INNotebookSettingsPresenter, + #superclass : #SpPresenter, + #instVars : [ + 'displayChoiceCheckbox', + 'ownerNotebook' + ], + #category : #InteractiveNotebookPresenter +} + +{ #category : #'instance creation' } +INNotebookSettingsPresenter class >> openFor: aSpPresenter [ + + | presenter | + presenter := self new ownerNotebook: aSpPresenter. + presenter displayChoiceCheckbox state: aSpPresenter displayInspectorView. + presenter open. + presenter owner whenClosedDo: [ + presenter ownerNotebook displayInspectorView: + presenter displayChoiceCheckbox state ] +] + +{ #category : #specs } +INNotebookSettingsPresenter class >> title [ + ^ 'Notebook settings' +] + +{ #category : #accessing } +INNotebookSettingsPresenter >> displayChoiceCheckbox [ + + ^ displayChoiceCheckbox +] + +{ #category : #initialization } +INNotebookSettingsPresenter >> initializeLayout [ + self layout: (SpBoxLayout newTopToBottom add: displayChoiceCheckbox; yourself) +] + +{ #category : #initialization } +INNotebookSettingsPresenter >> initializePresenters [ + + displayChoiceCheckbox := self newCheckBox + label: 'Display all inspector tabs?'; + yourself. + self initializeLayout. +] + +{ #category : #initialization } +INNotebookSettingsPresenter >> initializeWindow: aWindowPresenter [ + + super initializeWindow: aWindowPresenter. + aWindowPresenter initialExtent: 300.0 @ 100.0 +] + +{ #category : #accessing } +INNotebookSettingsPresenter >> ownerNotebook [ + + ^ ownerNotebook +] + +{ #category : #accessing } +INNotebookSettingsPresenter >> ownerNotebook: anObject [ + + ownerNotebook := anObject +] From e5ac120f71eecc4593a91d2524ac22a458762cc5 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Fri, 12 May 2023 14:03:31 +0200 Subject: [PATCH 29/41] preview updated to fit the new settings choice --- .../INNotebookPreviewPresenter.class.st | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st index 1ec2fb9..3a6ec0d 100644 --- a/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st @@ -40,10 +40,27 @@ INNotebookPreviewPresenter >> createInspectorViewFor: anObject [ | ctxs presenter | ctxs := anObject inspectionContexts. presenter := self newNotebook. - ctxs do: [ :ctx | - ctx evaluator: false. + ctxs do: [ :ctx | + ctx withoutEvaluator. presenter addPage: (self newPageForContext: ctx andObject: anObject) ]. - ^ presenter + ^ presenter +] + +{ #category : #'as yet unclassified' } +INNotebookPreviewPresenter >> createSinglePageViewFor: anObject [ + + | ctx | + ctx := anObject inspectionContexts first. + ctx withoutEvaluator. + ^ (self newPageForContext: ctx andObject: anObject) presenterProvider value +] + +{ #category : #'as yet unclassified' } +INNotebookPreviewPresenter >> createViewFor: anObject [ + + ^ self mustDisplayInspectorView + ifTrue: [ self createInspectorViewFor: anObject ] + ifFalse: [ self createSinglePageViewFor: anObject ] ] { #category : #initialization } @@ -94,6 +111,12 @@ INNotebookPreviewPresenter >> initializePresenters [ self initializeLayout ] +{ #category : #'as yet unclassified' } +INNotebookPreviewPresenter >> mustDisplayInspectorView [ + + ^ browser owner owner displayInspectorView +] + { #category : #actions } INNotebookPreviewPresenter >> newInspectionForContext: aContext andObject: anObject [ @@ -110,9 +133,6 @@ INNotebookPreviewPresenter >> newPageForContext: aContext andObject: anObject [ ^ SpNotebookPage new title: aContext title; presenterProvider: [ self newInspectionForContext: aContext andObject: anObject ]; - "whenRetrievedDo: [ :presenter | - self keepPresenter: presenter. - self addActivationTo: presenter ];" yourself ] @@ -121,11 +141,9 @@ INNotebookPreviewPresenter >> newPreviewCellWith: anObject [ | pCell | pCell := (self instantiate: INNotebookCellPreviewPresenter) - contentPresenter: (self createInspectorViewFor: anObject); + contentPresenter: (self createViewFor: anObject); parent: self; yourself. - "contentPresenter: (anObject createContentPreviewPresenter);" - "anObject addContentToPreviewPresenter: pCell contentPresenter." ^ pCell ] From 7d82e7d974d7aaf466479052f9537e638083f199 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Mon, 15 May 2023 11:23:58 +0200 Subject: [PATCH 30/41] cleaning + (ugly) fix for the UI after importing a STON file --- .../INNotebookCellPreviewPresenter.class.st | 14 +++----- .../INNotebookCodeCellPresenter.class.st | 2 +- .../INNotebookEditorPresenter.class.st | 14 ++++---- .../INNotebookModel.class.st | 5 ++- .../INNotebookPresenter.class.st | 8 ++--- .../INNotebookPreviewPresenter.class.st | 10 +++--- .../INNotebookSettingsPresenter.class.st | 4 +++ .../INNotebookWithPreviewPresenter.class.st | 33 +++++++------------ 8 files changed, 38 insertions(+), 52 deletions(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st index f9d9fe4..71ae473 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st @@ -51,13 +51,9 @@ INNotebookCellPreviewPresenter >> contentPresenter [ INNotebookCellPreviewPresenter >> contentPresenter: aPresenter [ contentPresenter := aPresenter. - self whenDisplayDo: [ - self updateHeight. - "presenter withAdapterDo: [ :a | - UIManager default defer: [ - a widget backgroundColor: self unselectedColor ] ]" ]. + self whenDisplayDo: [ self updateHeight ]. self initializeLayout. - contentPresenter eventHandler whenMouseDownDo: [ :anEvent | + contentPresenter eventHandler whenMouseDownDo: [ :anEvent | self selectMe ] ] @@ -97,7 +93,7 @@ INNotebookCellPreviewPresenter >> parent: anObject [ { #category : #actions } INNotebookCellPreviewPresenter >> select [ - "contentPresenter selectNotebookPresenter " + "contentPresenter selectNotebookPresenter" ] { #category : #actions } @@ -122,7 +118,7 @@ INNotebookCellPreviewPresenter >> text: aString [ { #category : #actions } INNotebookCellPreviewPresenter >> unselected [ - "contentPresenter unselectedNotebookPresenter " + "contentPresenter unselectedNotebookPresenter" ] { #category : #initialization } @@ -130,5 +126,5 @@ INNotebookCellPreviewPresenter >> updateHeight [ self withAdapterDo: [ :a | "UIManager default defer: [ contentPresenter updateNotebookPresenterHeight ]" - a widget height: 350 ] + a widget height: 150 ] ] diff --git a/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st index 68d7202..810032b 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st @@ -62,7 +62,7 @@ INNotebookCodeCellPresenter >> notebook: aNoteBook [ notebook := aNoteBook. ] -{ #category : #'as yet unclassified' } +{ #category : #updating } INNotebookCodeCellPresenter >> updateBindings [ | parsedContent | diff --git a/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st index 42fe415..05a1648 100644 --- a/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st @@ -216,6 +216,7 @@ INNotebookEditorPresenter >> scrollTo: aMiNoteBookCell [ { #category : #removing } INNotebookEditorPresenter >> select: aCell [ + selectedCell := aCell. cellList do: [ :c | c unselect ]. @@ -258,15 +259,14 @@ INNotebookEditorPresenter >> transformToTextCell: aCell [ { #category : #removing } INNotebookEditorPresenter >> updateAll [ - cellList := LinkedList new. - self model cellList do: [ :c | - cellList add: ((self instantiate: c presenterClass on: self) - model: c; - text: c text; - yourself) ]. + cellList := self model cellList collect: [ :c | + (self instantiate: c presenterClass on: self) + model: c; + text: c text; + yourself ]. cellList ifEmpty: [ ^ self ]. - selectedCell := cellList last. + self select: cellList last. self relayout ] diff --git a/src/InteractiveNotebookPresenter/INNotebookModel.class.st b/src/InteractiveNotebookPresenter/INNotebookModel.class.st index 49e7c12..8aa4d8d 100644 --- a/src/InteractiveNotebookPresenter/INNotebookModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookModel.class.st @@ -25,11 +25,10 @@ INNotebookModel class >> defaultName [ ] { #category : #initialization } -INNotebookModel class >> initializeWith: aFileReference on: aMooseModel [ +INNotebookModel class >> initializeWith: aFileReference [ ^ self new importCellsFrom: aFileReference; - followEntity: aMooseModel; yourself ] @@ -182,7 +181,7 @@ INNotebookModel >> name [ ^ fileName ifNil: [ self class defaultName ] ] -{ #category : #'as yet unclassified' } +{ #category : #updating } INNotebookModel >> needToUpdateAllCells [ cellList do: [ :c | c needToUpdate: true ] ] diff --git a/src/InteractiveNotebookPresenter/INNotebookPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookPresenter.class.st index e7dac67..5fc6395 100644 --- a/src/InteractiveNotebookPresenter/INNotebookPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookPresenter.class.st @@ -254,7 +254,7 @@ INNotebookPresenter >> preview [ self currentNotebook preview ] -{ #category : #'as yet unclassified' } +{ #category : #initialization } INNotebookPresenter >> previewReloaded [ self currentNotebook previewReloaded ] @@ -280,8 +280,6 @@ INNotebookPresenter >> separator [ { #category : #initialization } INNotebookPresenter >> updateWithFile: aFileReference [ - | newModel | - newModel := INNotebookModel new. - newModel importCellsFrom: aFileReference. - self addNewTabWithModel: newModel + self addNewTabWithModel: (INNotebookModel initializeWith: aFileReference). + self currentNotebook fixUIAfterImport ] diff --git a/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st index 3a6ec0d..9b95aa2 100644 --- a/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookPreviewPresenter.class.st @@ -34,7 +34,7 @@ INNotebookPreviewPresenter >> close [ browser closePreview ] -{ #category : #'as yet unclassified' } +{ #category : #creating } INNotebookPreviewPresenter >> createInspectorViewFor: anObject [ | ctxs presenter | @@ -46,16 +46,16 @@ INNotebookPreviewPresenter >> createInspectorViewFor: anObject [ ^ presenter ] -{ #category : #'as yet unclassified' } +{ #category : #creating } INNotebookPreviewPresenter >> createSinglePageViewFor: anObject [ | ctx | ctx := anObject inspectionContexts first. ctx withoutEvaluator. - ^ (self newPageForContext: ctx andObject: anObject) presenterProvider value + ^ (self newInspectionForContext: ctx andObject: anObject) ] -{ #category : #'as yet unclassified' } +{ #category : #creating } INNotebookPreviewPresenter >> createViewFor: anObject [ ^ self mustDisplayInspectorView @@ -111,7 +111,7 @@ INNotebookPreviewPresenter >> initializePresenters [ self initializeLayout ] -{ #category : #'as yet unclassified' } +{ #category : #'accessing - attributes' } INNotebookPreviewPresenter >> mustDisplayInspectorView [ ^ browser owner owner displayInspectorView diff --git a/src/InteractiveNotebookPresenter/INNotebookSettingsPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookSettingsPresenter.class.st index 1fb844b..f0333d9 100644 --- a/src/InteractiveNotebookPresenter/INNotebookSettingsPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookSettingsPresenter.class.st @@ -1,3 +1,7 @@ +" +I am a presenter opened in a window when pressing the ""Settings"" button. +I allow the user to choose between a inspector-like view of the cells, or the default view, which is the first page displayed in a inspector when inspecting the object returned by the cell. +" Class { #name : #INNotebookSettingsPresenter, #superclass : #SpPresenter, diff --git a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st index bc54a22..b85f964 100644 --- a/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookWithPreviewPresenter.class.st @@ -78,7 +78,7 @@ INNotebookWithPreviewPresenter >> exportDocument [ aFile ifNotNil: [ self model exportDocumentAt: aFile ] ] -{ #category : #'as yet unclassified' } +{ #category : #naming } INNotebookWithPreviewPresenter >> exportFilename [ ^ self model name = self model class defaultName @@ -118,6 +118,15 @@ INNotebookWithPreviewPresenter >> exportToText [ aFile ifNotNil: [ self model exportToTextAt: aFile ] ] +{ #category : #initialization } +INNotebookWithPreviewPresenter >> fixUIAfterImport [ + "ugly method to fix the ui of an imported page + After importing selecting cells doesn't work properly, the height of the editing cell is also slightly too big. Something must not set up right, I believe the deferred calls might be responsible somehow (at the very least, they make it hard figuring out what's going on). + Will do a clean fix if I find what's wrong" + notebook addTextCellAfter: notebook cellList last. + notebook removeCell: notebook cellList last. +] + { #category : #actions } INNotebookWithPreviewPresenter >> followEntity: anEntity [ @@ -125,18 +134,6 @@ INNotebookWithPreviewPresenter >> followEntity: anEntity [ notebook mooseModel: anEntity mooseModel ] -{ #category : #initialization } -INNotebookWithPreviewPresenter >> importMicrodownFile [ - - | file | - file := UIManager default - chooseExistingFileReference: 'Select your notebook file.' - extensions: { 'ston' } - path: '.'. - - file ifNotNil: [ self updateWithFile: file ] -] - { #category : #initialization } INNotebookWithPreviewPresenter >> initialize [ @@ -203,7 +200,7 @@ INNotebookWithPreviewPresenter >> preview [ andCells: notebook cellList ] -{ #category : #'as yet unclassified' } +{ #category : #initialization } INNotebookWithPreviewPresenter >> previewReloaded [ self model needToUpdateAllCells. self preview @@ -242,11 +239,3 @@ INNotebookWithPreviewPresenter >> updateModelCells [ notebook updateModelCells. self model cellList: notebook allModelCells. ] - -{ #category : #initialization } -INNotebookWithPreviewPresenter >> updateWithFile: aFileReference [ - - self model importCellsFrom: aFileReference. - self closePreview. - notebook updateAll -] From 65d02d8f406c9d097a0a0d272b135be7fcab29b2 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Tue, 16 May 2023 11:19:06 +0200 Subject: [PATCH 31/41] preview cells height is now slightly better --- .../INNotebookCellPreviewPresenter.class.st | 34 +++++++++++++++---- .../SpPresenter.extension.st | 13 +++++++ .../SpRoassalPresenter.extension.st | 3 +- .../SpTextPresenter.extension.st | 13 +++---- .../StObjectContextPresenter.extension.st | 7 ++++ 5 files changed, 56 insertions(+), 14 deletions(-) create mode 100644 src/InteractiveNotebookPresenter/SpPresenter.extension.st create mode 100644 src/InteractiveNotebookPresenter/StObjectContextPresenter.extension.st diff --git a/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st index 71ae473..d26fdeb 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st @@ -17,10 +17,16 @@ Class { #category : #InteractiveNotebookPresenter } +{ #category : #actions } +INNotebookCellPreviewPresenter class >> selectedColor [ + + ^ Color fromHexString: '77A8C8' +] + { #category : #initialization } INNotebookCellPreviewPresenter class >> unselectedColor [ - ^ Smalltalk ui theme backgroundColor + ^ Color transparent ] { #category : #actions } @@ -70,6 +76,14 @@ INNotebookCellPreviewPresenter >> initializeLayout [ yourself) ] +{ #category : #initialization } +INNotebookCellPreviewPresenter >> initializePresenters [ + + self whenDisplayDo: [ + self withAdapterDo: [ :a | + a widget announcer when: MorphGotFocus do: [ self selectMe ] ] ] +] + { #category : #initialization } INNotebookCellPreviewPresenter >> morphFor: aPresenter from: aMorph [ @@ -92,8 +106,8 @@ INNotebookCellPreviewPresenter >> parent: anObject [ { #category : #actions } INNotebookCellPreviewPresenter >> select [ - - "contentPresenter selectNotebookPresenter" + + self withAdapterDo: [ :a | a widget color: self class selectedColor ] ] { #category : #actions } @@ -118,13 +132,19 @@ INNotebookCellPreviewPresenter >> text: aString [ { #category : #actions } INNotebookCellPreviewPresenter >> unselected [ - "contentPresenter unselectedNotebookPresenter" + self withAdapterDo: [ :a | + a widget color: self class unselectedColor ] ] { #category : #initialization } INNotebookCellPreviewPresenter >> updateHeight [ - self withAdapterDo: [ :a | "UIManager default defer: [ - contentPresenter updateNotebookPresenterHeight ]" - a widget height: 150 ] + parent mustDisplayInspectorView + ifFalse: [ contentPresenter specPresenter updatePresenterHeight ] + ifTrue: [ self updateInspectorViewHeight ] +] + +{ #category : #'as yet unclassified' } +INNotebookCellPreviewPresenter >> updateInspectorViewHeight [ + self withAdapterDo: [ :a | a widget height: 350 ]. ] diff --git a/src/InteractiveNotebookPresenter/SpPresenter.extension.st b/src/InteractiveNotebookPresenter/SpPresenter.extension.st new file mode 100644 index 0000000..fc06f0d --- /dev/null +++ b/src/InteractiveNotebookPresenter/SpPresenter.extension.st @@ -0,0 +1,13 @@ +Extension { #name : #SpPresenter } + +{ #category : #'*InteractiveNotebookPresenter' } +SpPresenter >> previewCellOwner [ + + ^ self owner owner owner +] + +{ #category : #'*InteractiveNotebookPresenter' } +SpPresenter >> updatePresenterHeight [ + + self previewCellOwner withAdapterDo: [ :a | a widget height: 350 ]. +] diff --git a/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st b/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st index a5046b0..7f84676 100644 --- a/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st +++ b/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st @@ -35,7 +35,8 @@ SpRoassalPresenter >> updateNotebookPresenterHeight [ self owner withAdapterDo: [ :a | | canvas | canvas := self currentCanvas. - a widget height: self defaultHeight. + self previewCellOwner withAdapterDo: [ :b | + b widget height: self defaultHeight ]. canvas camera zoomToFit: a widget extent * self defaultZoom rectangle: canvas encompassingRectangle. diff --git a/src/InteractiveNotebookPresenter/SpTextPresenter.extension.st b/src/InteractiveNotebookPresenter/SpTextPresenter.extension.st index 23e9b4a..a9181ae 100644 --- a/src/InteractiveNotebookPresenter/SpTextPresenter.extension.st +++ b/src/InteractiveNotebookPresenter/SpTextPresenter.extension.st @@ -19,10 +19,11 @@ SpTextPresenter >> unselectedNotebookPresenter [ ] { #category : #'*InteractiveNotebookPresenter' } -SpTextPresenter >> updateNotebookPresenterHeight [ - self withAdapterDo: [ :a | - a widget defer: [ - a widget scrollPane textArea withoutSelectionBar. - self owner withAdapterDo: [ :b | - b widget height: a widget scrollPane textArea height ] ] ] +SpTextPresenter >> updatePresenterHeight [ + + self withAdapterDo: [ :a | + a widget scrollPane textArea withoutSelectionBar. + a widget vScrollbarShowNever. + self previewCellOwner withAdapterDo: [ :b | + b widget height: a widget scrollPane textArea height ] ] ] diff --git a/src/InteractiveNotebookPresenter/StObjectContextPresenter.extension.st b/src/InteractiveNotebookPresenter/StObjectContextPresenter.extension.st new file mode 100644 index 0000000..3980827 --- /dev/null +++ b/src/InteractiveNotebookPresenter/StObjectContextPresenter.extension.st @@ -0,0 +1,7 @@ +Extension { #name : #StObjectContextPresenter } + +{ #category : #'*InteractiveNotebookPresenter' } +StObjectContextPresenter >> specPresenter [ + + ^ view presenter +] From 504e4a762b39b8bc75780d9b02182780c5b5211a Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Tue, 16 May 2023 15:37:25 +0200 Subject: [PATCH 32/41] small cleaning + roassal preview fix --- .../INNotebookEditorPresenter.class.st | 10 ++++---- .../SpRoassal3InspectorPresenter.extension.st | 23 +++++++++++++++++++ .../SpRoassalPresenter.extension.st | 7 +++--- 3 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 src/InteractiveNotebookPresenter/SpRoassal3InspectorPresenter.extension.st diff --git a/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st index 05a1648..3ec0a20 100644 --- a/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st @@ -8,13 +8,13 @@ Class { #superclass : #SpPresenter, #instVars : [ 'cellList', - 'lastCellAdded', 'selectedCell', 'interactionModel', 'headerSep', 'cellLayout', 'browser', - 'codeCellPlaceholder' + 'codeCellPlaceholder', + 'firstCodeCell' ], #category : #InteractiveNotebookPresenter } @@ -22,6 +22,7 @@ Class { { #category : #initialization } INNotebookEditorPresenter >> addTextCellAfter: aCell [ + | lastCellAdded | lastCellAdded := self newTextCell. cellList add: lastCellAdded after: aCell. selectedCell := lastCellAdded. @@ -31,6 +32,7 @@ INNotebookEditorPresenter >> addTextCellAfter: aCell [ { #category : #initialization } INNotebookEditorPresenter >> addTextCellBefore: aCell [ + | lastCellAdded | lastCellAdded := self newTextCell. cellList add: lastCellAdded before: aCell. selectedCell := lastCellAdded. @@ -233,7 +235,7 @@ INNotebookEditorPresenter >> selectAndScrollTo: aMiNoteBookCell [ { #category : #adding } INNotebookEditorPresenter >> transformToCodeCell: aCell [ - | width | + | width lastCellAdded | lastCellAdded := self newCodeCell text: aCell text; yourself. @@ -246,7 +248,7 @@ INNotebookEditorPresenter >> transformToCodeCell: aCell [ { #category : #adding } INNotebookEditorPresenter >> transformToTextCell: aCell [ - | width | + | width lastCellAdded | lastCellAdded := self newTextCell text: aCell text; yourself. diff --git a/src/InteractiveNotebookPresenter/SpRoassal3InspectorPresenter.extension.st b/src/InteractiveNotebookPresenter/SpRoassal3InspectorPresenter.extension.st new file mode 100644 index 0000000..413983d --- /dev/null +++ b/src/InteractiveNotebookPresenter/SpRoassal3InspectorPresenter.extension.st @@ -0,0 +1,23 @@ +Extension { #name : #SpRoassal3InspectorPresenter } + +{ #category : #'*InteractiveNotebookPresenter' } +SpRoassal3InspectorPresenter >> defaultHeight [ + + ^ 500 +] + +{ #category : #'*InteractiveNotebookPresenter' } +SpRoassal3InspectorPresenter >> defaultZoom [ + + ^ 0.9 +] + +{ #category : #'*InteractiveNotebookPresenter' } +SpRoassal3InspectorPresenter >> updatePresenterHeight [ + self previewCellOwner withAdapterDo: [ :a | + a widget height: self defaultHeight. + canvas camera + zoomToFit: a widget extent * self defaultZoom + rectangle: canvas encompassingRectangle. + canvas signalUpdate ] +] diff --git a/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st b/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st index 7f84676..e72f4e1 100644 --- a/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st +++ b/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st @@ -30,13 +30,12 @@ SpRoassalPresenter >> unselectedNotebookPresenter [ ] { #category : #'*InteractiveNotebookPresenter' } -SpRoassalPresenter >> updateNotebookPresenterHeight [ +SpRoassalPresenter >> updatePresenterHeight [ - self owner withAdapterDo: [ :a | + self previewCellOwner withAdapterDo: [ :a | | canvas | canvas := self currentCanvas. - self previewCellOwner withAdapterDo: [ :b | - b widget height: self defaultHeight ]. + a widget height: self defaultHeight. canvas camera zoomToFit: a widget extent * self defaultZoom rectangle: canvas encompassingRectangle. From dbfda09b3582e5bf1a8f4eea41e060df1cbbb422 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Wed, 17 May 2023 10:50:28 +0200 Subject: [PATCH 33/41] table size adaptable --- .../SpTablePresenter.extension.st | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/InteractiveNotebookPresenter/SpTablePresenter.extension.st diff --git a/src/InteractiveNotebookPresenter/SpTablePresenter.extension.st b/src/InteractiveNotebookPresenter/SpTablePresenter.extension.st new file mode 100644 index 0000000..c5068e2 --- /dev/null +++ b/src/InteractiveNotebookPresenter/SpTablePresenter.extension.st @@ -0,0 +1,20 @@ +Extension { #name : #SpTablePresenter } + +{ #category : #'*InteractiveNotebookPresenter' } +SpTablePresenter >> maximumHeight [ + + ^ 350 +] + +{ #category : #'*InteractiveNotebookPresenter' } +SpTablePresenter >> updatePresenterHeight [ + + | height | + self withAdapterDo: [ :a | + "adding 1.5 to the row number to account for the table header and a small padding" + height := (a widget rowHeight * (a widget numberOfRows + 1.5)) ceiling ]. + self previewCellOwner withAdapterDo: [ :a | + a widget height: (height < self maximumHeight + ifTrue: [ height ] + ifFalse: [ self maximumHeight ]) ] +] From f8b4d56520c847c67945cd027608e026f58b7bd4 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Wed, 17 May 2023 11:19:46 +0200 Subject: [PATCH 34/41] fix export --- .../INNotebookCellPreviewPresenter.class.st | 7 ++++++- .../StObjectContextPresenter.extension.st | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st index d26fdeb..d38f357 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st @@ -65,7 +65,12 @@ INNotebookCellPreviewPresenter >> contentPresenter: aPresenter [ { #category : #accessing } INNotebookCellPreviewPresenter >> getContent [ - ^ contentPresenter getContent + + ^ parent mustDisplayInspectorView + ifTrue: [ + contentPresenter selectedPage activePresenter view context + inspectedObject ] + ifFalse: [ contentPresenter view context inspectedObject ] ] { #category : #initialization } diff --git a/src/InteractiveNotebookPresenter/StObjectContextPresenter.extension.st b/src/InteractiveNotebookPresenter/StObjectContextPresenter.extension.st index 3980827..d619977 100644 --- a/src/InteractiveNotebookPresenter/StObjectContextPresenter.extension.st +++ b/src/InteractiveNotebookPresenter/StObjectContextPresenter.extension.st @@ -5,3 +5,8 @@ StObjectContextPresenter >> specPresenter [ ^ view presenter ] + +{ #category : #'*InteractiveNotebookPresenter' } +StObjectContextPresenter >> view [ + ^ view +] From f3de9cb3279c374cf8baa23440c44f40b8203d87 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Wed, 17 May 2023 11:32:58 +0200 Subject: [PATCH 35/41] cleaning class extensions --- .../Collection.extension.st | 15 ----------- .../Object.extension.st | 13 +++++----- .../RSCanvas.extension.st | 26 ++----------------- .../SpRoassalPresenter.extension.st | 17 ------------ .../SpTextPresenter.extension.st | 18 ------------- .../String.extension.st | 5 ---- 6 files changed, 8 insertions(+), 86 deletions(-) diff --git a/src/InteractiveNotebookPresenter/Collection.extension.st b/src/InteractiveNotebookPresenter/Collection.extension.st index 54c2cef..3576a88 100644 --- a/src/InteractiveNotebookPresenter/Collection.extension.st +++ b/src/InteractiveNotebookPresenter/Collection.extension.st @@ -1,20 +1,5 @@ Extension { #name : #Collection } -{ #category : #'*InteractiveNotebookPresenter' } -Collection >> addContentToPreviewPresenter: aPresenter [ - - | text | - text := self - ifNotEmpty: [ - String streamContents: [ :s | - self do: [ :el | - s nextPutAll: '- '. - s nextPutAll: el asString. - s nextPut: Character cr ] ] ] - ifEmpty: [ 'Empty collection.' ]. - aPresenter text: text -] - { #category : #'*InteractiveNotebookPresenter' } Collection >> generateMicrodownAt: aFileReference withIndex: anIndex [ diff --git a/src/InteractiveNotebookPresenter/Object.extension.st b/src/InteractiveNotebookPresenter/Object.extension.st index 7ad2608..ade30ff 100644 --- a/src/InteractiveNotebookPresenter/Object.extension.st +++ b/src/InteractiveNotebookPresenter/Object.extension.st @@ -1,16 +1,15 @@ Extension { #name : #Object } { #category : #'*InteractiveNotebookPresenter' } -Object >> addContentToPreviewPresenter: aPresenter [ - aPresenter text: self asString +Object >> checkForResourcesDirectoryFor: aFileReference [ + "checks whether or not the notebook resources file is already created" + ^ (aFileReference / 'notebook_resources') exists ] { #category : #'*InteractiveNotebookPresenter' } -Object >> createContentPreviewPresenter [ - | textPresenter | - textPresenter := SpTextPresenter new. - textPresenter beNotEditable. - ^ textPresenter +Object >> createResourcesDirectoryFor: aFileReference [ + "create a resource directory, to store additional files necessary to the notebook export document, like images" + (aFileReference / 'notebook_resources') createDirectory ] { #category : #'*InteractiveNotebookPresenter' } diff --git a/src/InteractiveNotebookPresenter/RSCanvas.extension.st b/src/InteractiveNotebookPresenter/RSCanvas.extension.st index 5f809ba..a7ee680 100644 --- a/src/InteractiveNotebookPresenter/RSCanvas.extension.st +++ b/src/InteractiveNotebookPresenter/RSCanvas.extension.st @@ -1,32 +1,10 @@ Extension { #name : #RSCanvas } -{ #category : #'*InteractiveNotebookPresenter' } -RSCanvas >> addContentToPreviewPresenter: aPresenter [ - aPresenter canvas: self canvas -] - -{ #category : #'*InteractiveNotebookPresenter' } -RSCanvas >> checkForResourcesDirectoryAt: aFileReference [ - ^ (aFileReference / 'notebook_resources') exists -] - -{ #category : #'*InteractiveNotebookPresenter' } -RSCanvas >> createContentPreviewPresenter [ - | rPresenter | - rPresenter := SpRoassalPresenter new. - ^ rPresenter -] - -{ #category : #'*InteractiveNotebookPresenter' } -RSCanvas >> createResourcesDirectoryAt: aFileReference [ - (aFileReference / 'notebook_resources') createDirectory -] - { #category : #'*InteractiveNotebookPresenter' } RSCanvas >> generateMicrodownAt: aFileReference withIndex: anIndex [ - (self checkForResourcesDirectoryAt: aFileReference) ifFalse: [ - self createResourcesDirectoryAt: aFileReference ]. + (self checkForResourcesDirectoryFor: aFileReference) ifFalse: [ + self createResourcesDirectoryFor: aFileReference ]. RSPNGExporter new canvas: self; exportToFile: aFileReference / 'notebook_resources' / ('img' , (anIndex asString) , '.png'). diff --git a/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st b/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st index e72f4e1..7d238c0 100644 --- a/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st +++ b/src/InteractiveNotebookPresenter/SpRoassalPresenter.extension.st @@ -12,23 +12,6 @@ SpRoassalPresenter >> defaultZoom [ ^ 0.9 ] -{ #category : #'*InteractiveNotebookPresenter' } -SpRoassalPresenter >> getContent [ - ^ self canvas -] - -{ #category : #'*InteractiveNotebookPresenter' } -SpRoassalPresenter >> selectNotebookPresenter [ - - "todo" -] - -{ #category : #'*InteractiveNotebookPresenter' } -SpRoassalPresenter >> unselectedNotebookPresenter [ - - "todo" -] - { #category : #'*InteractiveNotebookPresenter' } SpRoassalPresenter >> updatePresenterHeight [ diff --git a/src/InteractiveNotebookPresenter/SpTextPresenter.extension.st b/src/InteractiveNotebookPresenter/SpTextPresenter.extension.st index a9181ae..7c7e948 100644 --- a/src/InteractiveNotebookPresenter/SpTextPresenter.extension.st +++ b/src/InteractiveNotebookPresenter/SpTextPresenter.extension.st @@ -1,23 +1,5 @@ Extension { #name : #SpTextPresenter } -{ #category : #'*InteractiveNotebookPresenter' } -SpTextPresenter >> getContent [ - ^ self text -] - -{ #category : #'*InteractiveNotebookPresenter' } -SpTextPresenter >> selectNotebookPresenter [ - - self withAdapterDo: [ :a | - a widget backgroundColor: (Color fromHexString: '77A8C8') ] -] - -{ #category : #'*InteractiveNotebookPresenter' } -SpTextPresenter >> unselectedNotebookPresenter [ - - self withAdapterDo: [ :a | a widget backgroundColor: INNotebookCellPreviewPresenter unselectedColor ] -] - { #category : #'*InteractiveNotebookPresenter' } SpTextPresenter >> updatePresenterHeight [ diff --git a/src/InteractiveNotebookPresenter/String.extension.st b/src/InteractiveNotebookPresenter/String.extension.st index cb27599..263be4e 100644 --- a/src/InteractiveNotebookPresenter/String.extension.st +++ b/src/InteractiveNotebookPresenter/String.extension.st @@ -1,10 +1,5 @@ Extension { #name : #String } -{ #category : #'*InteractiveNotebookPresenter' } -String >> addContentToPreviewPresenter: aPresenter [ - aPresenter text: self -] - { #category : #'*InteractiveNotebookPresenter' } String >> generateMicrodownAt: aFileReference withIndex: anIndex [ From 43c3b896739f27effb7b1fc664f798c2cac34e19 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Wed, 17 May 2023 11:41:05 +0200 Subject: [PATCH 36/41] fix canvas export --- src/InteractiveNotebookPresenter/RSCanvas.extension.st | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/InteractiveNotebookPresenter/RSCanvas.extension.st b/src/InteractiveNotebookPresenter/RSCanvas.extension.st index a7ee680..4bd4849 100644 --- a/src/InteractiveNotebookPresenter/RSCanvas.extension.st +++ b/src/InteractiveNotebookPresenter/RSCanvas.extension.st @@ -6,6 +6,8 @@ RSCanvas >> generateMicrodownAt: aFileReference withIndex: anIndex [ (self checkForResourcesDirectoryFor: aFileReference) ifFalse: [ self createResourcesDirectoryFor: aFileReference ]. + self zoomToFit. + RSPNGExporter new canvas: self; exportToFile: aFileReference / 'notebook_resources' / ('img' , (anIndex asString) , '.png'). ^ '![cell n°', anIndex asString ,'](notebook_resources/img', anIndex asString ,'.png)'. From bc1f028c2d2b9ed87232c4d6295df21507bb59bb Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Wed, 17 May 2023 11:55:24 +0200 Subject: [PATCH 37/41] deleting dead methods --- .../INNotebookEditorPresenter.class.st | 23 +------------------ 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st index 3ec0a20..9ad4f70 100644 --- a/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st @@ -13,8 +13,7 @@ Class { 'headerSep', 'cellLayout', 'browser', - 'codeCellPlaceholder', - 'firstCodeCell' + 'codeCellPlaceholder' ], #category : #InteractiveNotebookPresenter } @@ -258,20 +257,6 @@ INNotebookEditorPresenter >> transformToTextCell: aCell [ self relayout ] -{ #category : #removing } -INNotebookEditorPresenter >> updateAll [ - - cellList := self model cellList collect: [ :c | - (self instantiate: c presenterClass on: self) - model: c; - text: c text; - yourself ]. - - cellList ifEmpty: [ ^ self ]. - self select: cellList last. - self relayout -] - { #category : #removing } INNotebookEditorPresenter >> updateHeight [ @@ -282,9 +267,3 @@ INNotebookEditorPresenter >> updateHeight [ INNotebookEditorPresenter >> updateModelCells [ cellList do: [ :cell | cell model text: cell text ] ] - -{ #category : #initialization } -INNotebookEditorPresenter >> updatePresenter [ - - self updateAll -] From e14f44b668966e820f89c56bb7c73ff68b92830c Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Mon, 22 May 2023 14:26:53 +0200 Subject: [PATCH 38/41] dead methods were not dead, surprise --- .../INNotebookEditorPresenter.class.st | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st index 9ad4f70..67d1e52 100644 --- a/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st @@ -257,6 +257,20 @@ INNotebookEditorPresenter >> transformToTextCell: aCell [ self relayout ] +{ #category : #'updating screen' } +INNotebookEditorPresenter >> updateAll [ + + cellList := self model cellList collect: [ :c | + (self instantiate: c presenterClass on: self) + model: c; + text: c text; + yourself ]. + + cellList ifEmpty: [ ^ self ]. + self select: cellList last. + self relayout +] + { #category : #removing } INNotebookEditorPresenter >> updateHeight [ @@ -267,3 +281,9 @@ INNotebookEditorPresenter >> updateHeight [ INNotebookEditorPresenter >> updateModelCells [ cellList do: [ :cell | cell model text: cell text ] ] + +{ #category : #initialization } +INNotebookEditorPresenter >> updatePresenter [ + + self updateAll +] From c569711ad546582a15d1845073ef5d8f1d133a46 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Mon, 22 May 2023 14:27:57 +0200 Subject: [PATCH 39/41] rewrote generation system, nested collections supported (in microdown, seems like the HTML parser does not support them) --- .../Collection.extension.st | 30 ++++-- .../INNotebookGenerationHelper.class.st | 95 +++++++++++++++++++ .../INNotebookGenerationHelper.extension.st | 13 +++ .../INNotebookModel.class.st | 13 +-- .../Object.extension.st | 16 +--- .../RSCanvas.extension.st | 13 ++- .../String.extension.st | 2 +- 7 files changed, 149 insertions(+), 33 deletions(-) create mode 100644 src/InteractiveNotebookPresenter/INNotebookGenerationHelper.class.st create mode 100644 src/InteractiveNotebookPresenter/INNotebookGenerationHelper.extension.st diff --git a/src/InteractiveNotebookPresenter/Collection.extension.st b/src/InteractiveNotebookPresenter/Collection.extension.st index 3576a88..f1b22ce 100644 --- a/src/InteractiveNotebookPresenter/Collection.extension.st +++ b/src/InteractiveNotebookPresenter/Collection.extension.st @@ -1,13 +1,29 @@ Extension { #name : #Collection } { #category : #'*InteractiveNotebookPresenter' } -Collection >> generateMicrodownAt: aFileReference withIndex: anIndex [ +Collection >> generateMicrodownListOn: aStream using: aGenerationHelper [ + + self do: [ :el | + (el isKindOf: self class) + ifTrue: [ + aGenerationHelper listLevelIncrement. + el generateMicrodownListOn: aStream using: aGenerationHelper. + aGenerationHelper listLevelDecrement ] + ifFalse: [ + 0 to: aGenerationHelper listLevel do: [ :i | + aStream nextPut: Character tab ]. + aStream nextPutAll: '- '. + aStream nextPutAll: + (el generateMicrodownUsingHelper: aGenerationHelper). + aStream nextPut: Character cr ] ] +] + +{ #category : #'*InteractiveNotebookPresenter' } +Collection >> generateMicrodownUsingHelper: aGenerationHelper [ | text | - text := String streamContents: [ :s | - self do: [ :el | - s nextPutAll: '- '. - s nextPutAll: el asString. - s nextPut: Character cr ] ]. - ^ text + aGenerationHelper listLevel: 0. + text := String streamContents: [ :s | + self generateMicrodownListOn: s using: aGenerationHelper ]. + ^ text ] diff --git a/src/InteractiveNotebookPresenter/INNotebookGenerationHelper.class.st b/src/InteractiveNotebookPresenter/INNotebookGenerationHelper.class.st new file mode 100644 index 0000000..8b9fe73 --- /dev/null +++ b/src/InteractiveNotebookPresenter/INNotebookGenerationHelper.class.st @@ -0,0 +1,95 @@ +" +I am a helper class used to generate the document to export. +" +Class { + #name : #INNotebookGenerationHelper, + #superclass : #Object, + #instVars : [ + 'fileReferenceParent', + 'index', + 'listLevel' + ], + #category : #InteractiveNotebookPresenter +} + +{ #category : #'instance creation' } +INNotebookGenerationHelper class >> newFor: aFileReference [ + + ^ self new + fileReferenceParent: aFileReference; + index: 0; + yourself +] + +{ #category : #'*InteractiveNotebookPresenter' } +INNotebookGenerationHelper >> checkForResourcesDirectory [ + "checks whether or not the notebook resources file is already created" + ^ (fileReferenceParent / 'notebook_resources') exists +] + +{ #category : #'*InteractiveNotebookPresenter' } +INNotebookGenerationHelper >> createResourcesDirectory [ + "create a resource directory, to store additional files necessary to the notebook export document, like images" + (fileReferenceParent / 'notebook_resources') createDirectory +] + +{ #category : #accessing } +INNotebookGenerationHelper >> fileReferenceParent [ + + ^ fileReferenceParent +] + +{ #category : #accessing } +INNotebookGenerationHelper >> fileReferenceParent: anObject [ + + fileReferenceParent := anObject +] + +{ #category : #'as yet unclassified' } +INNotebookGenerationHelper >> generateObject: anObject [ + + self incrementIndex. + ^ anObject generateMicrodownUsingHelper: self +] + +{ #category : #'as yet unclassified' } +INNotebookGenerationHelper >> incrementIndex [ + + index := index + 1. +] + +{ #category : #accessing } +INNotebookGenerationHelper >> index [ + + ^ index +] + +{ #category : #accessing } +INNotebookGenerationHelper >> index: anObject [ + + index := anObject +] + +{ #category : #accessing } +INNotebookGenerationHelper >> listLevel [ + + ^ listLevel +] + +{ #category : #accessing } +INNotebookGenerationHelper >> listLevel: anObject [ + + listLevel := anObject +] + +{ #category : #accessing } +INNotebookGenerationHelper >> listLevelDecrement [ + + listLevel := listLevel - 1 +] + +{ #category : #accessing } +INNotebookGenerationHelper >> listLevelIncrement [ + + listLevel := listLevel + 1 +] diff --git a/src/InteractiveNotebookPresenter/INNotebookGenerationHelper.extension.st b/src/InteractiveNotebookPresenter/INNotebookGenerationHelper.extension.st new file mode 100644 index 0000000..7714bc3 --- /dev/null +++ b/src/InteractiveNotebookPresenter/INNotebookGenerationHelper.extension.st @@ -0,0 +1,13 @@ +Extension { #name : #INNotebookGenerationHelper } + +{ #category : #'*InteractiveNotebookPresenter' } +INNotebookGenerationHelper >> checkForResourcesDirectory [ + "checks whether or not the notebook resources file is already created" + ^ (fileReferenceParent / 'notebook_resources') exists +] + +{ #category : #'*InteractiveNotebookPresenter' } +INNotebookGenerationHelper >> createResourcesDirectory [ + "create a resource directory, to store additional files necessary to the notebook export document, like images" + (fileReferenceParent / 'notebook_resources') createDirectory +] diff --git a/src/InteractiveNotebookPresenter/INNotebookModel.class.st b/src/InteractiveNotebookPresenter/INNotebookModel.class.st index 8aa4d8d..6579543 100644 --- a/src/InteractiveNotebookPresenter/INNotebookModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookModel.class.st @@ -76,14 +76,15 @@ INNotebookModel >> context [ { #category : #export } INNotebookModel >> createGeneratedDocumentAt: aFileReference [ - | generatedDocument parentReference | + | generatedDocument parentReference generationHelper | parentReference := aFileReference parent. - generatedDocument := String streamContents: [ :stream | - cellList doWithIndex: [ :cell :index | + generationHelper := INNotebookGenerationHelper newFor: + parentReference. + generatedDocument := String streamContents: [ :stream | + cellList doWithIndex: [ :cell :index | stream nextPutAll: - (cell previewCell getContent - generateMicrodownAt: parentReference - withIndex: index). + (generationHelper generateObject: + cell previewCell getContent). stream nextPutAll: ' '. stream nextPut: Character cr ] ]. ^ generatedDocument diff --git a/src/InteractiveNotebookPresenter/Object.extension.st b/src/InteractiveNotebookPresenter/Object.extension.st index ade30ff..0bfba3f 100644 --- a/src/InteractiveNotebookPresenter/Object.extension.st +++ b/src/InteractiveNotebookPresenter/Object.extension.st @@ -1,21 +1,9 @@ Extension { #name : #Object } { #category : #'*InteractiveNotebookPresenter' } -Object >> checkForResourcesDirectoryFor: aFileReference [ - "checks whether or not the notebook resources file is already created" - ^ (aFileReference / 'notebook_resources') exists -] - -{ #category : #'*InteractiveNotebookPresenter' } -Object >> createResourcesDirectoryFor: aFileReference [ - "create a resource directory, to store additional files necessary to the notebook export document, like images" - (aFileReference / 'notebook_resources') createDirectory -] - -{ #category : #'*InteractiveNotebookPresenter' } -Object >> generateMicrodownAt: aFileReference withIndex: anIndex [ +Object >> generateMicrodownUsingHelper: aGenerationHelper [ "Returns a Microdown string to include in the generated document. This method can have side effects (if an image needs to be included for example, if must first be created). - The file reference is pointing to the directory containing the exported document, and the index is the index of the preview cell in the cell list. Those parameters are used to create a path for the eventual files to create." + The generation helper has accessors to various useful informations, like the file reference where the generated document will be created, or the index of the cell being generated currently." ^ self asString ] diff --git a/src/InteractiveNotebookPresenter/RSCanvas.extension.st b/src/InteractiveNotebookPresenter/RSCanvas.extension.st index 4bd4849..f9d22bc 100644 --- a/src/InteractiveNotebookPresenter/RSCanvas.extension.st +++ b/src/InteractiveNotebookPresenter/RSCanvas.extension.st @@ -1,14 +1,17 @@ Extension { #name : #RSCanvas } { #category : #'*InteractiveNotebookPresenter' } -RSCanvas >> generateMicrodownAt: aFileReference withIndex: anIndex [ +RSCanvas >> generateMicrodownUsingHelper: aGenerationHelper [ - (self checkForResourcesDirectoryFor: aFileReference) ifFalse: [ - self createResourcesDirectoryFor: aFileReference ]. + | index | + index := aGenerationHelper index asString. + + (aGenerationHelper checkForResourcesDirectory) ifFalse: [ + aGenerationHelper createResourcesDirectory ]. self zoomToFit. - RSPNGExporter new canvas: self; exportToFile: aFileReference / 'notebook_resources' / ('img' , (anIndex asString) , '.png'). + RSPNGExporter new canvas: self; exportToFile: aGenerationHelper fileReferenceParent / 'notebook_resources' / ('img' , index , '.png'). - ^ '![cell n°', anIndex asString ,'](notebook_resources/img', anIndex asString ,'.png)'. + ^ '![cell n°', index ,'](notebook_resources/img', index ,'.png)'. ] diff --git a/src/InteractiveNotebookPresenter/String.extension.st b/src/InteractiveNotebookPresenter/String.extension.st index 263be4e..366ee07 100644 --- a/src/InteractiveNotebookPresenter/String.extension.st +++ b/src/InteractiveNotebookPresenter/String.extension.st @@ -1,7 +1,7 @@ Extension { #name : #String } { #category : #'*InteractiveNotebookPresenter' } -String >> generateMicrodownAt: aFileReference withIndex: anIndex [ +String >> generateMicrodownUsingHelper: aGenerationHelper [ ^ self ] From feb3fac18e796de959428edb09cea3905c446bd4 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Tue, 23 May 2023 10:42:40 +0200 Subject: [PATCH 40/41] small cleaning of icons, more generation changes --- .../INNotebookGenerationHelper.class.st | 11 ++++ .../INNotebookIcons.class.st | 66 +------------------ .../INNotebookModel.class.st | 12 +--- 3 files changed, 15 insertions(+), 74 deletions(-) diff --git a/src/InteractiveNotebookPresenter/INNotebookGenerationHelper.class.st b/src/InteractiveNotebookPresenter/INNotebookGenerationHelper.class.st index 8b9fe73..d97c902 100644 --- a/src/InteractiveNotebookPresenter/INNotebookGenerationHelper.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookGenerationHelper.class.st @@ -45,6 +45,17 @@ INNotebookGenerationHelper >> fileReferenceParent: anObject [ fileReferenceParent := anObject ] +{ #category : #'as yet unclassified' } +INNotebookGenerationHelper >> generateDocument: aCellList [ + + ^ String streamContents: [ :stream | + aCellList do: [ :cell | + stream nextPutAll: + (self generateObject: cell previewCell getContent). + stream nextPutAll: ' '. + stream nextPut: Character cr ] ] +] + { #category : #'as yet unclassified' } INNotebookGenerationHelper >> generateObject: anObject [ diff --git a/src/InteractiveNotebookPresenter/INNotebookIcons.class.st b/src/InteractiveNotebookPresenter/INNotebookIcons.class.st index ce59981..284f5ec 100644 --- a/src/InteractiveNotebookPresenter/INNotebookIcons.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookIcons.class.st @@ -78,70 +78,6 @@ INNotebookIcons class >> iconAddAbove [ offset: 0 @ 0 ] ] -{ #category : #'icon creation' } -INNotebookIcons class >> iconAddBellow [ - - - ^ self icons at: #addBelow ifAbsentPut: [ - Form - extent: 16 @ 16 - depth: 32 - fromArray: - #( 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16rFF404040 16rFF404040 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16rFF404040 16rFF404040 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16rFF404040 - 16rFF404040 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16rFF404040 16rFF404040 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16rFF404040 16rFF404040 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16rFF404040 - 16rFF404040 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16rFF404040 16rFF404040 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16rFF404040 16rFF404040 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 ) - offset: 0 @ 0 ] -] - { #category : #'icon creation' } INNotebookIcons class >> iconAddBelow [ @@ -495,5 +431,5 @@ INNotebookIcons class >> showIcons [ display: [ :each | each key ]; displayIcon: [ :each | each value ]; open. - window title: 'Moose icons' + window title: 'Notebook icons' ] diff --git a/src/InteractiveNotebookPresenter/INNotebookModel.class.st b/src/InteractiveNotebookPresenter/INNotebookModel.class.st index 6579543..582903b 100644 --- a/src/InteractiveNotebookPresenter/INNotebookModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookModel.class.st @@ -76,18 +76,12 @@ INNotebookModel >> context [ { #category : #export } INNotebookModel >> createGeneratedDocumentAt: aFileReference [ - | generatedDocument parentReference generationHelper | + | parentReference generationHelper | parentReference := aFileReference parent. generationHelper := INNotebookGenerationHelper newFor: parentReference. - generatedDocument := String streamContents: [ :stream | - cellList doWithIndex: [ :cell :index | - stream nextPutAll: - (generationHelper generateObject: - cell previewCell getContent). - stream nextPutAll: ' '. - stream nextPut: Character cr ] ]. - ^ generatedDocument + + ^ generationHelper generateDocument: cellList ] { #category : #actions } From 1d785a9c6abb0667acbcb5efb7d9a422150a0c34 Mon Sep 17 00:00:00 2001 From: Romain Degrave Date: Wed, 14 Jun 2023 14:04:03 +0200 Subject: [PATCH 41/41] fix preview --- .../Collection.extension.st | 58 +- .../INNotebookAbstractCellModel.class.st | 188 ++-- .../INNotebookAbstractCellPresenter.class.st | 644 ++++++------- .../INNotebookCellPreviewPresenter.class.st | 308 +++---- .../INNotebookCodeCellModel.class.st | 90 +- .../INNotebookCodeCellPresenter.class.st | 144 +-- ...bookCodeScriptingInteractionModel.class.st | 66 +- .../INNotebookEditorPresenter.class.st | 578 ++++++------ .../INNotebookGenerationHelper.class.st | 212 ++--- .../INNotebookGenerationHelper.extension.st | 26 +- .../INNotebookIcons.class.st | 870 +++++++++--------- .../INNotebookModel.class.st | 364 ++++---- .../INNotebookPresenter.class.st | 570 ++++++------ .../INNotebookPreviewPresenter.class.st | 416 ++++----- .../INNotebookSettingsPresenter.class.st | 138 +-- .../INNotebookTextCellModel.class.st | 68 +- .../INNotebookTextCellPresenter.class.st | 92 +- .../INNotebookWithPreviewPresenter.class.st | 482 +++++----- .../Object.extension.st | 18 +- .../RSCanvas.extension.st | 34 +- .../SpPresenter.extension.st | 26 +- .../SpRoassal3InspectorPresenter.extension.st | 46 +- .../SpRoassalPresenter.extension.st | 52 +- .../SpTablePresenter.extension.st | 40 +- .../SpTextPresenter.extension.st | 22 +- .../StObjectContextPresenter.extension.st | 24 +- .../String.extension.st | 14 +- src/InteractiveNotebookPresenter/package.st | 2 +- 28 files changed, 2795 insertions(+), 2797 deletions(-) diff --git a/src/InteractiveNotebookPresenter/Collection.extension.st b/src/InteractiveNotebookPresenter/Collection.extension.st index f1b22ce..e03b159 100644 --- a/src/InteractiveNotebookPresenter/Collection.extension.st +++ b/src/InteractiveNotebookPresenter/Collection.extension.st @@ -1,29 +1,29 @@ -Extension { #name : #Collection } - -{ #category : #'*InteractiveNotebookPresenter' } -Collection >> generateMicrodownListOn: aStream using: aGenerationHelper [ - - self do: [ :el | - (el isKindOf: self class) - ifTrue: [ - aGenerationHelper listLevelIncrement. - el generateMicrodownListOn: aStream using: aGenerationHelper. - aGenerationHelper listLevelDecrement ] - ifFalse: [ - 0 to: aGenerationHelper listLevel do: [ :i | - aStream nextPut: Character tab ]. - aStream nextPutAll: '- '. - aStream nextPutAll: - (el generateMicrodownUsingHelper: aGenerationHelper). - aStream nextPut: Character cr ] ] -] - -{ #category : #'*InteractiveNotebookPresenter' } -Collection >> generateMicrodownUsingHelper: aGenerationHelper [ - - | text | - aGenerationHelper listLevel: 0. - text := String streamContents: [ :s | - self generateMicrodownListOn: s using: aGenerationHelper ]. - ^ text -] +Extension { #name : #Collection } + +{ #category : #'*InteractiveNotebookPresenter' } +Collection >> generateMicrodownListOn: aStream using: aGenerationHelper [ + + self do: [ :el | + (el isKindOf: self class) + ifTrue: [ + aGenerationHelper listLevelIncrement. + el generateMicrodownListOn: aStream using: aGenerationHelper. + aGenerationHelper listLevelDecrement ] + ifFalse: [ + 0 to: aGenerationHelper listLevel do: [ :i | + aStream nextPut: Character tab ]. + aStream nextPutAll: '- '. + aStream nextPutAll: + (el generateMicrodownUsingHelper: aGenerationHelper). + aStream nextPut: Character cr ] ] +] + +{ #category : #'*InteractiveNotebookPresenter' } +Collection >> generateMicrodownUsingHelper: aGenerationHelper [ + + | text | + aGenerationHelper listLevel: 0. + text := String streamContents: [ :s | + self generateMicrodownListOn: s using: aGenerationHelper ]. + ^ text +] diff --git a/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st b/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st index 44d0524..79835e4 100644 --- a/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookAbstractCellModel.class.st @@ -1,94 +1,94 @@ -" -I am an abstract editor cell model. - -I have an instance variable `needToUpdate` that is set to true if a preview cell was never created for me (i.e. if I was never compiled) or if I was modified after having created a preview cell. -It is set to false otherwise, this way I don't have to be recompiled or to create a new preview cell. - -I am responsible for the compilation of the content in my presenter's text input. -" -Class { - #name : #INNotebookAbstractCellModel, - #superclass : #Object, - #instVars : [ - 'text', - 'needToUpdate', - 'previewCell' - ], - #category : #InteractiveNotebookPresenter -} - -{ #category : #ston } -INNotebookAbstractCellModel class >> stonAllInstVarNames [ - ^ super stonAllInstVarNames \ { #needToUpdate. #previewCell } -] - -{ #category : #converting } -INNotebookAbstractCellModel >> beCodeModel [ - ^ self subclassResponsibility -] - -{ #category : #converting } -INNotebookAbstractCellModel >> beTextModel [ - ^ self subclassResponsibility -] - -{ #category : #printing } -INNotebookAbstractCellModel >> getContentwithContext: aContext [ - - ^ self subclassResponsibility -] - -{ #category : #initialization } -INNotebookAbstractCellModel >> initialize [ - - super initialize. - needToUpdate := true. - text := String empty -] - -{ #category : #accessing } -INNotebookAbstractCellModel >> needToUpdate [ - ^ needToUpdate -] - -{ #category : #accessing } -INNotebookAbstractCellModel >> needToUpdate: aBoolean [ - needToUpdate := aBoolean -] - -{ #category : #helpers } -INNotebookAbstractCellModel >> presenterClass [ - - self subclassResponsibility -] - -{ #category : #accessing } -INNotebookAbstractCellModel >> previewCell [ - - ^ previewCell -] - -{ #category : #accessing } -INNotebookAbstractCellModel >> previewCell: anObject [ - - previewCell := anObject -] - -{ #category : #printing } -INNotebookAbstractCellModel >> printContentIn: aStream withContext: aContext [ - - self subclassResponsibility -] - -{ #category : #accessing } -INNotebookAbstractCellModel >> text [ - - ^ text -] - -{ #category : #accessing } -INNotebookAbstractCellModel >> text: anObject [ - - (text = anObject) ifFalse: [ self needToUpdate: true ]. - text := anObject -] +" +I am an abstract editor cell model. + +I have an instance variable `needToUpdate` that is set to true if a preview cell was never created for me (i.e. if I was never compiled) or if I was modified after having created a preview cell. +It is set to false otherwise, this way I don't have to be recompiled or to create a new preview cell. + +I am responsible for the compilation of the content in my presenter's text input. +" +Class { + #name : #INNotebookAbstractCellModel, + #superclass : #Object, + #instVars : [ + 'text', + 'needToUpdate', + 'previewCell' + ], + #category : #InteractiveNotebookPresenter +} + +{ #category : #ston } +INNotebookAbstractCellModel class >> stonAllInstVarNames [ + ^ super stonAllInstVarNames \ { #needToUpdate. #previewCell } +] + +{ #category : #converting } +INNotebookAbstractCellModel >> beCodeModel [ + ^ self subclassResponsibility +] + +{ #category : #converting } +INNotebookAbstractCellModel >> beTextModel [ + ^ self subclassResponsibility +] + +{ #category : #printing } +INNotebookAbstractCellModel >> getContentwithContext: aContext [ + + ^ self subclassResponsibility +] + +{ #category : #initialization } +INNotebookAbstractCellModel >> initialize [ + + super initialize. + needToUpdate := true. + text := String empty +] + +{ #category : #accessing } +INNotebookAbstractCellModel >> needToUpdate [ + ^ needToUpdate +] + +{ #category : #accessing } +INNotebookAbstractCellModel >> needToUpdate: aBoolean [ + needToUpdate := aBoolean +] + +{ #category : #helpers } +INNotebookAbstractCellModel >> presenterClass [ + + self subclassResponsibility +] + +{ #category : #accessing } +INNotebookAbstractCellModel >> previewCell [ + + ^ previewCell +] + +{ #category : #accessing } +INNotebookAbstractCellModel >> previewCell: anObject [ + + previewCell := anObject +] + +{ #category : #printing } +INNotebookAbstractCellModel >> printContentIn: aStream withContext: aContext [ + + self subclassResponsibility +] + +{ #category : #accessing } +INNotebookAbstractCellModel >> text [ + + ^ text +] + +{ #category : #accessing } +INNotebookAbstractCellModel >> text: anObject [ + + (text = anObject) ifFalse: [ self needToUpdate: true ]. + text := anObject +] diff --git a/src/InteractiveNotebookPresenter/INNotebookAbstractCellPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookAbstractCellPresenter.class.st index 7d4682a..66ddee7 100644 --- a/src/InteractiveNotebookPresenter/INNotebookAbstractCellPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookAbstractCellPresenter.class.st @@ -1,322 +1,322 @@ -" -I am an abstract editing cell presenter. - -I have a presenter providing a text input (`cellTextInput`) in which the user can type Microdown text or code, depending on the cell type. - -I give to my children buttons allowing to transform themselves from code cell to text cell and vice versa, to add a new text cell before or after the current cell, to move the cell up or down in the notebook, and one to delete the current cell. - - - - -" -Class { - #name : #INNotebookAbstractCellPresenter, - #superclass : #SpPresenterWithModel, - #instVars : [ - 'icon', - 'notebook', - 'removeButton', - 'leftMenuCanvas', - 'rightMenuCanvas', - 'deleteButton', - 'addCellBellowButton', - 'addCellAboveButton', - 'moveCellUp', - 'moveCellDown', - 'previewCell', - 'cellTextInput' - ], - #category : #InteractiveNotebookPresenter -} - -{ #category : #converting } -INNotebookAbstractCellPresenter >> asModelCell [ - - self subclassResponsibility -] - -{ #category : #api } -INNotebookAbstractCellPresenter >> beCode [ - - self subclassResponsibility -] - -{ #category : #initialization } -INNotebookAbstractCellPresenter >> beSelected [ - - notebook select: self. - previewCell ifNotNil: [ :c | c beSelected ] -] - -{ #category : #api } -INNotebookAbstractCellPresenter >> beText [ - - self subclassResponsibility -] - -{ #category : #initialization } -INNotebookAbstractCellPresenter >> beUnselected [ - - leftMenuCanvas canvas color: self unselectedColor. - leftMenuCanvas canvas signalUpdate. - rightMenuCanvas canvas color: self unselectedColor. - rightMenuCanvas canvas signalUpdate -] - -{ #category : #accessing } -INNotebookAbstractCellPresenter >> cellTextInput [ - - ^ cellTextInput -] - -{ #category : #initialization } -INNotebookAbstractCellPresenter >> createDescriptionFor: aString [ - - ^ aString asTextMorph - backgroundColor: (Color white alpha: 0.6); - borderColor: Color gray; - textColor: Color black; - borderWidth: 1; - margins: 2; - yourself -] - -{ #category : #initialization } -INNotebookAbstractCellPresenter >> iconNamed: anIconName [ - - INNotebookIcons icons - at: anIconName - ifPresent: [ :found | ^ found ]. - ^ super iconNamed: anIconName -] - -{ #category : #initialization } -INNotebookAbstractCellPresenter >> initializeLayout [ - - self layout: (SpBoxLayout newLeftToRight - add: leftMenuCanvas width: 30; - add: cellTextInput; - add: rightMenuCanvas width: 100; - yourself) -] - -{ #category : #initialization } -INNotebookAbstractCellPresenter >> initializePresenters [ - - | buttons menu | - self whenDisplayDo: [ - self withAdapterDo: [ - self adapter children second textArea announcer - when: MorphGotFocus - do: [ self selectMe ] ]. - self updateHeight ]. - removeButton := self newButton - icon: (Smalltalk ui iconNamed: #remove); - action: [ self remove ]. - leftMenuCanvas := self newRoassal. - leftMenuCanvas canvas color: self unselectedColor. - rightMenuCanvas := self newRoassal. - rightMenuCanvas canvas color: Color transparent. - deleteButton := RSBitmap new - form: (self iconNamed: #trash); - model: 'Delete'; - size: 16; - yourself. - deleteButton when: RSMouseClick do: [ self remove ]. - - addCellBellowButton := RSBitmap new - form: (self iconNamed: #addBelow); - model: 'Add after'; - size: 16; - yourself. - addCellAboveButton := RSBitmap new - form: (self iconNamed: #addAbove); - model: 'Add before'; - size: 16; - yourself. - moveCellUp := RSBitmap new - form: (self iconNamed: #up); - model: 'Move up cell'; - size: 16; - yourself. - moveCellDown := RSBitmap new - form: (self iconNamed: #down); - model: 'Move down cell'; - size: 16; - yourself. - buttons := RSGroup withAll: { - moveCellUp. - moveCellDown. - addCellBellowButton. - addCellAboveButton. - - deleteButton }. - buttons @ (RSMorphicPopupInteraction new - morphBuilder: [ :model | self createDescriptionFor: model ]; - yourself). - RSHorizontalLineLayout new - alignMiddle; - horizontalGap: 2; - on: buttons. - menu := RSComposite new - addAll: buttons; - isFixed: true; - color: Color transparent; - translateBy: 50 @ 14; - yourself. - - rightMenuCanvas canvas add: menu. - menu adjustToChildren. - menu padding: 10. - moveCellUp when: RSMouseClick do: [ self moveUp ]. - moveCellDown when: RSMouseClick do: [ self moveDown ]. - addCellBellowButton - when: RSMouseClick - do: [ notebook addTextCellAfter: self ]. - addCellAboveButton - when: RSMouseClick - do: [ notebook addTextCellBefore: self ] -] - -{ #category : #initialization } -INNotebookAbstractCellPresenter >> moveDown [ - - notebook moveDown: self -] - -{ #category : #initialization } -INNotebookAbstractCellPresenter >> moveUp [ - - notebook moveUp: self -] - -{ #category : #accessing } -INNotebookAbstractCellPresenter >> notebook [ - - ^ notebook -] - -{ #category : #accessing } -INNotebookAbstractCellPresenter >> notebook: anObject [ - - notebook := anObject -] - -{ #category : #accessing } -INNotebookAbstractCellPresenter >> previewCell [ - - ^ previewCell -] - -{ #category : #accessing } -INNotebookAbstractCellPresenter >> previewCell: anObject [ - - previewCell := anObject -] - -{ #category : #initialization } -INNotebookAbstractCellPresenter >> remove [ - - notebook removeCell: self -] - -{ #category : #initialization } -INNotebookAbstractCellPresenter >> select [ - - self takeKeyboardFocus. - leftMenuCanvas canvas color: self selectedColor. - leftMenuCanvas canvas signalUpdate. - rightMenuCanvas canvas color: self selectedColor. - rightMenuCanvas canvas signalUpdate -] - -{ #category : #actions } -INNotebookAbstractCellPresenter >> selectAndScrollToMe [ - - notebook selectAndScrollTo: self -] - -{ #category : #actions } -INNotebookAbstractCellPresenter >> selectMe [ - - notebook select: self. - previewCell ifNotNil: [ :c | c selectAndScrollToMe ] -] - -{ #category : #initialization } -INNotebookAbstractCellPresenter >> selectedColor [ - - ^ Color fromHexString: '77A8C8' -] - -{ #category : #api } -INNotebookAbstractCellPresenter >> setModelBeforeInitialization: aModel [ - - self notebook: aModel -] - -{ #category : #protocol } -INNotebookAbstractCellPresenter >> takeKeyboardFocus [ - - cellTextInput takeKeyboardFocus -] - -{ #category : #initialization } -INNotebookAbstractCellPresenter >> text [ - - ^ cellTextInput text -] - -{ #category : #initialization } -INNotebookAbstractCellPresenter >> text: aText [ - - cellTextInput text: aText -] - -{ #category : #accessing } -INNotebookAbstractCellPresenter >> textAreaWidth [ - - self layout adapter ifNil: [ ^ -1 ]. - ^ self layout adapter children second width -] - -{ #category : #initialization } -INNotebookAbstractCellPresenter >> unselect [ - - self beUnselected -] - -{ #category : #initialization } -INNotebookAbstractCellPresenter >> unselectedColor [ - - ^ Color transparent -] - -{ #category : #initialization } -INNotebookAbstractCellPresenter >> updateHeight [ - UIManager default defer: [ - notebook headerSep withAdapterDo: [ :a | - cellTextInput withAdapterDo: [ :b | - | textMorph height width | - textMorph := b widget. - textMorph - borderColor: Color gray translucent; - borderWidth: 1. - textMorph scrollPane - vHideScrollbar; - vScrollbarShowNever. - width := a widget width. - textMorph scrollPane textArea withoutSelectionBar. - height := (RubEditingArea new - font: textMorph font; - width: width - 182; - beWrapped; - updateTextWith: cellTextInput text) height. - self withAdapterDo: [ :c | c widget height: height + 2 ] ] ] ] -] - -{ #category : #enumerating } -INNotebookAbstractCellPresenter >> whenTextChangedDo: aBlock [ - - cellTextInput whenTextChangedDo: aBlock -] +" +I am an abstract editing cell presenter. + +I have a presenter providing a text input (`cellTextInput`) in which the user can type Microdown text or code, depending on the cell type. + +I give to my children buttons allowing to transform themselves from code cell to text cell and vice versa, to add a new text cell before or after the current cell, to move the cell up or down in the notebook, and one to delete the current cell. + + + + +" +Class { + #name : #INNotebookAbstractCellPresenter, + #superclass : #SpPresenterWithModel, + #instVars : [ + 'icon', + 'notebook', + 'removeButton', + 'leftMenuCanvas', + 'rightMenuCanvas', + 'deleteButton', + 'addCellBellowButton', + 'addCellAboveButton', + 'moveCellUp', + 'moveCellDown', + 'previewCell', + 'cellTextInput' + ], + #category : #InteractiveNotebookPresenter +} + +{ #category : #converting } +INNotebookAbstractCellPresenter >> asModelCell [ + + self subclassResponsibility +] + +{ #category : #api } +INNotebookAbstractCellPresenter >> beCode [ + + self subclassResponsibility +] + +{ #category : #initialization } +INNotebookAbstractCellPresenter >> beSelected [ + + notebook select: self. + previewCell ifNotNil: [ :c | c beSelected ] +] + +{ #category : #api } +INNotebookAbstractCellPresenter >> beText [ + + self subclassResponsibility +] + +{ #category : #initialization } +INNotebookAbstractCellPresenter >> beUnselected [ + + leftMenuCanvas canvas color: self unselectedColor. + leftMenuCanvas canvas signalUpdate. + rightMenuCanvas canvas color: self unselectedColor. + rightMenuCanvas canvas signalUpdate +] + +{ #category : #accessing } +INNotebookAbstractCellPresenter >> cellTextInput [ + + ^ cellTextInput +] + +{ #category : #initialization } +INNotebookAbstractCellPresenter >> createDescriptionFor: aString [ + + ^ aString asTextMorph + backgroundColor: (Color white alpha: 0.6); + borderColor: Color gray; + textColor: Color black; + borderWidth: 1; + margins: 2; + yourself +] + +{ #category : #initialization } +INNotebookAbstractCellPresenter >> iconNamed: anIconName [ + + INNotebookIcons icons + at: anIconName + ifPresent: [ :found | ^ found ]. + ^ super iconNamed: anIconName +] + +{ #category : #initialization } +INNotebookAbstractCellPresenter >> initializeLayout [ + + self layout: (SpBoxLayout newLeftToRight + add: leftMenuCanvas width: 30; + add: cellTextInput; + add: rightMenuCanvas width: 100; + yourself) +] + +{ #category : #initialization } +INNotebookAbstractCellPresenter >> initializePresenters [ + + | buttons menu | + self whenDisplayDo: [ + self withAdapterDo: [ + self adapter children second textArea announcer + when: MorphGotFocus + do: [ self selectMe ] ]. + self updateHeight ]. + removeButton := self newButton + icon: (Smalltalk ui iconNamed: #remove); + action: [ self remove ]. + leftMenuCanvas := self newRoassal. + leftMenuCanvas canvas color: self unselectedColor. + rightMenuCanvas := self newRoassal. + rightMenuCanvas canvas color: Color transparent. + deleteButton := RSBitmap new + form: (self iconNamed: #trash); + model: 'Delete'; + size: 16; + yourself. + deleteButton when: RSMouseClick do: [ self remove ]. + + addCellBellowButton := RSBitmap new + form: (self iconNamed: #addBelow); + model: 'Add after'; + size: 16; + yourself. + addCellAboveButton := RSBitmap new + form: (self iconNamed: #addAbove); + model: 'Add before'; + size: 16; + yourself. + moveCellUp := RSBitmap new + form: (self iconNamed: #up); + model: 'Move up cell'; + size: 16; + yourself. + moveCellDown := RSBitmap new + form: (self iconNamed: #down); + model: 'Move down cell'; + size: 16; + yourself. + buttons := RSGroup withAll: { + moveCellUp. + moveCellDown. + addCellBellowButton. + addCellAboveButton. + + deleteButton }. + buttons @ (RSMorphicPopupInteraction new + morphBuilder: [ :model | self createDescriptionFor: model ]; + yourself). + RSHorizontalLineLayout new + alignMiddle; + horizontalGap: 2; + on: buttons. + menu := RSComposite new + addAll: buttons; + isFixed: true; + color: Color transparent; + translateBy: 50 @ 14; + yourself. + + rightMenuCanvas canvas add: menu. + menu adjustToChildren. + menu padding: 10. + moveCellUp when: RSMouseClick do: [ self moveUp ]. + moveCellDown when: RSMouseClick do: [ self moveDown ]. + addCellBellowButton + when: RSMouseClick + do: [ notebook addTextCellAfter: self ]. + addCellAboveButton + when: RSMouseClick + do: [ notebook addTextCellBefore: self ] +] + +{ #category : #initialization } +INNotebookAbstractCellPresenter >> moveDown [ + + notebook moveDown: self +] + +{ #category : #initialization } +INNotebookAbstractCellPresenter >> moveUp [ + + notebook moveUp: self +] + +{ #category : #accessing } +INNotebookAbstractCellPresenter >> notebook [ + + ^ notebook +] + +{ #category : #accessing } +INNotebookAbstractCellPresenter >> notebook: anObject [ + + notebook := anObject +] + +{ #category : #accessing } +INNotebookAbstractCellPresenter >> previewCell [ + + ^ previewCell +] + +{ #category : #accessing } +INNotebookAbstractCellPresenter >> previewCell: anObject [ + + previewCell := anObject +] + +{ #category : #initialization } +INNotebookAbstractCellPresenter >> remove [ + + notebook removeCell: self +] + +{ #category : #initialization } +INNotebookAbstractCellPresenter >> select [ + + self takeKeyboardFocus. + leftMenuCanvas canvas color: self selectedColor. + leftMenuCanvas canvas signalUpdate. + rightMenuCanvas canvas color: self selectedColor. + rightMenuCanvas canvas signalUpdate +] + +{ #category : #actions } +INNotebookAbstractCellPresenter >> selectAndScrollToMe [ + + notebook selectAndScrollTo: self +] + +{ #category : #actions } +INNotebookAbstractCellPresenter >> selectMe [ + + notebook select: self. + previewCell ifNotNil: [ :c | c selectAndScrollToMe ] +] + +{ #category : #initialization } +INNotebookAbstractCellPresenter >> selectedColor [ + + ^ Color fromHexString: '77A8C8' +] + +{ #category : #api } +INNotebookAbstractCellPresenter >> setModelBeforeInitialization: aModel [ + + self notebook: aModel +] + +{ #category : #protocol } +INNotebookAbstractCellPresenter >> takeKeyboardFocus [ + + cellTextInput takeKeyboardFocus +] + +{ #category : #initialization } +INNotebookAbstractCellPresenter >> text [ + + ^ cellTextInput text +] + +{ #category : #initialization } +INNotebookAbstractCellPresenter >> text: aText [ + + cellTextInput text: aText +] + +{ #category : #accessing } +INNotebookAbstractCellPresenter >> textAreaWidth [ + + self layout adapter ifNil: [ ^ -1 ]. + ^ self layout adapter children second width +] + +{ #category : #initialization } +INNotebookAbstractCellPresenter >> unselect [ + + self beUnselected +] + +{ #category : #initialization } +INNotebookAbstractCellPresenter >> unselectedColor [ + + ^ Color transparent +] + +{ #category : #initialization } +INNotebookAbstractCellPresenter >> updateHeight [ + UIManager default defer: [ + notebook headerSep withAdapterDo: [ :a | + cellTextInput withAdapterDo: [ :b | + | textMorph height width | + textMorph := b widget. + textMorph + borderColor: Color gray translucent; + borderWidth: 1. + textMorph scrollPane + vHideScrollbar; + vScrollbarShowNever. + width := a widget width. + textMorph scrollPane textArea withoutSelectionBar. + height := (RubEditingArea new + font: textMorph font; + width: width - 182; + beWrapped; + updateTextWith: cellTextInput text) height. + self withAdapterDo: [ :c | c widget height: height + 2 ] ] ] ] +] + +{ #category : #enumerating } +INNotebookAbstractCellPresenter >> whenTextChangedDo: aBlock [ + + cellTextInput whenTextChangedDo: aBlock +] diff --git a/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st index d38f357..7ec142d 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCellPreviewPresenter.class.st @@ -1,155 +1,153 @@ -" -I am a preview cell of a notebook page. -I display the compiled content of a cell, either in Microdown if I represent a text cell, or using different types of presenters for a code cell, depending on the class of the final compiled result of the cell. - -Using class extensions, the object resulting of the compilation of a cell provides me an appropriate presenter to display itself (using the extension method `createContentPreviewPresenter`). I can add this object to the created presenter (using the extension method `addContentToPreviewPresenter: anObject`). - -Those presenters also use extension methods : `selectNotebookPresenter`, `unselectedNotebookPresenter` and `updateNotebookPresenterHeight`. -" -Class { - #name : #INNotebookCellPreviewPresenter, - #superclass : #SpPresenter, - #instVars : [ - 'cell', - 'parent', - 'contentPresenter' - ], - #category : #InteractiveNotebookPresenter -} - -{ #category : #actions } -INNotebookCellPreviewPresenter class >> selectedColor [ - - ^ Color fromHexString: '77A8C8' -] - -{ #category : #initialization } -INNotebookCellPreviewPresenter class >> unselectedColor [ - - ^ Color transparent -] - -{ #category : #actions } -INNotebookCellPreviewPresenter >> beSelected [ - - self parent select: self. - -] - -{ #category : #accessing } -INNotebookCellPreviewPresenter >> cell: anObject [ - - cell := anObject -] - -{ #category : #accessing } -INNotebookCellPreviewPresenter >> cellTextInput [ - - ^ cell -] - -{ #category : #accessing } -INNotebookCellPreviewPresenter >> contentPresenter [ - ^ contentPresenter -] - -{ #category : #initialization } -INNotebookCellPreviewPresenter >> contentPresenter: aPresenter [ - - contentPresenter := aPresenter. - self whenDisplayDo: [ self updateHeight ]. - self initializeLayout. - contentPresenter eventHandler whenMouseDownDo: [ :anEvent | - self selectMe ] -] - -{ #category : #accessing } -INNotebookCellPreviewPresenter >> getContent [ - - ^ parent mustDisplayInspectorView - ifTrue: [ - contentPresenter selectedPage activePresenter view context - inspectedObject ] - ifFalse: [ contentPresenter view context inspectedObject ] -] - -{ #category : #initialization } -INNotebookCellPreviewPresenter >> initializeLayout [ - - self layout: (SpBoxLayout newLeftToRight - add: contentPresenter; - yourself) -] - -{ #category : #initialization } -INNotebookCellPreviewPresenter >> initializePresenters [ - - self whenDisplayDo: [ - self withAdapterDo: [ :a | - a widget announcer when: MorphGotFocus do: [ self selectMe ] ] ] -] - -{ #category : #initialization } -INNotebookCellPreviewPresenter >> morphFor: aPresenter from: aMorph [ - - aMorph presenter = aPresenter ifTrue: [ ^ aMorph ]. - aMorph owner ifNil: [ ^ nil ]. - ^ self morphFor: aPresenter from: aMorph owner -] - -{ #category : #accessing } -INNotebookCellPreviewPresenter >> parent [ - - ^ parent -] - -{ #category : #accessing } -INNotebookCellPreviewPresenter >> parent: anObject [ - - parent := anObject -] - -{ #category : #actions } -INNotebookCellPreviewPresenter >> select [ - - self withAdapterDo: [ :a | a widget color: self class selectedColor ] -] - -{ #category : #actions } -INNotebookCellPreviewPresenter >> selectAndScrollToMe [ - - self parent selectAndScrollTo: self -] - -{ #category : #actions } -INNotebookCellPreviewPresenter >> selectMe [ - - self parent select: self. - cell ifNotNil: [ :c | c selectAndScrollToMe ] -] - -{ #category : #accessing } -INNotebookCellPreviewPresenter >> text: aString [ - - contentPresenter text: aString -] - -{ #category : #actions } -INNotebookCellPreviewPresenter >> unselected [ - - self withAdapterDo: [ :a | - a widget color: self class unselectedColor ] -] - -{ #category : #initialization } -INNotebookCellPreviewPresenter >> updateHeight [ - - parent mustDisplayInspectorView - ifFalse: [ contentPresenter specPresenter updatePresenterHeight ] - ifTrue: [ self updateInspectorViewHeight ] -] - -{ #category : #'as yet unclassified' } -INNotebookCellPreviewPresenter >> updateInspectorViewHeight [ - self withAdapterDo: [ :a | a widget height: 350 ]. -] +" +I am a preview cell of a notebook page. +I display the compiled content of a cell, either in Microdown if I represent a text cell, or using different types of presenters for a code cell, depending on the class of the final compiled result of the cell. + +Using class extensions, the object resulting of the compilation of a cell provides me an appropriate presenter to display itself (using the extension method `createContentPreviewPresenter`). I can add this object to the created presenter (using the extension method `addContentToPreviewPresenter: anObject`). + +Those presenters also use extension methods : `selectNotebookPresenter`, `unselectedNotebookPresenter` and `updateNotebookPresenterHeight`. +" +Class { + #name : #INNotebookCellPreviewPresenter, + #superclass : #SpPresenter, + #instVars : [ + 'cell', + 'parent', + 'contentPresenter' + ], + #category : #InteractiveNotebookPresenter +} + +{ #category : #actions } +INNotebookCellPreviewPresenter class >> selectedColor [ + + ^ Color fromHexString: '77A8C8' +] + +{ #category : #initialization } +INNotebookCellPreviewPresenter class >> unselectedColor [ + + ^ Color transparent +] + +{ #category : #actions } +INNotebookCellPreviewPresenter >> beSelected [ + + self parent select: self. + +] + +{ #category : #accessing } +INNotebookCellPreviewPresenter >> cell: anObject [ + + cell := anObject +] + +{ #category : #accessing } +INNotebookCellPreviewPresenter >> cellTextInput [ + + ^ cell +] + +{ #category : #accessing } +INNotebookCellPreviewPresenter >> contentPresenter [ + ^ contentPresenter +] + +{ #category : #initialization } +INNotebookCellPreviewPresenter >> contentPresenter: aPresenter [ + + contentPresenter := aPresenter. + self whenDisplayDo: [ self updateHeight ]. + self initializeLayout +] + +{ #category : #accessing } +INNotebookCellPreviewPresenter >> getContent [ + + ^ parent mustDisplayInspectorView + ifTrue: [ + contentPresenter selectedPage activePresenter view context + inspectedObject ] + ifFalse: [ contentPresenter view context inspectedObject ] +] + +{ #category : #initialization } +INNotebookCellPreviewPresenter >> initializeLayout [ + + self layout: (SpBoxLayout newLeftToRight + add: contentPresenter; + yourself) +] + +{ #category : #initialization } +INNotebookCellPreviewPresenter >> initializePresenters [ + + self whenDisplayDo: [ + self withAdapterDo: [ :a | + a widget announcer when: MorphGotFocus do: [ self selectMe ] ] ] +] + +{ #category : #initialization } +INNotebookCellPreviewPresenter >> morphFor: aPresenter from: aMorph [ + + aMorph presenter = aPresenter ifTrue: [ ^ aMorph ]. + aMorph owner ifNil: [ ^ nil ]. + ^ self morphFor: aPresenter from: aMorph owner +] + +{ #category : #accessing } +INNotebookCellPreviewPresenter >> parent [ + + ^ parent +] + +{ #category : #accessing } +INNotebookCellPreviewPresenter >> parent: anObject [ + + parent := anObject +] + +{ #category : #actions } +INNotebookCellPreviewPresenter >> select [ + + self withAdapterDo: [ :a | a widget color: self class selectedColor ] +] + +{ #category : #actions } +INNotebookCellPreviewPresenter >> selectAndScrollToMe [ + + self parent selectAndScrollTo: self +] + +{ #category : #actions } +INNotebookCellPreviewPresenter >> selectMe [ + + self parent select: self. + cell ifNotNil: [ :c | c selectAndScrollToMe ] +] + +{ #category : #accessing } +INNotebookCellPreviewPresenter >> text: aString [ + + contentPresenter text: aString +] + +{ #category : #actions } +INNotebookCellPreviewPresenter >> unselected [ + + self withAdapterDo: [ :a | + a widget color: self class unselectedColor ] +] + +{ #category : #initialization } +INNotebookCellPreviewPresenter >> updateHeight [ + + parent mustDisplayInspectorView + ifFalse: [ contentPresenter specPresenter updatePresenterHeight ] + ifTrue: [ self updateInspectorViewHeight ] +] + +{ #category : #'as yet unclassified' } +INNotebookCellPreviewPresenter >> updateInspectorViewHeight [ + self withAdapterDo: [ :a | a widget height: 350 ]. +] diff --git a/src/InteractiveNotebookPresenter/INNotebookCodeCellModel.class.st b/src/InteractiveNotebookPresenter/INNotebookCodeCellModel.class.st index da4eae1..15565aa 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCodeCellModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCodeCellModel.class.st @@ -1,45 +1,45 @@ -Class { - #name : #INNotebookCodeCellModel, - #superclass : #INNotebookAbstractCellModel, - #category : #InteractiveNotebookPresenter -} - -{ #category : #converting } -INNotebookCodeCellModel >> beCodeModel [ - ^ self -] - -{ #category : #converting } -INNotebookCodeCellModel >> beTextModel [ - "no need to add the text of the current model in the new model, it will be compiled anyway in the next preview" - ^ INNotebookTextCellModel new -] - -{ #category : #printing } -INNotebookCodeCellModel >> getContentwithContext: aContext [ - - ^ self class compiler - compilationContext: aContext; - source: text; - evaluate -] - -{ #category : #compiling } -INNotebookCodeCellModel >> parseContent [ - - ^ RBParser parseExpression: text -] - -{ #category : #helpers } -INNotebookCodeCellModel >> presenterClass [ - - ^ INNotebookCodeCellPresenter -] - -{ #category : #printing } -INNotebookCodeCellModel >> printContentIn: aStream withContext: aContext [ - ^self class compiler - compilationContext: aContext; - source: text; - evaluate -] +Class { + #name : #INNotebookCodeCellModel, + #superclass : #INNotebookAbstractCellModel, + #category : #InteractiveNotebookPresenter +} + +{ #category : #converting } +INNotebookCodeCellModel >> beCodeModel [ + ^ self +] + +{ #category : #converting } +INNotebookCodeCellModel >> beTextModel [ + "no need to add the text of the current model in the new model, it will be compiled anyway in the next preview" + ^ INNotebookTextCellModel new +] + +{ #category : #printing } +INNotebookCodeCellModel >> getContentwithContext: aContext [ + + ^ self class compiler + compilationContext: aContext; + source: text; + evaluate +] + +{ #category : #compiling } +INNotebookCodeCellModel >> parseContent [ + + ^ RBParser parseExpression: text +] + +{ #category : #helpers } +INNotebookCodeCellModel >> presenterClass [ + + ^ INNotebookCodeCellPresenter +] + +{ #category : #printing } +INNotebookCodeCellModel >> printContentIn: aStream withContext: aContext [ + ^self class compiler + compilationContext: aContext; + source: text; + evaluate +] diff --git a/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st index 810032b..c39f8b4 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCodeCellPresenter.class.st @@ -1,72 +1,72 @@ -Class { - #name : #INNotebookCodeCellPresenter, - #superclass : #INNotebookAbstractCellPresenter, - #category : #InteractiveNotebookPresenter -} - -{ #category : #converting } -INNotebookCodeCellPresenter >> asModelCell [ - - ^ INNotebookCodeCellModel new - text: cellTextInput text; - yourself -] - -{ #category : #api } -INNotebookCodeCellPresenter >> beCode [ - - ^ self -] - -{ #category : #api } -INNotebookCodeCellPresenter >> beText [ - - notebook transformToTextCell: self -] - -{ #category : #initialization } -INNotebookCodeCellPresenter >> initializePresenters [ - - super initializePresenters. - cellTextInput := self newCode - withoutLineNumbers; - beForScripting; - placeholder: notebook codeCellPlaceholder; - yourself. - cellTextInput whenTextChangedDo: [ self updateHeight. self updateBindings. ]. - self interactionModel: notebook interactionModel. - - icon := self newButton - label: 'Code'; - action: [ notebook transformToTextCell: self ]. - - leftMenuCanvas canvas - add: (RSLabel new - text: '[ ]'; - bold; - color: Color black; - yourself); - when: RSMouseClick do: [ notebook transformToTextCell: self ]. - self initializeLayout -] - -{ #category : #api } -INNotebookCodeCellPresenter >> interactionModel: anEnvironment [ - - cellTextInput interactionModel: anEnvironment -] - -{ #category : #accessing } -INNotebookCodeCellPresenter >> notebook: aNoteBook [ - - notebook := aNoteBook. -] - -{ #category : #updating } -INNotebookCodeCellPresenter >> updateBindings [ - - | parsedContent | - self model text: cellTextInput text. - parsedContent := [ self model parseContent ] on: Exception do: [ ^ self ]. - notebook interactionModel setBindings: parsedContent -] +Class { + #name : #INNotebookCodeCellPresenter, + #superclass : #INNotebookAbstractCellPresenter, + #category : #InteractiveNotebookPresenter +} + +{ #category : #converting } +INNotebookCodeCellPresenter >> asModelCell [ + + ^ INNotebookCodeCellModel new + text: cellTextInput text; + yourself +] + +{ #category : #api } +INNotebookCodeCellPresenter >> beCode [ + + ^ self +] + +{ #category : #api } +INNotebookCodeCellPresenter >> beText [ + + notebook transformToTextCell: self +] + +{ #category : #initialization } +INNotebookCodeCellPresenter >> initializePresenters [ + + super initializePresenters. + cellTextInput := self newCode + withoutLineNumbers; + beForScripting; + placeholder: notebook codeCellPlaceholder; + yourself. + cellTextInput whenTextChangedDo: [ self updateHeight. self updateBindings. ]. + self interactionModel: notebook interactionModel. + + icon := self newButton + label: 'Code'; + action: [ notebook transformToTextCell: self ]. + + leftMenuCanvas canvas + add: (RSLabel new + text: '[ ]'; + bold; + color: Color black; + yourself); + when: RSMouseClick do: [ notebook transformToTextCell: self ]. + self initializeLayout +] + +{ #category : #api } +INNotebookCodeCellPresenter >> interactionModel: anEnvironment [ + + cellTextInput interactionModel: anEnvironment +] + +{ #category : #accessing } +INNotebookCodeCellPresenter >> notebook: aNoteBook [ + + notebook := aNoteBook. +] + +{ #category : #updating } +INNotebookCodeCellPresenter >> updateBindings [ + + | parsedContent | + self model text: cellTextInput text. + parsedContent := [ self model parseContent ] on: Exception do: [ ^ self ]. + notebook interactionModel setBindings: parsedContent +] diff --git a/src/InteractiveNotebookPresenter/INNotebookCodeScriptingInteractionModel.class.st b/src/InteractiveNotebookPresenter/INNotebookCodeScriptingInteractionModel.class.st index 3047545..af5a680 100644 --- a/src/InteractiveNotebookPresenter/INNotebookCodeScriptingInteractionModel.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookCodeScriptingInteractionModel.class.st @@ -1,33 +1,33 @@ -Class { - #name : #INNotebookCodeScriptingInteractionModel, - #superclass : #SpCodeScriptingInteractionModel, - #instVars : [ - 'receiver' - ], - #category : #InteractiveNotebookPresenter -} - -{ #category : #accessing } -INNotebookCodeScriptingInteractionModel >> doItReceiver [ - - ^ receiver -] - -{ #category : #accessing } -INNotebookCodeScriptingInteractionModel >> receiver [ - - ^ receiver -] - -{ #category : #accessing } -INNotebookCodeScriptingInteractionModel >> receiver: anObject [ - - receiver := anObject -] - -{ #category : #initialization } -INNotebookCodeScriptingInteractionModel >> setBindings: aASTTree [ - - aASTTree allChildren do: [ :l | - l class = RBAssignmentNode ifTrue: [ self bindingOf: l variable name ] ] -] +Class { + #name : #INNotebookCodeScriptingInteractionModel, + #superclass : #SpCodeScriptingInteractionModel, + #instVars : [ + 'receiver' + ], + #category : #InteractiveNotebookPresenter +} + +{ #category : #accessing } +INNotebookCodeScriptingInteractionModel >> doItReceiver [ + + ^ receiver +] + +{ #category : #accessing } +INNotebookCodeScriptingInteractionModel >> receiver [ + + ^ receiver +] + +{ #category : #accessing } +INNotebookCodeScriptingInteractionModel >> receiver: anObject [ + + receiver := anObject +] + +{ #category : #initialization } +INNotebookCodeScriptingInteractionModel >> setBindings: aASTTree [ + + aASTTree allChildren do: [ :l | + l class = RBAssignmentNode ifTrue: [ self bindingOf: l variable name ] ] +] diff --git a/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st b/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st index 67d1e52..9907158 100644 --- a/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookEditorPresenter.class.st @@ -1,289 +1,289 @@ -" -I am the editor panel for a notebook page. - -I allow the user to add cells before or after a cell, to transform a text cell into a code cell and vice versa, or to move up or down a cell. -" -Class { - #name : #INNotebookEditorPresenter, - #superclass : #SpPresenter, - #instVars : [ - 'cellList', - 'selectedCell', - 'interactionModel', - 'headerSep', - 'cellLayout', - 'browser', - 'codeCellPlaceholder' - ], - #category : #InteractiveNotebookPresenter -} - -{ #category : #initialization } -INNotebookEditorPresenter >> addTextCellAfter: aCell [ - - | lastCellAdded | - lastCellAdded := self newTextCell. - cellList add: lastCellAdded after: aCell. - selectedCell := lastCellAdded. - self relayout -] - -{ #category : #initialization } -INNotebookEditorPresenter >> addTextCellBefore: aCell [ - - | lastCellAdded | - lastCellAdded := self newTextCell. - cellList add: lastCellAdded before: aCell. - selectedCell := lastCellAdded. - self relayout -] - -{ #category : #accessing } -INNotebookEditorPresenter >> allModelCells [ - - ^ cellList asOrderedCollection collect: [ :cell | cell model ] -] - -{ #category : #accessing } -INNotebookEditorPresenter >> browser [ - - ^ browser -] - -{ #category : #accessing } -INNotebookEditorPresenter >> browser: anObject [ - - browser := anObject -] - -{ #category : #accessing } -INNotebookEditorPresenter >> cellList [ - - ^ cellList -] - -{ #category : #accessing } -INNotebookEditorPresenter >> codeCellPlaceholder [ - - ^ codeCellPlaceholder -] - -{ #category : #accessing } -INNotebookEditorPresenter >> codeCellPlaceholder: anObject [ - - codeCellPlaceholder := anObject -] - -{ #category : #initialization } -INNotebookEditorPresenter >> defer: aBlock times: n [ - - n traceCr. - self withAdapterDo: [ :a | - a widget defer: [ - n <= 0 - ifTrue: [ a widget defer: aBlock ] - ifFalse: [ self defer: aBlock times: n - 1 ] ] ] -] - -{ #category : #accessing } -INNotebookEditorPresenter >> headerSep [ - - ^ headerSep -] - -{ #category : #initialization } -INNotebookEditorPresenter >> initialize [ - - codeCellPlaceholder := 'Code'. - cellList := LinkedList new. - interactionModel := INNotebookCodeScriptingInteractionModel new - receiver: 1; - yourself. - super initialize -] - -{ #category : #initialization } -INNotebookEditorPresenter >> initializeLayout [ - - cellLayout := SpBoxLayout newTopToBottom - spacing: self layoutSpacing; - yourself. - self layout: (SpScrollableLayout with: (SpBoxLayout newTopToBottom - spacing: self layoutSpacing; - add: headerSep height: 1; - add: cellLayout; - yourself)) -] - -{ #category : #initialization } -INNotebookEditorPresenter >> initializePresenters [ - - (headerSep := self newRoassal) canvas color: Color transparent. - headerSep canvas when: RSExtentChangedEvent do: [ self updateHeight ]. - self whenDisplayDo: [ self updateHeight ]. - self initializeLayout -] - -{ #category : #accessing } -INNotebookEditorPresenter >> interactionModel [ - - ^ interactionModel -] - -{ #category : #initialization } -INNotebookEditorPresenter >> layoutSpacing [ - - ^ 10 -] - -{ #category : #accessing } -INNotebookEditorPresenter >> model [ - - ^ self owner model -] - -{ #category : #removing } -INNotebookEditorPresenter >> moveDown: aCell [ - - | idx | - idx := cellList indexOf: aCell. - idx >= cellList size ifTrue: [ ^ self ]. - cellList swap: idx with: idx + 1. - selectedCell := aCell. - self relayout -] - -{ #category : #removing } -INNotebookEditorPresenter >> moveUp: aCell [ - - | idx | - idx := cellList indexOf: aCell. - idx <= 1 ifTrue: [ ^ self ]. - cellList swap: idx with: idx - 1. - selectedCell := aCell. - self relayout -] - -{ #category : #initialization } -INNotebookEditorPresenter >> newCodeCell [ - - ^ (self instantiate: INNotebookCodeCellPresenter on: self) - notebook: self; - model: INNotebookCodeCellModel new; - yourself -] - -{ #category : #initialization } -INNotebookEditorPresenter >> newTextCell [ - - ^ (self instantiate: INNotebookTextCellPresenter) - notebook: self; - model: INNotebookTextCellModel new; - yourself -] - -{ #category : #adding } -INNotebookEditorPresenter >> relayout [ - - | newLayout | - newLayout := SpBoxLayout newTopToBottom - spacing: self layoutSpacing; - yourself. - cellList do: [ :cell | newLayout add: cell expand: false ]. - - cellLayout removeAll. - cellLayout add: (self newPresenter - layout: newLayout; - yourself). - cellList do: [ :cell | cell announceDisplayed ]. - self defer: [ - selectedCell ifNotNil: [ self selectAndScrollTo: selectedCell ] ] -] - -{ #category : #removing } -INNotebookEditorPresenter >> removeCell: aCell [ - - cellList remove: aCell. - self relayout -] - -{ #category : #adding } -INNotebookEditorPresenter >> scrollTo: aMiNoteBookCell [ - - self layout withAdapterDo: [ :a | - aMiNoteBookCell withAdapterDo: [ :b | - a widget scrollToShow: b widget bounds ] ] -] - -{ #category : #removing } -INNotebookEditorPresenter >> select: aCell [ - - - selectedCell := aCell. - cellList do: [ :c | c unselect ]. - selectedCell select -] - -{ #category : #adding } -INNotebookEditorPresenter >> selectAndScrollTo: aMiNoteBookCell [ - - self select: aMiNoteBookCell. - self scrollTo: aMiNoteBookCell -] - -{ #category : #adding } -INNotebookEditorPresenter >> transformToCodeCell: aCell [ - - | width lastCellAdded | - lastCellAdded := self newCodeCell - text: aCell text; - yourself. - width := aCell textAreaWidth. - cellList at: (cellList indexOf: aCell) put: lastCellAdded. - selectedCell := lastCellAdded. - self relayout -] - -{ #category : #adding } -INNotebookEditorPresenter >> transformToTextCell: aCell [ - - | width lastCellAdded | - lastCellAdded := self newTextCell - text: aCell text; - yourself. - width := aCell textAreaWidth. - cellList at: (cellList indexOf: aCell) put: lastCellAdded. - selectedCell := lastCellAdded. - self relayout -] - -{ #category : #'updating screen' } -INNotebookEditorPresenter >> updateAll [ - - cellList := self model cellList collect: [ :c | - (self instantiate: c presenterClass on: self) - model: c; - text: c text; - yourself ]. - - cellList ifEmpty: [ ^ self ]. - self select: cellList last. - self relayout -] - -{ #category : #removing } -INNotebookEditorPresenter >> updateHeight [ - - cellList do: [ :c | c updateHeight ] -] - -{ #category : #removing } -INNotebookEditorPresenter >> updateModelCells [ - cellList do: [ :cell | cell model text: cell text ] -] - -{ #category : #initialization } -INNotebookEditorPresenter >> updatePresenter [ - - self updateAll -] +" +I am the editor panel for a notebook page. + +I allow the user to add cells before or after a cell, to transform a text cell into a code cell and vice versa, or to move up or down a cell. +" +Class { + #name : #INNotebookEditorPresenter, + #superclass : #SpPresenter, + #instVars : [ + 'cellList', + 'selectedCell', + 'interactionModel', + 'headerSep', + 'cellLayout', + 'browser', + 'codeCellPlaceholder' + ], + #category : #InteractiveNotebookPresenter +} + +{ #category : #initialization } +INNotebookEditorPresenter >> addTextCellAfter: aCell [ + + | lastCellAdded | + lastCellAdded := self newTextCell. + cellList add: lastCellAdded after: aCell. + selectedCell := lastCellAdded. + self relayout +] + +{ #category : #initialization } +INNotebookEditorPresenter >> addTextCellBefore: aCell [ + + | lastCellAdded | + lastCellAdded := self newTextCell. + cellList add: lastCellAdded before: aCell. + selectedCell := lastCellAdded. + self relayout +] + +{ #category : #accessing } +INNotebookEditorPresenter >> allModelCells [ + + ^ cellList asOrderedCollection collect: [ :cell | cell model ] +] + +{ #category : #accessing } +INNotebookEditorPresenter >> browser [ + + ^ browser +] + +{ #category : #accessing } +INNotebookEditorPresenter >> browser: anObject [ + + browser := anObject +] + +{ #category : #accessing } +INNotebookEditorPresenter >> cellList [ + + ^ cellList +] + +{ #category : #accessing } +INNotebookEditorPresenter >> codeCellPlaceholder [ + + ^ codeCellPlaceholder +] + +{ #category : #accessing } +INNotebookEditorPresenter >> codeCellPlaceholder: anObject [ + + codeCellPlaceholder := anObject +] + +{ #category : #initialization } +INNotebookEditorPresenter >> defer: aBlock times: n [ + + n traceCr. + self withAdapterDo: [ :a | + a widget defer: [ + n <= 0 + ifTrue: [ a widget defer: aBlock ] + ifFalse: [ self defer: aBlock times: n - 1 ] ] ] +] + +{ #category : #accessing } +INNotebookEditorPresenter >> headerSep [ + + ^ headerSep +] + +{ #category : #initialization } +INNotebookEditorPresenter >> initialize [ + + codeCellPlaceholder := 'Code'. + cellList := LinkedList new. + interactionModel := INNotebookCodeScriptingInteractionModel new + receiver: 1; + yourself. + super initialize +] + +{ #category : #initialization } +INNotebookEditorPresenter >> initializeLayout [ + + cellLayout := SpBoxLayout newTopToBottom + spacing: self layoutSpacing; + yourself. + self layout: (SpScrollableLayout with: (SpBoxLayout newTopToBottom + spacing: self layoutSpacing; + add: headerSep height: 1; + add: cellLayout; + yourself)) +] + +{ #category : #initialization } +INNotebookEditorPresenter >> initializePresenters [ + + (headerSep := self newRoassal) canvas color: Color transparent. + headerSep canvas when: RSExtentChangedEvent do: [ self updateHeight ]. + self whenDisplayDo: [ self updateHeight ]. + self initializeLayout +] + +{ #category : #accessing } +INNotebookEditorPresenter >> interactionModel [ + + ^ interactionModel +] + +{ #category : #initialization } +INNotebookEditorPresenter >> layoutSpacing [ + + ^ 10 +] + +{ #category : #accessing } +INNotebookEditorPresenter >> model [ + + ^ self owner model +] + +{ #category : #removing } +INNotebookEditorPresenter >> moveDown: aCell [ + + | idx | + idx := cellList indexOf: aCell. + idx >= cellList size ifTrue: [ ^ self ]. + cellList swap: idx with: idx + 1. + selectedCell := aCell. + self relayout +] + +{ #category : #removing } +INNotebookEditorPresenter >> moveUp: aCell [ + + | idx | + idx := cellList indexOf: aCell. + idx <= 1 ifTrue: [ ^ self ]. + cellList swap: idx with: idx - 1. + selectedCell := aCell. + self relayout +] + +{ #category : #initialization } +INNotebookEditorPresenter >> newCodeCell [ + + ^ (self instantiate: INNotebookCodeCellPresenter on: self) + notebook: self; + model: INNotebookCodeCellModel new; + yourself +] + +{ #category : #initialization } +INNotebookEditorPresenter >> newTextCell [ + + ^ (self instantiate: INNotebookTextCellPresenter) + notebook: self; + model: INNotebookTextCellModel new; + yourself +] + +{ #category : #adding } +INNotebookEditorPresenter >> relayout [ + + | newLayout | + newLayout := SpBoxLayout newTopToBottom + spacing: self layoutSpacing; + yourself. + cellList do: [ :cell | newLayout add: cell expand: false ]. + + cellLayout removeAll. + cellLayout add: (self newPresenter + layout: newLayout; + yourself). + cellList do: [ :cell | cell announceDisplayed ]. + self defer: [ + selectedCell ifNotNil: [ self selectAndScrollTo: selectedCell ] ] +] + +{ #category : #removing } +INNotebookEditorPresenter >> removeCell: aCell [ + + cellList remove: aCell. + self relayout +] + +{ #category : #adding } +INNotebookEditorPresenter >> scrollTo: aMiNoteBookCell [ + + self layout withAdapterDo: [ :a | + aMiNoteBookCell withAdapterDo: [ :b | + a widget scrollToShow: b widget bounds ] ] +] + +{ #category : #removing } +INNotebookEditorPresenter >> select: aCell [ + + + selectedCell := aCell. + cellList do: [ :c | c unselect ]. + selectedCell select +] + +{ #category : #adding } +INNotebookEditorPresenter >> selectAndScrollTo: aMiNoteBookCell [ + + self select: aMiNoteBookCell. + self scrollTo: aMiNoteBookCell +] + +{ #category : #adding } +INNotebookEditorPresenter >> transformToCodeCell: aCell [ + + | width lastCellAdded | + lastCellAdded := self newCodeCell + text: aCell text; + yourself. + width := aCell textAreaWidth. + cellList at: (cellList indexOf: aCell) put: lastCellAdded. + selectedCell := lastCellAdded. + self relayout +] + +{ #category : #adding } +INNotebookEditorPresenter >> transformToTextCell: aCell [ + + | width lastCellAdded | + lastCellAdded := self newTextCell + text: aCell text; + yourself. + width := aCell textAreaWidth. + cellList at: (cellList indexOf: aCell) put: lastCellAdded. + selectedCell := lastCellAdded. + self relayout +] + +{ #category : #'updating screen' } +INNotebookEditorPresenter >> updateAll [ + + cellList := self model cellList collect: [ :c | + (self instantiate: c presenterClass on: self) + model: c; + text: c text; + yourself ]. + + cellList ifEmpty: [ ^ self ]. + self select: cellList last. + self relayout +] + +{ #category : #removing } +INNotebookEditorPresenter >> updateHeight [ + + cellList do: [ :c | c updateHeight ] +] + +{ #category : #removing } +INNotebookEditorPresenter >> updateModelCells [ + cellList do: [ :cell | cell model text: cell text ] +] + +{ #category : #initialization } +INNotebookEditorPresenter >> updatePresenter [ + + self updateAll +] diff --git a/src/InteractiveNotebookPresenter/INNotebookGenerationHelper.class.st b/src/InteractiveNotebookPresenter/INNotebookGenerationHelper.class.st index d97c902..fcfaaac 100644 --- a/src/InteractiveNotebookPresenter/INNotebookGenerationHelper.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookGenerationHelper.class.st @@ -1,106 +1,106 @@ -" -I am a helper class used to generate the document to export. -" -Class { - #name : #INNotebookGenerationHelper, - #superclass : #Object, - #instVars : [ - 'fileReferenceParent', - 'index', - 'listLevel' - ], - #category : #InteractiveNotebookPresenter -} - -{ #category : #'instance creation' } -INNotebookGenerationHelper class >> newFor: aFileReference [ - - ^ self new - fileReferenceParent: aFileReference; - index: 0; - yourself -] - -{ #category : #'*InteractiveNotebookPresenter' } -INNotebookGenerationHelper >> checkForResourcesDirectory [ - "checks whether or not the notebook resources file is already created" - ^ (fileReferenceParent / 'notebook_resources') exists -] - -{ #category : #'*InteractiveNotebookPresenter' } -INNotebookGenerationHelper >> createResourcesDirectory [ - "create a resource directory, to store additional files necessary to the notebook export document, like images" - (fileReferenceParent / 'notebook_resources') createDirectory -] - -{ #category : #accessing } -INNotebookGenerationHelper >> fileReferenceParent [ - - ^ fileReferenceParent -] - -{ #category : #accessing } -INNotebookGenerationHelper >> fileReferenceParent: anObject [ - - fileReferenceParent := anObject -] - -{ #category : #'as yet unclassified' } -INNotebookGenerationHelper >> generateDocument: aCellList [ - - ^ String streamContents: [ :stream | - aCellList do: [ :cell | - stream nextPutAll: - (self generateObject: cell previewCell getContent). - stream nextPutAll: ' '. - stream nextPut: Character cr ] ] -] - -{ #category : #'as yet unclassified' } -INNotebookGenerationHelper >> generateObject: anObject [ - - self incrementIndex. - ^ anObject generateMicrodownUsingHelper: self -] - -{ #category : #'as yet unclassified' } -INNotebookGenerationHelper >> incrementIndex [ - - index := index + 1. -] - -{ #category : #accessing } -INNotebookGenerationHelper >> index [ - - ^ index -] - -{ #category : #accessing } -INNotebookGenerationHelper >> index: anObject [ - - index := anObject -] - -{ #category : #accessing } -INNotebookGenerationHelper >> listLevel [ - - ^ listLevel -] - -{ #category : #accessing } -INNotebookGenerationHelper >> listLevel: anObject [ - - listLevel := anObject -] - -{ #category : #accessing } -INNotebookGenerationHelper >> listLevelDecrement [ - - listLevel := listLevel - 1 -] - -{ #category : #accessing } -INNotebookGenerationHelper >> listLevelIncrement [ - - listLevel := listLevel + 1 -] +" +I am a helper class used to generate the document to export. +" +Class { + #name : #INNotebookGenerationHelper, + #superclass : #Object, + #instVars : [ + 'fileReferenceParent', + 'index', + 'listLevel' + ], + #category : #InteractiveNotebookPresenter +} + +{ #category : #'instance creation' } +INNotebookGenerationHelper class >> newFor: aFileReference [ + + ^ self new + fileReferenceParent: aFileReference; + index: 0; + yourself +] + +{ #category : #'*InteractiveNotebookPresenter' } +INNotebookGenerationHelper >> checkForResourcesDirectory [ + "checks whether or not the notebook resources file is already created" + ^ (fileReferenceParent / 'notebook_resources') exists +] + +{ #category : #'*InteractiveNotebookPresenter' } +INNotebookGenerationHelper >> createResourcesDirectory [ + "create a resource directory, to store additional files necessary to the notebook export document, like images" + (fileReferenceParent / 'notebook_resources') createDirectory +] + +{ #category : #accessing } +INNotebookGenerationHelper >> fileReferenceParent [ + + ^ fileReferenceParent +] + +{ #category : #accessing } +INNotebookGenerationHelper >> fileReferenceParent: anObject [ + + fileReferenceParent := anObject +] + +{ #category : #'as yet unclassified' } +INNotebookGenerationHelper >> generateDocument: aCellList [ + + ^ String streamContents: [ :stream | + aCellList do: [ :cell | + stream nextPutAll: + (self generateObject: cell previewCell getContent). + stream nextPutAll: ' '. + stream nextPut: Character cr ] ] +] + +{ #category : #'as yet unclassified' } +INNotebookGenerationHelper >> generateObject: anObject [ + + self incrementIndex. + ^ anObject generateMicrodownUsingHelper: self +] + +{ #category : #'as yet unclassified' } +INNotebookGenerationHelper >> incrementIndex [ + + index := index + 1. +] + +{ #category : #accessing } +INNotebookGenerationHelper >> index [ + + ^ index +] + +{ #category : #accessing } +INNotebookGenerationHelper >> index: anObject [ + + index := anObject +] + +{ #category : #accessing } +INNotebookGenerationHelper >> listLevel [ + + ^ listLevel +] + +{ #category : #accessing } +INNotebookGenerationHelper >> listLevel: anObject [ + + listLevel := anObject +] + +{ #category : #accessing } +INNotebookGenerationHelper >> listLevelDecrement [ + + listLevel := listLevel - 1 +] + +{ #category : #accessing } +INNotebookGenerationHelper >> listLevelIncrement [ + + listLevel := listLevel + 1 +] diff --git a/src/InteractiveNotebookPresenter/INNotebookGenerationHelper.extension.st b/src/InteractiveNotebookPresenter/INNotebookGenerationHelper.extension.st index 7714bc3..f40f3d8 100644 --- a/src/InteractiveNotebookPresenter/INNotebookGenerationHelper.extension.st +++ b/src/InteractiveNotebookPresenter/INNotebookGenerationHelper.extension.st @@ -1,13 +1,13 @@ -Extension { #name : #INNotebookGenerationHelper } - -{ #category : #'*InteractiveNotebookPresenter' } -INNotebookGenerationHelper >> checkForResourcesDirectory [ - "checks whether or not the notebook resources file is already created" - ^ (fileReferenceParent / 'notebook_resources') exists -] - -{ #category : #'*InteractiveNotebookPresenter' } -INNotebookGenerationHelper >> createResourcesDirectory [ - "create a resource directory, to store additional files necessary to the notebook export document, like images" - (fileReferenceParent / 'notebook_resources') createDirectory -] +Extension { #name : #INNotebookGenerationHelper } + +{ #category : #'*InteractiveNotebookPresenter' } +INNotebookGenerationHelper >> checkForResourcesDirectory [ + "checks whether or not the notebook resources file is already created" + ^ (fileReferenceParent / 'notebook_resources') exists +] + +{ #category : #'*InteractiveNotebookPresenter' } +INNotebookGenerationHelper >> createResourcesDirectory [ + "create a resource directory, to store additional files necessary to the notebook export document, like images" + (fileReferenceParent / 'notebook_resources') createDirectory +] diff --git a/src/InteractiveNotebookPresenter/INNotebookIcons.class.st b/src/InteractiveNotebookPresenter/INNotebookIcons.class.st index 284f5ec..f9a76c3 100644 --- a/src/InteractiveNotebookPresenter/INNotebookIcons.class.st +++ b/src/InteractiveNotebookPresenter/INNotebookIcons.class.st @@ -1,435 +1,435 @@ -Class { - #name : #INNotebookIcons, - #superclass : #Object, - #classInstVars : [ - 'icons' - ], - #category : #InteractiveNotebookPresenter -} - -{ #category : #utilities } -INNotebookIcons class >> buildCache [ - - (Pragma allNamed: #icon in: self class) do: [ :pragma | - pragma method selector value: self ] -] - -{ #category : #'icon creation' } -INNotebookIcons class >> iconAddAbove [ - - - ^ self icons at: #addAbove ifAbsentPut: [ - Form - extent: 16 @ 16 - depth: 32 - fromArray: - #( 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16rFF404040 16rFF404040 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16rFF404040 - 16rFF404040 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16rFF404040 16rFF404040 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16rFF404040 16rFF404040 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16rFF404040 - 16rFF404040 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16rFF404040 16rFF404040 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16rFF404040 16rFF404040 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16rFF404040 16rFF404040 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 ) - offset: 0 @ 0 ] -] - -{ #category : #'icon creation' } -INNotebookIcons class >> iconAddBelow [ - - - ^ self icons at: #addBelow ifAbsentPut: [ - Form - extent: 16 @ 16 - depth: 32 - fromArray: - #( 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16rFF404040 16rFF404040 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16rFF404040 16rFF404040 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16rFF404040 - 16rFF404040 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16rFF404040 16rFF404040 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16rFF404040 16rFF404040 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16rFF404040 - 16rFF404040 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16rFF404040 16rFF404040 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16rFF404040 16rFF404040 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 ) - offset: 0 @ 0 ] -] - -{ #category : #utilities } -INNotebookIcons class >> iconDown [ - - - ^ self icons at: #down ifAbsentPut: [ - Form - extent: 16 @ 16 - depth: 32 - fromArray: - #( 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r40404040 16rFF404040 16r40404040 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r40404040 16rFF404040 16r40404040 16r00000000 16r00000000 - 16r00000000 16r00000000 16r40404040 16rFF404040 16rFF404040 - 16r40404040 16r00000000 16r00000000 16r00000000 16r00000000 - 16r40404040 16rFF404040 16rFF404040 16r40404040 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r40404040 - 16rFF404040 16rFF404040 16r40404040 16r00000000 16r00000000 - 16r40404040 16rFF404040 16rFF404040 16r40404040 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r40404040 16rFF404040 16rFF404040 16r40404040 - 16r40404040 16rFF404040 16rFF404040 16r40404040 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r40404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16r40404040 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r40404040 16rFF404040 16rFF404040 16r40404040 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r40404040 16r40404040 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 ) - offset: 0 @ 0 ] -] - -{ #category : #'icon creation' } -INNotebookIcons class >> iconRemove [ - - - ^ self icons at: #remove ifAbsentPut: [ - Form - extent: 16 @ 16 - depth: 32 - fromArray: - #( 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 2130706432 4278190080 4278190080 4278190080 - 4278190080 4278190080 4278190080 2130706432 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 2130706432 4278190080 4278190080 4278190080 4278190080 - 4278190080 4278190080 2130706432 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 16777215 - 16777215 16777215 16777215 16777215 16777215 ) - offset: 0 @ 0 ] -] - -{ #category : #'icon creation' } -INNotebookIcons class >> iconTrash [ - - - ^ self icons at: #trash ifAbsentPut: [ - Form - extent: 16 @ 16 - depth: 32 - fromArray: - #( 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16r00000000 16r00000000 16r00000000 16r00000000 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16rFF404040 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 ) - offset: 0 @ 0 ] -] - -{ #category : #'icon creation' } -INNotebookIcons class >> iconUp [ - - - ^ self icons at: #up ifAbsentPut: [ - Form - extent: 16 @ 16 - depth: 32 - fromArray: - #( 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r40404040 16r40404040 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r40404040 16rFF404040 16rFF404040 16r40404040 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r40404040 16rFF404040 16rFF404040 16rFF404040 - 16rFF404040 16r40404040 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r40404040 16rFF404040 16rFF404040 16r40404040 - 16r40404040 16rFF404040 16rFF404040 16r40404040 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r40404040 16rFF404040 16rFF404040 16r40404040 - 16r00000000 16r00000000 16r40404040 16rFF404040 16rFF404040 - 16r40404040 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r40404040 16rFF404040 16rFF404040 16r40404040 - 16r00000000 16r00000000 16r00000000 16r00000000 16r40404040 - 16rFF404040 16rFF404040 16r40404040 16r00000000 16r00000000 - 16r00000000 16r00000000 16r40404040 16rFF404040 16r40404040 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r40404040 16rFF404040 16r40404040 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 16r00000000 16r00000000 16r00000000 16r00000000 - 16r00000000 ) - offset: 0 @ 0 ] -] - -{ #category : #utilities } -INNotebookIcons class >> icons [ - - ^ icons ifNil: [ - icons := Dictionary new. - self buildCache. - icons ] -] - -{ #category : #import } -INNotebookIcons class >> importIcons: iconCollection fromFolder: aString inClass: aClass category: aCategory [ - iconCollection - do: [:each | - | method form | - form := PNGReadWriter formFromFileNamed: aString, '/', each , '.png'. - method := each , Character cr asString , - ('^ self icons - at: #', each , - ' ifAbsentPut: ['), - form storeString, - ']'. - aClass compile: method classified: aCategory ] -] - -{ #category : #utilities } -INNotebookIcons class >> resetIcons [ - -