diff --git a/src/Grafoscopio/GrafoscopioAbstractNode.class.st b/src/Grafoscopio/GrafoscopioAbstractNode.class.st index 8869ccd..57854ea 100644 --- a/src/Grafoscopio/GrafoscopioAbstractNode.class.st +++ b/src/Grafoscopio/GrafoscopioAbstractNode.class.st @@ -120,6 +120,11 @@ GrafoscopioAbstractNode >> initialize [ edited := DateAndTime now ] +{ #category : #accessing } +GrafoscopioAbstractNode >> isLeaf [ + ^ true +] + { #category : #accessing } GrafoscopioAbstractNode >> level [ "Returns the level of the node. See the setter message for details" @@ -189,7 +194,7 @@ GrafoscopioAbstractNode >> shouldAskBeforeRemove [ { #category : #'as yet unclassified' } GrafoscopioAbstractNode >> specModelClass [ - ^ GrafoscopioTextModel + ^ GrafoscopioNewTextModel ] { #category : #accessing } diff --git a/src/Grafoscopio/GrafoscopioCodeModel.class.st b/src/Grafoscopio/GrafoscopioCodeModel.class.st index 4656741..42e7942 100644 --- a/src/Grafoscopio/GrafoscopioCodeModel.class.st +++ b/src/Grafoscopio/GrafoscopioCodeModel.class.st @@ -4,7 +4,7 @@ embedded interactive Playground. " Class { #name : #GrafoscopioCodeModel, - #superclass : #SpPresenter, + #superclass : #ComposablePresenter, #instVars : [ 'body' ], diff --git a/src/Grafoscopio/GrafoscopioCodeNode.class.st b/src/Grafoscopio/GrafoscopioCodeNode.class.st index f3a35a7..877a72b 100644 --- a/src/Grafoscopio/GrafoscopioCodeNode.class.st +++ b/src/Grafoscopio/GrafoscopioCodeNode.class.st @@ -1,6 +1,6 @@ Class { #name : #GrafoscopioCodeNode, - #superclass : #GrafoscopioAbstractNode, + #superclass : #GrafoscopioTrunkNode, #instVars : [ 'icon', 'body' @@ -35,5 +35,5 @@ GrafoscopioCodeNode >> shouldAskBeforeRemove [ { #category : #'as yet unclassified' } GrafoscopioCodeNode >> specModelClass [ - ^ GrafoscopioCodeModel + ^ GrafoscopioNewCodeModel ] diff --git a/src/Grafoscopio/GrafoscopioNewCodeModel.class.st b/src/Grafoscopio/GrafoscopioNewCodeModel.class.st new file mode 100644 index 0000000..56718e5 --- /dev/null +++ b/src/Grafoscopio/GrafoscopioNewCodeModel.class.st @@ -0,0 +1,62 @@ +Class { + #name : #GrafoscopioNewCodeModel, + #superclass : #SpPresenter, + #instVars : [ + 'body' + ], + #category : #'Grafoscopio-New-UI' +} + +{ #category : #specs } +GrafoscopioNewCodeModel class >> defaultSpec [ + ^ SpBoxLayout newVertical + add: #body; + yourself +] + +{ #category : #accessing } +GrafoscopioNewCodeModel >> body [ + ^ body +] + +{ #category : #accessing } +GrafoscopioNewCodeModel >> body: anObject [ + body := anObject +] + +{ #category : #API } +GrafoscopioNewCodeModel >> content: aGrafoscopioNodeContent [ + body text: aGrafoscopioNodeContent +] + +{ #category : #'as yet unclassified' } +GrafoscopioNewCodeModel >> extractHtmlImages [ + "comment stating purpose of message" + |imgSoup imgHost imgList src| + + imgList := Set new. + imgSoup := Soup fromString: self body. + (imgSoup findAllTags: 'img') do: [ :each| + src := (each attributeAt: 'src') asUrl. + (src host) ifNil: [src host: self links last asUrl removeLastPathSegment]. + imgList add: src. + "imgList add: (each attributeAt: 'src') asUrl." + + "OSProcess waitForCommand: 'wget ', (each attributeAt: 'src')." + "imgHost := self links last removeLastPathSegment." + + "imgPath:= ((each attributeAt: 'src') asUrl). " + "ZnEasy getJpeg: (imgHost , imgPath) asUrl." + + "OSProcess waitForCommand: ('mkdir ', imgPath)." + + "Transcript show: ' wget ', imgPath , '/',(each attributeAt: 'src'). " + ]. + ^imgList . +] + +{ #category : #initialization } +GrafoscopioNewCodeModel >> initializeWidgets [ + + body := self newCode. +] diff --git a/src/Grafoscopio/GrafoscopioNewNotebook.class.st b/src/Grafoscopio/GrafoscopioNewNotebook.class.st index a884fdb..6bb6e18 100644 --- a/src/Grafoscopio/GrafoscopioNewNotebook.class.st +++ b/src/Grafoscopio/GrafoscopioNewNotebook.class.st @@ -26,7 +26,7 @@ Class { #classInstVars : [ 'recents' ], - #category : #'Grafoscopio-UI' + #category : #'Grafoscopio-New-UI' } { #category : #utility } @@ -112,30 +112,6 @@ GrafoscopioNewNotebook >> askToSaveBeforeClosing [ ^ saveChanges ] -{ #category : #operation } -GrafoscopioNewNotebook >> autoSaveBodyOf: aNode [ - | playground bodyContents | - bodyContents := aNode content. - self body class = GrafoscopioTextModel - ifTrue: [ self body body - whenTextChangedDo: [ :arg | - aNode content: arg. - "self body body whenTextIsAccepted: [:bodyText | - self inform: bodyText. - aNode updateEditionTimestamp ]." - bodyContents = arg - ifFalse: [ "self inform: arg.""aNode updateEditionTimestamp" ] ] ]. - self body body class = GlamourPresentationModel - ifFalse: [ ^ self ]. - playground := self body body glmPres. - playground - onChangeOfPort: #text - act: [ :x | - aNode content: (x pane port: #entity) value content - "aNode updateEditionTimestamp." - "self inform: aNode edited" ] -] - { #category : #accessing } GrafoscopioNewNotebook >> body [ ^ body @@ -530,9 +506,13 @@ GrafoscopioNewNotebook >> initializePresenter [ header whenTextChangedDo: [ :arg | tree selectedItem header = arg - ifFalse: [ tree selectedItem header: arg. + ifFalse: [ + | item | + item := tree selectedItem. + tree selectedItem header: arg. tree selectedItem updateEditionTimestamp. - tree roots: tree roots ] ]. + tree roots: tree roots. + tree selectItem:item ] ]. links whenTextChangedDo: [ :arg | (tree respondsTo: #link:) @@ -554,7 +534,10 @@ GrafoscopioNewNotebook >> initializeWidgets [ tree := self newTreeTable. tree addColumn: (SpStringTableColumn evaluated: #title); - children: [ : node | node children ]. + children: [ :node | + node isLeaf + ifTrue: [ {} ] + ifFalse: [ node children ] ]. " tree childrenBlock: [ :node | node children value ]; displayBlock: [ :node | node title value ]." @@ -1265,11 +1248,14 @@ GrafoscopioNewNotebook >> tree: anObject [ { #category : #operation } GrafoscopioNewNotebook >> updateBodyFor: aNode [ + | item | self needRebuild: false. tree needRebuild: false. + item := tree selectedItem. body needRebuild: true. aNode openIn: self. - self buildWithSpec + self buildWithSpec. + tree selectItem: item. ] { #category : #operation } diff --git a/src/Grafoscopio/GrafoscopioNewTextModel.class.st b/src/Grafoscopio/GrafoscopioNewTextModel.class.st new file mode 100644 index 0000000..f812cbb --- /dev/null +++ b/src/Grafoscopio/GrafoscopioNewTextModel.class.st @@ -0,0 +1,37 @@ +Class { + #name : #GrafoscopioNewTextModel, + #superclass : #SpPresenter, + #instVars : [ + 'body' + ], + #category : #'Grafoscopio-New-UI' +} + +{ #category : #specs } +GrafoscopioNewTextModel class >> defaultSpec [ + ^ SpBoxLayout newVertical + add: #body; + yourself +] + +{ #category : #accessing } +GrafoscopioNewTextModel >> body [ + ^ body +] + +{ #category : #accessing } +GrafoscopioNewTextModel >> body: anObject [ + body := anObject +] + +{ #category : #API } +GrafoscopioNewTextModel >> content: aGrafoscopioNodeContent [ + body text: aGrafoscopioNodeContent +] + +{ #category : #initialization } +GrafoscopioNewTextModel >> initializeWidgets [ + + body := self newText. + body autoAccept: true. +] diff --git a/src/Grafoscopio/GrafoscopioNotebook.class.st b/src/Grafoscopio/GrafoscopioNotebook.class.st index 56836ed..953a52c 100644 --- a/src/Grafoscopio/GrafoscopioNotebook.class.st +++ b/src/Grafoscopio/GrafoscopioNotebook.class.st @@ -107,25 +107,24 @@ GrafoscopioNotebook >> askToSaveBeforeClosing [ GrafoscopioNotebook >> autoSaveBodyOf: aNode [ | playground bodyContents | bodyContents := aNode body. - self body class = GrafoscopioTextModel - ifTrue: [ self body body whenTextChanged: [ :arg | - aNode body: arg. - "self body body whenTextIsAccepted: [:bodyText | + self body class = GrafoscopioTextModel + ifTrue: [ self body body + whenTextChangedDo: [ :arg | + aNode body: arg. + "self body body whenTextIsAccepted: [:bodyText | self inform: bodyText. aNode updateEditionTimestamp ]." - bodyContents = arg ifFalse: [ - "self inform: arg." - "aNode updateEditionTimestamp" ]]]. + bodyContents = arg + ifFalse: [ "self inform: arg.""aNode updateEditionTimestamp" ] ] ]. self body body class = GlamourPresentationModel ifFalse: [ ^ self ]. playground := self body body glmPres. playground onChangeOfPort: #text act: [ :x | - aNode body: (x pane port: #entity) value content. + aNode body: (x pane port: #entity) value content "aNode updateEditionTimestamp." "self inform: aNode edited" ] - ] { #category : #accessing } @@ -521,21 +520,21 @@ GrafoscopioNotebook >> initializeWidgets [ header := self newTextInput. header autoAccept: true. body := self newText. - body class logCr. + body class traceCr. body disable. body text: '<- Select a node'. body autoAccept: true. links := self newTextInput. tree := self newTree. - tree - childrenBlock: [:node | node children]; - displayBlock: [:node | node title ]. - self focusOrder + tree + childrenBlock: [ :node | node children ]; + displayBlock: [ :node | node title ]. + self focusOrder add: tree; add: header; add: body; add: links. - self askOkToClose: true. + self askOkToClose: true ] { #category : #persistence } @@ -1207,7 +1206,7 @@ GrafoscopioNotebook >> updateBodyFor: aNodeContainer [ body := self instantiate: aNode specModelClass new. body content: aNode body. links text: aNode lastLink. - self autoSaveBodyOf: aNode. + self buildWithSpecLayout: self class defaultSpec ] diff --git a/src/Grafoscopio/GrafoscopioTextModel.class.st b/src/Grafoscopio/GrafoscopioTextModel.class.st index c1dc510..cec06fd 100644 --- a/src/Grafoscopio/GrafoscopioTextModel.class.st +++ b/src/Grafoscopio/GrafoscopioTextModel.class.st @@ -4,7 +4,7 @@ Usually my content is markdown text. " Class { #name : #GrafoscopioTextModel, - #superclass : #SpPresenter, + #superclass : #ComposablePresenter, #instVars : [ 'body' ], diff --git a/src/Grafoscopio/GrafoscopioTextNode.class.st b/src/Grafoscopio/GrafoscopioTextNode.class.st index 9edf58a..24f9aa9 100644 --- a/src/Grafoscopio/GrafoscopioTextNode.class.st +++ b/src/Grafoscopio/GrafoscopioTextNode.class.st @@ -10,12 +10,11 @@ node " Class { #name : #GrafoscopioTextNode, - #superclass : #GrafoscopioAbstractNode, + #superclass : #GrafoscopioTrunkNode, #instVars : [ 'key', 'icon', 'body', - 'children', 'links' ], #classInstVars : [ @@ -257,21 +256,6 @@ GrafoscopioTextNode >> checksumForRootSubtree [ "^ (SHA1 new hashMessage: self root flatten asStonFromRoot) hex" ] -{ #category : #accessing } -GrafoscopioTextNode >> children [ - "Returns the receivers list of children" - - ^ children ifNil: [ children := OrderedCollection new ] -] - -{ #category : #accessing } -GrafoscopioTextNode >> children: aCollection [ - "Sets the receivers children" - - aCollection do: [:currentNode | currentNode parent: self ]. - children := aCollection. -] - { #category : #'as yet unclassified' } GrafoscopioTextNode >> content [ ^ body @@ -730,27 +714,9 @@ GrafoscopioTextNode >> metadataAsYamlIn: markdownStream [ nextPutAll: String cr, String cr. ] -{ #category : #movement } -GrafoscopioTextNode >> moveDown: aNode [ - | index | - "Moves the current node a place before in the children collection where is located" - index := (children indexOf: aNode) max: 1 . - - children swap: index with: (index + 1 min: children size) -] - -{ #category : #movement } -GrafoscopioTextNode >> moveUp: aNode [ - | index | - "Moves the current node a place before in the children collection where is located" - index := children indexOf: aNode. - children swap: index with: (index - 1 max: 1) -] - { #category : #accessing } GrafoscopioTextNode >> openIn: aNotebook [ super openIn: aNotebook. - aNotebook autoSaveBodyOf: self. aNotebook links text: self lastLink ] @@ -898,7 +864,7 @@ GrafoscopioTextNode >> shouldAskBeforeRemove [ GrafoscopioTextNode >> specModelClass [ "por defecto" - ^ GrafoscopioTextModel + ^ GrafoscopioNewTextModel ] { #category : #operation } diff --git a/src/Grafoscopio/GrafoscopioTrunkNode.class.st b/src/Grafoscopio/GrafoscopioTrunkNode.class.st new file mode 100644 index 0000000..58d4762 --- /dev/null +++ b/src/Grafoscopio/GrafoscopioTrunkNode.class.st @@ -0,0 +1,45 @@ +Class { + #name : #GrafoscopioTrunkNode, + #superclass : #GrafoscopioAbstractNode, + #instVars : [ + 'children' + ], + #category : #'Grafoscopio-Model' +} + +{ #category : #accessing } +GrafoscopioTrunkNode >> children [ + "Returns the receivers list of children" + + ^ children ifNil: [ children := OrderedCollection new ] +] + +{ #category : #accessing } +GrafoscopioTrunkNode >> children: aCollection [ + "Sets the receivers children" + + aCollection do: [:currentNode | currentNode parent: self ]. + children := aCollection. +] + +{ #category : #accessing } +GrafoscopioTrunkNode >> isLeaf [ + ^ false +] + +{ #category : #movement } +GrafoscopioTrunkNode >> moveDown: aNode [ + | index | + "Moves the current node a place before in the children collection where is located" + index := (children indexOf: aNode) max: 1 . + + children swap: index with: (index + 1 min: children size) +] + +{ #category : #movement } +GrafoscopioTrunkNode >> moveUp: aNode [ + | index | + "Moves the current node a place before in the children collection where is located" + index := children indexOf: aNode. + children swap: index with: (index - 1 max: 1) +] diff --git a/src/Grafoscopio/GrafoscopioUrlNode.class.st b/src/Grafoscopio/GrafoscopioUrlNode.class.st index 9340717..0928afd 100644 --- a/src/Grafoscopio/GrafoscopioUrlNode.class.st +++ b/src/Grafoscopio/GrafoscopioUrlNode.class.st @@ -7,6 +7,13 @@ Class { #category : #'Grafoscopio-Model' } +{ #category : #'instance creation' } +GrafoscopioUrlNode class >> new [ + ^ super new + content; + yourself +] + { #category : #'as yet unclassified' } GrafoscopioUrlNode >> content [ ^ (self url