From 2690e93460341bae9b72f7b2deb68052d39ce50a Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Fri, 4 Jan 2019 19:21:24 +0000 Subject: [PATCH] Reconvering Pandoc Markdown tranformation for node body. --- .../Grafoscopio/GrafoscopioLinksList.class.st | 51 +++++++++++++++++++ .../GrafoscopioLinkstModel.class.st | 8 +++ .../Grafoscopio/GrafoscopioNode.class.st | 35 +++++++++++++ .../Grafoscopio/GrafoscopioNotebook.class.st | 25 ++++++++- 4 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 repository/Grafoscopio/GrafoscopioLinksList.class.st create mode 100644 repository/Grafoscopio/GrafoscopioLinkstModel.class.st diff --git a/repository/Grafoscopio/GrafoscopioLinksList.class.st b/repository/Grafoscopio/GrafoscopioLinksList.class.st new file mode 100644 index 0000000..0999cd0 --- /dev/null +++ b/repository/Grafoscopio/GrafoscopioLinksList.class.st @@ -0,0 +1,51 @@ +" +I model the links of a GrafoscopioNode. + +I'm responsable for showing the links and selecting them. +" +Class { + #name : #GrafoscopioLinksList, + #superclass : #ComposableModel, + #instVars : [ + 'links' + ], + #category : #'Grafoscopio-UI' +} + +{ #category : #specs } +GrafoscopioLinksList class >> defaultSpec [ + ^ SpecLayout composed + add: #links; + yourself +] + +{ #category : #accessing } +GrafoscopioLinksList >> content: aGrafoscopioNode [ + links items: aGrafoscopioNode links +] + +{ #category : #initialization } +GrafoscopioLinksList >> initializeWidgets [ + links := self newList. + self focusOrder add: links +] + +{ #category : #accessing } +GrafoscopioLinksList >> links [ + ^ links +] + +{ #category : #accessing } +GrafoscopioLinksList >> links: anObject [ + links := anObject +] + +{ #category : #api } +GrafoscopioLinksList >> title [ + ^ 'Node links list' +] + +{ #category : #'api-events' } +GrafoscopioLinksList >> whenSelectedItemChanged: aBlock [ + links whenSelectedItemChanged: aBlock +] diff --git a/repository/Grafoscopio/GrafoscopioLinkstModel.class.st b/repository/Grafoscopio/GrafoscopioLinkstModel.class.st new file mode 100644 index 0000000..1d100fa --- /dev/null +++ b/repository/Grafoscopio/GrafoscopioLinkstModel.class.st @@ -0,0 +1,8 @@ +Class { + #name : #GrafoscopioLinkstModel, + #superclass : #ComposableModel, + #instVars : [ + 'links' + ], + #category : #'Grafoscopio-UI' +} diff --git a/repository/Grafoscopio/GrafoscopioNode.class.st b/repository/Grafoscopio/GrafoscopioNode.class.st index 7436afa..eed5ddb 100644 --- a/repository/Grafoscopio/GrafoscopioNode.class.st +++ b/repository/Grafoscopio/GrafoscopioNode.class.st @@ -1073,3 +1073,38 @@ GrafoscopioNode >> visitedGoTo: aCollection [ ] + +{ #category : #'as yet unclassified' } +GrafoscopioNode >> wrapBodyLines [ + "I convert the node body from HTML format to Pandoc's Markdown." + | bodyFile | + (self isTaggedAs: 'código' ) ifTrue: [ ^self ]. + bodyFile := FileLocator temp asFileReference / 'body.txt'. + bodyFile ensureCreateFile. + bodyFile writeStreamDo: [:out | out nextPutAll: self body ]. + Smalltalk platformName = 'unix' + ifTrue: [ self body: (self wrapBodyLinesFor: bodyFile) ]. + Smalltalk platformName = 'Win32' + ifTrue: [ self shouldBeImplemented ]. + bodyFile ensureDelete. +] + +{ #category : #'as yet unclassified' } +GrafoscopioNode >> wrapBodyLinesFor: inputFile [ + | outputFile | + outputFile := FileLocator temp / 'body.tmp.txt'. + outputFile ensureDelete. + outputFile ensureCreateFile. + OSSUnixSubprocess new + command: 'fold'; + arguments: {'-sw'. '80'. inputFile fullName. outputFile fullName}; + redirectStdout; + redirectStderr; + runAndWaitOnExitDo: [ :process :outString :errString | + process isSuccess + ifTrue: [ ^ outString ] + ifFalse: [ + self inform: errString. + ^inputFile contents ] + ] +] diff --git a/repository/Grafoscopio/GrafoscopioNotebook.class.st b/repository/Grafoscopio/GrafoscopioNotebook.class.st index d839db6..f564360 100644 --- a/repository/Grafoscopio/GrafoscopioNotebook.class.st +++ b/repository/Grafoscopio/GrafoscopioNotebook.class.st @@ -427,11 +427,21 @@ GrafoscopioNotebook >> links: anObject [ ] { #category : #'as yet unclassified' } +GrafoscopioNotebook >> linksList [ + | currentNode | + currentNode := tree highlightedItem content. + GrafoscopioLinksList new + content: currentNode; + openWithSpec + +] + +{ #category : #utilities } GrafoscopioNotebook >> listImagesUI [ ListModel new title: 'Images files list'; items: self imagesList ; - openWithSpec + openWithSpec ] { #category : #persistence } @@ -951,6 +961,13 @@ GrafoscopioNotebook >> topBar [ description: 'Toggle: code <--> text'; icon: MendaIcons new smalltalkCodeIcon; action: [ self toggleCodeNode ] ]. + group + addItem: [ :item | + item + name: nil; + description: 'List node links'; + icon: #tinyMenu asIcon; + action: [ self linksList ] ]. group addItem: [ :item | item @@ -1060,3 +1077,9 @@ GrafoscopioNotebook >> workingFile [ GrafoscopioNotebook >> workingFile: aFileReference [ workingFile := aFileReference. ] + +{ #category : #'as yet unclassified' } +GrafoscopioNotebook >> wrapBodyLines [ + self currentNodeContent wrapBodyLines. + self updateBodyFor: self currentNode +]