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 {
#name : #GrafoscopioButtonModel,
#superclass : #ComposableModel,
#superclass : #ComposablePresenter,
#instVars : [
'button'
],

View File

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

View File

@ -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)
]

View File

@ -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 |

View File

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