Commit 3f242c54 authored by Jonathan Wilkes's avatar Jonathan Wilkes
Browse files

Merge branch 'print-dialog' into master

parents f51a52fb c3462eac
...@@ -287,6 +287,7 @@ function make_index() { ...@@ -287,6 +287,7 @@ function make_index() {
finish_index(); finish_index();
} }
} }
pdsend("pd gui-busy 1");
index_started = true; index_started = true;
index_start_time = new Date().getTime() / 1000; index_start_time = new Date().getTime() / 1000;
var idx, manif; var idx, manif;
...@@ -329,6 +330,7 @@ function make_index() { ...@@ -329,6 +330,7 @@ function make_index() {
post("building help index in " + doc_path); post("building help index in " + doc_path);
dive(doc_path, read_file, browser_path?make_index_cont:finish_index); dive(doc_path, read_file, browser_path?make_index_cont:finish_index);
} }
pdsend("pd gui-busy 0");
} }
// AG: This is called from dialog_search.html with a callback that expects to // AG: This is called from dialog_search.html with a callback that expects to
...@@ -1160,52 +1162,17 @@ function menu_saveas(name) { ...@@ -1160,52 +1162,17 @@ function menu_saveas(name) {
exports.menu_saveas = menu_saveas; exports.menu_saveas = menu_saveas;
function gui_canvas_print(name, initfile, initdir) { function gui_canvas_print(name, initfile, initdir) {
// AG: This works mostly like gui_canvas_saveas above, except that we // AG: The print dialog presents its own file picker anyway if PDF
// create a pdf file and use a different input element and callback. // output is chosen, and just ignores the settings for pdf_path. So
var input, chooser, // initfile and initdir are only used here to provide a useful default
span = patchwin[name].window.document.querySelector("#printDialogSpan"); // for the header and footer information -- otherwise the print() method
if (!fs.existsSync(initdir)) { // uses some random internal document URL which isn't helpful.
initdir = pwd; pdsend("pd gui-busy 1");
} patchwin[name].print({ autoprint: false, headerString: initfile, footerString: path.join(initdir, initfile) });
// If we don't have a ".pd" file extension (e.g., "Untitled-1", add one) pdsend("pd gui-busy 0");
if (initfile.slice(-3) !== ".pd") { post("printed "+initfile);
initfile += ".pd";
}
// Adding an "f" now gives .pdf which is what we want.
initfile += "f";
input = build_file_dialog_string({
style: "display: none;",
type: "file",
id: "printDialog",
nwsaveas: path.join(initdir, initfile),
nwworkingdir: initdir,
accept: ".pdf"
});
span.innerHTML = input;
chooser = patchwin[name].window.document.querySelector("#printDialog");
chooser.onchange = function() {
print_callback(name, this.value);
// reset value so that we can open the same file twice
this.value = null;
console.log("tried to print something");
}
chooser.click();
} }
function print_callback(cid, file) {
var filename = defunkify_windows_path(file);
// It probably isn't possible to arrive at the callback with an
// empty string. But I've only tested on Debian so far...
if (filename === null) {
return;
}
// Let nw.js do the rest (requires nw.js 0.14.6+)
patchwin[cid].print({ pdf_path: filename, headerFooterEnabled: false });
post("printed to: " + filename);
}
exports.print_callback = print_callback;
function menu_print(name) { function menu_print(name) {
pdsend(name + " menuprint"); pdsend(name + " menuprint");
} }
...@@ -1398,7 +1365,9 @@ function gui_quit_dialog() { ...@@ -1398,7 +1365,9 @@ function gui_quit_dialog() {
function menu_send(name) { function menu_send(name) {
var message, var message,
win = name ? patchwin[name] : pd_window; win = name ? patchwin[name] : pd_window;
pdsend("pd gui-busy 1");
message = win.window.prompt("Type a message to send to Pd", name); message = win.window.prompt("Type a message to send to Pd", name);
pdsend("pd gui-busy 0");
if (message != undefined && message.length) { if (message != undefined && message.length) {
post("Sending message to Pd: " + message + ";"); post("Sending message to Pd: " + message + ";");
pdsend(message); pdsend(message);
......
...@@ -107,6 +107,12 @@ static void glob_gui_properties(t_pd *dummy) ...@@ -107,6 +107,12 @@ static void glob_gui_properties(t_pd *dummy)
sys_autopatch_yoffset); sys_autopatch_yoffset);
} }
int sys_gui_busy;
static void glob_gui_busy(void *dummy, t_float f)
{
sys_gui_busy = f != 0;
}
// ths one lives inside g_editor so that it can access the clipboard // ths one lives inside g_editor so that it can access the clipboard
extern void glob_clipboard_text(t_pd *dummy, float f); extern void glob_clipboard_text(t_pd *dummy, float f);
...@@ -201,6 +207,8 @@ void glob_init(void) ...@@ -201,6 +207,8 @@ void glob_init(void)
gensym("add-recent-file"), A_SYMBOL, 0); gensym("add-recent-file"), A_SYMBOL, 0);
class_addmethod(glob_pdobject, (t_method)glob_clear_recent_files, class_addmethod(glob_pdobject, (t_method)glob_clear_recent_files,
gensym("clear-recent-files"), 0); gensym("clear-recent-files"), 0);
class_addmethod(glob_pdobject, (t_method)glob_gui_busy, gensym("gui-busy"),
A_DEFFLOAT, 0);
#ifdef UNIX #ifdef UNIX
class_addmethod(glob_pdobject, (t_method)glob_watchdog, class_addmethod(glob_pdobject, (t_method)glob_watchdog,
gensym("watchdog"), 0); gensym("watchdog"), 0);
......
...@@ -312,11 +312,12 @@ static void sched_pollformeters( void) ...@@ -312,11 +312,12 @@ static void sched_pollformeters( void)
{ {
int inclip, outclip, indb, outdb; int inclip, outclip, indb, outdb;
static int sched_nextmeterpolltime, sched_nextpingtime; static int sched_nextmeterpolltime, sched_nextpingtime;
extern int sys_gui_busy;
/* if there's no GUI but we're running in "realtime", here is /* if there's no GUI but we're running in "realtime", here is
where we arrange to ping the watchdog every 2 seconds. */ where we arrange to ping the watchdog every 2 seconds. */
#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__GNU__) #if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__GNU__)
if (sys_nogui && sys_hipriority && (sched_diddsp - sched_nextpingtime > 0)) if ((sys_nogui||sys_gui_busy) && sys_hipriority && (sched_diddsp - sched_nextpingtime > 0))
{ {
glob_watchdog(0); glob_watchdog(0);
/* ping every 2 seconds */ /* ping every 2 seconds */
......
...@@ -195,6 +195,7 @@ double sys_getrealtime(void) ...@@ -195,6 +195,7 @@ double sys_getrealtime(void)
} }
extern int sys_nosleep; extern int sys_nosleep;
static int fdschanged;
static int sys_domicrosleep(int microsec, int pollem) static int sys_domicrosleep(int microsec, int pollem)
{ {
...@@ -203,7 +204,7 @@ static int sys_domicrosleep(int microsec, int pollem) ...@@ -203,7 +204,7 @@ static int sys_domicrosleep(int microsec, int pollem)
t_fdpoll *fp; t_fdpoll *fp;
timout.tv_sec = 0; timout.tv_sec = 0;
timout.tv_usec = (sys_nosleep ? 0 : microsec); timout.tv_usec = (sys_nosleep ? 0 : microsec);
if (pollem) if (pollem && sys_nfdpoll)
{ {
fd_set readset, writeset, exceptset; fd_set readset, writeset, exceptset;
FD_ZERO(&writeset); FD_ZERO(&writeset);
...@@ -216,8 +217,10 @@ static int sys_domicrosleep(int microsec, int pollem) ...@@ -216,8 +217,10 @@ static int sys_domicrosleep(int microsec, int pollem)
Sleep(microsec/1000); Sleep(microsec/1000);
else else
#endif #endif
select(sys_maxfd+1, &readset, &writeset, &exceptset, &timout); if (select(sys_maxfd+1, &readset, &writeset, &exceptset, &timout) < 0)
for (i = 0; i < sys_nfdpoll; i++) perror("microsleep select");
fdschanged = 0;
for (i = 0; i < sys_nfdpoll && !fdschanged; i++)
if (FD_ISSET(sys_fdpoll[i].fdp_fd, &readset)) if (FD_ISSET(sys_fdpoll[i].fdp_fd, &readset))
{ {
#ifdef THREAD_LOCKING #ifdef THREAD_LOCKING
...@@ -229,18 +232,23 @@ static int sys_domicrosleep(int microsec, int pollem) ...@@ -229,18 +232,23 @@ static int sys_domicrosleep(int microsec, int pollem)
#endif #endif
didsomething = 1; didsomething = 1;
} }
return (didsomething); if (didsomething) return (1);
} }
else if (microsec)
{ {
#ifdef THREAD_LOCKING
sys_unlock();
#endif
#ifdef MSW #ifdef MSW
if (sys_maxfd == 0) Sleep(microsec/1000);
Sleep(microsec/1000); #else
else usleep(microsec);
#endif
#ifdef THREAD_LOCKING
sys_lock();
#endif #endif
select(0, 0, 0, 0, &timout);
return (0);
} }
return (0);
} }
void sys_microsleep(int microsec) void sys_microsleep(int microsec)
...@@ -438,6 +446,7 @@ void sys_addpollfn(int fd, t_fdpollfn fn, void *ptr) ...@@ -438,6 +446,7 @@ void sys_addpollfn(int fd, t_fdpollfn fn, void *ptr)
fp->fdp_ptr = ptr; fp->fdp_ptr = ptr;
sys_nfdpoll = nfd + 1; sys_nfdpoll = nfd + 1;
if (fd >= sys_maxfd) sys_maxfd = fd + 1; if (fd >= sys_maxfd) sys_maxfd = fd + 1;
fdschanged = 1;
} }
void sys_rmpollfn(int fd) void sys_rmpollfn(int fd)
...@@ -445,6 +454,7 @@ void sys_rmpollfn(int fd) ...@@ -445,6 +454,7 @@ void sys_rmpollfn(int fd)
int nfd = sys_nfdpoll; int nfd = sys_nfdpoll;
int i, size = nfd * sizeof(t_fdpoll); int i, size = nfd * sizeof(t_fdpoll);
t_fdpoll *fp; t_fdpoll *fp;
fdschanged = 1;
for (i = nfd, fp = sys_fdpoll; i--; fp++) for (i = nfd, fp = sys_fdpoll; i--; fp++)
{ {
if (fp->fdp_fd == fd) if (fp->fdp_fd == fd)
...@@ -624,6 +634,7 @@ void socketreceiver_read(t_socketreceiver *x, int fd) ...@@ -624,6 +634,7 @@ void socketreceiver_read(t_socketreceiver *x, int fd)
void sys_closesocket(int fd) void sys_closesocket(int fd)
{ {
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
if (fd<0) return;
close(fd); close(fd);
#endif #endif
#ifdef MSW #ifdef MSW
......
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