Finish new item action on enter

This commit is contained in:
crschnick 2024-05-20 07:18:08 +00:00
parent 89776bb6da
commit 7c6906d86e
3 changed files with 24 additions and 8 deletions

View file

@ -48,7 +48,8 @@ public class ErrorOverlayComp extends SimpleComp {
return new StackPane(graphic); return new StackPane(graphic);
}), }),
null, null,
() -> {})); () -> {},
false));
}); });
}); });
content.addListener((observable, oldValue, newValue) -> { content.addListener((observable, oldValue, newValue) -> {

View file

@ -14,6 +14,8 @@ import javafx.geometry.Insets;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar; import javafx.scene.control.ButtonBar;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.Region; import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
@ -81,6 +83,7 @@ public class ModalOverlayComp extends SimpleComp {
finishButton.setOnAction(event -> { finishButton.setOnAction(event -> {
newValue.onFinish.run(); newValue.onFinish.run();
overlayContent.setValue(null); overlayContent.setValue(null);
event.consume();
}); });
var buttonBar = new ButtonBar(); var buttonBar = new ButtonBar();
@ -105,6 +108,16 @@ public class ModalOverlayComp extends SimpleComp {
}); });
modal.show(modalBox); modal.show(modalBox);
if (newValue.finishOnEnter) {
modalBox.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
if (event.getCode() == KeyCode.ENTER) {
newValue.onFinish.run();
overlayContent.setValue(null);
event.consume();
}
});
}
// Wait 2 pulses before focus so that the scene can be assigned to r // Wait 2 pulses before focus so that the scene can be assigned to r
Platform.runLater(() -> { Platform.runLater(() -> {
Platform.runLater(() -> { Platform.runLater(() -> {
@ -124,5 +137,6 @@ public class ModalOverlayComp extends SimpleComp {
Comp<?> graphic; Comp<?> graphic;
String finishKey; String finishKey;
Runnable onFinish; Runnable onFinish;
boolean finishOnEnter;
} }
} }

View file

@ -11,12 +11,10 @@ import io.xpipe.app.core.AppI18n;
import io.xpipe.app.fxcomps.Comp; import io.xpipe.app.fxcomps.Comp;
import io.xpipe.app.util.OptionsBuilder; import io.xpipe.app.util.OptionsBuilder;
import io.xpipe.core.process.OsType; import io.xpipe.core.process.OsType;
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import org.kordamp.ikonli.javafx.FontIcon; import org.kordamp.ikonli.javafx.FontIcon;
import java.util.List; import java.util.List;
@ -66,12 +64,13 @@ public class NewItemAction implements BrowserAction, BranchAction {
var creationName = new TextField(); var creationName = new TextField();
creationName.textProperty().bindBidirectional(name); creationName.textProperty().bindBidirectional(name);
return creationName; return creationName;
}), }).prefWidth(350),
null, null,
"finish", "finish",
() -> { () -> {
model.createFileAsync(name.getValue()); model.createFileAsync(name.getValue());
})); },
true));
} }
@Override @Override
@ -95,12 +94,13 @@ public class NewItemAction implements BrowserAction, BranchAction {
var creationName = new TextField(); var creationName = new TextField();
creationName.textProperty().bindBidirectional(name); creationName.textProperty().bindBidirectional(name);
return creationName; return creationName;
}), }).prefWidth(350),
null, null,
"finish", "finish",
() -> { () -> {
model.createDirectoryAsync(name.getValue()); model.createDirectoryAsync(name.getValue());
})); },
true));
} }
@Override @Override
@ -132,7 +132,8 @@ public class NewItemAction implements BrowserAction, BranchAction {
"finish", "finish",
() -> { () -> {
model.createLinkAsync(linkName.getValue(), target.getValue()); model.createLinkAsync(linkName.getValue(), target.getValue());
})); },
true));
} }
@Override @Override