Chrome.bindKey

This commit is contained in:
Chris Wanstrath
2011-08-18 23:55:27 -07:00
parent 211cdbbc69
commit b48ca2859c
4 changed files with 46 additions and 39 deletions

View File

@@ -17,39 +17,28 @@ saveAs = ->
App.window.title = _.last filename.split('/')
save()
canon = require 'pilot/canon'
bindKey = (name, shortcut, callback) ->
canon.addCommand
name: name
exec: callback
bindKey:
win: null
mac: shortcut
sender: 'editor'
bindKey 'open', 'Command-O', (env, args, request) ->
Chrome.bindKey 'open', 'Command-O', (env, args, request) ->
if file = Chrome.openPanel()
filename = file
App.window.title = _.last filename.split('/')
code = File.read file
env.editor.getSession().setValue code
bindKey 'saveAs', 'Command-Shift-S', (env, args, request) ->
Chrome.bindKey 'saveAs', 'Command-Shift-S', (env, args, request) ->
saveAs()
bindKey 'save', 'Command-S', (env, args, request) ->
Chrome.bindKey 'save', 'Command-S', (env, args, request) ->
if filename then save() else saveAs()
bindKey 'copy', 'Command-C', (env, args, request) ->
Chrome.bindKey 'copy', 'Command-C', (env, args, request) ->
text = editor.getSession().doc.getTextRange editor.getSelectionRange()
Chrome.writeToPasteboard text
bindKey 'eval', 'Command-R', (env, args, request) ->
Chrome.bindKey 'eval', 'Command-R', (env, args, request) ->
eval env.editor.getSession().getValue()
bindKey 'togglecomment', 'Command-/', (env) ->
Chrome.bindKey 'togglecomment', 'Command-/', (env) ->
env.editor.toggleCommentLines()
bindKey 'fullscreen', 'Command-Return', (env) ->
Chrome.bindKey 'fullscreen', 'Command-Return', (env) ->
OSX.NSLog 'coming soon'

View File

@@ -1,5 +1,5 @@
(function() {
var JavaScriptMode, bindKey, canon, editor, filename, save, saveAs;
var JavaScriptMode, editor, filename, save, saveAs;
console.log = OSX.NSLog;
editor = ace.edit("editor");
editor.setTheme("ace/theme/twilight");
@@ -19,19 +19,7 @@
return save();
}
};
canon = require('pilot/canon');
bindKey = function(name, shortcut, callback) {
return canon.addCommand({
name: name,
exec: callback,
bindKey: {
win: null,
mac: shortcut,
sender: 'editor'
}
});
};
bindKey('open', 'Command-O', function(env, args, request) {
Chrome.bindKey('open', 'Command-O', function(env, args, request) {
var code, file;
if (file = Chrome.openPanel()) {
filename = file;
@@ -40,28 +28,28 @@
return env.editor.getSession().setValue(code);
}
});
bindKey('saveAs', 'Command-Shift-S', function(env, args, request) {
Chrome.bindKey('saveAs', 'Command-Shift-S', function(env, args, request) {
return saveAs();
});
bindKey('save', 'Command-S', function(env, args, request) {
Chrome.bindKey('save', 'Command-S', function(env, args, request) {
if (filename) {
return save();
} else {
return saveAs();
}
});
bindKey('copy', 'Command-C', function(env, args, request) {
Chrome.bindKey('copy', 'Command-C', function(env, args, request) {
var text;
text = editor.getSession().doc.getTextRange(editor.getSelectionRange());
return Chrome.writeToPasteboard(text);
});
bindKey('eval', 'Command-R', function(env, args, request) {
Chrome.bindKey('eval', 'Command-R', function(env, args, request) {
return eval(env.editor.getSession().getValue());
});
bindKey('togglecomment', 'Command-/', function(env) {
Chrome.bindKey('togglecomment', 'Command-/', function(env) {
return env.editor.toggleCommentLines();
});
bindKey('fullscreen', 'Command-Return', function(env) {
Chrome.bindKey('fullscreen', 'Command-Return', function(env) {
return OSX.NSLog('coming soon');
});
}).call(this);

View File

@@ -1,5 +1,7 @@
# This is the CoffeeScript API that wraps all of Cocoa.
canon = require 'pilot/canon'
# Handles the UI chrome
Chrome =
# Returns null or a file path.
@@ -21,6 +23,22 @@ Chrome =
pb.declareTypes_owner [OSX.NSStringPboardType], null
pb.setString_forType text, OSX.NSStringPboardType
# name - Command name, like "Find in file"
# shortcut - String command name, e.g.
# "Command-T"
# "Command-Shift-F"
# "Ctrl-I"
# callback - (env, args, request)
#
# Returns nothing.
bindKey: (name, shortcut, callback) ->
canon.addCommand
name: name
exec: callback
bindKey:
win: null
mac: shortcut
sender: 'editor'
# Handles the file system

View File

@@ -1,5 +1,6 @@
(function() {
var Chrome, File;
var Chrome, File, canon;
canon = require('pilot/canon');
Chrome = {
openPanel: function() {
var panel;
@@ -22,6 +23,17 @@
pb = OSX.NSPasteboard.generalPasteboard;
pb.declareTypes_owner([OSX.NSStringPboardType], null);
return pb.setString_forType(text, OSX.NSStringPboardType);
},
bindKey: function(name, shortcut, callback) {
return canon.addCommand({
name: name,
exec: callback,
bindKey: {
win: null,
mac: shortcut,
sender: 'editor'
}
});
}
};
File = {