mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2025-11-05 11:56:37 +00:00
truncate labels to persistable max label length and notify user via tooltip
This commit is contained in:
parent
cbae280cc8
commit
201c9ccca3
9 changed files with 28 additions and 12 deletions
2
drongo
2
drongo
|
|
@ -1 +1 @@
|
|||
Subproject commit b2c362d5a71b8c46f8990a6b6b9b96f81ee24c90
|
||||
Subproject commit 342c85a39e45c8e14c4b35f5188ecf93a6c826d6
|
||||
|
|
@ -1,16 +1,20 @@
|
|||
package com.sparrowwallet.sparrow.control;
|
||||
|
||||
import com.sparrowwallet.drongo.wallet.BlockTransactionHash;
|
||||
import com.sparrowwallet.drongo.wallet.Persistable;
|
||||
import com.sparrowwallet.sparrow.wallet.Entry;
|
||||
import javafx.animation.PauseTransition;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.IntegerProperty;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.event.Event;
|
||||
import javafx.geometry.Point2D;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.cell.TextFieldTreeTableCell;
|
||||
import javafx.scene.input.Clipboard;
|
||||
import javafx.scene.input.ClipboardContent;
|
||||
import javafx.scene.input.DataFormat;
|
||||
import javafx.util.Duration;
|
||||
import javafx.util.converter.DefaultStringConverter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -47,6 +51,20 @@ class LabelCell extends TextFieldTreeTableCell<Entry, String> implements Confirm
|
|||
public void commitEdit(String label) {
|
||||
if(label != null) {
|
||||
label = label.trim();
|
||||
if(label.length() > Persistable.MAX_LABEL_LENGTH) {
|
||||
label = label.substring(0, Persistable.MAX_LABEL_LENGTH);
|
||||
Platform.runLater(() -> {
|
||||
Point2D p = this.localToScene(0.0, 0.0);
|
||||
final Tooltip truncateTooltip = new Tooltip();
|
||||
truncateTooltip.setText("Labels are truncated at " + Persistable.MAX_LABEL_LENGTH + " characters");
|
||||
truncateTooltip.setAutoHide(true);
|
||||
truncateTooltip.show(this, p.getX() + this.getScene().getX() + this.getScene().getWindow().getX() + this.getHeight(),
|
||||
p.getY() + this.getScene().getY() + this.getScene().getWindow().getY() + this.getHeight());
|
||||
PauseTransition pt = new PauseTransition(Duration.millis(2000));
|
||||
pt.setOnFinished(_ -> truncateTooltip.hide());
|
||||
pt.play();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// This block is necessary to support commit on losing focus, because
|
||||
|
|
|
|||
|
|
@ -61,6 +61,6 @@ public interface BlockTransactionDao {
|
|||
}
|
||||
|
||||
default String truncate(String label) {
|
||||
return (label != null && label.length() > 255 ? label.substring(0, 255) : label);
|
||||
return (label != null && label.length() > BlockTransaction.MAX_LABEL_LENGTH ? label.substring(0, BlockTransaction.MAX_LABEL_LENGTH) : label);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -268,7 +268,7 @@ public class DbPersistence implements Persistence {
|
|||
}
|
||||
|
||||
if(dirtyPersistables.label != null) {
|
||||
walletDao.updateLabel(wallet.getId(), dirtyPersistables.label.length() > 255 ? dirtyPersistables.label.substring(0, 255) : dirtyPersistables.label);
|
||||
walletDao.updateLabel(wallet.getId(), dirtyPersistables.label.length() > Wallet.MAX_LABEL_LENGTH ? dirtyPersistables.label.substring(0, Wallet.MAX_LABEL_LENGTH) : dirtyPersistables.label);
|
||||
}
|
||||
|
||||
if(dirtyPersistables.blockHeight != null) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.sparrowwallet.sparrow.io.db;
|
||||
|
||||
import com.sparrowwallet.drongo.wallet.Persistable;
|
||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||
import org.jdbi.v3.sqlobject.config.RegisterRowMapper;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlBatch;
|
||||
|
|
@ -26,7 +27,7 @@ public interface DetachedLabelDao {
|
|||
List<String> labels = new ArrayList<>();
|
||||
for(Map.Entry<String, String> labelEntry : new HashSet<>(wallet.getDetachedLabels().entrySet())) {
|
||||
entries.add(truncate(labelEntry.getKey(), 80));
|
||||
labels.add(truncate(labelEntry.getValue(), 255));
|
||||
labels.add(truncate(labelEntry.getValue(), Persistable.MAX_LABEL_LENGTH));
|
||||
}
|
||||
|
||||
insertDetachedLabels(entries, labels);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
package com.sparrowwallet.sparrow.io.db;
|
||||
|
||||
import com.sparrowwallet.drongo.crypto.EncryptedData;
|
||||
import com.sparrowwallet.drongo.wallet.DeterministicSeed;
|
||||
import com.sparrowwallet.drongo.wallet.Keystore;
|
||||
import com.sparrowwallet.drongo.wallet.MasterPrivateExtendedKey;
|
||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||
import com.sparrowwallet.drongo.wallet.*;
|
||||
import org.jdbi.v3.sqlobject.config.RegisterRowMapper;
|
||||
import org.jdbi.v3.sqlobject.statement.GetGeneratedKeys;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlQuery;
|
||||
|
|
@ -106,6 +103,6 @@ public interface KeystoreDao {
|
|||
}
|
||||
|
||||
default String truncate(String label) {
|
||||
return (label != null && label.length() > 255 ? label.substring(0, 255) : label);
|
||||
return (label != null && label.length() > Persistable.MAX_LABEL_LENGTH ? label.substring(0, Persistable.MAX_LABEL_LENGTH) : label);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -154,6 +154,6 @@ public interface WalletDao {
|
|||
}
|
||||
|
||||
default String truncate(String label) {
|
||||
return (label != null && label.length() > 255 ? label.substring(0, 255) : label);
|
||||
return (label != null && label.length() > Wallet.MAX_LABEL_LENGTH ? label.substring(0, Wallet.MAX_LABEL_LENGTH) : label);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,6 +121,6 @@ public interface WalletNodeDao {
|
|||
}
|
||||
|
||||
default String truncate(String label) {
|
||||
return (label != null && label.length() > 255 ? label.substring(0, 255) : label);
|
||||
return (label != null && label.length() > WalletNode.MAX_LABEL_LENGTH ? label.substring(0, WalletNode.MAX_LABEL_LENGTH) : label);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1599,7 +1599,7 @@ public class HeadersController extends TransactionFormController implements Init
|
|||
name += matcher.group(2);
|
||||
}
|
||||
}
|
||||
blockTransaction.setLabel(name != null && name.length() > 255 ? name.substring(0, 255) : name);
|
||||
blockTransaction.setLabel(name != null && name.length() > BlockTransaction.MAX_LABEL_LENGTH ? name.substring(0, BlockTransaction.MAX_LABEL_LENGTH) : name);
|
||||
changedLabelEntries.add(new TransactionEntry(event.getWallet(), blockTransaction, Collections.emptyMap(), Collections.emptyMap()));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue