Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/firm1/zest-writer
Browse files Browse the repository at this point in the history
  • Loading branch information
firm1 committed Dec 26, 2016
2 parents a27a80b + ca376ef commit 74b6503
Show file tree
Hide file tree
Showing 35 changed files with 318 additions and 329 deletions.
10 changes: 5 additions & 5 deletions src/main/java/com/zestedesavoir/zestwriter/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static Logger getLogger() {
@Override
public void start(Stage primaryStage) {
setPrimaryStage(primaryStage);
getPrimaryStage().setTitle(Configuration.bundle.getString("ui.app_name.text"));
getPrimaryStage().setTitle(Configuration.getBundle().getString("ui.app_name.text"));
getPrimaryStage().getIcons().add(new Image(getClass().getResourceAsStream("images/logo.png")));
getPrimaryStage().setMinWidth(400);
getPrimaryStage().setMinHeight(400);
Expand Down Expand Up @@ -270,9 +270,9 @@ public void initConnection(){

loginTask.setOnCancelled(t -> {
Alert alert = new CustomAlert(Alert.AlertType.ERROR);
alert.setTitle(Configuration.bundle.getString("ui.dialog.auth.title"));
alert.setHeaderText(Configuration.bundle.getString("ui.dialog.auth.state.header"));
alert.setContentText(Configuration.bundle.getString("ui.dialog.auth.failed.text"));
alert.setTitle(Configuration.getBundle().getString("ui.dialog.auth.title"));
alert.setHeaderText(Configuration.getBundle().getString("ui.dialog.auth.state.header"));
alert.setContentText(Configuration.getBundle().getString("ui.dialog.auth.failed.text"));

alert.showAndWait();
menuController.getMenuDownload().setDisable(false);
Expand Down Expand Up @@ -301,7 +301,7 @@ public void handle(KeyEvent t) {
if(key.toString().equals("_CONTROL_C_L_E_M")){
// Create the custom dialog.
Dialog<Void> dialog = new Dialog<>();
dialog.setTitle(Configuration.bundle.getString("ui.menu.easteregg"));
dialog.setTitle(Configuration.getBundle().getString("ui.menu.easteregg"));
dialog.setHeaderText(null);
dialog.setContentText(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ public class Constant {
public static final String SET_COOKIE_HEADER = "Set-Cookie";
public static final String CSRF_ZDS_KEY = "csrfmiddlewaretoken";
public static final String CSRF_COOKIE_KEY = "csrftoken";

private Constant() {
throw new IllegalAccessError("Utility class");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public class Container extends MetaContent implements ContentNode {
public Container(@JsonProperty("object") String object, @JsonProperty("slug") String slug, @JsonProperty("title") String title, @JsonProperty("introduction") String introduction, @JsonProperty("conclusion") String conclusion,
@JsonProperty("children") List<MetaContent> children) {
super(object, slug, title);
this._introduction = new MetaAttribute(introduction, Configuration.bundle.getString("ui.model.intro"));
this._conclusion = new MetaAttribute(conclusion, Configuration.bundle.getString("ui.model.conclusion"));
this._introduction = new MetaAttribute(introduction, Configuration.getBundle().getString("ui.model.intro"));
this._conclusion = new MetaAttribute(conclusion, Configuration.getBundle().getString("ui.model.conclusion"));
this._children = children;
}

Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/zestedesavoir/zestwriter/model/License.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@ public void setCode(String code) {
this.code = code;
}



public String getLabel() {
return label;
}


public void setLabel(String label) {
this.label = label;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public String getTitle() {
return title;
}

@Override
public void setTitle(String title) {
this.title = title;
}
Expand All @@ -54,6 +55,7 @@ public String getBasePath() {
return basePath;
}

@Override
public void setBasePath(String basePath) {
this.basePath = basePath;
File base = new File(getFilePath());
Expand Down
17 changes: 4 additions & 13 deletions src/main/java/com/zestedesavoir/zestwriter/model/MetaContent.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.zestedesavoir.zestwriter.MainApp;
import com.zestedesavoir.zestwriter.view.com.FunctionTreeFactory;

import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.function.Function;

Expand Down Expand Up @@ -38,7 +37,7 @@ public void setRootContent(Content rootContent, String basePath) {
setBasePath(basePath);
this.rootContent = rootContent;
if(this instanceof Container) {
Container c = ((Container) this);
Container c = (Container) this;
c.getIntroduction().setRootContent(rootContent, basePath);
c.getConclusion().setRootContent(rootContent, basePath);
for(MetaContent meta: c.getChildren()) {
Expand Down Expand Up @@ -87,22 +86,14 @@ public void setBasePath(String basePath) {
if(! base.exists()) {
base.mkdirs();
}
Container c = ((Container) this);
Container c = (Container) this;
c.getIntroduction().setBasePath(basePath);
c.getConclusion().setBasePath(basePath);
for(MetaContent meta: c.getChildren()) {
meta.setBasePath(basePath);
}
} else {
if(! base.exists()) {
try {
if(!base.createNewFile()) {
MainApp.getLogger().error("Problème lors de la création de "+base.getAbsolutePath());
}
} catch (IOException e) {
MainApp.getLogger().error("Problème lors de la création de "+base.getAbsolutePath(), e);
}
}
FunctionTreeFactory.performCreateNewFile(base);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public String getType() {
return type;
}

public boolean isArticle() {return type.equalsIgnoreCase("article");}
public boolean isArticle() {return "article".equalsIgnoreCase(type);}

public boolean isTutorial() {return type.equalsIgnoreCase("tutorial");}
public boolean isTutorial() {return "tutorial".equalsIgnoreCase(type);}

@Override
public String toString() {
Expand Down
23 changes: 2 additions & 21 deletions src/main/java/com/zestedesavoir/zestwriter/model/Textual.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,24 @@ public interface Textual{

String getMarkdown();
default void save() {
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(getFilePath()), "UTF8"));
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(getFilePath()), "UTF8"))) {
writer.append(getMarkdown());
writer.flush();
} catch (Exception e) {
MainApp.getLogger().error(e.getMessage(), e);
} finally {
try {
if (writer != null) {
writer.close();
}
} catch (Exception ignored) {
}
}
}
default String readMarkdown() {
Path path = Paths.get(this.getFilePath());
Scanner scanner = null;
StringBuilder bfString = new StringBuilder();
try {
scanner = new Scanner(path, StandardCharsets.UTF_8.name());
try(Scanner scanner = new Scanner(path, StandardCharsets.UTF_8.name())) {
while (scanner.hasNextLine()) {
bfString.append(scanner.nextLine());
bfString.append("\n");
}
scanner.close();
return bfString.toString();
} catch (IOException e) {
MainApp.getLogger().error(e.getMessage(), e);
} finally {
try {
if (scanner != null) {
scanner.close();
}
} catch (Exception ignored) {
}
}
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Configuration {
private StorageSaver onlineSaver;
private LocalDirectoryFactory workspaceFactory;
private Properties props;
public static ResourceBundle bundle;
private static ResourceBundle bundle;

/**
* Class constructor
Expand Down Expand Up @@ -164,6 +164,10 @@ public LocalDirectoryFactory getWorkspaceFactory() {
return workspaceFactory;
}

public static ResourceBundle getBundle() {
return bundle;
}

public void loadWorkspace() {

this.workspaceFactory = new LocalDirectoryFactory(getWorkspacePath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public String checkHtmlContent(String htmlContent) {
desc = new HtmlToPlainText().getPlainText(Jsoup.parse(desc));

if (!match.getSuggestedReplacements().isEmpty()) {
desc += Configuration.bundle.getString("ui.alert.correction.tooltip.suggestion")
desc += Configuration.getBundle().getString("ui.alert.correction.tooltip.suggestion")
+ match.getSuggestedReplacements();
}
String before = "<span class=\"error-french\" title=\"" + desc + "\">";
Expand Down Expand Up @@ -199,7 +199,7 @@ public String checkHtmlContentToText(String htmlContent, String source) {
bf.append("> ");
bf.append(markup.getPlainText().split("[\n|\r]")[match.getLine()].replace(txt, "**" + txt + "**"));
bf.append("\n");
bf.append(Configuration.bundle.getString("ui.alert.correction.source")).append(source);
bf.append(Configuration.getBundle().getString("ui.alert.correction.source")).append(source);
bf.append("\n\n");
bf.append(match.getRule().getDescription());
bf.append("\n\n");
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/zestedesavoir/zestwriter/utils/Theme.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public class Theme {
private int endMonth=0;

private static List<Theme> themeAvailable = Arrays.asList(
new Theme("dark.css", Configuration.bundle.getString("ui.options.display.theme.dark")),
new Theme("light.css", Configuration.bundle.getString("ui.options.display.theme.light")),
new Theme("halloween.css", Configuration.bundle.getString("ui.options.display.theme.halloween"), 31, 10, 2, 11),
new Theme("dark.css", Configuration.getBundle().getString("ui.options.display.theme.dark")),
new Theme("light.css", Configuration.getBundle().getString("ui.options.display.theme.light")),
new Theme("halloween.css", Configuration.getBundle().getString("ui.options.display.theme.halloween"), 31, 10, 2, 11),
new Theme("winxaito_light.css", "WinXaito's Light"),
new Theme("winxaito_dark.css", "WinXaito's Dark"),
new Theme("christmas.css", Configuration.bundle.getString("ui.options.display.theme.christmas"), 15, 12, 27, 12));
new Theme("christmas.css", Configuration.getBundle().getString("ui.options.display.theme.christmas"), 15, 12, 27, 12));

public Theme(String filename, String label, int startDay, int startMonth, int endDay, int endMonth) {
this.filename = filename;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ private void handleSmartTab() {
@FXML private void handleImgButtonAction(ActionEvent event) {
FXMLLoader loader = new CustomFXMLLoader(MainApp.class.getResource("fxml/ImageInput.fxml"));

Stage dialogStage = new CustomStage(loader, Configuration.bundle.getString("ui.dialog.upload.img.title"));
Stage dialogStage = new CustomStage(loader, Configuration.getBundle().getString("ui.dialog.upload.img.title"));

ImageInputDialog imageController = loader.getController();
if(!mainApp.getContents().isEmpty()) {
Expand Down Expand Up @@ -351,9 +351,9 @@ private void handleSmartTab() {
FunctionTreeFactory.addTheming(dialog.getDialogPane());
dialog.initModality(Modality.APPLICATION_MODAL);
dialog.initOwner(MainApp.getPrimaryStage());
dialog.setTitle(Configuration.bundle.getString("ui.editor.dialog.bloc.title"));
dialog.setHeaderText(Configuration.bundle.getString("ui.editor.dialog.bloc.header"));
dialog.setContentText(Configuration.bundle.getString("ui.editor.dialog.bloc.text"));
dialog.setTitle(Configuration.getBundle().getString("ui.editor.dialog.bloc.title"));
dialog.setHeaderText(Configuration.getBundle().getString("ui.editor.dialog.bloc.header"));
dialog.setContentText(Configuration.getBundle().getString("ui.editor.dialog.bloc.text"));

// Traditional way to get the response value.
Optional<String> result = dialog.showAndWait();
Expand All @@ -367,7 +367,7 @@ private void handleSmartTab() {
@FXML private void handleTableButtonAction(ActionEvent event) throws IOException {
// Create the custom dialog.
Dialog<Pair<ObservableList, ObservableList<ZRow>>> dialog = new CustomDialog<>();
dialog.setTitle(Configuration.bundle.getString("ui.editor.button.table"));
dialog.setTitle(Configuration.getBundle().getString("ui.editor.button.table"));
dialog.setHeaderText("");

// Set the button types.
Expand All @@ -378,7 +378,6 @@ private void handleSmartTab() {
TableView<ZRow> tbView = (TableView) tableEditor.getCenter();

TableController controller = loader.getController();
controller.setEditor(this);

dialog.getDialogPane().setContent(tableEditor);

Expand Down Expand Up @@ -416,8 +415,8 @@ private void handleSmartTab() {

// Create the custom dialog.
Dialog<Pair<String, String>> dialog = new CustomDialog<>();
dialog.setTitle(Configuration.bundle.getString("ui.editor.dialog.link.title"));
dialog.setHeaderText(Configuration.bundle.getString("ui.editor.dialog.link.header"));
dialog.setTitle(Configuration.getBundle().getString("ui.editor.dialog.link.title"));
dialog.setHeaderText(Configuration.getBundle().getString("ui.editor.dialog.link.header"));

// Set the icon (must be included in the project).
dialog.setGraphic(IconFactory.createLinkIcon());
Expand All @@ -435,9 +434,9 @@ private void handleSmartTab() {
TextField tLabel = new TextField();
tLabel.setText(link);

grid.add(new Label(Configuration.bundle.getString("ui.editor.dialog.link.field.url")), 0, 0);
grid.add(new Label(Configuration.getBundle().getString("ui.editor.dialog.link.field.url")), 0, 0);
grid.add(tLink, 1, 0);
grid.add(new Label(Configuration.bundle.getString("ui.editor.dialog.link.field.label")), 0, 1);
grid.add(new Label(Configuration.getBundle().getString("ui.editor.dialog.link.field.label")), 0, 1);
grid.add(tLabel, 1, 1);

dialog.getDialogPane().setContent(grid);
Expand Down Expand Up @@ -472,8 +471,8 @@ private void handleSmartTab() {

// Create the custom dialog.
Dialog<Pair<String, String>> dialog = new CustomDialog<>();
dialog.setTitle(Configuration.bundle.getString("ui.editor.dialog.code.title"));
dialog.setHeaderText(Configuration.bundle.getString("ui.editor.dialog.code.header"));
dialog.setTitle(Configuration.getBundle().getString("ui.editor.dialog.code.title"));
dialog.setHeaderText(Configuration.getBundle().getString("ui.editor.dialog.code.header"));

// Set the icon (must be included in the project).
dialog.setGraphic(IconFactory.createCodeIcon());
Expand All @@ -491,9 +490,9 @@ private void handleSmartTab() {
TextArea tCode = new TextArea();
tCode.setText(code);

grid.add(new Label(Configuration.bundle.getString("ui.editor.dialog.code.field.lang")), 0, 0);
grid.add(new Label(Configuration.getBundle().getString("ui.editor.dialog.code.field.lang")), 0, 0);
grid.add(tLangage, 1, 0);
grid.add(new Label(Configuration.bundle.getString("ui.editor.dialog.code.field.code")), 0, 1);
grid.add(new Label(Configuration.getBundle().getString("ui.editor.dialog.code.field.code")), 0, 1);
grid.add(tCode, 1, 1);

dialog.getDialogPane().setContent(grid);
Expand Down Expand Up @@ -603,7 +602,7 @@ protected String call() throws Exception {
@FXML private void handleExternalButtonAction(ActionEvent event){
splitPane.getItems().remove(1);

Stage stage = new CustomStage(Configuration.bundle.getString("ui.window.externalrender.title"));
Stage stage = new CustomStage(Configuration.getBundle().getString("ui.window.externalrender.title"));
AnchorPane pane = new AnchorPane(renderView);
AnchorPane.setTopAnchor(renderView, 0.0);
AnchorPane.setLeftAnchor(renderView, 0.0);
Expand All @@ -630,8 +629,8 @@ protected String call() throws Exception {

public void performStats() {
Readability readText = new Readability(SourceText.getText());
countChars.setValue(Configuration.bundle.getString("ui.statusbar.stats.chars") + readText.getCharacters());
countWords.setValue(Configuration.bundle.getString("ui.statusbar.stats.words") + readText.getWords());
countChars.setValue(Configuration.getBundle().getString("ui.statusbar.stats.chars") + readText.getCharacters());
countWords.setValue(Configuration.getBundle().getString("ui.statusbar.stats.words") + readText.getWords());
countTimes.setValue(FunctionTreeFactory.getNumberOfTextualReadMinutes(SourceText.getText()));
}

Expand Down Expand Up @@ -668,9 +667,9 @@ public void initStats() {

public void handleGoToLineAction() {
TextInputDialog dialog = new TextInputDialog();
dialog.setTitle(Configuration.bundle.getString("ui.editor.dialog.goto.title"));
dialog.setHeaderText(Configuration.bundle.getString("ui.editor.dialog.goto.header"));
dialog.setContentText(Configuration.bundle.getString("ui.editor.dialog.goto.text"));
dialog.setTitle(Configuration.getBundle().getString("ui.editor.dialog.goto.title"));
dialog.setHeaderText(Configuration.getBundle().getString("ui.editor.dialog.goto.header"));
dialog.setContentText(Configuration.getBundle().getString("ui.editor.dialog.goto.text"));
dialog.initOwner(MainApp.getPrimaryStage());

Optional<String> result = dialog.showAndWait();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public MdTextController() {

loadFonts();
EditorList.getSelectionModel().selectedItemProperty().addListener(
(observable, oldValue, newValue) -> mainApp.getMenuController().isOnReadingTab.set(! (newValue.getContent() instanceof SplitPane))
(observable, oldValue, newValue) -> mainApp.getMenuController().setIsOnReadingTab(! (newValue.getContent() instanceof SplitPane))
);
}

Expand Down Expand Up @@ -268,13 +268,13 @@ public void createTabExtract(Textual extract) throws IOException {
tab.setOnCloseRequest(t -> {
if(!controllerConvert.isSaved()) {
Alert alert = new CustomAlert(AlertType.CONFIRMATION);
alert.setTitle(Configuration.bundle.getString("ui.alert.tab.close.title"));
alert.setHeaderText(Configuration.bundle.getString("ui.alert.tab.close.header")+" : "+tab.getText().substring(1));
alert.setContentText(Configuration.bundle.getString("ui.alert.tab.close.text"));
alert.setTitle(Configuration.getBundle().getString("ui.alert.tab.close.title"));
alert.setHeaderText(Configuration.getBundle().getString("ui.alert.tab.close.header")+" : "+tab.getText().substring(1));
alert.setContentText(Configuration.getBundle().getString("ui.alert.tab.close.text"));

ButtonType buttonTypeYes = new ButtonType(Configuration.bundle.getString("ui.yes"));
ButtonType buttonTypeNo = new ButtonType(Configuration.bundle.getString("ui.no"));
ButtonType buttonTypeCancel = new ButtonType(Configuration.bundle.getString("ui.cancel"), ButtonData.CANCEL_CLOSE);
ButtonType buttonTypeYes = new ButtonType(Configuration.getBundle().getString("ui.yes"));
ButtonType buttonTypeNo = new ButtonType(Configuration.getBundle().getString("ui.no"));
ButtonType buttonTypeCancel = new ButtonType(Configuration.getBundle().getString("ui.cancel"), ButtonData.CANCEL_CLOSE);

alert.getButtonTypes().setAll(buttonTypeYes, buttonTypeNo, buttonTypeCancel);
alert.setResizable(true);
Expand Down
Loading

0 comments on commit 74b6503

Please sign in to comment.