mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
accept pasting a whitespace delimited sequence of words into
a textfield of mnemonic word entry
This commit is contained in:
parent
9a09bb8cda
commit
b9e64d42ff
1 changed files with 37 additions and 8 deletions
|
@ -20,6 +20,7 @@ import javafx.geometry.Orientation;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.input.Clipboard;
|
||||||
import javafx.scene.layout.*;
|
import javafx.scene.layout.*;
|
||||||
import javafx.util.Callback;
|
import javafx.util.Callback;
|
||||||
import org.controlsfx.control.textfield.AutoCompletionBinding;
|
import org.controlsfx.control.textfield.AutoCompletionBinding;
|
||||||
|
@ -163,7 +164,8 @@ public class MnemonicKeystoreImportPane extends TitledDescriptionPane {
|
||||||
wordEntries.add(new WordEntry(i, wordEntryList));
|
wordEntries.add(new WordEntry(i, wordEntryList));
|
||||||
}
|
}
|
||||||
for(int i = 0; i < numWords - 1; i++) {
|
for(int i = 0; i < numWords - 1; i++) {
|
||||||
wordEntries.get(i).setNext(wordEntries.get(i + 1).getEditor());
|
wordEntries.get(i).setNextEntry(wordEntries.get(i + 1));
|
||||||
|
wordEntries.get(i).setNextField(wordEntries.get(i + 1).getEditor());
|
||||||
}
|
}
|
||||||
wordsPane.getChildren().addAll(wordEntries);
|
wordsPane.getChildren().addAll(wordEntries);
|
||||||
|
|
||||||
|
@ -171,7 +173,7 @@ public class MnemonicKeystoreImportPane extends TitledDescriptionPane {
|
||||||
|
|
||||||
if(!displayWordsOnly) {
|
if(!displayWordsOnly) {
|
||||||
PassphraseEntry passphraseEntry = new PassphraseEntry();
|
PassphraseEntry passphraseEntry = new PassphraseEntry();
|
||||||
wordEntries.get(wordEntries.size() - 1).setNext(passphraseEntry.getEditor());
|
wordEntries.get(wordEntries.size() - 1).setNextField(passphraseEntry.getEditor());
|
||||||
passphraseEntry.setPadding(new Insets(0, 26, 10, 10));
|
passphraseEntry.setPadding(new Insets(0, 26, 10, 10));
|
||||||
vBox.getChildren().add(passphraseEntry);
|
vBox.getChildren().add(passphraseEntry);
|
||||||
|
|
||||||
|
@ -401,7 +403,8 @@ public class MnemonicKeystoreImportPane extends TitledDescriptionPane {
|
||||||
private static class WordEntry extends HBox {
|
private static class WordEntry extends HBox {
|
||||||
private static List<String> wordList;
|
private static List<String> wordList;
|
||||||
private final TextField wordField;
|
private final TextField wordField;
|
||||||
private Node next;
|
private WordEntry nextEntry;
|
||||||
|
private TextField nextField;
|
||||||
|
|
||||||
public WordEntry(int wordNumber, ObservableList<String> wordEntryList) {
|
public WordEntry(int wordNumber, ObservableList<String> wordEntryList) {
|
||||||
super();
|
super();
|
||||||
|
@ -411,7 +414,29 @@ public class MnemonicKeystoreImportPane extends TitledDescriptionPane {
|
||||||
Label label = new Label((wordNumber+1) + ".");
|
Label label = new Label((wordNumber+1) + ".");
|
||||||
label.setPrefWidth(22);
|
label.setPrefWidth(22);
|
||||||
label.setAlignment(Pos.CENTER_RIGHT);
|
label.setAlignment(Pos.CENTER_RIGHT);
|
||||||
wordField = new TextField();
|
wordField = new TextField() {
|
||||||
|
@Override
|
||||||
|
public void paste() {
|
||||||
|
Clipboard clipboard = Clipboard.getSystemClipboard();
|
||||||
|
if(clipboard.hasString() && clipboard.getString().matches("(?m).+[\\n\\s][\\S\\s]*")) {
|
||||||
|
String[] words = clipboard.getString().split("[\\n\\s]");
|
||||||
|
WordEntry entry = WordEntry.this;
|
||||||
|
for(String word : words) {
|
||||||
|
if(entry.nextField != null) {
|
||||||
|
entry.nextField.requestFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
entry.wordField.setText(word);
|
||||||
|
entry = entry.nextEntry;
|
||||||
|
if(entry == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
super.paste();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
wordField.setMaxWidth(100);
|
wordField.setMaxWidth(100);
|
||||||
TextFormatter<?> formatter = new TextFormatter<>((TextFormatter.Change change) -> {
|
TextFormatter<?> formatter = new TextFormatter<>((TextFormatter.Change change) -> {
|
||||||
String text = change.getText();
|
String text = change.getText();
|
||||||
|
@ -431,8 +456,8 @@ public class MnemonicKeystoreImportPane extends TitledDescriptionPane {
|
||||||
AutoCompletionBinding<String> autoCompletionBinding = TextFields.bindAutoCompletion(wordField, new WordlistSuggestionProvider(wordList));
|
AutoCompletionBinding<String> autoCompletionBinding = TextFields.bindAutoCompletion(wordField, new WordlistSuggestionProvider(wordList));
|
||||||
autoCompletionBinding.setDelay(50);
|
autoCompletionBinding.setDelay(50);
|
||||||
autoCompletionBinding.setOnAutoCompleted(event -> {
|
autoCompletionBinding.setOnAutoCompleted(event -> {
|
||||||
if (next != null) {
|
if(nextField != null) {
|
||||||
next.requestFocus();
|
nextField.requestFocus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -454,8 +479,12 @@ public class MnemonicKeystoreImportPane extends TitledDescriptionPane {
|
||||||
return wordField;
|
return wordField;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNext(Node node) {
|
public void setNextEntry(WordEntry nextEntry) {
|
||||||
next = node;
|
this.nextEntry = nextEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNextField(TextField field) {
|
||||||
|
this.nextField = field;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isValid(String word) {
|
public static boolean isValid(String word) {
|
||||||
|
|
Loading…
Reference in a new issue