Skip to content

Commit

Permalink
Merge pull request #20 from demarey/spec2
Browse files Browse the repository at this point in the history
Make Cupboard a Spec presenter.
  • Loading branch information
astares committed Feb 2, 2023
2 parents 11e3e5e + 34d82f3 commit b5596e1
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 40 deletions.
210 changes: 170 additions & 40 deletions source/Teapot-Tools/Cupboard.class.st
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
"
A cupboad for teapots
A cupboard for teapots.
I'm the main User Interface to manage teapots instances.
You can open me with:
self soleInstance open
"
Class {
#name : #Cupboard,
#superclass : #Object,
#superclass : #SpPresenter,
#instVars : [
'teapots',
'toolbar'
],
#classInstVars : [
'soleInstance',
'icons'
Expand All @@ -25,7 +34,7 @@ Cupboard class >> menuCommandOn: aBuilder [
help: 'Teatime';
parent: #'Tools' translated;
icon: self iconProvider teapotIcon;
action: [ self soleInstance inspect ].
action: [ self soleInstance open ].
aBuilder withSeparatorAfter
]

Expand All @@ -50,58 +59,160 @@ Cupboard class >> soleInstance [
^ soleInstance ifNil: [ soleInstance := self basicNew initialize ]
]

{ #category : #private }
Cupboard >> iconForTeapot: aTeapot [
^aTeapot server isRunning
ifTrue: [ self iconProvider teapotServerStartIcon ]
ifFalse: [ self iconProvider teapotServerStopIcon ]
]
{ #category : #initialization }
Cupboard >> buildBrowseToolBarItem [

{ #category : #accessing }
Cupboard >> iconProvider [
^ self class iconProvider
^ SpToolbarButtonPresenter new
label: 'Browse';
icon: self iconProvider teapotServerIcon;
action: [ self selectedTeapot browse ];
help: 'Browse the selected Teapot';
yourself
]

{ #category : #accessing }
Cupboard >> inspectTeapot: aBuilder [
<inspectorPresentationOrder: 0 title: 'Teapots'>
| list |
list := aBuilder newList.
list
items: self teapots;
displayIcon: [:each | self iconForTeapot: each ];
display: [ :each | self nameForTeapot: each ];
contextMenu: (SpMenuPresenter new
{ #category : #initialization }
Cupboard >> buildContextMenu [

^ SpMenuPresenter new
addItem: [ :item |
item
name: 'Start';
icon: self iconProvider teapotServerStartIcon;
action: [ list selectedItem start. list refresh ] ];
action: [ teapots selectedItem start. self refreshTeapots ] ];
addItem: [ :item |
item
name: 'Stop';
icon: self iconProvider teapotServerStopIcon;
action: [ list selectedItem stop. list refresh ] ];
action: [ teapots selectedItem stop. self refreshTeapots ] ];
addItem: [ :item |
item
name: 'Browse';
icon: self iconProvider teapotServerIcon;
action: [ list selectedItem browse. list refresh ] ];
" TODO: this doesn't work properly:
1. After adding a new Teapot the list is not refreshed
2. It shouldn't be a context menu. If there is no existing Teapot in the list, the context menu cannot be shown.
addItem: [ :item |
item
name: 'New Teapot';
icon: self iconProvider teapotServerIcon;
action: [ self onNewServer. list refresh ] ];
addItem: [ :item |
item
name: 'New Teapot (serving static)';
icon: self iconProvider teapotServerStaticIcon;
action: [ self onNewStaticServer. list refresh ] ]; "
yourself).
^ list
action: [ teapots selectedItem browse. self refreshTeapots ] ];
yourself
]

{ #category : #initialization }
Cupboard >> buildInspectToolBarItem [

^ SpToolbarButtonPresenter new
label: 'Inspect';
icon: self iconProvider teapotInspectIcon;
action: [ self selectedTeapot inspect ];
help: 'Inspect the selected Teapot';
yourself
]

{ #category : #initialization }
Cupboard >> buildNewStaticToolBarItem [

^ SpToolbarButtonPresenter new
label: 'New Teapot (serving static)';
icon: self iconProvider teapotServerStaticIcon;
action: [ self onNewStaticServer. self refreshTeapots ];
help: 'Create a new Teapot serving static files';
yourself
]

{ #category : #initialization }
Cupboard >> buildNewToolBarItem [

^ SpToolbarButtonPresenter new
label: 'New Teapot';
icon: self iconProvider teapotServerIcon;
action: [ self onNewServer. self refreshTeapots ];
help: 'Create a new Teapot';
yourself

]

{ #category : #initialization }
Cupboard >> buildRefreshToolBarItem [

^ SpToolbarButtonPresenter new
label: 'Refresh';
icon: self iconProvider teapotRefreshIcon;
action: [ self refreshTeapots ];
help: 'Refresh the Teapot list';
yourself
]

{ #category : #initialization }
Cupboard >> buildStartToolBarItem [

^ SpToolbarButtonPresenter new
label: 'Start';
icon: self iconProvider teapotServerStartIcon;
action: [ self selectedTeapot start. self refreshTeapots ];
help: 'Start the selected Teapot';
yourself
]

{ #category : #initialization }
Cupboard >> buildStopToolBarItem [

^ SpToolbarButtonPresenter new
label: 'Stop';
icon: self iconProvider teapotServerStopIcon;
action: [ self selectedTeapot stop. self refreshTeapots ];
help: 'Stop the selected Teapot';
yourself
]

{ #category : #initialization }
Cupboard >> buildToolbar [

^ self newToolbar
addItem: self buildRefreshToolBarItem;
addItem: self buildNewToolBarItem;
addItem: self buildNewStaticToolBarItem;
addItem: self buildStartToolBarItem;
addItem: self buildStopToolBarItem;
addItem: self buildBrowseToolBarItem;
addItem: self buildInspectToolBarItem;
yourself
]

{ #category : #layout }
Cupboard >> defaultLayout [

^ SpBoxLayout newTopToBottom
add: teapots;
yourself
]

{ #category : #private }
Cupboard >> iconForTeapot: aTeapot [
^aTeapot server isRunning
ifTrue: [ self iconProvider teapotServerStartIcon ]
ifFalse: [ self iconProvider teapotServerStopIcon ]
]

{ #category : #accessing }
Cupboard >> iconProvider [
^ self class iconProvider
]

{ #category : #initialization }
Cupboard >> initializePresenters [

teapots := self newList.
teapots
items: self teapots;
displayIcon: [:each | self iconForTeapot: each ];
display: [ :each | self nameForTeapot: each ];
whenActivatedDo: [ self selectedTeapot inspect ];
bindKeyCombination: Character cr asShortcut toAction: [ self selectedTeapot inspect ];
contextMenu: self buildContextMenu
]

{ #category : #initialization }
Cupboard >> initializeWindow: aWindowPresenter [

super initializeWindow: aWindowPresenter.
aWindowPresenter
title: 'Teapots';
toolbar: (toolbar := self buildToolbar).
]

{ #category : #private }
Expand Down Expand Up @@ -144,11 +255,30 @@ Cupboard >> onNewStaticServer [

]

{ #category : #actions }
Cupboard >> open [

self refreshTeapots.
super open.
]

{ #category : #printing }
Cupboard >> printOn: aStream [
aStream nextPutAll: 'Cupboard'
]

{ #category : #actions }
Cupboard >> refreshTeapots [

teapots items: self teapots
]

{ #category : #accessing }
Cupboard >> selectedTeapot [

^ teapots selectedItem
]

{ #category : #accessing }
Cupboard >> teapots [
^ Teapot allInstances
Expand Down
12 changes: 12 additions & 0 deletions source/Teapot-Tools/TeaIconProvider.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ QD2vUC8Qkkf0uiT9wFon5OSVqUL65oui6hGxBy3TMMsAU+Y9Ki5M3KZ1lZZqi5oBr2z5j75R
N5raAAAAAElFTkSuQmCC'
]

{ #category : #icons }
TeaIconProvider class >> teapotInspectIcon [

^ self iconNamed: #'glamorousInspect'
]

{ #category : #icons }
TeaIconProvider class >> teapotRefreshIcon [

^ self iconNamed: #'glamorousRefresh'
]

{ #category : #icons }
TeaIconProvider class >> teapotServerIcon [

Expand Down

0 comments on commit b5596e1

Please sign in to comment.