mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-02 12:26:45 +00:00
select existing tab on same file
This commit is contained in:
parent
3d04ce4686
commit
001da5c534
2 changed files with 53 additions and 3 deletions
|
@ -81,8 +81,8 @@ public class AppController implements Initializable {
|
|||
|
||||
tabs.getSelectionModel().selectedItemProperty().addListener((observable, old_val, selectedTab) -> {
|
||||
if(selectedTab != null) {
|
||||
String tabType = (String)selectedTab.getUserData();
|
||||
if(tabType.equals(TRANSACTION_TAB_TYPE)) {
|
||||
TabData tabData = (TabData)selectedTab.getUserData();
|
||||
if(tabData.getType() == TabData.TabType.TRANSACTION) {
|
||||
EventManager.get().post(new TransactionTabSelectedEvent(selectedTab));
|
||||
}
|
||||
}
|
||||
|
@ -109,6 +109,14 @@ public class AppController implements Initializable {
|
|||
}
|
||||
|
||||
private void openFile(File file) {
|
||||
for(Tab tab : tabs.getTabs()) {
|
||||
TabData tabData = (TabData)tab.getUserData();
|
||||
if(file.equals(tabData.getFile())) {
|
||||
tabs.getSelectionModel().select(tab);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(file.exists()) {
|
||||
try {
|
||||
byte[] bytes = new byte[(int)file.length()];
|
||||
|
@ -119,6 +127,8 @@ public class AppController implements Initializable {
|
|||
|
||||
try {
|
||||
Tab tab = addTransactionTab(name, bytes);
|
||||
TabData tabData = (TabData)tab.getUserData();
|
||||
tabData.setFile(file);
|
||||
tabs.getSelectionModel().select(tab);
|
||||
} catch(ParseException e) {
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
|
||||
|
@ -153,6 +163,8 @@ public class AppController implements Initializable {
|
|||
if(text.isPresent() && !text.get().isEmpty()) {
|
||||
try {
|
||||
Tab tab = addTransactionTab(null, text.get().trim());
|
||||
TabData tabData = (TabData)tab.getUserData();
|
||||
tabData.setText(text.get());
|
||||
tabs.getSelectionModel().select(tab);
|
||||
} catch(PSBTParseException e) {
|
||||
showErrorDialog("Invalid PSBT", e.getMessage());
|
||||
|
@ -240,7 +252,8 @@ public class AppController implements Initializable {
|
|||
}
|
||||
|
||||
Tab tab = new Tab(tabName);
|
||||
tab.setUserData(TRANSACTION_TAB_TYPE);
|
||||
TabData tabData = new TabData(TabData.TabType.TRANSACTION);
|
||||
tab.setUserData(tabData);
|
||||
tab.setClosable(true);
|
||||
FXMLLoader transactionLoader = new FXMLLoader(getClass().getResource("transaction/transaction.fxml"));
|
||||
tab.setContent(transactionLoader.load());
|
||||
|
|
37
src/main/java/com/sparrowwallet/sparrow/TabData.java
Normal file
37
src/main/java/com/sparrowwallet/sparrow/TabData.java
Normal file
|
@ -0,0 +1,37 @@
|
|||
package com.sparrowwallet.sparrow;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class TabData {
|
||||
private TabType type;
|
||||
private File file;
|
||||
private String text;
|
||||
|
||||
public TabData(TabType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public TabType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public void setFile(File file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public enum TabType {
|
||||
TRANSACTION
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue