Finally! Node edition is working after a big simplification :-).

This commit is contained in:
Offray Vladimir Luna Cárdenas 2016-09-09 11:39:47 +00:00
parent 283a4523fd
commit 9c613ddf84
4 changed files with 95 additions and 79 deletions

View File

@ -237,12 +237,6 @@ GrafoscopioBrowser >> exportAsLatex [
] ]
] ]
{ #category : #persistence }
GrafoscopioBrowser >> exportAsMarkdown: aTree on: locator [
locator writeStreamDo: [:stream | stream nextPutAll: aTree asMarkdown]
]
{ #category : #persistence } { #category : #persistence }
GrafoscopioBrowser >> exportAsPdf [ GrafoscopioBrowser >> exportAsPdf [
"Exports the current tree to HTML, using the same name but different extension (.pdf). "Exports the current tree to HTML, using the same name but different extension (.pdf).

View File

@ -196,7 +196,7 @@ GrafoscopioNode >> becomeDefaultTree [
self level: 0. self level: 0.
self header: 'Arbol principal'. self header: 'Arbol principal'.
node1 := GrafoscopioNode node1 := GrafoscopioNode
header: 'Nodo 1' header: 'Node 1'
body: ''. body: ''.
self addNode: node1. self addNode: node1.
] ]
@ -265,7 +265,7 @@ GrafoscopioNode >> exportCodeBlockTo: aStream [
"I convert the content of a node taged as 'código' (code) as pandoc markdown and put it Into aStream. "I convert the content of a node taged as 'código' (code) as pandoc markdown and put it Into aStream.
The code block is decorated with LaTeX commands for proper syntax highlighting using pygments. The code block is decorated with LaTeX commands for proper syntax highlighting using pygments.
Pdf exportation requires the installation of pygments and minted package for latex" Pdf exportation requires the installation of pygments and minted package for latex"
aStream nextPutAll: ('\begin{minted}{smalltalk}[frame=lines]'); lf. aStream nextPutAll: ('\begin{minted}{smalltalk}'); lf.
aStream nextPutAll: (self body contents withInternetLineEndings); lf. aStream nextPutAll: (self body contents withInternetLineEndings); lf.
aStream nextPutAll: '\end{minted}';lf;lf. aStream nextPutAll: '\end{minted}';lf;lf.
^aStream contents ^aStream contents
@ -277,6 +277,7 @@ GrafoscopioNode >> exportPreambleTo: aStream [
| configDict | | configDict |
aStream nextPutAll: '---'; lf. aStream nextPutAll: '---'; lf.
aStream nextPutAll: 'header-includes:'; lf. aStream nextPutAll: 'header-includes:'; lf.
aStream nextPutAll: ' - \documentclass{article}'; lf.
aStream nextPutAll: ' - \usepackage{minted}'; lf. aStream nextPutAll: ' - \usepackage{minted}'; lf.
aStream nextPutAll: ' - \usemintedstyle{friendly}'; lf. aStream nextPutAll: ' - \usemintedstyle{friendly}'; lf.
(self header = '%config') (self header = '%config')

View File

@ -46,12 +46,29 @@ GrafoscopioNotebook class >> defaultSpec [
bc add: #body ]]] bc add: #body ]]]
] ]
{ #category : #operation } { #category : #'editing nodes' }
GrafoscopioNotebook >> addNode [ GrafoscopioNotebook >> addNode [
| addedNode | | addedNode |
tree needRebuild: true.
addedNode := tree highlightedItem content addNodeAfterMe. addedNode := tree highlightedItem content addNodeAfterMe.
self updateTreeEditing: addedNode self notebookContent: notebook.
]
{ #category : #operation }
GrafoscopioNotebook >> autoSaveBodyOf: aNode [
body body class = TextModel
ifTrue: [ body body whenTextChanged: [ :arg | aNode body: arg ] ].
body body class = GlamourPresentationModel
ifTrue: [ | playground |
playground := body body glmPres.
playground
when: GLMContextChanged
do: [ :ann |
ann property = #text
ifTrue: [ | playgroundText |
playgroundText := (playground pane ports at: 2) value.
aNode body: playgroundText ]
]
]
] ]
{ #category : #accessing } { #category : #accessing }
@ -64,36 +81,28 @@ GrafoscopioNotebook >> body: anObject [
body := anObject body := anObject
] ]
{ #category : #operation } { #category : #'editing nodes' }
GrafoscopioNotebook >> changeBody: aNode [
self needRebuild: false.
tree needRebuild: false.
body needRebuild: true.
body := self instantiate: aNode content specModelClass new.
body content: aNode content.
body body class = TextModel
ifTrue: [body body whenTextChanged: [ :arg | aNode content body: arg ]].
body body class = GlamourPresentationModel
ifTrue: [ | playground |
playground := body body glmPres.
playground when: GLMContextChanged
do: [ :ann | ann property = #text
ifTrue: [ | playgroundText |
playgroundText := (playground pane ports at: 2) value.
aNode content body: playgroundText]
]
].
header text: aNode content header.
self buildWithSpecLayout: self class defaultSpec.
]
{ #category : #operation }
GrafoscopioNotebook >> demoteNode [ GrafoscopioNotebook >> demoteNode [
| currentContent | | editedNode |
currentContent := tree highlightedItem content. editedNode := tree highlightedItem content.
currentContent demote. editedNode demote.
self updateTreeEditing: currentContent self notebookContent: notebook.
]
{ #category : #persistence }
GrafoscopioNotebook >> exportAsMarkdown [
"I save the current tree/document to a file"
| markdownFile |
workingFile
ifNil: [ self inform: 'File NOT exported. Please save the notebook on hard drive first' ]
ifNotNil: [
markdownFile := (((workingFile parent) / workingFile basenameWithoutExtension) fullName, '.markdown') asFileReference.
markdownFile exists ifTrue: [ markdownFile delete ].
markdownFile ensureCreateFile.
markdownFile writeStreamDo: [:stream | stream nextPutAll: self notebook asMarkdown].
"[ self exportAsMarkdown: self notebook on: ( markdownFile writeStream )]
ensure: [ (markdownFile writeStream) ifNotNil: #close ]."
self inform: ('File exported as: ', String cr, markdownFile fullName)]
] ]
{ #category : #persistence } { #category : #persistence }
@ -129,21 +138,22 @@ GrafoscopioNotebook >> highlightItemFor: nodeContent [
| currentItem | | currentItem |
currentItem := tree highlightedItem. currentItem := tree highlightedItem.
currentItem currentItem
ifNotNil: [ | allItems index childrenSize parentNode | ifNotNil: [ | allItems allContents index childrenSize parentNode |
currentItem parentNode currentItem parentNode
ifNil: [ ifNil: [
parentNode := currentItem container. parentNode := currentItem container.
allItems := parentNode roots ] allItems := parentNode roots ]
ifNotNil: [ ifNotNil: [
parentNode := currentItem parentNode. parentNode := currentItem parentNode.
allItems := parentNode children value. ]. allItems := parentNode children value ].
allContents := allItems collect: [ :each | each content ].
childrenSize := currentItem content parent children size. childrenSize := currentItem content parent children size.
index := allItems indexOf: currentItem. index := allContents indexOf: currentItem content.
(index < childrenSize) ifTrue: [ (index < childrenSize) ifTrue: [
currentItem ifNotNil: [currentItem selected: false]. currentItem := (allItems at:(index+1)) selected: true.
parentNode "currentItem := parentNode highlightedItem: ((allItems at:(index+1)) selected:true;
highlightedItem: ((allItems at:(index+1)) selected:true; takeHighlight;yourself); yourself."
takeHighlight;yourself). { parentNode . currentItem . nodeContent } inspect.
] ]
] ]
] ]
@ -175,7 +185,12 @@ GrafoscopioNotebook >> highlightNextItem [
{ #category : #initialization } { #category : #initialization }
GrafoscopioNotebook >> initializePresenter [ GrafoscopioNotebook >> initializePresenter [
tree whenHighlightedItemChanged: [ :item | self updateBodyFor: item]. tree whenHighlightedItemChanged: [ :item |
tree highlightedItem ifNotNil: [
self inform: item content header.
self updateBodyFor: item].
].
tree whenTreeUpdated: [ :item | item ifNotNil: [self updateBodyFor: item]].
header whenTextChanged: [ :arg | header whenTextChanged: [ :arg |
(tree highlightedItem content header) = arg (tree highlightedItem content header) = arg
ifFalse: [ (tree highlightedItem) content header: arg. ifFalse: [ (tree highlightedItem) content header: arg.
@ -200,20 +215,20 @@ GrafoscopioNotebook >> initializeWidgets [
add: body. add: body.
] ]
{ #category : #operation } { #category : #'editing nodes' }
GrafoscopioNotebook >> moveNodeAfter [ GrafoscopioNotebook >> moveNodeAfter [
| currentContent | | editedNode |
currentContent := tree selectedItem content. editedNode := tree selectedItem content.
currentContent moveAfter. editedNode moveAfter.
self updateTreeEditing: currentContent self notebookContent: notebook
] ]
{ #category : #operation } { #category : #'editing nodes' }
GrafoscopioNotebook >> moveNodeBefore [ GrafoscopioNotebook >> moveNodeBefore [
| currentContent | | editedNode |
currentContent := tree selectedItem content. editedNode := tree highlightedItem content.
currentContent moveBefore. editedNode moveBefore.
self updateTreeEditing: currentContent self notebookContent: notebook
] ]
{ #category : #initialization } { #category : #initialization }
@ -353,6 +368,11 @@ GrafoscopioNotebook >> notebookSubMenu [
name: 'Save as...'; name: 'Save as...';
icon: Smalltalk ui icons smallSaveAsIcon; icon: Smalltalk ui icons smallSaveAsIcon;
action: [ self saveToFileUI ] ]. action: [ self saveToFileUI ] ].
group addItem: [ :item |
item
name: 'Export as markdown';
icon: Smalltalk ui icons smallSaveAsIcon;
action: [ self exportAsMarkdown ] ].
group addItem: [ :item | group addItem: [ :item |
item item
name: 'Export as html'; name: 'Export as html';
@ -487,15 +507,15 @@ GrafoscopioNotebook >> projectSubMenu [
] ]
{ #category : #operation } { #category : #'editing nodes' }
GrafoscopioNotebook >> promoteNode [ GrafoscopioNotebook >> promoteNode [
| currentContent | | editedNote |
currentContent := tree selectedItem content. editedNote := tree selectedItem content.
currentContent promote. editedNote promote.
self updateTreeEditing: currentContent self notebookContent: notebook
] ]
{ #category : #operation } { #category : #'editing nodes' }
GrafoscopioNotebook >> removeNode [ GrafoscopioNotebook >> removeNode [
| contentToDelete parentContent newSelectedContent children | | contentToDelete parentContent newSelectedContent children |
contentToDelete := tree selectedItem content. contentToDelete := tree selectedItem content.
@ -508,7 +528,7 @@ GrafoscopioNotebook >> removeNode [
] ]
ifFalse: [ newSelectedContent := parentContent ]. ifFalse: [ newSelectedContent := parentContent ].
contentToDelete parent removeNode: contentToDelete. contentToDelete parent removeNode: contentToDelete.
self updateTreeEditing: newSelectedContent self notebookContent: notebook
] ]
{ #category : #persistence } { #category : #persistence }
@ -552,14 +572,14 @@ GrafoscopioNotebook >> saveWorkingNotebook [
] ]
{ #category : #operation } { #category : #'editing nodes' }
GrafoscopioNotebook >> toggleCodeNode [ GrafoscopioNotebook >> toggleCodeNode [
| currentNode | | currentNode |
currentNode := tree highlightedItem. currentNode := tree highlightedItem.
(currentNode content tags = 'código') (currentNode content tags = 'código')
ifTrue: [ currentNode content tagAs: '' ] ifTrue: [ currentNode content tagAs: '' ]
ifFalse: [ currentNode content tagAs: 'código' ]. ifFalse: [ currentNode content tagAs: 'código' ].
self changeBody: currentNode. self updateBodyFor: currentNode.
] ]
{ #category : #accessing } { #category : #accessing }
@ -573,17 +593,17 @@ GrafoscopioNotebook >> tree: anObject [
] ]
{ #category : #operation } { #category : #operation }
GrafoscopioNotebook >> updateBodyFor: item [ GrafoscopioNotebook >> updateBodyFor: aNodeContainer [
item | aNode |
ifNotNil: [ self changeBody: item ] self needRebuild: false.
ifNil: [ "self inform: 'Select a node.'" ] tree needRebuild: false.
] body needRebuild: true.
aNode := aNodeContainer content.
{ #category : #operation } header text: aNode header.
GrafoscopioNotebook >> updateTreeEditing: currentContent [ body := self instantiate: aNode specModelClass new.
self notebookContent: notebook. body content: aNode body.
self highlightItemFor: currentContent. self inform: aNode body.
tree needRebuild: true. self autoSaveBodyOf: aNode.
self buildWithSpecLayout: self class defaultSpec self buildWithSpecLayout: self class defaultSpec
] ]

View File

@ -33,4 +33,5 @@ GrafoscopioTextModel >> initializeWidgets [
body := self newText. body := self newText.
body beForText. body beForText.
body autoAccept: true.
] ]