From 772ac377bd0e36aa5326b7862987899a47317506 Mon Sep 17 00:00:00 2001 From: Rohit Awate Date: Sat, 21 Jul 2018 16:04:12 +0530 Subject: [PATCH] Re-wrote tab text reflection logic --- .../controllers/HomeWindowController.java | 43 +++++++++++-------- .../controllers/state/ComposerState.java | 5 +++ src/main/resources/templates/LogsFile.html | 2 +- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/rohitawate/everest/controllers/HomeWindowController.java b/src/main/java/com/rohitawate/everest/controllers/HomeWindowController.java index 421a167..67adc19 100644 --- a/src/main/java/com/rohitawate/everest/controllers/HomeWindowController.java +++ b/src/main/java/com/rohitawate/everest/controllers/HomeWindowController.java @@ -24,7 +24,6 @@ import com.rohitawate.everest.misc.KeyMap; import com.rohitawate.everest.misc.Services; import com.rohitawate.everest.misc.ThemeManager; import javafx.application.Platform; -import javafx.beans.binding.Bindings; import javafx.beans.property.StringProperty; import javafx.beans.value.ObservableValue; import javafx.fxml.FXML; @@ -94,6 +93,29 @@ public class HomeWindowController implements Initializable { }); tabPane.getSelectionModel().selectedItemProperty().addListener(this::onTabSwitched); + + initAddressReflection(); + } + + private void initAddressReflection() { + addressProperty.addListener(((observable, oldValue, newValue) -> { + Tab activeTab = tabPane.getSelectionModel().getSelectedItem(); + if (activeTab != null) { + if (newValue.equals("")) + activeTab.setText("New Tab"); + else + activeTab.setText(newValue); + } + })); + + // Initialize the text of tabs loaded by the state recovery logic + tabPane.getTabs().forEach(tab -> { + String target = tabStateMap.get(tab).composer.target; + if (target.equals("")) + tab.setText("New Tab"); + else + tab.setText(target); + }); } /** @@ -131,7 +153,7 @@ public class HomeWindowController implements Initializable { } private void addTab() { - addTab(null); + addTab(new ComposerState()); } /** @@ -140,6 +162,7 @@ public class HomeWindowController implements Initializable { */ private void addTab(ComposerState composerState) { Tab newTab = new Tab(); + newTab.setText("New Tab"); DashboardState newState = new DashboardState(composerState); tabStateMap.put(newTab, newState); @@ -158,13 +181,6 @@ public class HomeWindowController implements Initializable { tabPane.getSelectionModel().select(newTab); onTabSwitched(prevState, prevTab, newTab); - // Makes the Tab's text change with the URL - newTab.textProperty().bind( - Bindings.when(Bindings.and(addressProperty.isNotEmpty(), newTab.selectedProperty())) - .then(addressProperty) - .otherwise(getTabText(newTab)) - ); - newTab.setOnCloseRequest(e -> { tabStateMap.remove(newTab); tabPane.getTabs().remove(newTab); @@ -178,15 +194,6 @@ public class HomeWindowController implements Initializable { }); } - private String getTabText(Tab newTab) { - DashboardState state = tabStateMap.get(newTab); - - if (state == null || state.composer == null || state.composer.target.equals("")) - return "New Tab"; - else - return state.composer.target; - } - private void saveState() { /* Updating the state of the selected tab before saving it. diff --git a/src/main/java/com/rohitawate/everest/controllers/state/ComposerState.java b/src/main/java/com/rohitawate/everest/controllers/state/ComposerState.java index c898de9..32bc43d 100644 --- a/src/main/java/com/rohitawate/everest/controllers/state/ComposerState.java +++ b/src/main/java/com/rohitawate/everest/controllers/state/ComposerState.java @@ -23,6 +23,7 @@ import java.util.ArrayList; */ public class ComposerState { public String target; + public String httpMethod; public ArrayList params; public ArrayList headers; @@ -43,4 +44,8 @@ public class ComposerState { // File path of application/octet-stream requests public String binaryFilePath; + + public ComposerState() { + this.httpMethod = "GET"; + } } diff --git a/src/main/resources/templates/LogsFile.html b/src/main/resources/templates/LogsFile.html index bc47a82..91e276b 100644 --- a/src/main/resources/templates/LogsFile.html +++ b/src/main/resources/templates/LogsFile.html @@ -54,4 +54,4 @@ -

Everest Log: %% Date %%

+

Everest Logs: %% Date %%