diff --git a/pd/nw/index.js b/pd/nw/index.js index 4548018bf8b6f14ffe8f0e4b1642a0164b5b2da7..6ac9353f9e881de5f96325aa873ed38fc5e293ed 100644 --- a/pd/nw/index.js +++ b/pd/nw/index.js @@ -1,11 +1,14 @@ "use strict"; 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 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; pdgui.set_port(port_no); pdgui.set_pwd(pwd); +pdgui.set_gui_dir(gui_dir); pdgui.set_pd_window(this); pdgui.set_app_quitfn(app_quit); @@ -593,7 +596,9 @@ function nw_create_pd_window_menus () { mediaMenu.append(new nw.MenuItem({ label: l("menu.test"), - click: pdmenu_test_audio, + click: function() { + pdgui.pd_doc_open("doc/7.stuff/tools", "testtone.pd"); + }, //key: "a", //modifiers: "ctrl", tooltip: l("menu.test_tt") @@ -601,7 +606,9 @@ function nw_create_pd_window_menus () { mediaMenu.append(new nw.MenuItem({ label: l("menu.loadmeter"), - click: pdmenu_load_meter, + click: function() { + pdgui.pd_doc_open("doc/7.stuff/tools", "load-meter.pd"); + }, //key: "a", //modifiers: "ctrl", tooltip: l("menu.loadmeter_tt") @@ -619,7 +626,9 @@ function nw_create_pd_window_menus () { // Help sub-entries helpMenu.append(new nw.MenuItem({ label: l("menu.about"), - click: pdmenu_about_pd, + click: function() { +// pd_doc_open("doc/1.manual", "1.introduc + }, //key: "c", //modifiers: "ctrl", tooltip: l("menu.about_tt") diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js index 9b51a128d996c29e2125c84c05d5dc2891d3a43d..b68c9862b81ace328ebe0163280eb304ecb75f33 100644 --- a/pd/nw/pdgui.js +++ b/pd/nw/pdgui.js @@ -3,6 +3,7 @@ // Modules var pwd; +var gui_dir; exports.set_pwd = function(pwd_string) { pwd = pwd_string; @@ -12,6 +13,14 @@ exports.get_pwd = function() { 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 path = require("path"); // for path.dirname path.extname path.join @@ -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) { startup_files.push(file); } diff --git a/pd/src/s_inter.c b/pd/src/s_inter.c index 94e78a98ea0e3fce1cf3d6345d5d09d7962fc3f7..8b5306ae20175c1de09906b72d609d1ac753e76f 100644 --- a/pd/src/s_inter.c +++ b/pd/src/s_inter.c @@ -1287,13 +1287,19 @@ int sys_startgui(const char *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, - "%s/nw/nw %s %d localhost %s\n", + "%s/nw/nw %s %d localhost %s %s\n", guidir, guidir, // "/home/user/pd-nw/pd/nw", portno, - (sys_k12_mode ? "pd-l2ork-k12" : "pd-l2ork")); + (sys_k12_mode ? "pd-l2ork-k12" : "pd-l2ork"), + guidir); #endif sys_guicmd = cmdbuf;