Skip to content

Commit 92adcc2

Browse files
committed
auto-load connections list on tab show, if needed
ensure default value of "encrypt/decrypt" is not changed when a corresponding user setting is not present
1 parent 584664e commit 92adcc2

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

FiddView/src/main/java/com/fidd/view/forms/MainForm.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public class MainForm {
8686
@Nullable Integer fiddApiPort;
8787

8888
@FXML @Nullable TabPane mainTabPane;
89+
@FXML @Nullable Tab fiddConnectionsTab;
8990
@FXML @Nullable AnchorPane topPane;
9091
@FXML @Nullable TableView<FiddConnection> fiddConnectionTableView;
9192
@FXML @Nullable CheckBox encryptDecryptFiddConnectionsCheckBox;
@@ -128,16 +129,23 @@ public void init(Stage mainStage, BaseRepositories repositories, FiddContentServ
128129
String fiddConnectionsFileStr = UserPreferencesManager.getUserPreference(FIDD_VIEW_FIDD_CONNECTIONS_FILE);
129130
String encryptDecryptFileStr = UserPreferencesManager.getUserPreference(FIDD_VIEW_ENCRYPT_DECRYPT);
130131
try {
131-
boolean encryptDecryptFile = Boolean.parseBoolean(encryptDecryptFileStr);
132-
checkNotNull(encryptDecryptFiddConnectionsCheckBox).selectedProperty().set(encryptDecryptFile);
132+
if (!StringUtils.isBlank(encryptDecryptFileStr)) {
133+
boolean encryptDecryptFile = Boolean.parseBoolean(encryptDecryptFileStr);
134+
checkNotNull(encryptDecryptFiddConnectionsCheckBox).selectedProperty().set(encryptDecryptFile);
135+
}
133136
} catch (Exception e) { }
134137

135138
if (!StringUtils.isBlank(fiddConnectionsFileStr)) {
136139
checkNotNull(fiddConnectionsFileTextField).textProperty().set(fiddConnectionsFileStr);
137-
loadFiddConnections(false);
138140
}
139141
checkNotNull(fiddConnectionsFileTextField).textProperty().addListener(
140142
(observableValue, s, t1) -> fiddConnectionsFileChanged());
143+
144+
checkNotNull(mainTabPane).getSelectionModel().selectedItemProperty().addListener((obs, oldTab, newTab) -> {
145+
if (newTab == fiddConnectionsTab && checkNotNull(fiddConnections).isEmpty()) {
146+
loadFiddConnections(false);
147+
}
148+
});
141149
}
142150

143151
private static TabKeyProvider buildMainKeyProvider(Stage mainStage) {
@@ -463,7 +471,7 @@ public void openFiddConnections() {
463471
}
464472

465473
public void loadFiddConnections(boolean showAlerts) {
466-
if (!checkNotNull(fiddConnections).isEmpty()) {
474+
if (showAlerts && !checkNotNull(fiddConnections).isEmpty()) {
467475
if (JavaFxUtils.YesNo.NO ==
468476
JavaFxUtils.showYesNoDialog("Load Fidd Connections File",
469477
"Current Fidd Connections will be lost. Continue?")) {
@@ -487,8 +495,10 @@ public void loadFiddConnections(boolean showAlerts) {
487495
if (decrypt) {
488496
Pair<X509Certificate, PrivateKey> pair = getCurrentCertificate();
489497
if (pair == null) {
490-
JavaFxUtils.showMessage("Certificate load error",
491-
"Certificate load error. If you do not plan to use a certificate, uncheck \"Decrypt / Encrypt\" checkbox.");
498+
if (showAlerts) {
499+
JavaFxUtils.showMessage("Certificate load error",
500+
"Certificate load error. If you do not plan to use a certificate, uncheck \"Decrypt / Encrypt\" checkbox.");
501+
}
492502
return;
493503
}
494504

FiddView/src/main/resources/com/fidd/view/forms/MainForm.fxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
</padding></AnchorPane>
3131
</content>
3232
</Tab>
33-
<Tab closable="false" text="Fidd Connections">
33+
<Tab fx:id="fiddConnectionsTab" closable="false" text="Fidd Connections">
3434
<content>
3535
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
3636
<children>

0 commit comments

Comments
 (0)