diff --git a/src/Grafoscopio/GrafoscopioButtonModel.class.st b/src/Grafoscopio/GrafoscopioButtonModel.class.st index a79e165..2e0db13 100644 --- a/src/Grafoscopio/GrafoscopioButtonModel.class.st +++ b/src/Grafoscopio/GrafoscopioButtonModel.class.st @@ -6,7 +6,7 @@ to explore. " Class { #name : #GrafoscopioButtonModel, - #superclass : #ComposableModel, + #superclass : #ComposablePresenter, #instVars : [ 'button' ], diff --git a/src/Grafoscopio/GrafoscopioCodeModel.class.st b/src/Grafoscopio/GrafoscopioCodeModel.class.st index 154a21a..6b6bd87 100644 --- a/src/Grafoscopio/GrafoscopioCodeModel.class.st +++ b/src/Grafoscopio/GrafoscopioCodeModel.class.st @@ -4,7 +4,7 @@ embedded interactive Playground. " Class { #name : #GrafoscopioCodeModel, - #superclass : #ComposableModel, + #superclass : #ComposablePresenter, #instVars : [ 'body' ], diff --git a/src/Grafoscopio/GrafoscopioNode.class.st b/src/Grafoscopio/GrafoscopioNode.class.st index 2d4bf3c..8bc38b7 100644 --- a/src/Grafoscopio/GrafoscopioNode.class.st +++ b/src/Grafoscopio/GrafoscopioNode.class.st @@ -851,7 +851,8 @@ GrafoscopioNode >> moveDown [ GrafoscopioNode >> moveDown: aNode [ | index | "Moves the current node a place before in the children collection where is located" - index := children indexOf: aNode. + index := (children indexOf: aNode) max: 1 . + children swap: index with: (index + 1 min: children size) ] diff --git a/src/Grafoscopio/GrafoscopioNotebook.class.st b/src/Grafoscopio/GrafoscopioNotebook.class.st index b77fbaa..9a41ab0 100644 --- a/src/Grafoscopio/GrafoscopioNotebook.class.st +++ b/src/Grafoscopio/GrafoscopioNotebook.class.st @@ -87,8 +87,10 @@ GrafoscopioNotebook >> addCommandFrom: dictionary into: stream [ { #category : #'editing nodes' } GrafoscopioNotebook >> addNode [ - self currentNode addNodeAfterMe. + | newNode | + newNode := self currentNode addNodeAfterMe. self notebookContent: notebook. + self selectedItem: newNode. ] { #category : #persistence } @@ -625,7 +627,8 @@ GrafoscopioNotebook >> moveSelectedNodeDown [ | editedNode | editedNode := tree selectedItem content. editedNode moveDown. - self notebookContent: notebook + self notebookContent: notebook. + tree needRebuild: true. ] { #category : #'editing nodes' } @@ -673,8 +676,7 @@ GrafoscopioNotebook >> notebook: anObject [ { #category : #api } GrafoscopioNotebook >> notebookContent: aTree [ tree - roots: (aTree children collect: [ :gfcNode | gfcNode asTreeNodePresenter ]). - tree selectedIndex: (tree selectedIndex min: aTree children size) + roots: (aTree children collect: [ :gfcNode | gfcNode asTreeNodePresenter ]) ] { #category : #initialization } @@ -920,6 +922,12 @@ GrafoscopioNotebook >> removeNode [ tree selectedItem ifNil: [ ^ self inform: 'No node available or properly selected ' ]. contentToDelete := tree selectedItem content. + (contentToDelete body isNotEmpty or: [ contentToDelete hasChildren ]) + ifTrue: [ (UIManager default + questionWithoutCancel: + 'The selected node has children and / or content. This change so far cannot be undone. Are you sure you want to proceed? ' + title: 'Remove node') + ifFalse: [ ^ self ] ]. parentContent := contentToDelete parent. children := parentContent children. children size > 1 @@ -927,7 +935,15 @@ GrafoscopioNotebook >> removeNode [ ifTrue: [ newSelectedContent := children at: children size - 1 ] ] ifFalse: [ newSelectedContent := parentContent ]. contentToDelete parent removeNode: contentToDelete. - self notebookContent: notebook + self notebookContent: notebook. + self resetSelectedItem. +] + +{ #category : #'editing nodes' } +GrafoscopioNotebook >> resetSelectedItem [ + tree selectedIndex: (tree selectedIndex min: notebook children size). + tree highlightedItem: tree selectedItem. + tree updatePresenter. ] { #category : #persistence } @@ -982,6 +998,12 @@ GrafoscopioNotebook >> seePdf [ onSuccessDo: [ :v | (#open command argument: self pdfFile fullName) schedule ] ] +{ #category : #'editing nodes' } +GrafoscopioNotebook >> selectedItem: anItem [ + tree selectedItem: (tree roots detect: [ : p | p content = anItem ]). + tree highlightedItem: tree selectedItem. +] + { #category : #persistence } GrafoscopioNotebook >> subtreeAsMarkdown [ | currentNode | diff --git a/src/Grafoscopio/GrafoscopioReplace.class.st b/src/Grafoscopio/GrafoscopioReplace.class.st index 4c23603..c266ef2 100644 --- a/src/Grafoscopio/GrafoscopioReplace.class.st +++ b/src/Grafoscopio/GrafoscopioReplace.class.st @@ -4,7 +4,7 @@ nodes. " Class { #name : #GrafoscopioReplace, - #superclass : #ComposableModel, + #superclass : #ComposablePresenter, #instVars : [ 'find', 'replace',