Commit f75669d0 authored by Jonathan Wilkes's avatar Jonathan Wilkes
Browse files

first draft of functionality for opening pd patches from the menu

parent d8f5606c
"use strict"; "use strict";
var nw = require("nw.gui"); var nw = require("nw.gui");
console.log(nw.App.argv); console.log("foo is foo");
console.log("gurgle is " + nw.App.argv);
var pdgui = require("./pdgui.js"); var pdgui = require("./pdgui.js");
var port_no = nw.App.argv[0]; // fed to us by the Pd process var port_no = nw.App.argv[0]; // fed to us by the Pd process
var gui_dir = nw.App.argv[3];
var pwd = process.env.PWD; var pwd = process.env.PWD;
pdgui.set_port(port_no); pdgui.set_port(port_no);
pdgui.set_pwd(pwd); pdgui.set_pwd(pwd);
pdgui.set_gui_dir(gui_dir);
pdgui.set_pd_window(this); pdgui.set_pd_window(this);
pdgui.set_app_quitfn(app_quit); pdgui.set_app_quitfn(app_quit);
...@@ -593,7 +596,9 @@ function nw_create_pd_window_menus () { ...@@ -593,7 +596,9 @@ function nw_create_pd_window_menus () {
mediaMenu.append(new nw.MenuItem({ mediaMenu.append(new nw.MenuItem({
label: l("menu.test"), label: l("menu.test"),
click: pdmenu_test_audio, click: function() {
pdgui.pd_doc_open("doc/7.stuff/tools", "testtone.pd");
},
//key: "a", //key: "a",
//modifiers: "ctrl", //modifiers: "ctrl",
tooltip: l("menu.test_tt") tooltip: l("menu.test_tt")
...@@ -601,7 +606,9 @@ function nw_create_pd_window_menus () { ...@@ -601,7 +606,9 @@ function nw_create_pd_window_menus () {
mediaMenu.append(new nw.MenuItem({ mediaMenu.append(new nw.MenuItem({
label: l("menu.loadmeter"), label: l("menu.loadmeter"),
click: pdmenu_load_meter, click: function() {
pdgui.pd_doc_open("doc/7.stuff/tools", "load-meter.pd");
},
//key: "a", //key: "a",
//modifiers: "ctrl", //modifiers: "ctrl",
tooltip: l("menu.loadmeter_tt") tooltip: l("menu.loadmeter_tt")
...@@ -619,7 +626,9 @@ function nw_create_pd_window_menus () { ...@@ -619,7 +626,9 @@ function nw_create_pd_window_menus () {
// Help sub-entries // Help sub-entries
helpMenu.append(new nw.MenuItem({ helpMenu.append(new nw.MenuItem({
label: l("menu.about"), label: l("menu.about"),
click: pdmenu_about_pd, click: function() {
// pd_doc_open("doc/1.manual", "1.introduc
},
//key: "c", //key: "c",
//modifiers: "ctrl", //modifiers: "ctrl",
tooltip: l("menu.about_tt") tooltip: l("menu.about_tt")
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// Modules // Modules
var pwd; var pwd;
var gui_dir;
exports.set_pwd = function(pwd_string) { exports.set_pwd = function(pwd_string) {
pwd = pwd_string; pwd = pwd_string;
...@@ -12,6 +13,14 @@ exports.get_pwd = function() { ...@@ -12,6 +13,14 @@ exports.get_pwd = function() {
return pwd; return pwd;
} }
exports.set_gui_dir = function(dir_string) {
gui_dir = path.normalize(path.join(dir_string, ".."));
}
exports.get_gui_dir = function() {
return gui_dir;
}
var fs = require("fs"); // for fs.existsSync var fs = require("fs"); // for fs.existsSync
var path = require("path"); // for path.dirname path.extname path.join var path = require("path"); // for path.dirname path.extname path.join
...@@ -506,6 +515,31 @@ function gui_open_files_via_unique(filenames) ...@@ -506,6 +515,31 @@ function gui_open_files_via_unique(filenames)
} }
} }
// Think about renaming this and pd_doc_open...
// Open a file-- html, text, or Pd.
function doc_open (dir, basename) {
// Just Pd files at the moment... we'll add the others later
var norm_path = path.normalize(dir);
if (basename.slice(-4) === ".txt"
|| basename.slice(-2) === ".c") {
open_text(path.join(norm_path, basename));
} else if (basename.slice(-5) === ".html"
|| basename.slice(-4) === ".htm"
|| basename.slice(-4) === ".pdf") {
open_html(path.join(norm_path, basename));
} else {
pdsend("pd open", enquote(basename), enquote(norm_path));
}
}
// Open a file relative to the main directory where "doc/" and "extra/" live
function pd_doc_open(dir, basename) {
doc_open(path.join(gui_dir, dir), basename);
}
exports.pd_doc_open = pd_doc_open;
function gui_build_filelist(file) { function gui_build_filelist(file) {
startup_files.push(file); startup_files.push(file);
} }
......
...@@ -1287,13 +1287,19 @@ int sys_startgui(const char *guidir) ...@@ -1287,13 +1287,19 @@ int sys_startgui(const char *guidir)
fprintf(stderr, "guidir is %s\n", guidir); fprintf(stderr, "guidir is %s\n", guidir);
/* For some reason, the nw binary doesn't give you access to
the first argument-- this is the path to the directory where
package.json lives (or the zip file if it's compressed). So
we add it again as the last argument to make sure we can fetch
it on the GUI side. */
sprintf(cmdbuf, sprintf(cmdbuf,
"%s/nw/nw %s %d localhost %s\n", "%s/nw/nw %s %d localhost %s %s\n",
guidir, guidir,
guidir, guidir,
// "/home/user/pd-nw/pd/nw", // "/home/user/pd-nw/pd/nw",
portno, portno,
(sys_k12_mode ? "pd-l2ork-k12" : "pd-l2ork")); (sys_k12_mode ? "pd-l2ork-k12" : "pd-l2ork"),
guidir);
#endif #endif
sys_guicmd = cmdbuf; sys_guicmd = cmdbuf;
......
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