mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-25 09:00:26 +00:00
Make password manager command a text area
This commit is contained in:
parent
bdce4576d4
commit
b0491bbd66
2 changed files with 64 additions and 32 deletions
|
@ -1,23 +1,24 @@
|
|||
package io.xpipe.app.comp.base;
|
||||
|
||||
import atlantafx.base.theme.Styles;
|
||||
import io.xpipe.app.fxcomps.Comp;
|
||||
import io.xpipe.app.fxcomps.SimpleComp;
|
||||
import io.xpipe.app.fxcomps.CompStructure;
|
||||
import io.xpipe.app.fxcomps.impl.IconButtonComp;
|
||||
import io.xpipe.app.fxcomps.impl.TextAreaComp;
|
||||
import io.xpipe.app.util.FileOpener;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.Property;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.StackPane;
|
||||
|
||||
import atlantafx.base.theme.Styles;
|
||||
import lombok.Builder;
|
||||
import lombok.Value;
|
||||
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class IntegratedTextAreaComp extends SimpleComp {
|
||||
public class IntegratedTextAreaComp extends Comp<IntegratedTextAreaComp.Structure> {
|
||||
|
||||
private final Property<String> value;
|
||||
private final boolean lazy;
|
||||
|
@ -32,26 +33,7 @@ public class IntegratedTextAreaComp extends SimpleComp {
|
|||
this.fileType = fileType;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Region createSimple() {
|
||||
var fileDrop = new FileDropOverlayComp<>(
|
||||
Comp.of(() -> {
|
||||
var textArea = new TextAreaComp(value, lazy).createRegion();
|
||||
var copyButton = createOpenButton(textArea);
|
||||
var pane = new AnchorPane(copyButton);
|
||||
pane.setPickOnBounds(false);
|
||||
AnchorPane.setTopAnchor(copyButton, 10.0);
|
||||
AnchorPane.setRightAnchor(copyButton, 10.0);
|
||||
|
||||
var c = new StackPane();
|
||||
c.getChildren().addAll(textArea, pane);
|
||||
return c;
|
||||
}),
|
||||
paths -> value.setValue(Files.readString(paths.getFirst())));
|
||||
return fileDrop.createRegion();
|
||||
}
|
||||
|
||||
private Region createOpenButton(Region container) {
|
||||
private Region createOpenButton() {
|
||||
return new IconButtonComp(
|
||||
"mdal-edit",
|
||||
() -> FileOpener.openString(
|
||||
|
@ -65,4 +47,49 @@ public class IntegratedTextAreaComp extends SimpleComp {
|
|||
.apply(struc -> struc.get().getStyleClass().remove(Styles.FLAT))
|
||||
.createRegion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Structure createBase() {
|
||||
var fileDrop = new FileDropOverlayComp<>(new Comp<TextAreaStructure>() {
|
||||
@Override
|
||||
public TextAreaStructure createBase() {
|
||||
var textArea = new TextAreaComp(value, lazy).createStructure();
|
||||
var copyButton = createOpenButton();
|
||||
var pane = new AnchorPane(copyButton);
|
||||
pane.setPickOnBounds(false);
|
||||
AnchorPane.setTopAnchor(copyButton, 10.0);
|
||||
AnchorPane.setRightAnchor(copyButton, 10.0);
|
||||
|
||||
var c = new StackPane();
|
||||
c.getChildren().addAll(textArea.get(), pane);
|
||||
return new TextAreaStructure(c, textArea.getTextArea());
|
||||
}
|
||||
}, paths -> value.setValue(Files.readString(paths.getFirst())));
|
||||
var struc = fileDrop.createStructure();
|
||||
return new Structure(struc.get(), struc.getCompStructure().getTextArea());
|
||||
}
|
||||
|
||||
@Value
|
||||
@Builder
|
||||
public static class TextAreaStructure implements CompStructure<StackPane> {
|
||||
StackPane pane;
|
||||
TextArea textArea;
|
||||
|
||||
@Override
|
||||
public StackPane get() {
|
||||
return pane;
|
||||
}
|
||||
}
|
||||
|
||||
@Value
|
||||
@Builder
|
||||
public static class Structure implements CompStructure<StackPane> {
|
||||
StackPane pane;
|
||||
TextArea textArea;
|
||||
|
||||
@Override
|
||||
public StackPane get() {
|
||||
return pane;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,25 @@
|
|||
package io.xpipe.app.prefs;
|
||||
|
||||
import atlantafx.base.theme.Styles;
|
||||
import io.xpipe.app.comp.base.ButtonComp;
|
||||
import io.xpipe.app.comp.base.IntegratedTextAreaComp;
|
||||
import io.xpipe.app.core.AppI18n;
|
||||
import io.xpipe.app.fxcomps.Comp;
|
||||
import io.xpipe.app.fxcomps.impl.HorizontalComp;
|
||||
import io.xpipe.app.fxcomps.impl.TextFieldComp;
|
||||
import io.xpipe.app.fxcomps.impl.VerticalComp;
|
||||
import io.xpipe.app.util.OptionsBuilder;
|
||||
import io.xpipe.app.util.TerminalLauncher;
|
||||
import io.xpipe.app.util.ThreadHelper;
|
||||
import io.xpipe.core.process.CommandBuilder;
|
||||
import io.xpipe.core.process.CommandControl;
|
||||
import io.xpipe.core.process.ProcessControlProvider;
|
||||
import io.xpipe.core.store.LocalStore;
|
||||
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.MenuButton;
|
||||
import javafx.scene.control.MenuItem;
|
||||
|
||||
import atlantafx.base.theme.Styles;
|
||||
import org.kordamp.ikonli.javafx.FontIcon;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -69,11 +70,15 @@ public class PasswordManagerCategory extends AppPrefsCategory {
|
|||
});
|
||||
};
|
||||
|
||||
var c = new TextFieldComp(prefs.passwordManagerCommand, true)
|
||||
.apply(struc -> struc.get().setPromptText("mypassmgr get $KEY"))
|
||||
.minWidth(350);
|
||||
var c = new IntegratedTextAreaComp(prefs.passwordManagerCommand, true, "pw", new SimpleStringProperty(
|
||||
ProcessControlProvider.get().getEffectiveLocalDialect().getScriptFileEnding()))
|
||||
.apply(struc -> {
|
||||
struc.getTextArea().setPromptText("mypassmgr get $KEY");
|
||||
})
|
||||
.minWidth(350)
|
||||
.minHeight(120);
|
||||
var visit = createTemplateChoice();
|
||||
var choice = new HorizontalComp(List.of(c, visit)).apply(struc -> {
|
||||
var choice = new VerticalComp(List.of(c, visit)).apply(struc -> {
|
||||
struc.get().setAlignment(Pos.CENTER_LEFT);
|
||||
struc.get().setSpacing(10);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue