Skip to content

Commit 71410cf

Browse files
authored
Add open settings keyboard shortcut. (#106)
1 parent 6ddbe9b commit 71410cf

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/main/java/com/github/mfl28/boundingboxeditor/controller/Controller.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,9 @@ private List<KeyCombinationEventHandler> createKeyCombinationHandlers() {
783783
new KeyCombinationEventHandler(KeyCombinations.simplifyPolygon,
784784
null, event -> view.simplifyCurrentSelectedBoundingPolygon()),
785785
new KeyCombinationEventHandler(KeyCombinations.saveBoundingShapeAsImage,
786-
null, event -> view.saveCurrentSelectedBoundingShapeAsImage())
786+
null, event -> view.saveCurrentSelectedBoundingShapeAsImage()),
787+
new KeyCombinationEventHandler(KeyCombinations.openSettings,
788+
null, event -> onRegisterSettingsAction())
787789
);
788790
}
789791

@@ -1654,6 +1656,9 @@ public static class KeyCombinations {
16541656
public static final KeyCombination saveBoundingShapeAsImage =
16551657
new KeyCodeCombination(KeyCode.I, KeyCombination.SHIFT_DOWN);
16561658

1659+
public static final KeyCombination openSettings =
1660+
new KeyCodeCombination(KeyCode.COMMA, KeyCombination.SHORTCUT_DOWN);
1661+
16571662
private KeyCombinations() {
16581663
throw new IllegalStateException("Key Combination Class");
16591664
}

src/test/java/com/github/mfl28/boundingboxeditor/controller/SceneKeyShortcutTests.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import javafx.event.EventType;
2727
import javafx.geometry.Point2D;
2828
import javafx.scene.Cursor;
29+
import javafx.scene.control.ButtonType;
2930
import javafx.scene.input.*;
3031
import javafx.stage.FileChooser;
3132
import javafx.stage.Stage;
@@ -74,9 +75,10 @@ void onSceneKeyPressed_ShouldPerformCorrectAction(TestInfo testinfo, FxRobot rob
7475
Controller.KeyCombinations.selectFreehandDrawingMode, Controller.KeyCombinations.removeEditingVerticesWhenBoundingPolygonSelected,
7576
Controller.KeyCombinations.changeSelectedBoundingShapeCategory,
7677
Controller.KeyCombinations.hideNonSelectedBoundingShapes, Controller.KeyCombinations.simplifyPolygon,
77-
Controller.KeyCombinations.saveBoundingShapeAsImage
78+
Controller.KeyCombinations.saveBoundingShapeAsImage, Controller.KeyCombinations.openSettings
7879
));
7980

81+
testOpenSettingsKeyEvent(robot, testinfo);
8082
testNavigateNextKeyEvent(testinfo, true, true, "wexor-tmg-L-2p8fapOA8-unsplash.jpg");
8183
testNavigatePreviousKeyEvent(testinfo, true, true, "rachel-hisko-rEM3cK8F1pk-unsplash.jpg");
8284
testNavigateNextKeyEvent(testinfo, false, true, "wexor-tmg-L-2p8fapOA8-unsplash.jpg");
@@ -172,6 +174,20 @@ void onSceneKeyPressed_ShouldPerformCorrectAction(TestInfo testinfo, FxRobot rob
172174
testResetImageViewSizeKeyEvent(robot);
173175
}
174176

177+
private void testOpenSettingsKeyEvent(FxRobot robot, TestInfo testinfo) {
178+
KeyEvent openSettingsKeyEvent = buildKeyEventFromCombination((KeyCodeCombination) Controller.KeyCombinations.openSettings, KeyEvent.KEY_RELEASED);
179+
Platform.runLater(() -> controller.onRegisterSceneKeyReleased(openSettingsKeyEvent));
180+
WaitForAsyncUtils.waitForFxEvents();
181+
182+
final Stage settingsStage = timeOutGetTopModalStage(robot, "Settings", testinfo);
183+
verifyThat(settingsStage.isShowing(), Matchers.is(true), saveScreenshot(testinfo));
184+
185+
timeOutClickOnButtonInDialogStage(robot, settingsStage, ButtonType.CANCEL, testinfo);
186+
timeOutAssertNoTopModelStage(robot, testinfo);
187+
188+
verifyThat(settingsStage.isShowing(), Matchers.is(false));
189+
}
190+
175191
private void testSaveCurrentlySelectedBoundingShapeKeyEvent() {
176192
final AtomicReference<MockedConstruction<FileChooser>> mockedFileChooser = createMockedFileChooser(null);
177193
verifyThat(mockedFileChooser.get(), Matchers.notNullValue());

0 commit comments

Comments
 (0)