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 1 commit
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
32 changes: 13 additions & 19 deletions src/main/java/com/zestedesavoir/zestwriter/view/KeyListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,57 +25,51 @@ public KeyListener(){
@Override
public void nativeKeyPressed(NativeKeyEvent e){
if(sourceText != null && enable){
logger.debug("Keypressed: " + e.getKeyCode() + " -- " + e.getModifiers());

if(e.getKeyCode() == 26 && e.getModifiers() == 0){
//Circumflex on Linux (27 for Windows)
// + without modifiers
logger.debug("Keypressed: " + e.getRawCode() + " -- " + e.getModifiers());

if(e.getRawCode() == 221){
if(cirumflex){
Platform.runLater(() -> sourceText.appendText("^^"));
appendSpecialCharacter("^^");
cirumflex = false;
}else{
cirumflex = true;
trema = false;
}
}else if(e.getKeyCode() == 26 && e.getModifiers() == 1){
//Trema with shift
// + (41 for Windows without shift) (Shift is the modifiers)

}else if(e.getRawCode() == 192){
if(trema){
Platform.runLater(() -> sourceText.appendText("¨¨"));
appendSpecialCharacter("¨¨");
trema = false;
}else{
trema = true;
cirumflex = false;
}
}else{
switch(e.getKeyCode()){
case 18: //E
switch(e.getRawCode()){
case 69: //E
if(cirumflex)
appendSpecialCharacter("ê");
else if(trema)
appendSpecialCharacter("ë");
break;
case 30: //A
case 65: //A
if(cirumflex)
appendSpecialCharacter("â");
else if(trema)
appendSpecialCharacter("ä");
break;
case 23: //I
case 73: //I
if(cirumflex)
appendSpecialCharacter("î");
else if(trema)
appendSpecialCharacter("ï");
break;
case 24: //O
case 79: //O
if(cirumflex)
appendSpecialCharacter("ô");
else if(trema)
appendSpecialCharacter("ö");
break;
case 22: //U
case 85: //U
if(cirumflex)
appendSpecialCharacter("û");
else if(trema)
Expand Down Expand Up @@ -106,8 +100,8 @@ public void setEnable(boolean enable){
}

private void appendSpecialCharacter(String letter){
logger.debug("Append special character (Linux Only): " + letter);
Platform.runLater(() -> sourceText.deleteText(sourceText.getCaretPosition() - 1, sourceText.getCaretPosition()));
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,6 @@ public MdConvertController() {
super();
logger = LoggerFactory.getLogger(MdConvertController.class);
SourceText = new CustomStyledClassedTextArea();

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

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

public MdTextController getMdBox() {
Expand Down Expand Up @@ -139,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
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ public static boolean isWindowsOs(){
}

public static boolean isLinuxOs(){
String os = System.getProperty("os.name").toLowerCase();
return os.contains("lin") || os.contains("nix") || os.contains("nux") || os.contains("aix") || os.contains("uni");
return true;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Ne pas oublié de modifier ici (J'ai mis ça pour que je puisse essayé aussi :p)

/*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