Skip to content

Commit d50e5ec

Browse files
Add sections for shortcutsets per platform. jbaron#130
1 parent e21185e commit d50e5ec

File tree

3 files changed

+45
-42
lines changed

3 files changed

+45
-42
lines changed

lib/main.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -719,25 +719,22 @@ var Cats;
719719
Ide.prototype.loadShortCuts = function () {
720720
var fileName = Cats.OS.File.join(this.catsHomeDir, "resource/shortcuts.json");
721721
var c = Cats.OS.File.readTextFile(fileName);
722-
var shortCuts = JSON.parse(c);
723-
for (var shortCut in shortCuts) {
724-
var catsCommand = shortCuts[shortCut];
725-
this.addShortCut(shortCut, catsCommand);
722+
var shortCutSets = JSON.parse(c);
723+
var os = "linux";
724+
if (Cats.OS.File.isWindows()) {
725+
os = "win";
726726
}
727-
};
728-
Ide.prototype.addShortCut = function (shortCut, catsCommand) {
729-
if (/^Cmd-/.test(shortCut)) {
730-
if (process.platform === "darwin") {
731-
shortCut = shortCut.replace(/^Cmd-/, "Meta-");
732-
}
733-
else {
734-
shortCut = shortCut.replace(/^Cmd-/, "Ctrl-");
735-
}
727+
else if (Cats.OS.File.isOSX()) {
728+
os = "osx";
729+
}
730+
var shortCuts = shortCutSets[os];
731+
for (var shortCut in shortCuts) {
732+
var commandName = shortCuts[shortCut];
733+
var cmd = new qx.ui.core.Command(shortCut);
734+
cmd.addListener("execute", (function (commandName) {
735+
Cats.Commands.CMDS[commandName].command();
736+
}).bind(null, commandName));
736737
}
737-
var cmd = new qx.ui.core.Command(shortCut);
738-
cmd.addListener("execute", function () {
739-
Cats.Commands.CMDS[catsCommand].command();
740-
});
741738
};
742739
/**
743740
* Load the icons map from the file.

resource/shortcuts.json

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
{
2-
"Cmd-W" : "file_close",
3-
"Cmd-Shift-W" : "file_closeAll",
4-
"Cmd-B": "project_build",
5-
"Cmd-F11": "project_run",
6-
"Cmd-R": "project_run"
2+
"osx": {
3+
"Meta-W" : "file_close",
4+
"Meta-Shift-W" : "file_closeAll",
5+
"Meta-B": "project_build",
6+
"Meta-R": "project_run"
7+
},
8+
"win": {
9+
"Ctrl-W" : "file_close",
10+
"Ctrl-Shift-W" : "file_closeAll",
11+
"Ctrl-B": "project_build",
12+
"Ctrl-R": "project_run"
13+
},
14+
"linux": {
15+
"Ctrl-W" : "file_close",
16+
"Ctrl-Shift-W" : "file_closeAll",
17+
"Ctrl-B": "project_build",
18+
"Ctrl-R": "project_run"
19+
}
720
}

src/cats/ide.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,30 +81,23 @@ module Cats {
8181
private loadShortCuts() {
8282
var fileName = OS.File.join(this.catsHomeDir, "resource/shortcuts.json");
8383
var c = OS.File.readTextFile(fileName);
84-
var shortCuts:{} = JSON.parse(c);
84+
var shortCutSets:{} = JSON.parse(c);
85+
var os = "linux";
86+
if (Cats.OS.File.isWindows()) {
87+
os = "win";
88+
} else if (Cats.OS.File.isOSX()) {
89+
os = "osx";
90+
}
91+
var shortCuts = shortCutSets[os];
8592
for (var shortCut in shortCuts) {
86-
var catsCommand = shortCuts[shortCut];
87-
this.addShortCut(shortCut, catsCommand);
93+
var commandName = shortCuts[shortCut];
94+
var cmd = new qx.ui.core.Command(shortCut);
95+
cmd.addListener("execute", (function(commandName: string) {
96+
Cats.Commands.CMDS[commandName].command();
97+
}).bind(null, commandName));
8898
}
8999

90100
}
91-
92-
private addShortCut(shortCut: string, catsCommand: string) {
93-
if (/^Cmd-/.test(shortCut)) {
94-
if (process.platform === "darwin") {
95-
shortCut = shortCut.replace(/^Cmd-/, "Meta-");
96-
} else {
97-
shortCut = shortCut.replace(/^Cmd-/, "Ctrl-");
98-
}
99-
}
100-
101-
var cmd = new qx.ui.core.Command(shortCut);
102-
cmd.addListener("execute", () => {
103-
Cats.Commands.CMDS[catsCommand].command();
104-
});
105-
}
106-
107-
108101

109102
/**
110103
* Load the icons map from the file.

0 commit comments

Comments
 (0)