Skip to content

Commit 2c506c4

Browse files
committed
Add code examples for chapter on Commander with Mail Application
1 parent ea88929 commit 2c506c4

11 files changed

+368
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Class {
2+
#name : 'DeleteMailCommand',
3+
#superclass : 'MailClientCommand',
4+
#category : 'CodeOfSpec20Book-Chapter19',
5+
#package : 'CodeOfSpec20Book',
6+
#tag : 'Chapter19'
7+
}
8+
9+
{ #category : 'converting' }
10+
DeleteMailCommand >> asSpecCommand [
11+
12+
^ super asSpecCommand
13+
shortcutKey: $d meta;
14+
yourself
15+
]
16+
17+
{ #category : 'testing' }
18+
DeleteMailCommand >> canBeExecuted [
19+
20+
^ self mailClientPresenter hasSelectedEmail
21+
]
22+
23+
{ #category : 'testing' }
24+
DeleteMailCommand >> execute [
25+
26+
^ self mailClientPresenter deleteMail
27+
]
28+
29+
{ #category : 'initialization' }
30+
DeleteMailCommand >> initialize [
31+
32+
super initialize.
33+
self
34+
name: 'Delete';
35+
description: 'Delete the selected email'
36+
]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Class {
2+
#name : 'FetchMailCommand',
3+
#superclass : 'MailClientCommand',
4+
#category : 'CodeOfSpec20Book-Chapter19',
5+
#package : 'CodeOfSpec20Book',
6+
#tag : 'Chapter19'
7+
}
8+
9+
{ #category : 'converting' }
10+
FetchMailCommand >> asSpecCommand [
11+
12+
^ super asSpecCommand
13+
iconName: #refresh;
14+
shortcutKey: $f meta;
15+
beDisplayedOnRightSide;
16+
yourself
17+
]
18+
19+
{ #category : 'executing' }
20+
FetchMailCommand >> execute [
21+
22+
self mailClientPresenter fetchMail
23+
]
24+
25+
{ #category : 'initialization' }
26+
FetchMailCommand >> initialize [
27+
28+
super initialize.
29+
self
30+
name: 'Fetch';
31+
description: 'Fetch email from the server'
32+
]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Class {
2+
#name : 'FormatPlainTextCommand',
3+
#superclass : 'MailClientCommand',
4+
#category : 'CodeOfSpec20Book-Chapter19',
5+
#package : 'CodeOfSpec20Book',
6+
#tag : 'Chapter19'
7+
}
8+
9+
{ #category : 'initialization' }
10+
FormatPlainTextCommand >> initialize [
11+
12+
super initialize.
13+
self
14+
name: 'Plain text';
15+
description: 'Use plain text'
16+
]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Class {
2+
#name : 'FormatRichTextCommand',
3+
#superclass : 'MailClientCommand',
4+
#category : 'CodeOfSpec20Book-Chapter19',
5+
#package : 'CodeOfSpec20Book',
6+
#tag : 'Chapter19'
7+
}
8+
9+
{ #category : 'initialization' }
10+
FormatRichTextCommand >> initialize [
11+
12+
super initialize.
13+
self
14+
name: 'Rich text';
15+
description: 'Use rich text'
16+
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Class {
2+
#name : 'MailClientCommand',
3+
#superclass : 'CmCommand',
4+
#category : 'CodeOfSpec20Book-Chapter19',
5+
#package : 'CodeOfSpec20Book',
6+
#tag : 'Chapter19'
7+
}
8+
9+
{ #category : 'private' }
10+
MailClientCommand >> mailClientPresenter [
11+
12+
^ self context
13+
]
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
"
2+
My superclasses uses traditional means for menubars, toolsbars and context menus. I use commands.
3+
"
4+
Class {
5+
#name : 'MailClientPresenterWithCommands',
6+
#superclass : 'MailClientPresenterWithDecorations',
7+
#category : 'CodeOfSpec20Book-Chapter19',
8+
#package : 'CodeOfSpec20Book',
9+
#tag : 'Chapter19'
10+
}
11+
12+
{ #category : 'commands' }
13+
MailClientPresenterWithCommands class >> buildAccountMenuWith: presenter [
14+
15+
^ (CmCommandGroup named: 'AccountMenu') asSpecGroup
16+
beRoot;
17+
register: (DeleteMailCommand forSpec context: presenter);
18+
register: (SendMailCommand forSpec context: presenter);
19+
yourself
20+
]
21+
22+
{ #category : 'commands' }
23+
MailClientPresenterWithCommands class >> buildCommandsGroupWith: presenter forRoot: rootCommandGroup [
24+
25+
rootCommandGroup
26+
register: (self buildMenuBarGroupWith: presenter);
27+
register: (self buildToolBarGroupWith: presenter);
28+
register: (self buildAccountMenuWith: presenter)
29+
]
30+
31+
{ #category : 'commands' }
32+
MailClientPresenterWithCommands class >> buildFormatMenuWith: presenter [
33+
34+
^ (CmCommandGroup named: 'Format') asSpecGroup
35+
register: (FormatPlainTextCommand forSpec context: presenter);
36+
register: (FormatRichTextCommand forSpec context: presenter);
37+
yourself
38+
]
39+
40+
{ #category : 'commands' }
41+
MailClientPresenterWithCommands class >> buildMenuBarGroupWith: presenter [
42+
43+
^ (CmCommandGroup named: 'MenuBar') asSpecGroup
44+
beRoot;
45+
register: (self buildMessageMenuWith: presenter);
46+
register: (self buildViewMenuWith: presenter);
47+
register: (self buildFormatMenuWith: presenter);
48+
yourself
49+
]
50+
51+
{ #category : 'commands' }
52+
MailClientPresenterWithCommands class >> buildMessageMenuWith: presenter [
53+
54+
| fetchGroup |
55+
fetchGroup := CmCommandGroup new asSpecGroup
56+
register: (FetchMailCommand forSpec context: presenter);
57+
beDisplayedAsGroup;
58+
yourself.
59+
^ (CmCommandGroup named: 'Message') asSpecGroup
60+
register: (NewMailCommand forSpec context: presenter);
61+
register: (SaveMailCommand forSpec context: presenter);
62+
register: (DeleteMailCommand forSpec context: presenter);
63+
register: (SendMailCommand forSpec context: presenter);
64+
register: fetchGroup;
65+
yourself
66+
]
67+
68+
{ #category : 'commands' }
69+
MailClientPresenterWithCommands class >> buildToolBarGroupWith: presenter [
70+
71+
^ (CmCommandGroup named: 'ToolBar') asSpecGroup
72+
beRoot;
73+
register: (NewMailCommand forSpec context: presenter);
74+
register: (SaveMailCommand forSpec context: presenter);
75+
register: (SendMailCommand forSpec context: presenter);
76+
register: (FetchMailCommand forSpec context: presenter);
77+
yourself
78+
]
79+
80+
{ #category : 'commands' }
81+
MailClientPresenterWithCommands class >> buildViewMenuWith: presenter [
82+
83+
^ (CmCommandGroup named: 'View') asSpecGroup
84+
register: (ShowCcFieldCommand forSpec context: presenter);
85+
register: (ShowBccFieldCommand forSpec context: presenter);
86+
yourself
87+
]
88+
89+
{ #category : 'private' }
90+
MailClientPresenterWithCommands >> accountMenu [
91+
92+
^ (self rootCommandsGroup / 'AccountMenu') asMenuPresenter
93+
]
94+
95+
{ #category : 'testing' }
96+
MailClientPresenterWithCommands >> hasSelectedEmail [
97+
98+
^ account hasSelectedEmail
99+
]
100+
101+
{ #category : 'nil' }
102+
MailClientPresenterWithCommands >> initializeMenuBar [
103+
104+
menuBar := (self rootCommandsGroup / 'MenuBar') asMenuBarPresenter
105+
]
106+
107+
{ #category : 'initialization' }
108+
MailClientPresenterWithCommands >> initializeToolBar [
109+
110+
toolBar := self newToolbar.
111+
toolBar fillWith: self rootCommandsGroup / 'ToolBar'
112+
]
113+
114+
{ #category : 'private' }
115+
MailClientPresenterWithCommands >> updateToolBarButtons [
116+
117+
toolBar items
118+
]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Class {
2+
#name : 'NewMailCommand',
3+
#superclass : 'MailClientCommand',
4+
#category : 'CodeOfSpec20Book-Chapter19',
5+
#package : 'CodeOfSpec20Book',
6+
#tag : 'Chapter19'
7+
}
8+
9+
{ #category : 'converting' }
10+
NewMailCommand >> asSpecCommand [
11+
12+
^ super asSpecCommand
13+
iconName: #smallNew;
14+
shortcutKey: $n meta;
15+
yourself
16+
]
17+
18+
{ #category : 'executing' }
19+
NewMailCommand >> execute [
20+
21+
self mailClientPresenter newMail
22+
]
23+
24+
{ #category : 'initialization' }
25+
NewMailCommand >> initialize [
26+
27+
super initialize.
28+
self
29+
name: 'New';
30+
description: 'Create a new email'
31+
]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Class {
2+
#name : 'SaveMailCommand',
3+
#superclass : 'MailClientCommand',
4+
#category : 'CodeOfSpec20Book-Chapter19',
5+
#package : 'CodeOfSpec20Book',
6+
#tag : 'Chapter19'
7+
}
8+
9+
{ #category : 'converting' }
10+
SaveMailCommand >> asSpecCommand [
11+
12+
^ super asSpecCommand
13+
iconName: #smallSave;
14+
shortcutKey: $s meta;
15+
yourself
16+
]
17+
18+
{ #category : 'testing' }
19+
SaveMailCommand >> canBeExecuted [
20+
21+
^ self mailClientPresenter hasDraft
22+
]
23+
24+
{ #category : 'executing' }
25+
SaveMailCommand >> execute [
26+
27+
self mailClientPresenter saveMail
28+
]
29+
30+
{ #category : 'initialization' }
31+
SaveMailCommand >> initialize [
32+
33+
super initialize.
34+
self
35+
name: 'Save';
36+
description: 'Save the email'
37+
]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Class {
2+
#name : 'SendMailCommand',
3+
#superclass : 'MailClientCommand',
4+
#category : 'CodeOfSpec20Book-Chapter19',
5+
#package : 'CodeOfSpec20Book',
6+
#tag : 'Chapter19'
7+
}
8+
9+
{ #category : 'converting' }
10+
SendMailCommand >> asSpecCommand [
11+
12+
^ super asSpecCommand
13+
iconName: #smallExport;
14+
shortcutKey: $l meta;
15+
yourself
16+
]
17+
18+
{ #category : 'testing' }
19+
SendMailCommand >> canBeExecuted [
20+
21+
^ self mailClientPresenter hasDraft
22+
]
23+
24+
{ #category : 'executing' }
25+
SendMailCommand >> execute [
26+
27+
self mailClientPresenter sendMail
28+
]
29+
30+
{ #category : 'initialization' }
31+
SendMailCommand >> initialize [
32+
33+
super initialize.
34+
self
35+
name: 'Send';
36+
description: 'Send the selected email'
37+
]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Class {
2+
#name : 'ShowBccFieldCommand',
3+
#superclass : 'MailClientCommand',
4+
#category : 'CodeOfSpec20Book-Chapter19',
5+
#package : 'CodeOfSpec20Book',
6+
#tag : 'Chapter19'
7+
}
8+
9+
{ #category : 'initialization' }
10+
ShowBccFieldCommand >> initialize [
11+
12+
super initialize.
13+
self
14+
name: 'Show BCC field';
15+
description: 'Turn on the BCC field'
16+
]

0 commit comments

Comments
 (0)