Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Règle le problème des accents sur Linux (ou pas) #296

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ dependencies {
compile group: 'com.zestedesavoir.zmarkdown', name: 'java-zmarkdown', version: '2.6.0.17'
compile group: 'com.fasterxml', name: 'jackson-module-json-org', version: '0.9.1'
compile group: 'commons-io', name: 'commons-io', version: '2.5'
compile group: 'com.1stleg', name: 'jnativehook', version: '2.0.2'
}

test {
Expand Down
30 changes: 25 additions & 5 deletions src/main/java/com/zestedesavoir/zestwriter/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.zestedesavoir.zestwriter.utils.Configuration;
import com.zestedesavoir.zestwriter.utils.Markdown;
import com.zestedesavoir.zestwriter.utils.ZdsHttp;
import com.zestedesavoir.zestwriter.view.KeyListener;
import com.zestedesavoir.zestwriter.view.MdTextController;
import com.zestedesavoir.zestwriter.view.MenuController;
import com.zestedesavoir.zestwriter.view.com.CustomAlert;
Expand Down Expand Up @@ -35,6 +36,8 @@
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import org.jnativehook.GlobalScreen;
import org.jnativehook.NativeHookException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -45,6 +48,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.logging.Level;

public class MainApp extends Application{
public static Configuration config;
Expand All @@ -62,21 +66,37 @@ public class MainApp extends Application{
private PluginsManager pm;
private static ContentsConfig contentsConfigPlugins;
private static ContentsConfig contentsConfigThemes;
private static String[] args;
protected static File defaultHome;
public static String[] args;
public static File defaultHome;
public static KeyListener keyListener;


public MainApp() {
super();

initEnvVariable();
logger = LoggerFactory.getLogger(MainApp.class);

if(FunctionTreeFactory.isLinuxOs()){
java.util.logging.Logger logger2 = java.util.logging.Logger.getLogger(GlobalScreen.class.getPackage().getName());
logger2.setLevel(Level.OFF);

try{
GlobalScreen.registerNativeHook();
keyListener = new KeyListener();
GlobalScreen.addNativeKeyListener(keyListener);
}catch(NativeHookException e){
logger.error("Error for initialize KeyListener", e);
}
}

logger.info("Version Java de l'utilisateur: " + System.getProperty("java.version"));
logger.info("Architecture du système utilisateur: " + System.getProperty("os.arch"));
logger.info("Nom du système utilisateur: " + System.getProperty("os.name"));
logger.info("Version du système utilisateur: " + System.getProperty("os.version"));
logger.info("Emplacement du fichier de log: " + System.getProperty("zw.logPath"));


if(args.length > 0) {
config = new Configuration(args[0]);
} else {
Expand Down Expand Up @@ -105,13 +125,13 @@ private void initEnvVariable() {
Path logDir;
String appName = "zest-writer";
String os = System.getProperty("os.name").toLowerCase();
if(os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0 || os.indexOf("aix") >= 0) {
if(FunctionTreeFactory.isLinuxOs()) {
logPath = Paths.get(System.getProperty("user.home"), ".config", appName, appName+".log");
logDir = logPath.getParent();
} else if(os.indexOf("win") >= 0) {
} else if(FunctionTreeFactory.isWindowsOs()) {
logPath = Paths.get(System.getProperty("user.home"), "AppData", "Local", appName, appName+".log");
logDir = logPath.getParent();
} else if(os.indexOf("mac") >= 0) {
} else if(FunctionTreeFactory.isMacOs()) {
logPath = Paths.get(System.getProperty("user.home"), "Library", "Application Support", appName, appName+".log");
logDir = logPath.getParent();
} else {
Expand Down
109 changes: 109 additions & 0 deletions src/main/java/com/zestedesavoir/zestwriter/view/KeyListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.zestedesavoir.zestwriter.view;

import com.zestedesavoir.zestwriter.view.com.CustomStyledClassedTextArea;
import javafx.application.Platform;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.jnativehook.keyboard.NativeKeyEvent;
import org.jnativehook.keyboard.NativeKeyListener;

/**
* Created by: WinXaito (Kevin Vuilleumier)
*/
public class KeyListener implements NativeKeyListener{
private Logger logger = LogManager.getLogger(KeyListener.class);
private CustomStyledClassedTextArea sourceText;

private boolean enable = false;
private boolean cirumflex = false;
private boolean trema;

public KeyListener(){
logger.debug("Initialize keyListener");
}

@Override
public void nativeKeyPressed(NativeKeyEvent e){
if(sourceText != null && enable){
logger.debug("Keypressed: " + e.getRawCode() + " -- " + e.getModifiers());

if(e.getRawCode() == 221){
if(cirumflex){
appendSpecialCharacter("^^");
cirumflex = false;
}else{
cirumflex = true;
trema = false;
}
}else if(e.getRawCode() == 192){
if(trema){
appendSpecialCharacter("¨¨");
trema = false;
}else{
trema = true;
cirumflex = false;
}
}else{
switch(e.getRawCode()){
case 69: //E
if(cirumflex)
appendSpecialCharacter("ê");
else if(trema)
appendSpecialCharacter("ë");
break;
case 65: //A
if(cirumflex)
appendSpecialCharacter("â");
else if(trema)
appendSpecialCharacter("ä");
break;
case 73: //I
if(cirumflex)
appendSpecialCharacter("î");
else if(trema)
appendSpecialCharacter("ï");
break;
case 79: //O
if(cirumflex)
appendSpecialCharacter("ô");
else if(trema)
appendSpecialCharacter("ö");
break;
case 85: //U
if(cirumflex)
appendSpecialCharacter("û");
else if(trema)
appendSpecialCharacter("ü");
break;
}

cirumflex = false;
}
}
}

@Override
public void nativeKeyReleased(NativeKeyEvent nativeKeyEvent){
}

@Override
public void nativeKeyTyped(NativeKeyEvent nativeKeyEvent){
}

public void setSourceText(CustomStyledClassedTextArea sourceText){
this.sourceText = sourceText;
enable = true;
}

public void setEnable(boolean enable){
this.enable = enable;
}

private void appendSpecialCharacter(String letter){
logger.debug("Append special character (Linux Only): " + letter + " (Length: " + letter.length() + ")");
Platform.runLater(() -> sourceText.deleteText(sourceText.getCaretPosition() - letter.length(), sourceText.getCaretPosition()));
Platform.runLater(() -> sourceText.appendText(letter));
cirumflex = false;
trema = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.zestedesavoir.zestwriter.utils.readability.Readability;
import com.zestedesavoir.zestwriter.view.com.*;
import com.zestedesavoir.zestwriter.view.dialogs.ImageInputDialog;
import com.ziclix.python.sql.pipe.Source;
import javafx.application.Platform;
import javafx.beans.property.BooleanPropertyBase;
import javafx.beans.property.SimpleBooleanProperty;
Expand Down Expand Up @@ -130,6 +131,14 @@ public void setMdBox(MdTextController mdBox, Textual extract, Tab tab) throws IO
updateRender();
});
updateRender();

if(FunctionTreeFactory.isLinuxOs()){
MainApp.keyListener.setSourceText(SourceText);

SourceText.focusedProperty().addListener((observable, oldValue, newValue) -> {
MainApp.keyListener.setEnable(newValue);
});
}
});

EventHandlerHelper.install(SourceText.onKeyPressedProperty(),
Expand Down Expand Up @@ -749,4 +758,8 @@ public int getHScrollValue(WebView view) {
return 0;
}
}

public void appendSourceText(String text){
SourceText.appendText(text);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,18 @@
import java.util.regex.Pattern;

public class FunctionTreeFactory {

public static boolean isMacOs() {
return System.getProperty("os.name").toLowerCase().indexOf("mac") >= 0;
return System.getProperty("os.name").toLowerCase().contains("mac");
}

public static boolean isWindowsOs(){
return System.getProperty("os.name").toLowerCase().contains("win");
}

public static boolean isLinuxOs(){
return true;
/*String os = System.getProperty("os.name").toLowerCase();
return os.contains("lin") || os.contains("nix") || os.contains("nux") || os.contains("aix") || os.contains("uni");*/
}

public static Map<String,Object> initContentDialog(Content defaultContent) {
Expand Down