Skip to content

Commit 082a98d

Browse files
committed
use async futures to compute coder context menu
1 parent 3b7a444 commit 082a98d

2 files changed

Lines changed: 48 additions & 18 deletions

File tree

src/GToolkit-Coder-UI/GtTextualCoderEditorElement.class.st

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ Class {
1010
'shortcuts',
1111
'cursorsUpdater',
1212
'textUpdater',
13-
'addOnsElementFuture'
13+
'addOnsElementFuture',
14+
'menuItemsElementFuture'
1415
],
1516
#category : #'GToolkit-Coder-UI-Coder - Textual'
1617
}
@@ -66,12 +67,12 @@ GtTextualCoderEditorElement >> createContextMenu [
6667
"wait for the addons to be computed"
6768
<return: #BrMenuItems>
6869

69-
| aMenu aMenuItemsPromise |
70+
| aMenu aMenuItemsFuture |
7071
aMenu := BrMenuItems new.
7172
aMenu beGroupedElementType.
7273

73-
aMenuItemsPromise := self textualCoderViewModel addOns
74-
asyncThen: [ :theAddOns |
74+
aMenuItemsFuture := self textualCoderViewModel addOnsFuture
75+
map: [ :theAddOns |
7576
| theItems theContextMenuAstAddons theMenuItems |
7677
"extra context menu items that depend on ast and view model state such as selection"
7778
theContextMenuAstAddons := self textualCoderViewModel
@@ -83,13 +84,11 @@ GtTextualCoderEditorElement >> createContextMenu [
8384
collect: [ :eachAction | eachAction asBrMenuItemForCoderElement: self ]
8485
thenReject: #isNil.
8586

86-
self enqueueTask: (BlTaskAction new
87-
action: [
88-
aMenu items: theMenuItems ]) ].
87+
aMenu -> theMenuItems ].
88+
89+
menuItemsElementFuture future: aMenuItemsFuture.
8990

90-
self enqueueTask: (BlPromiseTask new promise: aMenuItemsPromise).
91-
92-
^ aMenu
91+
^ aMenu
9392
]
9493

9594
{ #category : #initialization }
@@ -157,6 +156,13 @@ GtTextualCoderEditorElement >> initialize [
157156
self textualCoderViewModel onAddOnsChanged: theAddOns ];
158157
whenError: [ :anEditorElement :anError |
159158
self onAddOnsError: anError ].
159+
160+
menuItemsElementFuture := (BrAsyncElementFuture on: self)
161+
executionConfiguration: (GtSingleCoderViewModel methodAddOnsExecutionConfiguration);
162+
whenSuccess: [ :anEditorElement :anAssoc |
163+
anAssoc key items: anAssoc value ];
164+
whenError: [ :anEditorElement :anError |
165+
self onContextMenuError: anError ].
160166

161167
self initializeListeners.
162168

@@ -249,6 +255,15 @@ GtTextualCoderEditorElement >> onCoderViewModelFocused: aBoolean [
249255
ifFalse: [ self loseFocus ]
250256
]
251257

258+
{ #category : #initialization }
259+
GtTextualCoderEditorElement >> onContextMenuError: anError [
260+
anError emit.
261+
NonInteractiveTranscript stderr
262+
show: '[GtTextualCoderEditorElement>>#onContextMenuError:] ';
263+
show: anError;
264+
newLine
265+
]
266+
252267
{ #category : #'private - event handling' }
253268
GtTextualCoderEditorElement >> onFocusChangedAnnouncement: anAnnouncement [
254269
anAnnouncement source == self ifTrue: [ ^ self ].

src/GToolkit-Coder-UI/GtTextualCoderElement.class.st

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Class {
1111
'cursorsUpdater',
1212
'textUpdater',
1313
'addOnsElementFuture',
14-
'editorElement'
14+
'editorElement',
15+
'menuItemsElementFuture'
1516
],
1617
#classVars : [
1718
'DefaultCompletionControllerClass'
@@ -84,12 +85,12 @@ GtTextualCoderElement >> createContextMenu [
8485
"wait for the addons to be computed"
8586
<return: #BrMenuItems>
8687

87-
| aMenu aMenuItemsPromise |
88+
| aMenu aMenuItemsFuture |
8889
aMenu := BrMenuItems new.
8990
aMenu beGroupedElementType.
9091

91-
aMenuItemsPromise := self textualCoderViewModel addOns
92-
asyncThen: [ :theAddOns |
92+
aMenuItemsFuture := self textualCoderViewModel addOnsFuture
93+
map: [ :theAddOns |
9394
| theItems theContextMenuAstAddons theMenuItems |
9495
"extra context menu items that depend on ast and view model state such as selection"
9596
theContextMenuAstAddons := self textualCoderViewModel
@@ -101,11 +102,9 @@ GtTextualCoderElement >> createContextMenu [
101102
collect: [ :eachAction | eachAction asBrMenuItemForCoderElement: self ]
102103
thenReject: #isNil.
103104

104-
self enqueueTask: (BlTaskAction new
105-
action: [
106-
aMenu items: theMenuItems ]) ].
105+
aMenu -> theMenuItems ].
107106

108-
self enqueueTask: (BlPromiseTask new promise: aMenuItemsPromise).
107+
menuItemsElementFuture future: aMenuItemsFuture.
109108

110109
^ aMenu
111110
]
@@ -214,6 +213,13 @@ GtTextualCoderElement >> initialize [
214213
whenSuccess: [ :anEditorElement :theAddOns | self textualCoderViewModel onAddOnsChanged: theAddOns ];
215214
whenError: [ :anEditorElement :anError | self onAddOnsError: anError ].
216215

216+
menuItemsElementFuture := (BrAsyncElementFuture on: self)
217+
executionConfiguration: (GtSingleCoderViewModel methodAddOnsExecutionConfiguration);
218+
whenSuccess: [ :anEditorElement :anAssoc |
219+
anAssoc key items: anAssoc value ];
220+
whenError: [ :anEditorElement :anError |
221+
self onContextMenuError: anError ].
222+
217223
self initializeListeners.
218224

219225
self
@@ -354,6 +360,15 @@ GtTextualCoderElement >> onCoderViewModelFocused: aBoolean [
354360
ifFalse: [ self loseFocus ]
355361
]
356362

363+
{ #category : #initialization }
364+
GtTextualCoderElement >> onContextMenuError: anError [
365+
anError emit.
366+
NonInteractiveTranscript stderr
367+
show: '[GtTextualCoderElement>>#onContextMenuError:] ';
368+
show: anError;
369+
newLine
370+
]
371+
357372
{ #category : #'private - event handling' }
358373
GtTextualCoderElement >> onFocusChangedAnnouncement: anAnnouncement [
359374
anAnnouncement source == self ifTrue: [ ^ self ].

0 commit comments

Comments
 (0)