Skip to content

Commit a79dc00

Browse files
authored
Merge pull request #4138 from gchq/step-refresh-key-bind
Add ctrl-enter key bind for step refresh on code pane
2 parents 4de8d13 + 6e2ca36 commit a79dc00

File tree

7 files changed

+119
-0
lines changed

7 files changed

+119
-0
lines changed

Diff for: stroom-core-client-widget/src/main/java/stroom/widget/util/client/KeyBinding.java

+12
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ static void add(final Action action, final Shortcut... shortcuts) {
231231
}
232232
}
233233

234+
235+
// --------------------------------------------------------------------------------
236+
237+
234238
private static class Binding {
235239

236240
private final Shortcut shortcut;
@@ -271,6 +275,10 @@ public Binding build() {
271275
}
272276
}
273277

278+
279+
// --------------------------------------------------------------------------------
280+
281+
274282
private static class Shortcut {
275283

276284
private final int keyCode;
@@ -357,6 +365,10 @@ public boolean hasModifiers() {
357365
}
358366
}
359367

368+
369+
// --------------------------------------------------------------------------------
370+
371+
360372
public static class Builder {
361373

362374
private int keyCode;

Diff for: stroom-core-client/src/main/java/stroom/core/client/KeyboardInterceptor.java

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ private void handleKeyEvent(final NativeEvent event) {
6161
}
6262
}
6363

64+
65+
// --------------------------------------------------------------------------------
66+
67+
6468
public interface KeyTest {
6569

6670
boolean match(NativeEvent event);

Diff for: stroom-core-client/src/main/java/stroom/pipeline/stepping/client/presenter/ElementPresenter.java

+20
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import stroom.pipeline.shared.data.PipelineElementType;
3535
import stroom.pipeline.shared.data.PipelineProperty;
3636
import stroom.pipeline.shared.stepping.FindElementDocRequest;
37+
import stroom.pipeline.shared.stepping.StepType;
3738
import stroom.pipeline.shared.stepping.SteppingResource;
3839
import stroom.pipeline.stepping.client.presenter.ElementPresenter.ElementView;
3940
import stroom.util.shared.ErrorType;
@@ -48,6 +49,8 @@
4849

4950
import com.google.gwt.core.client.GWT;
5051
import com.google.gwt.core.client.Scheduler;
52+
import com.google.gwt.event.dom.client.KeyCodes;
53+
import com.google.gwt.event.dom.client.KeyDownEvent;
5154
import com.google.inject.Inject;
5255
import com.google.inject.Provider;
5356
import com.google.web.bindery.event.shared.EventBus;
@@ -60,6 +63,7 @@
6063
import java.util.EnumMap;
6164
import java.util.List;
6265
import java.util.Objects;
66+
import java.util.function.Consumer;
6367
import java.util.function.Function;
6468
import java.util.stream.Collectors;
6569

@@ -97,6 +101,7 @@ public class ElementPresenter extends MyPresenterWidget<ElementView> implements
97101
private ClassificationWrapperView inputView;
98102
private ClassificationWrapperView outputView;
99103
private View logView;
104+
private Consumer<StepType> stepRequestHandler = null;
100105

101106
@Inject
102107
public ElementPresenter(final EventBus eventBus,
@@ -307,6 +312,17 @@ public void setCode(final String code) {
307312
codePresenter.getLiveAutoCompletionOption().setOff();
308313

309314
codePresenter.setMode(getMode(element));
315+
316+
317+
registerHandler(codePresenter.getView().asWidget().addDomHandler(e -> {
318+
if (KeyCodes.KEY_ENTER == e.getNativeKeyCode() &&
319+
(e.isShiftKeyDown() || e.isControlKeyDown())) {
320+
e.preventDefault();
321+
if (stepRequestHandler != null) {
322+
stepRequestHandler.accept(StepType.REFRESH);
323+
}
324+
}
325+
}, KeyDownEvent.getType()));
310326
}
311327
}
312328

@@ -611,6 +627,10 @@ private void setCommonEditorOptions(final EditorPresenter editorPresenter) {
611627
editorPresenter.getUseVimBindingsOption().setAvailable();
612628
}
613629

630+
public void setStepRequestHandler(final Consumer<StepType> onStepRefreshRequest) {
631+
this.stepRequestHandler = onStepRefreshRequest;
632+
}
633+
614634

615635
// --------------------------------------------------------------------------------
616636

Diff for: stroom-core-client/src/main/java/stroom/pipeline/stepping/client/presenter/StepControlPresenter.java

+33
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,33 @@ public void stepRefresh() {
7373
StepControlEvent.fire(this, StepType.REFRESH);
7474
}
7575

76+
public void step(final StepType stepType) {
77+
//noinspection EnhancedSwitchMigration // cos GWT
78+
switch (stepType) {
79+
case FIRST:
80+
stepFirst();
81+
break;
82+
case BACKWARD:
83+
stepBackward();
84+
break;
85+
case FORWARD:
86+
stepForward();
87+
break;
88+
case LAST:
89+
stepLast();
90+
break;
91+
case REFRESH:
92+
stepRefresh();
93+
break;
94+
default:
95+
throw new RuntimeException("Unknown type " + stepType);
96+
}
97+
}
98+
99+
public boolean isEnabled(final StepType stepType) {
100+
return getView().isEnabled(stepType);
101+
}
102+
76103
public void setEnabledButtons(final boolean justStepped,
77104
final StepType stepType,
78105
final boolean showingData,
@@ -164,6 +191,10 @@ public HandlerRegistration addStepControlHandler(final StepControlHandler handle
164191
return addHandlerToSource(StepControlEvent.getType(), handler);
165192
}
166193

194+
195+
// --------------------------------------------------------------------------------
196+
197+
167198
public interface StepControlView extends View, HasUiHandlers<StepControlUIHandlers> {
168199

169200
void setStepFirstEnabled(boolean enabled);
@@ -175,5 +206,7 @@ public interface StepControlView extends View, HasUiHandlers<StepControlUIHandle
175206
void setStepLastEnabled(boolean enabled);
176207

177208
void setStepRefreshEnabled(boolean enabled);
209+
210+
boolean isEnabled(final StepType stepType);
178211
}
179212
}

Diff for: stroom-core-client/src/main/java/stroom/pipeline/stepping/client/presenter/SteppingPresenter.java

+7
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,13 @@ private PresenterWidget<?> getContent(final PipelineElement element) {
367367
elementPresenterMap.put(elementId, presenter);
368368
presenter.addDirtyHandler(dirtyEditorHandler);
369369

370+
// Allow step refresh to be called from the editor
371+
presenter.setStepRequestHandler(stepType -> {
372+
if (stepControlPresenter.isEnabled(stepType)) {
373+
stepControlPresenter.step(stepType);
374+
}
375+
});
376+
370377
elementPresenter = presenter;
371378
}
372379
currentElementPresenter = elementPresenter;

Diff for: stroom-core-client/src/main/java/stroom/pipeline/stepping/client/view/StepControlViewImpl.java

+24
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package stroom.pipeline.stepping.client.view;
1818

19+
import stroom.pipeline.shared.stepping.StepType;
1920
import stroom.pipeline.stepping.client.presenter.StepControlPresenter.StepControlView;
2021
import stroom.pipeline.stepping.client.presenter.StepControlUIHandlers;
2122
import stroom.svg.shared.SvgImage;
@@ -103,6 +104,25 @@ public void setStepRefreshEnabled(boolean enabled) {
103104
refreshButton.setEnabled(enabled);
104105
}
105106

107+
@Override
108+
public boolean isEnabled(final StepType stepType) {
109+
//noinspection EnhancedSwitchMigration // cos GWT
110+
switch (stepType) {
111+
case FIRST:
112+
return firstButton.isEnabled();
113+
case BACKWARD:
114+
return backwardButton.isEnabled();
115+
case FORWARD:
116+
return forwardButton.isEnabled();
117+
case LAST:
118+
return lastButton.isEnabled();
119+
case REFRESH:
120+
return refreshButton.isEnabled();
121+
default:
122+
return false;
123+
}
124+
}
125+
106126
@UiHandler("filterButton")
107127
public void onFilterButtonClick(final ClickEvent event) {
108128
if (getUiHandlers() != null) {
@@ -145,6 +165,10 @@ public void onRefreshButtonClick(final ClickEvent event) {
145165
}
146166
}
147167

168+
169+
// --------------------------------------------------------------------------------
170+
171+
148172
public interface Binder extends UiBinder<Widget, StepControlViewImpl> {
149173

150174
}

Diff for: unreleased_changes/20240229_155848_398__0.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
* Add the key bind `ctrl-enter` to do a step refresh on the code pane of the stepper.
2+
3+
4+
```sh
5+
# ONLY the top line will be included as a change entry in the CHANGELOG.
6+
# The entry should be in GitHub flavour markdown and should be written on a SINGLE
7+
# line with no hard breaks. You can have multiple change files for a single GitHub issue.
8+
# The entry should be written in the imperative mood, i.e. 'Fix nasty bug' rather than
9+
# 'Fixed nasty bug'.
10+
#
11+
# Examples of acceptable entries are:
12+
#
13+
#
14+
# * Issue **123** : Fix bug with an associated GitHub issue in this repository
15+
#
16+
# * Issue **namespace/other-repo#456** : Fix bug with an associated GitHub issue in another repository
17+
#
18+
# * Fix bug with no associated GitHub issue.
19+
```

0 commit comments

Comments
 (0)