Skip to content

Commit fc2460b

Browse files
Renamed all packages to begin with 'Commander2'.
1 parent 5eb7170 commit fc2460b

File tree

86 files changed

+3311
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+3311
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Class {
2+
#name : #BaselineOfCommander2,
3+
#superclass : #BaselineOf,
4+
#category : #BaselineOfCommander2
5+
}
6+
7+
{ #category : #baselines }
8+
BaselineOfCommander2 >> baseline: spec [
9+
<baseline>
10+
11+
spec for: #common do: [
12+
spec
13+
package: 'Commander2';
14+
package: 'Commander2-Spec' with: [ spec requires: #('Commander2') ];
15+
package: 'Commander2-Example';
16+
package: 'Commander2-Tests';
17+
package: 'Commander2-ContactBook' with: [ spec requires: #('Commander2-Spec') ];
18+
package: 'Commander2-ContactBook-Extensions' with: [ spec requires: #('Commander2-ContactBook') ];
19+
package: 'Commander2-ToIntegrateInSpec' ]
20+
]

BaselineOfCommander2/package.st

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Package { #name : #BaselineOfCommander2 }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Class {
2+
#name : #CmChangePhoneCommand,
3+
#superclass : #CmContactBookCommand,
4+
#instVars : [
5+
'newPhone'
6+
],
7+
#category : #'Commander2-ContactBook-Extensions'
8+
}
9+
10+
{ #category : #hooks }
11+
CmChangePhoneCommand >> execute [
12+
"One should never manipulate UI directly from a commande.
13+
Instead, you can use one of the subclass of LtCommandNotification.
14+
The UI interactions will be handled by the command decorator.
15+
Using this mechanism a command is not dependent on the context in which it is used.
16+
"
17+
self selectedContact phone: self context newPhone.
18+
self contactBookPresenter updateView
19+
]
20+
21+
{ #category : #initialization }
22+
CmChangePhoneCommand >> initialize [
23+
super initialize.
24+
self
25+
basicName: 'Change phone';
26+
basicDescription: 'Change the phone number of the contact.'
27+
]
28+
29+
{ #category : #accessing }
30+
CmChangePhoneCommand >> newPhone [
31+
^ newPhone
32+
]
33+
34+
{ #category : #accessing }
35+
CmChangePhoneCommand >> newPhone: anObject [
36+
newPhone := anObject
37+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Extension { #name : #CmContactBookPresenter }
2+
3+
{ #category : #'*Commander2-ContactBook-Extensions' }
4+
CmContactBookPresenter class >> changePhoneCommandWith: presenter forRootGroup: aCmCommandsGroup [
5+
<lieutenantExtension>
6+
(aCmCommandsGroup / 'Edition') "Inject an additional command in 'Edition' group."
7+
register: (CmChangePhoneCommand forSpec context: presenter)
8+
]
9+
10+
{ #category : #'*Commander2-ContactBook-Extensions' }
11+
CmContactBookPresenter class >> extraCommandsWith: presenter forRootGroup: aCmCommandsGroup [
12+
<lieutenantExtension>
13+
aCmCommandsGroup
14+
register: ((CmCommandsGroup named: 'Extra') asSpecGroup
15+
basicDescription: 'Extra commands to help during development.';
16+
"Below is an example of reusing the same command for 2 different purposes."
17+
register: ((CmInspectCommand forSpec context: [ presenter selectedContact ]) "Here context is computed at the moment the command is executed."
18+
"The name and description can be adapted for its specific usage."
19+
basicName: 'Inspect contact';
20+
basicDescription: 'Open an inspector on the selected contact.';
21+
yourself);
22+
register: ((CmInspectCommand forSpec context: [ presenter contactBook ])
23+
basicName: 'Inspect contact book';
24+
basicDescription: 'Open an inspector on the contact book.';
25+
yourself);
26+
yourself)
27+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Package { #name : #'Commander2-ContactBook-Extensions' }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"
2+
I am a command allowing to add a contact.
3+
"
4+
Class {
5+
#name : #CmAddContactCommand,
6+
#superclass : #CmContactBookCommand,
7+
#category : #'Commander2-ContactBook-Commands'
8+
}
9+
10+
{ #category : #converting }
11+
CmAddContactCommand >> asSpecCommand [
12+
"Here we define the additional information that the command will need to know
13+
when used in Spec framework.
14+
"
15+
^ super asSpecCommand
16+
shortcutKey: KMModifier meta + $n asKeyCombination;
17+
yourself
18+
]
19+
20+
{ #category : #hooks }
21+
CmAddContactCommand >> execute [
22+
"One should never manipulate UI directly from a commande.
23+
Instead, you can use one of the subclass of LtCommandNotification.
24+
The UI interactions will be handled by the command decorator.
25+
Using this mechanism a command is not dependent on the context in which it is used.
26+
"
27+
| contact |
28+
contact := self context newContact.
29+
self hasSelectedContact
30+
ifTrue: [ self contactBook addContact: contact after: self selectedContact ]
31+
ifFalse: [ self contactBook addContact: contact ].
32+
33+
self contactBookPresenter updateView
34+
]
35+
36+
{ #category : #initialization }
37+
CmAddContactCommand >> initialize [
38+
super initialize.
39+
self
40+
basicName: 'New contact'; "This is the name of the command that will be shown to user."
41+
basicDescription: 'Creates a new contact and add it to the contact book.' "This is the description of the command that will be shown to user."
42+
]
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"
2+
I model a contact, I have a name and a phone.
3+
"
4+
Class {
5+
#name : #CmContact,
6+
#superclass : #Object,
7+
#instVars : [
8+
'name',
9+
'phone'
10+
],
11+
#category : #'Commander2-ContactBook-Model'
12+
}
13+
14+
{ #category : #'instance creation' }
15+
CmContact class >> named: aString phone: phone [
16+
^self new
17+
name: aString;
18+
phone: phone
19+
]
20+
21+
{ #category : #accessing }
22+
CmContact >> name [
23+
^ name
24+
]
25+
26+
{ #category : #accessing }
27+
CmContact >> name: anObject [
28+
name := anObject
29+
]
30+
31+
{ #category : #accessing }
32+
CmContact >> phone [
33+
^ phone
34+
]
35+
36+
{ #category : #accessing }
37+
CmContact >> phone: anObject [
38+
phone := anObject
39+
]
40+
41+
{ #category : #printing }
42+
CmContact >> printOn: aStream [
43+
super printOn: aStream.
44+
45+
aStream nextPut: $(.
46+
aStream nextPutAll: name.
47+
aStream nextPut: $).
48+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
"
2+
I am a contact book. I hold a list of contacts.
3+
"
4+
Class {
5+
#name : #CmContactBook,
6+
#superclass : #Object,
7+
#instVars : [
8+
'contents'
9+
],
10+
#classInstVars : [
11+
'family',
12+
'coworkers'
13+
],
14+
#category : #'Commander2-ContactBook-Model'
15+
}
16+
17+
{ #category : #accessing }
18+
CmContactBook class >> coworkers [
19+
^coworkers ifNil: [
20+
coworkers := self new
21+
add: 'Stef' phone: '112 378';
22+
add: 'Pavel' phone: '898 678';
23+
add: 'Marcus' phone: '444 888';
24+
yourself]
25+
]
26+
27+
{ #category : #accessing }
28+
CmContactBook class >> family [
29+
^family ifNil: [
30+
family := self new
31+
add: 'John' phone: '342 345';
32+
add: 'Bill' phone: '123 678';
33+
add: 'Marry' phone: '789 567';
34+
yourself]
35+
]
36+
37+
{ #category : #accessing }
38+
CmContactBook class >> reset [
39+
<script>
40+
coworkers := nil.
41+
family := nil
42+
]
43+
44+
{ #category : #accessing }
45+
CmContactBook >> add: contactName phone: phone [
46+
| contact |
47+
contact := CmContact named: contactName phone: phone.
48+
self addContact: contact.
49+
^contact
50+
]
51+
52+
{ #category : #accessing }
53+
CmContactBook >> addContact: aContact [
54+
contents add: aContact
55+
]
56+
57+
{ #category : #accessing }
58+
CmContactBook >> addContact: newContact after: contactAfter [
59+
contents add: newContact after: contactAfter
60+
]
61+
62+
{ #category : #accessing }
63+
CmContactBook >> contents [
64+
^ contents
65+
]
66+
67+
{ #category : #accessing }
68+
CmContactBook >> contents: anObject [
69+
contents := anObject
70+
]
71+
72+
{ #category : #testing }
73+
CmContactBook >> includesContact: aContact [
74+
^ contents includes: aContact
75+
76+
]
77+
78+
{ #category : #initialization }
79+
CmContactBook >> initialize [
80+
super initialize.
81+
contents := OrderedCollection new.
82+
]
83+
84+
{ #category : #accessing }
85+
CmContactBook >> removeContact: aContact [
86+
contents remove: aContact
87+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"
2+
I am an abstract command for the contact book example.
3+
4+
I define methods to access information in my #context more easily.
5+
"
6+
Class {
7+
#name : #CmContactBookCommand,
8+
#superclass : #CmCommand,
9+
#category : #'Commander2-ContactBook-Commands'
10+
}
11+
12+
{ #category : #accessing }
13+
CmContactBookCommand >> contactBook [
14+
"Again, this is totally optional, it justs make access to selected contact easier.
15+
Thus code in #execute is easier to read.
16+
"
17+
^ self contactBookPresenter contactBook
18+
]
19+
20+
{ #category : #accessing }
21+
CmContactBookCommand >> contactBookPresenter [
22+
"Optional, simply aliasing the context (the LtContactBookPresenter) to a more explicit name.
23+
It will just make the code easier to read in #execute methods of my subclasses.
24+
"
25+
^ self context
26+
]
27+
28+
{ #category : #testing }
29+
CmContactBookCommand >> hasSelectedContact [
30+
^ self contactBookPresenter isContactSelected
31+
]
32+
33+
{ #category : #accessing }
34+
CmContactBookCommand >> selectedContact [
35+
"Again, this is totally optional, it justs make access to selected contact easier.
36+
Thus code in #execute is easier to read.
37+
"
38+
^ self contactBookPresenter selectedContact
39+
]

0 commit comments

Comments
 (0)