Skip to content

Commit

Permalink
Configurable Shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
rahmanusta committed Dec 17, 2014
1 parent 8aa6b2b commit dfa7c4b
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 8 deletions.
3 changes: 3 additions & 0 deletions conf/shortcuts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
!ShortCuts
keys:
- 'AltGR-0+}'
22 changes: 22 additions & 0 deletions src/main/java/com/kodcu/bean/ShortCuts.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.kodcu.bean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Created by usta on 17.12.2014.
*/
public class ShortCuts {

private String[] keys;

public String[] getKeys() {
return keys;
}

public void setKeys(String[] keys) {
this.keys = keys;
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/kodcu/controller/AsciiDocController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.esotericsoftware.yamlbeans.YamlWriter;
import com.kodcu.bean.Config;
import com.kodcu.bean.RecentFiles;
import com.kodcu.bean.ShortCuts;
import com.kodcu.component.MyTab;
import com.kodcu.other.Current;
import com.kodcu.other.IOHelper;
Expand Down Expand Up @@ -180,6 +181,7 @@ public class AsciiDocController extends TextWebSocketHandler implements Initiali
private Optional<Path> workingDirectory = Optional.of(Paths.get(System.getProperty("user.home")));
private Optional<File> initialDirectory = Optional.empty();
private List<Optional<Path>> closedPaths = new ArrayList<>();
private String[] shortCuts;

private List<String> bookNames = Arrays.asList("book.asc", "book.txt", "book.asciidoc", "book.adoc", "book.ad");

Expand Down Expand Up @@ -449,6 +451,7 @@ public void initialize(URL url, ResourceBundle rb) {

loadConfigurations();
loadRecentFileList();
loadShortCuts();

recentListView.setItems(recentFiles);
recentFiles.addListener((ListChangeListener<String>) c -> {
Expand Down Expand Up @@ -586,6 +589,18 @@ public void initialize(URL url, ResourceBundle rb) {

}

private void loadShortCuts() {
try {
YamlReader yamlReader =
new YamlReader(new FileReader(configPath.resolve("shortcuts.yml").toFile()));
yamlReader.getConfig().setClassTag("ShortCuts", ShortCuts.class);
shortCuts = yamlReader.read(ShortCuts.class).getKeys();

} catch (Exception e) {
e.printStackTrace();
}
}

private void addImageTab(Path imagePath) {
MyTab tab = createTab();
Label label = (Label) tab.getGraphic();
Expand Down Expand Up @@ -1483,4 +1498,8 @@ public ObservableList<String> getRecentFiles() {
public TabPane getTabPane() {
return tabPane;
}

public String[] getShortCuts() {
return shortCuts;
}
}
36 changes: 28 additions & 8 deletions src/main/resources/public/js/editor-shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,34 @@ editor.commands.addCommand({
readOnly: true
});

editor.commands.addCommand({
name: 'right-brace-1',
bindKey: {win: 'Ctrl-Alt-0', mac: 'Command-Alt-0'},
exec: function (editor) {
editor.insert("}");
},
readOnly: true
});
//editor.commands.addCommand({
// name: 'right-brace-1',
// bindKey: {win: 'Ctrl-Alt-0', mac: 'Command-Alt-0'},
// exec: function (editor) {
// editor.insert("}");
// },
// readOnly: true
//});

// loads from shortcuts.yml
var shortCuts = app.getShortCuts();
for (var i = 0; i < shortCuts.length; i++) {
var key = shortCuts[i].toString();
key = key.replace("AltGR", "Ctrl-Alt");
var split = key.split("+");

editor.commands.addCommand({
name: key,
bindKey: {
win: split[0].replace("Command", "Ctrl"),
mac: split[0].replace("Ctrl", "Command")
},
exec: function (editor) {
editor.insert(split[1]);
},
readOnly: true
});
}

function formatText(editor, matcher, firstCharacter, lastCharacter) {
var range = editor.getSelectionRange();
Expand Down

0 comments on commit dfa7c4b

Please sign in to comment.