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";
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")
......
......@@ -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);
}
......
......@@ -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;
......
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