Skip to content

Commit

Permalink
fix #28 clic on open extract send immediatly on
Browse files Browse the repository at this point in the history
  • Loading branch information
firm1 committed Mar 8, 2016
1 parent e594c6c commit 90bccb8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
7 changes: 3 additions & 4 deletions src/com/zestedesavoir/zestwriter/MainApp.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -32,7 +31,7 @@ public class MainApp extends Application {
private Scene scene;
private Stage primaryStage;
private BorderPane rootLayout;
private ObservableList<ExtractFile> extracts = FXCollections.observableArrayList();
private ObservableMap<ExtractFile, Tab> extracts = FXCollections.observableMap(new HashMap<>());
private ObservableMap<String, String> contents = FXCollections.observableMap(new HashMap<>());
private ZdsHttp zdsutils;
private MdTextController Index;
Expand Down Expand Up @@ -74,7 +73,7 @@ public ZdsHttp getZdsutils() {
return zdsutils;
}

public ObservableList<ExtractFile> getExtracts() {
public ObservableMap<ExtractFile, Tab> getExtracts() {
return extracts;
}

Expand Down
20 changes: 13 additions & 7 deletions src/com/zestedesavoir/zestwriter/view/MdTextController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<String, Object> getMapFromTreeItem(TreeItem<ExtractFile> node, Map<String, Object> map) {
Expand Down Expand Up @@ -358,12 +359,17 @@ public void openContent(String filePath) throws IOException {
TreeItem<ExtractFile> 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()));
}
}
}
Expand Down

0 comments on commit 90bccb8

Please sign in to comment.