diff --git a/src/com/zestedesavoir/zestwriter/MainApp.java b/src/com/zestedesavoir/zestwriter/MainApp.java index 8969559e9..6f186f3e1 100644 --- a/src/com/zestedesavoir/zestwriter/MainApp.java +++ b/src/com/zestedesavoir/zestwriter/MainApp.java @@ -1,9 +1,7 @@ package com.zestedesavoir.zestwriter; import java.io.IOException; -import java.io.InputStream; import java.util.HashMap; -import java.util.Properties; import com.zestedesavoir.zestwriter.model.ExtractFile; import com.zestedesavoir.zestwriter.utils.Configuration; @@ -21,6 +19,7 @@ import javafx.scene.Scene; import javafx.scene.control.ButtonType; import javafx.scene.control.Dialog; +import javafx.scene.control.Tab; import javafx.scene.image.ImageView; import javafx.scene.input.KeyEvent; import javafx.scene.layout.AnchorPane; @@ -32,7 +31,7 @@ public class MainApp extends Application { private Scene scene; private Stage primaryStage; private BorderPane rootLayout; - private ObservableList extracts = FXCollections.observableArrayList(); + private ObservableMap extracts = FXCollections.observableMap(new HashMap<>()); private ObservableMap contents = FXCollections.observableMap(new HashMap<>()); private ZdsHttp zdsutils; private MdTextController Index; @@ -74,7 +73,7 @@ public ZdsHttp getZdsutils() { return zdsutils; } - public ObservableList getExtracts() { + public ObservableMap getExtracts() { return extracts; } diff --git a/src/com/zestedesavoir/zestwriter/view/MdTextController.java b/src/com/zestedesavoir/zestwriter/view/MdTextController.java index 8c2628aa8..2c56848b3 100644 --- a/src/com/zestedesavoir/zestwriter/view/MdTextController.java +++ b/src/com/zestedesavoir/zestwriter/view/MdTextController.java @@ -195,7 +195,6 @@ public void setMainApp(MainApp mainApp) { public void createTabExtract(ExtractFile extract) throws IOException { extract.loadMarkdown(); - mainApp.getExtracts().add(extract); FXMLLoader loader = new FXMLLoader(); loader.setLocation(MainApp.class.getResource("view/Editor.fxml")); SplitPane writer = loader.load(); @@ -238,6 +237,8 @@ public void createTabExtract(ExtractFile extract) throws IOException { tab.setOnClosed(t -> { mainApp.getExtracts().remove(extract); }); + + mainApp.getExtracts().put(extract, tab); } public Map getMapFromTreeItem(TreeItem node, Map map) { @@ -358,12 +359,17 @@ public void openContent(String filePath) throws IOException { TreeItem item = Summary.getSelectionModel().getSelectedItem(); if(!item.getValue().isContainer()) { - if ((!mainApp.getExtracts().contains(item.getValue())) - && (item.getValue().getFilePath() != null)) { - try { - createTabExtract(item.getValue()); - } catch (IOException e) { - e.printStackTrace(); + if (item.getValue().getFilePath() != null) { + if (!mainApp.getExtracts().containsKey(item.getValue())) { + try { + createTabExtract(item.getValue()); + } catch (IOException e) { + e.printStackTrace(); + } + } else { + TabPaneSkin skin = (TabPaneSkin) EditorList.getSkin(); + TabPaneBehavior tabPaneBehavior = (TabPaneBehavior) skin.getBehavior(); + tabPaneBehavior.selectTab(mainApp.getExtracts().get(item.getValue())); } } }