Grafoscopio/repository/Grafoscopio/GrafoscopioNewTextModel.cla...

79 lines
2.1 KiB
Smalltalk

Class {
#name : #GrafoscopioNewTextModel,
#superclass : #GrafoscopioNewTextInputModel,
#instVars : [
'up',
'down',
'delete',
'editionMode',
'lastHeightUsed'
],
#category : 'Grafoscopio-New-UI'
}
{ #category : #initialization }
GrafoscopioNewTextModel >> createLayoutFor: aGrafoscopioNodeContent [
lastHeightUsed := (self heightFor: aGrafoscopioNodeContent).
^ editionMode
ifTrue: [ self editionLayoutFor: aGrafoscopioNodeContent ]
ifFalse: [ self normalLayoutFor: aGrafoscopioNodeContent ]
]
{ #category : #initialization }
GrafoscopioNewTextModel >> editionLayoutFor: aGrafoscopioNodeContent [
^ SpBoxLayout newVertical
add:
(SpBoxLayout newHorizontal
add:
(SpBoxLayout newVertical
add: #up;
add: #down;
add: #delete;
yourself)
width: 30;
add: #body;
yourself)
height: (self heightFor: aGrafoscopioNodeContent)
]
{ #category : #initialization }
GrafoscopioNewTextModel >> initializeWidgets [
super initializeWidgets .
editionMode := true.
up := self newButton icon: (self iconNamed: #up) ; color: Color transparent ; yourself .
down := self newButton icon: (self iconNamed: #down) ; color: Color transparent ; yourself .
delete := self newButton icon: (self iconNamed: #delete) ; color: Color transparent ; yourself .
up action: [ model moveUp. self informModification. ].
down action: [ model moveDown. self informModification.].
delete action: [ model remove .self informModification. ]
]
{ #category : #initialization }
GrafoscopioNewTextModel >> newTextComponent [
^ self newText
whenTextChangedDo: [ self textChanged ];
autoAccept: true;
yourself
]
{ #category : #initialization }
GrafoscopioNewTextModel >> normalLayoutFor: aGrafoscopioNodeContent [
^ SpBoxLayout newVertical
add: #body
height: (self heightFor: aGrafoscopioNodeContent)
]
{ #category : #initialization }
GrafoscopioNewTextModel >> textChanged [
model text: body text.
(lastHeightUsed - (self heightFor: model text )) abs
> (lastHeightUsed * 0.1)
ifTrue: [ self modelChanged ]
]
{ #category : #initialization }
GrafoscopioNewTextModel >> toogleEditionMode [
editionMode := editionMode not.
]