From bacbdb848b27511e65e95ef86bc6e44fc39888f7 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Tue, 6 Sep 2022 12:42:18 +0200 Subject: [PATCH] add move left and right context menu items to reorder wallet and transaction tabs --- .../sparrowwallet/sparrow/AppController.java | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index 3c18029f..c3af76c5 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -1860,6 +1860,27 @@ public class AppController implements Initializable { contextMenu.getItems().addAll(lock); } + MenuItem moveRight = new MenuItem("Move Right"); + moveRight.setOnAction(event -> { + int index = tabs.getTabs().indexOf(tab); + tabs.getTabs().remove(tab); + tabs.getTabs().add(index + 1, tab); + tabs.getSelectionModel().select(tab); + }); + MenuItem moveLeft = new MenuItem("Move Left"); + moveLeft.setOnAction(event -> { + int index = tabs.getTabs().indexOf(tab); + tabs.getTabs().remove(tab); + tabs.getTabs().add(index - 1, tab); + tabs.getSelectionModel().select(tab); + }); + contextMenu.getItems().addAll(moveRight, moveLeft); + + contextMenu.setOnShowing(event -> { + moveRight.setDisable(tabs.getTabs().indexOf(tab) == tabs.getTabs().size() - 1); + moveLeft.setDisable(tabs.getTabs().indexOf(tab) == 0); + }); + MenuItem close = new MenuItem("Close"); close.setOnAction(event -> { tabs.getTabs().remove(tab); @@ -1877,12 +1898,16 @@ public class AppController implements Initializable { tabs.getTabs().removeAll(tabs.getTabs()); }); - MenuItem delete = new MenuItem("Delete..."); - delete.setOnAction(event -> { - deleteWallet(getSelectedWalletForm()); - }); + contextMenu.getItems().addAll(new SeparatorMenuItem(), close, closeOthers, closeAll); + + if(tab.getUserData() instanceof WalletTabData) { + MenuItem delete = new MenuItem("Delete..."); + delete.setOnAction(event -> { + deleteWallet(getSelectedWalletForm()); + }); + contextMenu.getItems().addAll(new SeparatorMenuItem(), delete); + } - contextMenu.getItems().addAll(close, closeOthers, closeAll, delete); return contextMenu; }