Skip to content

Commit df0afee

Browse files
committed
updated editor API to works with key events.
1 parent d0b92d1 commit df0afee

File tree

6 files changed

+61
-26
lines changed

6 files changed

+61
-26
lines changed

src/main/java/com/ss/editor/plugin/api/editor/BaseFileEditor.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.ss.editor.ui.component.editor.impl.AbstractFileEditor;
1313
import com.ss.editor.ui.component.editor.state.EditorState;
1414
import javafx.event.Event;
15+
import javafx.scene.input.KeyCode;
1516
import javafx.scene.layout.BorderPane;
1617
import javafx.scene.layout.StackPane;
1718
import org.jetbrains.annotations.NotNull;
@@ -63,6 +64,7 @@ protected BaseFileEditor() {
6364
*
6465
* @return the editor operation control.
6566
*/
67+
@FXThread
6668
protected @NotNull EditorOperationControl createOperationControl() {
6769
return new EditorOperationControl(this);
6870
}
@@ -73,6 +75,26 @@ public void execute(@NotNull final EditorOperation operation) {
7375
operationControl.execute(operation);
7476
}
7577

78+
@FXThread
79+
@Override
80+
protected boolean handleKeyActionImpl(@NotNull final KeyCode keyCode, final boolean isPressed,
81+
final boolean isControlDown, final boolean isShiftDown,
82+
final boolean isButtonMiddleDown) {
83+
84+
if (isPressed && isControlDown && keyCode == KeyCode.Z) {
85+
undo();
86+
return true;
87+
} else if (isPressed && isControlDown && isShiftDown && keyCode == KeyCode.Z) {
88+
redo();
89+
return true;
90+
} else if (isPressed && isControlDown && keyCode == KeyCode.Y) {
91+
redo();
92+
return true;
93+
}
94+
95+
return super.handleKeyActionImpl(keyCode, isPressed, isControlDown, isShiftDown, isButtonMiddleDown);
96+
}
97+
7698
@Override
7799
@FXThread
78100
public void incrementChange() {
@@ -198,8 +220,8 @@ protected boolean isIgnoreListeners() {
198220
return editorState;
199221
}
200222

201-
@FXThread
202223
@Override
224+
@FXThread
203225
public boolean isInside(final double sceneX, final double sceneY, @NotNull final Class<? extends Event> eventType) {
204226
return false;
205227
}

src/main/java/com/ss/editor/plugin/api/editor/material/BaseMaterialEditor3DState.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,17 @@ protected void registerActionHandlers(@NotNull final ObjectDictionary<String, Bo
126126

127127
final T fileEditor = getFileEditor();
128128

129-
actionHandlers.put(KEY_S, (isPressed, tpf) -> fileEditor.handleKeyAction(KeyCode.S, isPressed, isControlDown(), isButtonMiddleDown()));
130-
actionHandlers.put(KEY_C, (isPressed, tpf) -> fileEditor.handleKeyAction(KeyCode.C, isPressed, isControlDown(), isButtonMiddleDown()));
131-
actionHandlers.put(KEY_P, (isPressed, tpf) -> fileEditor.handleKeyAction(KeyCode.P, isPressed, isControlDown(), isButtonMiddleDown()));
132-
actionHandlers.put(KEY_L, (isPressed, tpf) -> fileEditor.handleKeyAction(KeyCode.L, isPressed, isControlDown(), isButtonMiddleDown()));
129+
actionHandlers.put(KEY_S, (isPressed, tpf) ->
130+
fileEditor.handleKeyAction(KeyCode.S, isPressed, isControlDown(), isShiftDown(), isButtonMiddleDown()));
131+
132+
actionHandlers.put(KEY_C, (isPressed, tpf) ->
133+
fileEditor.handleKeyAction(KeyCode.C, isPressed, isControlDown(), isShiftDown(), isButtonMiddleDown()));
134+
135+
actionHandlers.put(KEY_P, (isPressed, tpf) ->
136+
fileEditor.handleKeyAction(KeyCode.P, isPressed, isControlDown(), isShiftDown(), isButtonMiddleDown()));
137+
138+
actionHandlers.put(KEY_L, (isPressed, tpf) ->
139+
fileEditor.handleKeyAction(KeyCode.L, isPressed, isControlDown(), isShiftDown(), isButtonMiddleDown()));
133140
}
134141

135142
@Override

src/main/java/com/ss/editor/plugin/api/editor/material/BaseMaterialFileEditor.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,10 @@ protected C getChangeConsumer() {
112112
@Override
113113
@FXThread
114114
protected boolean handleKeyActionImpl(@NotNull final KeyCode keyCode, final boolean isPressed,
115-
final boolean isControlDown, final boolean isButtonMiddleDown) {
115+
final boolean isControlDown, final boolean isShiftDown,
116+
final boolean isButtonMiddleDown) {
116117

117-
if (isPressed && isControlDown && keyCode == KeyCode.Z) {
118-
undo();
119-
return true;
120-
} else if (isPressed && isControlDown && keyCode == KeyCode.Y) {
121-
redo();
122-
return true;
123-
} else if (isPressed && keyCode == KeyCode.C && !isControlDown && !isButtonMiddleDown) {
118+
if (isPressed && keyCode == KeyCode.C && !isControlDown && !isButtonMiddleDown) {
124119
final ToggleButton cubeButton = getCubeButton();
125120
cubeButton.setSelected(true);
126121
return true;
@@ -138,7 +133,7 @@ protected boolean handleKeyActionImpl(@NotNull final KeyCode keyCode, final bool
138133
return true;
139134
}
140135

141-
return super.handleKeyActionImpl(keyCode, isPressed, isControlDown, isButtonMiddleDown);
136+
return super.handleKeyActionImpl(keyCode, isPressed, isControlDown, isShiftDown, isButtonMiddleDown);
142137
}
143138

144139
@Override

src/main/java/com/ss/editor/state/editor/impl/scene/AbstractSceneEditor3DState.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,17 @@ protected void registerActionHandlers(@NotNull final ObjectDictionary<String, Bo
355355

356356
final T fileEditor = getFileEditor();
357357

358-
actionHandlers.put(KEY_S, (isPressed, tpf) -> fileEditor.handleKeyAction(KeyCode.S, isPressed, isControlDown(), isButtonMiddleDown()));
359-
actionHandlers.put(KEY_G, (isPressed, tpf) -> fileEditor.handleKeyAction(KeyCode.G, isPressed, isControlDown(), isButtonMiddleDown()));
360-
actionHandlers.put(KEY_R, (isPressed, tpf) -> fileEditor.handleKeyAction(KeyCode.R, isPressed, isControlDown(), isButtonMiddleDown()));
361-
actionHandlers.put(KEY_DEL, (isPressed, tpf) -> fileEditor.handleKeyAction(KeyCode.DELETE, isPressed, isControlDown(), isButtonMiddleDown()));
358+
actionHandlers.put(KEY_S, (isPressed, tpf) ->
359+
fileEditor.handleKeyAction(KeyCode.S, isPressed, isControlDown(), isShiftDown(), isButtonMiddleDown()));
360+
361+
actionHandlers.put(KEY_G, (isPressed, tpf) ->
362+
fileEditor.handleKeyAction(KeyCode.G, isPressed, isControlDown(), isShiftDown(), isButtonMiddleDown()));
363+
364+
actionHandlers.put(KEY_R, (isPressed, tpf) ->
365+
fileEditor.handleKeyAction(KeyCode.R, isPressed, isControlDown(), isShiftDown(), isButtonMiddleDown()));
366+
367+
actionHandlers.put(KEY_DEL, (isPressed, tpf) ->
368+
fileEditor.handleKeyAction(KeyCode.DELETE, isPressed, isControlDown(), isShiftDown(), isButtonMiddleDown()));
362369
}
363370

364371
@Override

src/main/java/com/ss/editor/ui/component/editor/impl/AbstractFileEditor.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ protected void processKeyReleased(@NotNull final KeyEvent event) {
266266

267267
final KeyCode code = event.getCode();
268268

269-
if (handleKeyActionImpl(code, true, event.isControlDown(), false)) {
269+
if (handleKeyActionImpl(code, true, event.isControlDown(), event.isShiftDown(), false)) {
270270
event.consume();
271271
}
272272
}
@@ -277,12 +277,13 @@ protected void processKeyReleased(@NotNull final KeyEvent event) {
277277
* @param keyCode the key code.
278278
* @param isPressed true if key is pressed.
279279
* @param isControlDown true if control is down.
280+
* @param isShiftDown true if shift is down.
280281
* @param isButtonMiddleDown true if mouse middle button is pressed.
281282
*/
282283
@FromAnyThread
283284
public void handleKeyAction(@NotNull final KeyCode keyCode, final boolean isPressed, final boolean isControlDown,
284-
final boolean isButtonMiddleDown) {
285-
EXECUTOR_MANAGER.addFXTask(() -> handleKeyActionImpl(keyCode, isPressed, isControlDown, isButtonMiddleDown));
285+
final boolean isShiftDown, final boolean isButtonMiddleDown) {
286+
EXECUTOR_MANAGER.addFXTask(() -> handleKeyActionImpl(keyCode, isPressed, isControlDown, isShiftDown, isButtonMiddleDown));
286287
}
287288

288289
/**
@@ -291,12 +292,14 @@ public void handleKeyAction(@NotNull final KeyCode keyCode, final boolean isPres
291292
* @param keyCode the key code.
292293
* @param isPressed true if key is pressed.
293294
* @param isControlDown true if control is down.
295+
* @param isShiftDown true if shift is down.
294296
* @param isButtonMiddleDown true if mouse middle button is pressed.
295-
* @return true if can consume an event.
297+
* @return true if need to consume an event.
296298
*/
297299
@FXThread
298300
protected boolean handleKeyActionImpl(@NotNull final KeyCode keyCode, final boolean isPressed,
299-
final boolean isControlDown, final boolean isButtonMiddleDown) {
301+
final boolean isControlDown, final boolean isShiftDown,
302+
final boolean isButtonMiddleDown) {
300303
return false;
301304
}
302305

@@ -312,7 +315,7 @@ protected void processKeyPressed(@NotNull final KeyEvent event) {
312315

313316
if (code == KeyCode.S && event.isControlDown() && isDirty()) {
314317
save();
315-
} else if (handleKeyActionImpl(code, true, event.isControlDown(), false)) {
318+
} else if (handleKeyActionImpl(code, true, event.isControlDown(), event.isShiftDown(), false)) {
316319
event.consume();
317320
}
318321
}

src/main/java/com/ss/editor/ui/component/editor/impl/scene/AbstractSceneFileEditor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,8 @@ protected void loadState() {
459459
@Override
460460
@FXThread
461461
protected boolean handleKeyActionImpl(@NotNull final KeyCode keyCode, final boolean isPressed,
462-
final boolean isControlDown, final boolean isButtonMiddleDown) {
462+
final boolean isControlDown, final boolean isShiftDown,
463+
final boolean isButtonMiddleDown) {
463464

464465
final MA editor3DState = getEditor3DState();
465466
if (editor3DState.isCameraMoving()) {
@@ -508,7 +509,7 @@ protected boolean handleKeyActionImpl(@NotNull final KeyCode keyCode, final bool
508509
return true;
509510
}
510511

511-
return super.handleKeyActionImpl(keyCode, isPressed, isControlDown, isButtonMiddleDown);
512+
return super.handleKeyActionImpl(keyCode, isPressed, isControlDown, isShiftDown, isButtonMiddleDown);
512513
}
513514

514515
/**

0 commit comments

Comments
 (0)