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 }
GrafoscopioBrowser >> exportAsPdf [
"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 header: 'Arbol principal'.
node1 := GrafoscopioNode
header: 'Nodo 1'
header: 'Node 1'
body: ''.
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.
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"
aStream nextPutAll: ('\begin{minted}{smalltalk}[frame=lines]'); lf.
aStream nextPutAll: ('\begin{minted}{smalltalk}'); lf.
aStream nextPutAll: (self body contents withInternetLineEndings); lf.
aStream nextPutAll: '\end{minted}';lf;lf.
^aStream contents
@ -277,6 +277,7 @@ GrafoscopioNode >> exportPreambleTo: aStream [
| configDict |
aStream nextPutAll: '---'; lf.
aStream nextPutAll: 'header-includes:'; lf.
aStream nextPutAll: ' - \documentclass{article}'; lf.
aStream nextPutAll: ' - \usepackage{minted}'; lf.
aStream nextPutAll: ' - \usemintedstyle{friendly}'; lf.
(self header = '%config')

View File

@ -46,12 +46,29 @@ GrafoscopioNotebook class >> defaultSpec [
bc add: #body ]]]
]
{ #category : #operation }
{ #category : #'editing nodes' }
GrafoscopioNotebook >> addNode [
| addedNode |
tree needRebuild: true.
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 }
@ -64,36 +81,28 @@ GrafoscopioNotebook >> body: anObject [
body := anObject
]
{ #category : #operation }
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 : #'editing nodes' }
GrafoscopioNotebook >> demoteNode [
| editedNode |
editedNode := tree highlightedItem content.
editedNode demote.
self notebookContent: notebook.
]
{ #category : #operation }
GrafoscopioNotebook >> demoteNode [
| currentContent |
currentContent := tree highlightedItem content.
currentContent demote.
self updateTreeEditing: currentContent
{ #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 }
@ -129,21 +138,22 @@ GrafoscopioNotebook >> highlightItemFor: nodeContent [
| currentItem |
currentItem := tree highlightedItem.
currentItem
ifNotNil: [ | allItems index childrenSize parentNode |
ifNotNil: [ | allItems allContents index childrenSize parentNode |
currentItem parentNode
ifNil: [
parentNode := currentItem container.
allItems := parentNode roots ]
ifNotNil: [
parentNode := currentItem parentNode.
allItems := parentNode children value. ].
allItems := parentNode children value ].
allContents := allItems collect: [ :each | each content ].
childrenSize := currentItem content parent children size.
index := allItems indexOf: currentItem.
index := allContents indexOf: currentItem content.
(index < childrenSize) ifTrue: [
currentItem ifNotNil: [currentItem selected: false].
parentNode
highlightedItem: ((allItems at:(index+1)) selected:true;
takeHighlight;yourself).
currentItem := (allItems at:(index+1)) selected: true.
"currentItem := parentNode highlightedItem: ((allItems at:(index+1)) selected:true;
takeHighlight;yourself); yourself."
{ parentNode . currentItem . nodeContent } inspect.
]
]
]
@ -175,7 +185,12 @@ GrafoscopioNotebook >> highlightNextItem [
{ #category : #initialization }
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 |
(tree highlightedItem content header) = arg
ifFalse: [ (tree highlightedItem) content header: arg.
@ -200,20 +215,20 @@ GrafoscopioNotebook >> initializeWidgets [
add: body.
]
{ #category : #operation }
{ #category : #'editing nodes' }
GrafoscopioNotebook >> moveNodeAfter [
| currentContent |
currentContent := tree selectedItem content.
currentContent moveAfter.
self updateTreeEditing: currentContent
| editedNode |
editedNode := tree selectedItem content.
editedNode moveAfter.
self notebookContent: notebook
]
{ #category : #operation }
{ #category : #'editing nodes' }
GrafoscopioNotebook >> moveNodeBefore [
| currentContent |
currentContent := tree selectedItem content.
currentContent moveBefore.
self updateTreeEditing: currentContent
| editedNode |
editedNode := tree highlightedItem content.
editedNode moveBefore.
self notebookContent: notebook
]
{ #category : #initialization }
@ -348,11 +363,16 @@ GrafoscopioNotebook >> notebookSubMenu [
icon: Smalltalk ui icons smallSaveIcon;
shortcut: $s command;
action: [ self saveWorkingNotebook ] ].
group addItem: [ :item |
group addItem: [ :item |
item
name: 'Save as...';
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 |
item
name: 'Export as html';
@ -487,15 +507,15 @@ GrafoscopioNotebook >> projectSubMenu [
]
{ #category : #operation }
{ #category : #'editing nodes' }
GrafoscopioNotebook >> promoteNode [
| currentContent |
currentContent := tree selectedItem content.
currentContent promote.
self updateTreeEditing: currentContent
| editedNote |
editedNote := tree selectedItem content.
editedNote promote.
self notebookContent: notebook
]
{ #category : #operation }
{ #category : #'editing nodes' }
GrafoscopioNotebook >> removeNode [
| contentToDelete parentContent newSelectedContent children |
contentToDelete := tree selectedItem content.
@ -508,7 +528,7 @@ GrafoscopioNotebook >> removeNode [
]
ifFalse: [ newSelectedContent := parentContent ].
contentToDelete parent removeNode: contentToDelete.
self updateTreeEditing: newSelectedContent
self notebookContent: notebook
]
{ #category : #persistence }
@ -552,14 +572,14 @@ GrafoscopioNotebook >> saveWorkingNotebook [
]
{ #category : #operation }
{ #category : #'editing nodes' }
GrafoscopioNotebook >> toggleCodeNode [
| currentNode |
currentNode := tree highlightedItem.
(currentNode content tags = 'código')
ifTrue: [ currentNode content tagAs: '' ]
ifFalse: [ currentNode content tagAs: 'código' ].
self changeBody: currentNode.
self updateBodyFor: currentNode.
]
{ #category : #accessing }
@ -573,17 +593,17 @@ GrafoscopioNotebook >> tree: anObject [
]
{ #category : #operation }
GrafoscopioNotebook >> updateBodyFor: item [
item
ifNotNil: [ self changeBody: item ]
ifNil: [ "self inform: 'Select a node.'" ]
]
{ #category : #operation }
GrafoscopioNotebook >> updateTreeEditing: currentContent [
self notebookContent: notebook.
self highlightItemFor: currentContent.
tree needRebuild: true.
GrafoscopioNotebook >> updateBodyFor: aNodeContainer [
| aNode |
self needRebuild: false.
tree needRebuild: false.
body needRebuild: true.
aNode := aNodeContainer content.
header text: aNode header.
body := self instantiate: aNode specModelClass new.
body content: aNode body.
self inform: aNode body.
self autoSaveBodyOf: aNode.
self buildWithSpecLayout: self class defaultSpec
]

View File

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