From 9c613ddf84a177bec68aebdb7214b396caa55f0e Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Fri, 9 Sep 2016 11:39:47 +0000 Subject: [PATCH] Finally! Node edition is working after a big simplification :-). --- .../Grafoscopio/GrafoscopioBrowser.class.st | 6 - .../Grafoscopio/GrafoscopioNode.class.st | 5 +- .../Grafoscopio/GrafoscopioNotebook.class.st | 162 ++++++++++-------- .../Grafoscopio/GrafoscopioTextModel.class.st | 1 + 4 files changed, 95 insertions(+), 79 deletions(-) diff --git a/repository/Grafoscopio/GrafoscopioBrowser.class.st b/repository/Grafoscopio/GrafoscopioBrowser.class.st index 5aa3033..ea3ba0a 100644 --- a/repository/Grafoscopio/GrafoscopioBrowser.class.st +++ b/repository/Grafoscopio/GrafoscopioBrowser.class.st @@ -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). diff --git a/repository/Grafoscopio/GrafoscopioNode.class.st b/repository/Grafoscopio/GrafoscopioNode.class.st index c4f6819..adcc2f8 100644 --- a/repository/Grafoscopio/GrafoscopioNode.class.st +++ b/repository/Grafoscopio/GrafoscopioNode.class.st @@ -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') diff --git a/repository/Grafoscopio/GrafoscopioNotebook.class.st b/repository/Grafoscopio/GrafoscopioNotebook.class.st index 2284bfb..4398bda 100644 --- a/repository/Grafoscopio/GrafoscopioNotebook.class.st +++ b/repository/Grafoscopio/GrafoscopioNotebook.class.st @@ -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 ] diff --git a/repository/Grafoscopio/GrafoscopioTextModel.class.st b/repository/Grafoscopio/GrafoscopioTextModel.class.st index 15180db..146a109 100644 --- a/repository/Grafoscopio/GrafoscopioTextModel.class.st +++ b/repository/Grafoscopio/GrafoscopioTextModel.class.st @@ -33,4 +33,5 @@ GrafoscopioTextModel >> initializeWidgets [ body := self newText. body beForText. + body autoAccept: true. ]