From a4dadda39b6cab2a85fb21a25fd2d5e18a4a7a5f Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Thu, 18 Aug 2016 19:48:10 +0000 Subject: [PATCH] Adding nodes "almost" done. Now the problem is deletion... :-/ ..anyway, I'm making progres :-) --- .../Grafoscopio/GrafoscopioNotebook.class.st | 71 ++++++++++++++----- 1 file changed, 52 insertions(+), 19 deletions(-) diff --git a/repository/Grafoscopio/GrafoscopioNotebook.class.st b/repository/Grafoscopio/GrafoscopioNotebook.class.st index b8a55ef..69611dc 100644 --- a/repository/Grafoscopio/GrafoscopioNotebook.class.st +++ b/repository/Grafoscopio/GrafoscopioNotebook.class.st @@ -47,12 +47,13 @@ GrafoscopioNotebook class >> defaultSpec [ ] { #category : #operation } -GrafoscopioNotebook >> addNode [ +GrafoscopioNotebook >> addNode [ + | addedNode | tree needRebuild: true. - tree highlightedItem content addNodeAfterMe. + addedNode := tree highlightedItem content addNodeAfterMe. self notebookContent: notebook. tree roots: tree roots. - self highlightNextItem. + self highlightItemFor: addedNode. self buildWithSpecLayout: self class defaultSpec. ] @@ -92,11 +93,12 @@ GrafoscopioNotebook >> changeBody: aNode [ { #category : #operation } GrafoscopioNotebook >> demoteNode [ - | currentNode | - currentNode := tree selectedItem content. - currentNode demote. + | currentContent | + currentContent := tree highlightedItem content. + currentContent demote. + self notebookContent: notebook. + self highlightItemFor: currentContent. tree needRebuild: true. - tree roots: tree roots. self buildWithSpecLayout: self class defaultSpec. ] @@ -128,6 +130,31 @@ GrafoscopioNotebook >> header: anObject [ header := anObject ] +{ #category : #operation } +GrafoscopioNotebook >> highlightItemFor: nodeContent [ + | currentItem | + currentItem := tree highlightedItem. + currentItem + ifNotNil: [ | allItems index childrenSize parentNode | + currentItem parentNode + ifNil: [ + parentNode := currentItem container. + allItems := parentNode roots ] + ifNotNil: [ + parentNode := currentItem parentNode. + allItems := parentNode children value. ]. + childrenSize := currentItem content parent children size. + index := allItems indexOf: currentItem. + (index < childrenSize) ifTrue: [ + "{allItems . currentItem . index } inspect." + currentItem selected: false. + parentNode + highlightedItem: ((allItems at:(index+1)) selected:true; + takeHighlight;yourself). + ] + ] +] + { #category : #operation } GrafoscopioNotebook >> highlightNextItem [ | currentItem | @@ -473,26 +500,32 @@ GrafoscopioNotebook >> projectSubMenu [ { #category : #operation } GrafoscopioNotebook >> promoteNode [ - | currentNode | - currentNode := tree selectedItem content. - currentNode promote. + | currentContent | + currentContent := tree selectedItem content. + currentContent promote. + self notebookContent: notebook. + self highlightItemFor: currentContent. tree needRebuild: true. - tree roots: tree roots. self buildWithSpecLayout: self class defaultSpec. ] { #category : #operation } GrafoscopioNotebook >> removeNode [ - | nodeToDelete | - nodeToDelete := tree selectedItem content. - nodeToDelete parent removeNode: nodeToDelete. - "tree selectedItem: tree selectedItem parentNode." - tree selectOnlyLastHighlighted. + | contentToDelete parentContent newSelectedContent children | + contentToDelete := tree selectedItem content. + parentContent := contentToDelete parent. + children := parentContent children. + children size > 1 + ifTrue: [ + children last = contentToDelete + ifTrue: [ newSelectedContent := children at: (children size - 1) ] + ] + ifFalse: [ newSelectedContent := parentContent ]. + contentToDelete parent removeNode: contentToDelete. + self notebookContent: notebook. + self highlightItemFor: newSelectedContent. tree needRebuild: true. - tree roots: tree roots. self buildWithSpecLayout: self class defaultSpec. - - ] { #category : #persistence }