Grafoscopio/src/Grafoscopio/GrafoscopioDocumentTextEdit...

190 lines
5.4 KiB
Smalltalk

Class {
#name : #GrafoscopioDocumentTextEditionPerspective,
#superclass : #GrafoscopioPerspective,
#instVars : [
'tree',
'document',
'buildingVisitor'
],
#category : #'Grafoscopio-New-UI'
}
{ #category : #accessing }
GrafoscopioDocumentTextEditionPerspective class >> buildCommandsGroupWith: presenterInstance forRoot: rootCommandGroup [
rootCommandGroup
register: (self buildMenuBarGroupWith: presenterInstance)";
register: (self buildContextualMenuGroupWith: presenterInstance)"
]
{ #category : #accessing }
GrafoscopioDocumentTextEditionPerspective class >> buildContextualMenuGroupWith: presenterInstance [
^ (CmCommandGroup named: 'Context Menu') asSpecGroup
register: (self buildEditionGroupWith: presenterInstance);
register: (self buildAddingGroupWith: presenterInstance);
register: (self buildRemovingGroupWith: presenterInstance);
yourself
]
{ #category : #accessing }
GrafoscopioDocumentTextEditionPerspective class >> buildMenuBarGroupWith: presenterInstance [
^ (CmCommandGroup named: 'Context Menu') asSpecGroup
register:
(CmBlockCommand new
name: 'Inspect node';
block:
[ :context | context viewport selectedPage activePresenter inspectNode ];
asSpecCommand);
register:
(CmBlockCommand new
name: 'Inspect runs';
block:
[ :context | context viewport selectedPage activePresenter inspectRuns ];
asSpecCommand);
yourself
]
{ #category : #accessing }
GrafoscopioDocumentTextEditionPerspective class >> defaultSpec [
^ SpBoxLayout newVertical
add: #toolbar height: self toolbarHeight;
add:
(SpBoxLayout newHorizontal
add: #tree width: 100;
add: #viewport;
yourself) yourself
]
{ #category : #accessing }
GrafoscopioDocumentTextEditionPerspective class >> icon [
^ self iconNamed: #edit
]
{ #category : #'adding - convenience' }
GrafoscopioDocumentTextEditionPerspective >> aboutToBeUninstalledFrom: aTreeNotebook [
aTreeNotebook removePerspective: self
]
{ #category : #'adding - convenience' }
GrafoscopioDocumentTextEditionPerspective >> addAtLastNewNodeOfClass: aClass [
self
addAtLastOf: (tree selectedItem ifNil: [ document ])
aNodeOfClass: aClass
]
{ #category : #'adding - base' }
GrafoscopioDocumentTextEditionPerspective >> addAtLastOf: aNode aNodeOfClass: aClass [
aNode
addChild: [ self instantiateNode: aClass ]
ofClass: aClass.
self modelChanged
]
{ #category : #'adding - convenience' }
GrafoscopioDocumentTextEditionPerspective >> addNewNodeOfClass: aClass [
^ self addAtLastNewNodeOfClass: aClass
]
{ #category : #initialization }
GrafoscopioDocumentTextEditionPerspective >> buildingVisitor [
^ buildingVisitor
ifNil: [ buildingVisitor := self createDefaultViewportVisitor ]
]
{ #category : #initialization }
GrafoscopioDocumentTextEditionPerspective >> buildingVisitor: aVisitor [
buildingVisitor := aVisitor
]
{ #category : #initialization }
GrafoscopioDocumentTextEditionPerspective >> createDefaultViewportVisitor [
^ GrafoscopioViewportTextVisitor new
]
{ #category : #initialization }
GrafoscopioDocumentTextEditionPerspective >> createViewport [
^ self renderViewport: document
]
{ #category : #initialization }
GrafoscopioDocumentTextEditionPerspective >> informNodeHasChanged: aNode [
| path |
path := tree selection selectedPath.
tree roots: {document}.
tree selectPath: path.
]
{ #category : #initialization }
GrafoscopioDocumentTextEditionPerspective >> initializeWidgets [
super initializeWidgets.
tree := self newTreeTable.
tree
addColumn: (SpStringTableColumn evaluated: #name);
children: [ :node |
node isLeaf
ifTrue: [ {} ]
ifFalse: [ node children ] ].
tree activateOnDoubleClick.
tree
whenSelectionChangedDo: [ :a | self renderViewport: a selectedItem ].
tree whenActivatedDo: [ : a | self requestNewNameFor: a selectedItem ]
]
{ #category : #'as yet unclassified' }
GrafoscopioDocumentTextEditionPerspective >> instantiateNode: aClass [
| name |
name := UIManager default
request: 'Please, name the item'
initialAnswer: 'New item'.
^ aClass new
name: name;
yourself
]
{ #category : #initialization }
GrafoscopioDocumentTextEditionPerspective >> modelChanged [
| path |
path := tree selection selectedPath.
tree roots: {document}.
tree selectPath: path.
self needRebuild: false.
self buildWithSpec
]
{ #category : #initialization }
GrafoscopioDocumentTextEditionPerspective >> nameChanged [
| path |
path := tree selection selectedPath.
tree roots: {document}.
tree buildWithSpec.
tree selectPath: path
]
{ #category : #initialization }
GrafoscopioDocumentTextEditionPerspective >> renderViewport: aNode [
^ self buildingVisitor createViewportFor: ( aNode ifNil: [ document ]) into: self
]
{ #category : #initialization }
GrafoscopioDocumentTextEditionPerspective >> requestNewNameFor: aNode [
| name |
name := UIManager default
request: 'Please, name the node'
initialAnswer: aNode name asString.
name ifNotNil: [ aNode name: name ].
self buildingVisitor renamePageFor: aNode.
self nameChanged .
]
{ #category : #initialization }
GrafoscopioDocumentTextEditionPerspective >> setModelBeforeInitialization: aDomainObject [
super setModelBeforeInitialization: aDomainObject.
document := aDomainObject .
]
{ #category : #initialization }
GrafoscopioDocumentTextEditionPerspective >> viewport [
^ viewport
]