Adding some behaviour on the up/down remove add

This commit is contained in:
Santiago Bragagnolo 2020-02-20 18:02:09 +00:00 committed by Offray Luna
parent c9457c0e60
commit d57e560554
5 changed files with 32 additions and 9 deletions

View File

@ -6,7 +6,7 @@ to explore.
" "
Class { Class {
#name : #GrafoscopioButtonModel, #name : #GrafoscopioButtonModel,
#superclass : #ComposableModel, #superclass : #ComposablePresenter,
#instVars : [ #instVars : [
'button' 'button'
], ],

View File

@ -4,7 +4,7 @@ embedded interactive Playground.
" "
Class { Class {
#name : #GrafoscopioCodeModel, #name : #GrafoscopioCodeModel,
#superclass : #ComposableModel, #superclass : #ComposablePresenter,
#instVars : [ #instVars : [
'body' 'body'
], ],

View File

@ -851,7 +851,8 @@ GrafoscopioNode >> moveDown [
GrafoscopioNode >> moveDown: aNode [ GrafoscopioNode >> moveDown: aNode [
| index | | index |
"Moves the current node a place before in the children collection where is located" "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) children swap: index with: (index + 1 min: children size)
] ]

View File

@ -87,8 +87,10 @@ GrafoscopioNotebook >> addCommandFrom: dictionary into: stream [
{ #category : #'editing nodes' } { #category : #'editing nodes' }
GrafoscopioNotebook >> addNode [ GrafoscopioNotebook >> addNode [
self currentNode addNodeAfterMe. | newNode |
newNode := self currentNode addNodeAfterMe.
self notebookContent: notebook. self notebookContent: notebook.
self selectedItem: newNode.
] ]
{ #category : #persistence } { #category : #persistence }
@ -625,7 +627,8 @@ GrafoscopioNotebook >> moveSelectedNodeDown [
| editedNode | | editedNode |
editedNode := tree selectedItem content. editedNode := tree selectedItem content.
editedNode moveDown. editedNode moveDown.
self notebookContent: notebook self notebookContent: notebook.
tree needRebuild: true.
] ]
{ #category : #'editing nodes' } { #category : #'editing nodes' }
@ -673,8 +676,7 @@ GrafoscopioNotebook >> notebook: anObject [
{ #category : #api } { #category : #api }
GrafoscopioNotebook >> notebookContent: aTree [ GrafoscopioNotebook >> notebookContent: aTree [
tree tree
roots: (aTree children collect: [ :gfcNode | gfcNode asTreeNodePresenter ]). roots: (aTree children collect: [ :gfcNode | gfcNode asTreeNodePresenter ])
tree selectedIndex: (tree selectedIndex min: aTree children size)
] ]
{ #category : #initialization } { #category : #initialization }
@ -920,6 +922,12 @@ GrafoscopioNotebook >> removeNode [
tree selectedItem tree selectedItem
ifNil: [ ^ self inform: 'No node available or properly selected ' ]. ifNil: [ ^ self inform: 'No node available or properly selected ' ].
contentToDelete := tree selectedItem content. 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. parentContent := contentToDelete parent.
children := parentContent children. children := parentContent children.
children size > 1 children size > 1
@ -927,7 +935,15 @@ GrafoscopioNotebook >> removeNode [
ifTrue: [ newSelectedContent := children at: children size - 1 ] ] ifTrue: [ newSelectedContent := children at: children size - 1 ] ]
ifFalse: [ newSelectedContent := parentContent ]. ifFalse: [ newSelectedContent := parentContent ].
contentToDelete parent removeNode: contentToDelete. 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 } { #category : #persistence }
@ -982,6 +998,12 @@ GrafoscopioNotebook >> seePdf [
onSuccessDo: [ :v | (#open command argument: self pdfFile fullName) schedule ] 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 } { #category : #persistence }
GrafoscopioNotebook >> subtreeAsMarkdown [ GrafoscopioNotebook >> subtreeAsMarkdown [
| currentNode | | currentNode |

View File

@ -4,7 +4,7 @@ nodes.
" "
Class { Class {
#name : #GrafoscopioReplace, #name : #GrafoscopioReplace,
#superclass : #ComposableModel, #superclass : #ComposablePresenter,
#instVars : [ #instVars : [
'find', 'find',
'replace', 'replace',