Commit dbb1f2a9 authored by Jonathan Wilkes's avatar Jonathan Wilkes

Merge branch 'add-shortcuts'

parents a61dbaa6 f8ad0dc0
......@@ -640,6 +640,7 @@ function nw_create_pd_window_menus(gui, w) {
minit(m.put.number, { enabled: false });
minit(m.put.symbol, { enabled: false });
minit(m.put.comment, { enabled: false });
minit(m.put.dropdown, { enabled: false });
minit(m.put.bang, { enabled: false });
minit(m.put.toggle, { enabled: false });
minit(m.put.number2, { enabled: false });
......
......@@ -157,7 +157,7 @@ var canvas_events = (function() {
two = text.charAt(1);
return (one === "#" && (two === "N" || two === "X"));
},
grow_svg_for_element= function(elem) {
grow_svg_for_element = function(elem) {
// See if an element overflows the svg bbox, and
// enlarge the svg to accommodate it.
// Note: window.scrollX and window.scrollY might not work
......@@ -817,6 +817,59 @@ var canvas_events = (function() {
close_save_dialog: function() {
document.getElementById("save_before_quit").close();
},
paste_from_pd_file: function(name, clipboard_data) {
var line, lines, i, pd_message;
// This lets the user copy some Pd source file from another
// application and paste the code directly into a canvas window
// (empty or otherwise). It does a quick check to make sure the OS
// clipboard is holding text that could conceivably be Pd source
// code. But that's not 100% foolproof and the engine might crash
// and burn, so be careful! :)
// We only want to check the external buffer and/or send a "paste"
// event to Pd if the canvas is in a "normal" state.
if (canvas_events.get_state() !== "normal") {
return;
}
if (!might_be_a_pd_file(clipboard_data)) {
pdgui.post("paste error: clipboard doesn't appear to contain valid Pd code");
return;
}
// clear the buffer
pdgui.pdsend(name, "copyfromexternalbuffer");
pd_message = "";
lines = clipboard_data.split("\n");
for (i = 0; i < lines.length; i++) {
line = lines[i];
// process pd_message if it ends with a semicolon that
// isn't preceded by a backslash
if (line.slice(-1) === ";" &&
(line.length < 2 || line.slice(-2, -1) !== "\\")) {
if (pd_message === "") {
pd_message = line;
} else {
pd_message = pd_message + " " + line;
}
pdgui.pdsend(name, "copyfromexternalbuffer", pd_message);
pd_message = "";
} else {
pd_message = pd_message + " " + line;
pd_message = pd_message.replace(/\n/g, "");
}
}
// This signals to the engine that we're done filling the external
// buffer, that it can do necessary checks and call some internal
// cleanup code.
pdgui.pdsend(name, "copyfromexternalbuffer");
// Send a canvas "paste" message to Pd
pdgui.pdsend(name, "paste");
// Finally, make sure to reset the buffer so that next time around
// we start from a clean slate. (Otherwise, the engine will just
// add stuff to the existing buffer contents.)
pdgui.pdsend(name, "reset_copyfromexternalbuffer");
},
init: function() {
document.getElementById("saveDialog")
.setAttribute("nwworkingdir", pdgui.get_pwd());
......@@ -1149,60 +1202,6 @@ function instantiate_live_box() {
}
}
function canvas_paste_from_clipboard(name, clipboard_data)
{
var line, lines, i, pd_message;
// This lets the user copy some Pd source file from another application
// and paste the code directly into a canvas window (empty or otherwise).
// It does a quick check to make sure the OS clipboard is holding text
// that could conceivably be Pd source code. But that's not 100% foolproof
// and if it's not then the engine might crash and burn, so be careful! :)
// We only want to check the external buffer and/or send a "paste" event
// to Pd if the canvas is in a "normal" state.
if (canvas_events.get_state() !== "normal") {
return;
}
if (!might_be_a_pd_file(clipboard_data)) {
pdgui.post("paste error: clipboard doesn't appear to contain valid Pd code");
return;
}
// clear the buffer
pdgui.pdsend(name, "copyfromexternalbuffer");
pd_message = "";
lines = clipboard_data.split("\n");
for (i = 0; i < lines.length; i++) {
line = lines[i];
// process pd_message if it ends with a semicolon that
// isn't preceded by a backslash
if (line.slice(-1) === ";" &&
(line.length < 2 || line.slice(-2, -1) !== "\\")) {
if (pd_message === "") {
pd_message = line;
} else {
pd_message = pd_message + " " + line;
}
pdgui.pdsend(name, "copyfromexternalbuffer", pd_message);
pd_message = "";
} else {
pd_message = pd_message + " " + line;
pd_message = pd_message.replace(/\n/g, "");
}
}
// This signals to the engine that we're done filling the external buffer,
// that it can do necessary checks and call some internal cleanup code.
pdgui.pdsend(name, "copyfromexternalbuffer");
// Send a canvas "paste" message to Pd
pdgui.pdsend(name, "paste");
// Finally, make sure to reset the buffer so that next time around we
// start from a clean slate. (Otherwise, the engine will just add stuff to
// the existing buffer contents.)
pdgui.pdsend(name, "reset_copyfromexternalbuffer");
}
// Menus for the Patch window
var canvas_menu = {};
......@@ -1362,7 +1361,7 @@ function nw_create_patch_window_menus(gui, w, name) {
var clipboard = nw.Clipboard.get();
var text = clipboard.get('text');
//pdgui.post("** paste from clipboard: "+text);
canvas_paste_from_clipboard(name, text);
canvas_events.paste_from_pd_file(name, text);
}
});
minit(m.edit.duplicate, {
......
This diff is collapsed.
"use strict";
var cmd_or_ctrl = (process.platform === "darwin") ? "cmd" : "ctrl";
exports.menu = {
"new": { key: "n", modifiers: cmd_or_ctrl },
"open": { key: "o", modifiers: cmd_or_ctrl },
"save": { key: "s", modifiers: cmd_or_ctrl },
"saveas": { key: "s", modifiers: cmd_or_ctrl + "+shift" },
"print": { key: "p", modifiers: cmd_or_ctrl + "+shift" },
"message" : { key: "m", modifiers: cmd_or_ctrl },
"close": { key: "w", modifiers: cmd_or_ctrl },
"quit": { key: "q", modifiers: cmd_or_ctrl },
"undo": { key: "z", modifiers: cmd_or_ctrl },
"redo": { key: "z", modifiers: cmd_or_ctrl + "+shift" },
"selectall":{ key: "a", modifiers: cmd_or_ctrl },
"cut": { key: "x", modifiers: cmd_or_ctrl },
"copy": { key: "c", modifiers: cmd_or_ctrl },
"paste": { key: "v", modifiers: cmd_or_ctrl },
"paste_clipboard": { key: "v", modifiers: cmd_or_ctrl + "+alt" },
"duplicate": { key: "d", modifiers: cmd_or_ctrl },
"undo": { key: "z", modifiers: cmd_or_ctrl },
"reselect": { key: String.fromCharCode(10), modifiers: cmd_or_ctrl },
"clear_console": { key: "l", modifiers: cmd_or_ctrl + "+shift" },
"tidyup": { key: "y", modifiers: cmd_or_ctrl },
"cordinspector": { key: "r", modifiers: cmd_or_ctrl + "+shift" },
"find": { key: "f", modifiers: cmd_or_ctrl },
"findagain":{ key: "g", modifiers: cmd_or_ctrl },
"editmode": { key: "e", modifiers: cmd_or_ctrl },
"preferences": { key: (process.platform === "darwin") ? "," : "p",
modifiers: cmd_or_ctrl },
"zoomin": { key: "=", modifiers: cmd_or_ctrl },
"zoomout": { key: "-", modifiers: cmd_or_ctrl },
"zoomreset": { key: "0", modifiers: cmd_or_ctrl },
"zoomoptimal": { key: "9", modifiers: cmd_or_ctrl },
"zoomhoriz": { key: "9", modifiers: cmd_or_ctrl + "+alt" },
"zoomvert": { key: "9", modifiers: cmd_or_ctrl + "+shift" },
"fullscreen": { key: (process.platform === "darwin") ? "f" : "F11",
modifiers: (process.platform === "darwin") ? "cmd+ctrl" : null },
"object": { key: "1", modifiers: cmd_or_ctrl },
"msgbox": { key: "2", modifiers: cmd_or_ctrl },
"number": { key: "3", modifiers: cmd_or_ctrl },
"symbol": { key: "4", modifiers: cmd_or_ctrl },
"comment": { key: "5", modifiers: cmd_or_ctrl },
"dropdown": { key: "6", modifiers: cmd_or_ctrl },
"bang": { key: "b", modifiers: cmd_or_ctrl + "+shift" },
"toggle": { key: "t", modifiers: cmd_or_ctrl + "+shift" },
"number2": { key: "n", modifiers: cmd_or_ctrl + "+shift" },
"vslider": { key: "v", modifiers: cmd_or_ctrl + "+shift" },
"hslider": { key: "h", modifiers: cmd_or_ctrl + "+shift" },
"vradio": { key: "d", modifiers: cmd_or_ctrl + "+shift" },
"hradio": { key: "i", modifiers: cmd_or_ctrl + "+shift" },
"vu": { key: "u", modifiers: cmd_or_ctrl + "+shift" },
"cnv": { key: "c", modifiers: cmd_or_ctrl + "+shift" },
"nextwin": { key: "PageDown", modifiers: cmd_or_ctrl },
"prevwin": { key: "PageUp", modifiers: cmd_or_ctrl },
"pdwin": { key: "r", modifiers: cmd_or_ctrl },
"audio_on": { key: "/", modifiers: cmd_or_ctrl },
"audio_off": { key: ".", modifiers: cmd_or_ctrl },
"browser": { key: "b", modifiers: cmd_or_ctrl },
"audio_off": { key: ".", modifiers: cmd_or_ctrl },
"audio_off": { key: ".", modifiers: cmd_or_ctrl },
"audio_off": { key: ".", modifiers: cmd_or_ctrl },
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment