Skip to content

Commit

Permalink
tab context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Raw committed Apr 12, 2020
1 parent 001da5c commit 64dca54
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/main/java/com/sparrowwallet/sparrow/AppController.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
import com.sparrowwallet.sparrow.event.TransactionTabChangedEvent;
import com.sparrowwallet.sparrow.event.TransactionTabSelectedEvent;
import com.sparrowwallet.sparrow.transaction.TransactionController;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
Expand All @@ -26,9 +29,7 @@
import java.io.*;
import java.net.URL;
import java.text.ParseException;
import java.util.Base64;
import java.util.Optional;
import java.util.ResourceBundle;
import java.util.*;

public class AppController implements Initializable {
private static final String TRANSACTION_TAB_TYPE = "transaction";
Expand Down Expand Up @@ -254,6 +255,7 @@ private Tab addTransactionTab(String name, Transaction transaction, PSBT psbt) {
Tab tab = new Tab(tabName);
TabData tabData = new TabData(TabData.TabType.TRANSACTION);
tab.setUserData(tabData);
tab.setContextMenu(getTabContextMenu(tab));
tab.setClosable(true);
FXMLLoader transactionLoader = new FXMLLoader(getClass().getResource("transaction/transaction.fxml"));
tab.setContent(transactionLoader.load());
Expand All @@ -272,6 +274,30 @@ private Tab addTransactionTab(String name, Transaction transaction, PSBT psbt) {
}
}

private ContextMenu getTabContextMenu(Tab tab) {
ContextMenu contextMenu = new ContextMenu();

MenuItem close = new MenuItem("Close");
close.setOnAction(event -> {
tabs.getTabs().remove(tab);
});

MenuItem closeOthers = new MenuItem("Close Others");
closeOthers.setOnAction(event -> {
List<Tab> otherTabs = new ArrayList<>(tabs.getTabs());
otherTabs.remove(tab);
tabs.getTabs().removeAll(otherTabs);
});

MenuItem closeAll = new MenuItem("Close All");
closeAll.setOnAction(event -> {
tabs.getTabs().removeAll(tabs.getTabs());
});

contextMenu.getItems().addAll(close, closeOthers, closeAll);
return contextMenu;
}

@Subscribe
public void tabSelected(TabEvent event) {
Tab selectedTab = event.getTab();
Expand Down

0 comments on commit 64dca54

Please sign in to comment.