Making notebook to work in pharo 8

This commit is contained in:
Santiago Bragagnolo 2020-02-24 13:15:10 +00:00 committed by Offray Luna
parent bb9dda9eef
commit 4b59a7cd30
11 changed files with 193 additions and 86 deletions

View File

@ -120,6 +120,11 @@ GrafoscopioAbstractNode >> initialize [
edited := DateAndTime now edited := DateAndTime now
] ]
{ #category : #accessing }
GrafoscopioAbstractNode >> isLeaf [
^ true
]
{ #category : #accessing } { #category : #accessing }
GrafoscopioAbstractNode >> level [ GrafoscopioAbstractNode >> level [
"Returns the level of the node. See the setter message for details" "Returns the level of the node. See the setter message for details"
@ -189,7 +194,7 @@ GrafoscopioAbstractNode >> shouldAskBeforeRemove [
{ #category : #'as yet unclassified' } { #category : #'as yet unclassified' }
GrafoscopioAbstractNode >> specModelClass [ GrafoscopioAbstractNode >> specModelClass [
^ GrafoscopioTextModel ^ GrafoscopioNewTextModel
] ]
{ #category : #accessing } { #category : #accessing }

View File

@ -4,7 +4,7 @@ embedded interactive Playground.
" "
Class { Class {
#name : #GrafoscopioCodeModel, #name : #GrafoscopioCodeModel,
#superclass : #SpPresenter, #superclass : #ComposablePresenter,
#instVars : [ #instVars : [
'body' 'body'
], ],

View File

@ -1,6 +1,6 @@
Class { Class {
#name : #GrafoscopioCodeNode, #name : #GrafoscopioCodeNode,
#superclass : #GrafoscopioAbstractNode, #superclass : #GrafoscopioTrunkNode,
#instVars : [ #instVars : [
'icon', 'icon',
'body' 'body'
@ -35,5 +35,5 @@ GrafoscopioCodeNode >> shouldAskBeforeRemove [
{ #category : #'as yet unclassified' } { #category : #'as yet unclassified' }
GrafoscopioCodeNode >> specModelClass [ GrafoscopioCodeNode >> specModelClass [
^ GrafoscopioCodeModel ^ GrafoscopioNewCodeModel
] ]

View File

@ -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.
]

View File

@ -26,7 +26,7 @@ Class {
#classInstVars : [ #classInstVars : [
'recents' 'recents'
], ],
#category : 'Grafoscopio-UI' #category : 'Grafoscopio-New-UI'
} }
{ #category : #utility } { #category : #utility }
@ -112,30 +112,6 @@ GrafoscopioNewNotebook >> askToSaveBeforeClosing [
^ saveChanges ^ 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 } { #category : #accessing }
GrafoscopioNewNotebook >> body [ GrafoscopioNewNotebook >> body [
^ body ^ body
@ -530,9 +506,13 @@ GrafoscopioNewNotebook >> initializePresenter [
header header
whenTextChangedDo: [ :arg | whenTextChangedDo: [ :arg |
tree selectedItem header = arg tree selectedItem header = arg
ifFalse: [ tree selectedItem header: arg. ifFalse: [
| item |
item := tree selectedItem.
tree selectedItem header: arg.
tree selectedItem updateEditionTimestamp. tree selectedItem updateEditionTimestamp.
tree roots: tree roots ] ]. tree roots: tree roots.
tree selectItem:item ] ].
links links
whenTextChangedDo: [ :arg | whenTextChangedDo: [ :arg |
(tree respondsTo: #link:) (tree respondsTo: #link:)
@ -554,7 +534,10 @@ GrafoscopioNewNotebook >> initializeWidgets [
tree := self newTreeTable. tree := self newTreeTable.
tree tree
addColumn: (SpStringTableColumn evaluated: #title); addColumn: (SpStringTableColumn evaluated: #title);
children: [ : node | node children ]. children: [ :node |
node isLeaf
ifTrue: [ {} ]
ifFalse: [ node children ] ].
" tree " tree
childrenBlock: [ :node | node children value ]; childrenBlock: [ :node | node children value ];
displayBlock: [ :node | node title value ]." displayBlock: [ :node | node title value ]."
@ -1265,11 +1248,14 @@ GrafoscopioNewNotebook >> tree: anObject [
{ #category : #operation } { #category : #operation }
GrafoscopioNewNotebook >> updateBodyFor: aNode [ GrafoscopioNewNotebook >> updateBodyFor: aNode [
| item |
self needRebuild: false. self needRebuild: false.
tree needRebuild: false. tree needRebuild: false.
item := tree selectedItem.
body needRebuild: true. body needRebuild: true.
aNode openIn: self. aNode openIn: self.
self buildWithSpec self buildWithSpec.
tree selectItem: item.
] ]
{ #category : #operation } { #category : #operation }

View File

@ -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.
]

View File

@ -108,24 +108,23 @@ GrafoscopioNotebook >> autoSaveBodyOf: aNode [
| playground bodyContents | | playground bodyContents |
bodyContents := aNode body. bodyContents := aNode body.
self body class = GrafoscopioTextModel self body class = GrafoscopioTextModel
ifTrue: [ self body body whenTextChanged: [ :arg | ifTrue: [ self body body
aNode body: arg. whenTextChangedDo: [ :arg |
"self body body whenTextIsAccepted: [:bodyText | aNode body: arg.
"self body body whenTextIsAccepted: [:bodyText |
self inform: bodyText. self inform: bodyText.
aNode updateEditionTimestamp ]." aNode updateEditionTimestamp ]."
bodyContents = arg ifFalse: [ bodyContents = arg
"self inform: arg." ifFalse: [ "self inform: arg.""aNode updateEditionTimestamp" ] ] ].
"aNode updateEditionTimestamp" ]]].
self body body class = GlamourPresentationModel self body body class = GlamourPresentationModel
ifFalse: [ ^ self ]. ifFalse: [ ^ self ].
playground := self body body glmPres. playground := self body body glmPres.
playground playground
onChangeOfPort: #text onChangeOfPort: #text
act: [ :x | act: [ :x |
aNode body: (x pane port: #entity) value content. aNode body: (x pane port: #entity) value content
"aNode updateEditionTimestamp." "aNode updateEditionTimestamp."
"self inform: aNode edited" ] "self inform: aNode edited" ]
] ]
{ #category : #accessing } { #category : #accessing }
@ -521,21 +520,21 @@ GrafoscopioNotebook >> initializeWidgets [
header := self newTextInput. header := self newTextInput.
header autoAccept: true. header autoAccept: true.
body := self newText. body := self newText.
body class logCr. body class traceCr.
body disable. body disable.
body text: '<- Select a node'. body text: '<- Select a node'.
body autoAccept: true. body autoAccept: true.
links := self newTextInput. links := self newTextInput.
tree := self newTree. tree := self newTree.
tree tree
childrenBlock: [:node | node children]; childrenBlock: [ :node | node children ];
displayBlock: [:node | node title ]. displayBlock: [ :node | node title ].
self focusOrder self focusOrder
add: tree; add: tree;
add: header; add: header;
add: body; add: body;
add: links. add: links.
self askOkToClose: true. self askOkToClose: true
] ]
{ #category : #persistence } { #category : #persistence }
@ -1207,7 +1206,7 @@ GrafoscopioNotebook >> updateBodyFor: aNodeContainer [
body := self instantiate: aNode specModelClass new. body := self instantiate: aNode specModelClass new.
body content: aNode body. body content: aNode body.
links text: aNode lastLink. links text: aNode lastLink.
self autoSaveBodyOf: aNode.
self buildWithSpecLayout: self class defaultSpec self buildWithSpecLayout: self class defaultSpec
] ]

View File

@ -4,7 +4,7 @@ Usually my content is markdown text.
" "
Class { Class {
#name : #GrafoscopioTextModel, #name : #GrafoscopioTextModel,
#superclass : #SpPresenter, #superclass : #ComposablePresenter,
#instVars : [ #instVars : [
'body' 'body'
], ],

View File

@ -10,12 +10,11 @@ node
" "
Class { Class {
#name : #GrafoscopioTextNode, #name : #GrafoscopioTextNode,
#superclass : #GrafoscopioAbstractNode, #superclass : #GrafoscopioTrunkNode,
#instVars : [ #instVars : [
'key', 'key',
'icon', 'icon',
'body', 'body',
'children',
'links' 'links'
], ],
#classInstVars : [ #classInstVars : [
@ -257,21 +256,6 @@ GrafoscopioTextNode >> checksumForRootSubtree [
"^ (SHA1 new hashMessage: self root flatten asStonFromRoot) hex" "^ (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' } { #category : #'as yet unclassified' }
GrafoscopioTextNode >> content [ GrafoscopioTextNode >> content [
^ body ^ body
@ -730,27 +714,9 @@ GrafoscopioTextNode >> metadataAsYamlIn: markdownStream [
nextPutAll: String cr, String cr. 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 } { #category : #accessing }
GrafoscopioTextNode >> openIn: aNotebook [ GrafoscopioTextNode >> openIn: aNotebook [
super openIn: aNotebook. super openIn: aNotebook.
aNotebook autoSaveBodyOf: self.
aNotebook links text: self lastLink aNotebook links text: self lastLink
] ]
@ -898,7 +864,7 @@ GrafoscopioTextNode >> shouldAskBeforeRemove [
GrafoscopioTextNode >> specModelClass [ GrafoscopioTextNode >> specModelClass [
"por defecto" "por defecto"
^ GrafoscopioTextModel ^ GrafoscopioNewTextModel
] ]
{ #category : #operation } { #category : #operation }

View File

@ -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)
]

View File

@ -7,6 +7,13 @@ Class {
#category : 'Grafoscopio-Model' #category : 'Grafoscopio-Model'
} }
{ #category : #'instance creation' }
GrafoscopioUrlNode class >> new [
^ super new
content;
yourself
]
{ #category : #'as yet unclassified' } { #category : #'as yet unclassified' }
GrafoscopioUrlNode >> content [ GrafoscopioUrlNode >> content [
^ (self url ^ (self url