forked from pharo-project/pharo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpDualChangeSorterPresenter.class.st
341 lines (270 loc) · 9.35 KB
/
SpDualChangeSorterPresenter.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
"
A `SpDualChangeSorterPresenter is a dual change sorter. It manages two sets of changes so that we can cherry pick and creates new changes.
`SpDualChangeSorterPresenter` shares the model between its two subcomponents that are instances of `SpChangeSorterPresenter`. The class `ChangeSorterModel` defines the application logic.
"
Class {
#name : #SpDualChangeSorterPresenter,
#superclass : #StPresenter,
#instVars : [
'model',
'changeSorterLeft',
'changeSorterRight',
'isRefreshing'
],
#category : #'NewTools-ChangeSorter'
}
{ #category : #specs }
SpDualChangeSorterPresenter class >> defaultSpec [
<spec>
^ SpPanedLayout newHorizontal
add: #changeSorterLeft;
add: #changeSorterRight;
yourself
]
{ #category : #menu }
SpDualChangeSorterPresenter class >> menuCommandOn: aBuilder [
<worldMenu>
(aBuilder group: #SystemChanges)
parent: #Tools;
order: 410;
with: [
(aBuilder item: #'Change Sorter')
action: [ self open ];
help: 'Examine the different change set of the image.';
icon: self taskbarIcon ].
aBuilder withSeparatorAfter
]
{ #category : #opening }
SpDualChangeSorterPresenter class >> open [
<script>
self new openWithSpec
]
{ #category : #'tools-registry' }
SpDualChangeSorterPresenter class >> registerToolsOn: registry [
"Add ourselves to registry. See [Smalltalk tools]"
registry register: self as: #changeSorter
]
{ #category : #icons }
SpDualChangeSorterPresenter class >> taskbarIconName [
^ #changeSorterIcon
]
{ #category : #accessing }
SpDualChangeSorterPresenter class >> title [
^ 'Dual Change Sorter'
]
{ #category : #menu }
SpDualChangeSorterPresenter >> changeSetMenuFrom: sourcePanel to: destinationPanel [
"Fill aMenu with items appropriate for the changes list"
^ sourcePanel changeSetMenu
addGroup: [ :aGroup |
aGroup
addItem: [ :anItem |
anItem
name: 'Copy all to the other change set';
shortcut: $s meta;
action: [ self copyAllFrom: sourcePanel to: destinationPanel ] ];
addItem: [ :anItem |
anItem
name: 'Submerge into the other change set';
action: [ self submerge: sourcePanel into: destinationPanel ] ];
addItem: [ :anItem |
anItem
name: 'Subtract the other change set';
shortcut: $- meta;
action: [ self subtractFrom: sourcePanel to: destinationPanel ] ] ];
yourself
]
{ #category : #accessing }
SpDualChangeSorterPresenter >> changeSorterLeft [
^ changeSorterLeft
]
{ #category : #accessing }
SpDualChangeSorterPresenter >> changeSorterRight [
^ changeSorterRight
]
{ #category : #'menu - change set' }
SpDualChangeSorterPresenter >> checkThatSidesDiffer: escapeBlock [
"If the change sets on both sides of the dual sorter are the same, put up an error message and escape via escapeBlock, else proceed happily"
changeSorterLeft selectedChangeSet == changeSorterRight selectedChangeSet
ifFalse: [ ^ self ].
self
inform:
'This command requires that the
change sets selected on the two
sides of the change sorter *not*
be the same.'.
^ escapeBlock value
]
{ #category : #menu }
SpDualChangeSorterPresenter >> classMenuFrom: sourcePanel to: destinationPanel [
"Fill aMenu with items appropriate for the class list"
^ sourcePanel classMenu
addGroup: [ :aGroup |
aGroup
addItem: [ :anItem |
anItem
name: 'Copy class to the other change set';
action: [ self copyClassFrom: sourcePanel to: destinationPanel ] ];
addItem: [ :anItem |
anItem
name: 'Move class to the other change set';
action: [ self moveClassFrom: sourcePanel to: destinationPanel ] ] ];
yourself
]
{ #category : #initialization }
SpDualChangeSorterPresenter >> connectPresenters [
changeSorterLeft whenChangesListChanges: [ self refeshedChangeSet: changeSorterRight ].
changeSorterRight whenChangesListChanges: [ self refeshedChangeSet: changeSorterLeft ].
]
{ #category : #'menu - change set' }
SpDualChangeSorterPresenter >> copyAllFrom: src to: dest [
self checkThatSidesDiffer: [ ^ self ].
self model copyAllChangesFrom: (src selectedChangeSet) to: (dest selectedChangeSet).
dest updateClassesList.
]
{ #category : #'menu - class' }
SpDualChangeSorterPresenter >> copyClassFrom: src to: dest [
"Place these changes in the other changeSet also"
| otherChangeSet |
self checkThatSidesDiffer: [ ^ self ].
self okToChange ifFalse: [ ^ self inform: 'Can''t discard edits.' ].
src selectedClass ifNil: [ ^ self inform: 'Selected class is nil.' ].
otherChangeSet := dest selectedChangeSet.
self model copyClass: src selectedClass from: src selectedChangeSet to: otherChangeSet.
dest setSelectedChangeSet: otherChangeSet.
]
{ #category : #'menu - method' }
SpDualChangeSorterPresenter >> copyMethodFrom: src to: dest [
"Place this change in the other changeSet also"
| other |
self checkThatSidesDiffer: [^ self].
other := dest selectedChangeSet.
src selectedSelector ifNotNil: [:selector || class |
class := src selectedClass.
self model
copySelector: selector
inClass: class
from: src selectedChangeSet
to: other.
dest updateClassesListAndMessagesList ].
]
{ #category : #initialization }
SpDualChangeSorterPresenter >> initialize [
super initialize.
model := ChangeSorterModel new.
isRefreshing := false.
SystemAnnouncer uniqueInstance weak
when: CurrentChangeSetChanged
send: #updateTitle
to: self
]
{ #category : #initialization }
SpDualChangeSorterPresenter >> initializePresenters [
changeSorterLeft := self instantiate: SpChangeSorterPresenter.
changeSorterRight := self instantiate: SpChangeSorterPresenter.
self menusRegistration.
self shortcutsRegistration.
self setFocusOrder
]
{ #category : #initialization }
SpDualChangeSorterPresenter >> initializeWindow: aWindowPresenter [
aWindowPresenter initialExtent: 900 @ 530.
aWindowPresenter title: self title
]
{ #category : #initialization }
SpDualChangeSorterPresenter >> menusRegistration [
self menusRegistrationFrom: changeSorterLeft to: changeSorterRight.
self menusRegistrationFrom: changeSorterRight to: changeSorterLeft
]
{ #category : #menu }
SpDualChangeSorterPresenter >> menusRegistrationFrom: src to: dest [
src changesMenu: (self changeSetMenuFrom: src to: dest).
src classesMenu: (self classMenuFrom: src to: dest).
src methodsMenu: (self messageMenuFrom: src to: dest)
]
{ #category : #menu }
SpDualChangeSorterPresenter >> messageMenuFrom: sourcePanel to: destinationPanel [
"Fill aMenu with items appropriate for the message list; could be for a single or double changeSorter"
^ sourcePanel messageMenu
addGroup: [ :aGroup |
aGroup
addItem: [ :anItem |
anItem
name: 'Copy method to the other change set';
action: [ self copyMethodFrom: sourcePanel to: destinationPanel ] ];
addItem: [ :anItem |
anItem
name: 'Move method to the other change set';
action: [ self moveMethodFrom: sourcePanel to: destinationPanel ] ] ];
yourself
]
{ #category : #accessing }
SpDualChangeSorterPresenter >> model [
^ model
]
{ #category : #'menu - class' }
SpDualChangeSorterPresenter >> moveClassFrom: src to: dest [
self checkThatSidesDiffer: [^ self].
(self okToChange and: [ src selectedClass notNil]) ifFalse: [ ^ self ].
self copyClassFrom: src to: dest.
src forgetClass
]
{ #category : #'menu - method' }
SpDualChangeSorterPresenter >> moveMethodFrom: src to: dest [
self copyMethodFrom: src to: dest.
src forgetMessage.
src updateClassesListAndMessagesList.
]
{ #category : #event }
SpDualChangeSorterPresenter >> refeshedChangeSet: changeSet [
isRefreshing
ifTrue: [ ^ self ].
isRefreshing := true.
changeSet updateChangesList.
isRefreshing := false
]
{ #category : #initialization }
SpDualChangeSorterPresenter >> setFocusOrder [
self focusOrder
add: changeSorterLeft;
add: changeSorterRight.
]
{ #category : #initialization }
SpDualChangeSorterPresenter >> shortcutsRegistration [
self shortcutsRegistrationFrom: changeSorterLeft to: changeSorterRight.
self shortcutsRegistrationFrom: changeSorterRight to: changeSorterLeft.
]
{ #category : #initialization }
SpDualChangeSorterPresenter >> shortcutsRegistrationFrom: src to: dest [
src changesPresenterOn: $c meta do: [ self copyAllFrom: src to: dest ].
src changesPresenterOn: $- meta do: [ self subtractFrom: src to: dest ].
]
{ #category : #'menu - change set' }
SpDualChangeSorterPresenter >> submergeFrom: src into: dest [
"Copy the contents of the receiver to the other side, then remove the receiver -- all after checking that all is well."
| source destination index |
source := src selectedChangeSet.
destination := dest selectedChangeSet.
index := src selectedChangeSetIndex.
(self model submerge: source into: destination) ifFalse: [ ^ self ].
src updateChangesList.
src setSelectedChangeSetIndex: index.
]
{ #category : #'menu - change set' }
SpDualChangeSorterPresenter >> subtractFrom: src to: dest [
"Subtract the changes found on the other side from the requesting side."
| source destination |
source := src selectedChangeSet.
destination := dest selectedChangeSet.
self checkThatSidesDiffer: [^ self].
self model subtractFrom: source to: destination.
changeSorterRight setSelectedChangeSet: source.
]
{ #category : #'api-window' }
SpDualChangeSorterPresenter >> title [
^ String streamContents: [ :stream | stream << self class title << ' on: ' << self model currentChangeSet name ]
]
{ #category : #api }
SpDualChangeSorterPresenter >> updateTitle [
self window title: self title
]