From e9c00940de7f75314d1ca15a8120c9792616f4db Mon Sep 17 00:00:00 2001 From: Jonathan Wilkes <jon.w.wilkes@gmail.com> Date: Wed, 11 Nov 2015 21:24:19 -0500 Subject: [PATCH] finish up the Windows menu for canvases and the pd window --- pd/nw/index.js | 8 ++++++-- pd/nw/pd_canvas.js | 8 ++++++-- pd/nw/pdgui.js | 50 +++++++++++++++++++++++++++++++++++++++++++++- pd/nw/todo.txt | 2 ++ 4 files changed, 63 insertions(+), 5 deletions(-) diff --git a/pd/nw/index.js b/pd/nw/index.js index 95195b20c..4237824b6 100644 --- a/pd/nw/index.js +++ b/pd/nw/index.js @@ -510,7 +510,9 @@ function nw_create_pd_window_menus () { // Winman sub-entries winmanMenu.append(new gui.MenuItem({ label: l("menu.nextwin"), - click: pdmenu_next_win, + click: function() { + pdgui.raise_next("pd_window"); + }, //key: "c", //modifiers: "ctrl", tooltip: l("menu.nextwin_tt") @@ -518,7 +520,9 @@ function nw_create_pd_window_menus () { winmanMenu.append(new gui.MenuItem({ label: l("menu.prevwin"), - click: pdmenu_previous_win, + click: function() { + pdgui.raise_prev("pd_window"); + }, //key: "a", //modifiers: "ctrl", tooltip: l("menu.prevwin_tt") diff --git a/pd/nw/pd_canvas.js b/pd/nw/pd_canvas.js index cf2544a4d..ab0b5fd53 100644 --- a/pd/nw/pd_canvas.js +++ b/pd/nw/pd_canvas.js @@ -1218,7 +1218,9 @@ function nw_create_patch_window_menus(name) { winmanMenu.append(new gui.MenuItem({ label: l("menu.nextwin"), - click: menu_generic, + click: function() { + pdgui.raise_next(name); + }, key: String.fromCharCode(12), // Page down modifiers: "ctrl", tooltip: l("menu.nextwin_tt"), @@ -1226,7 +1228,9 @@ function nw_create_patch_window_menus(name) { winmanMenu.append(new gui.MenuItem({ label: l("menu.prevwin"), - click: menu_generic, + click: function() { + pdgui.raise_prev(name); + }, key: String.fromCharCode(11), // Page up modifiers: "ctrl", tooltip: l("menu.prevwin_tt"), diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js index 0991bdfcc..d322b83e8 100644 --- a/pd/nw/pdgui.js +++ b/pd/nw/pdgui.js @@ -40,6 +40,16 @@ exports.get_local_string = lang.get_local_string; var pd_window; exports.pd_window; +// Turns out I messed this up. pd_window should really be an +// "nw window", so that you can use it to access all the +// nw window methods and settings. Instead I set it to the +// DOM window object. This complicates things-- for example, +// in walk_window_list I have to take care when comparing +// patchwin[]-- which are nw windows-- and pd_window. +// I'm not sure of the best way to fix this. Probably we want to +// just deal with DOM windows, but that would mean abstracting +// out the stuff that deals with nw window size and +// positioning. exports.set_pd_window = function(win) { pd_window = win; exports.pd_window = win; @@ -2897,9 +2907,47 @@ function gui_raise_window(cid) { } function gui_raise_pd_window() { - pd_window.focus(); + pd_window.focus(-1); +} + +// Walk the list of open patch windows. They are walked in the order +// they were created. +// This is a bit complicated because of the way I set pd_window above +function walk_window_list(cid, offset) { + var win_store = global.__nwWindowsStore, + my_win = cid === "pd_window" ? pd_window : patchwin[cid].window, + id_array = [], + my_id, id, next_id; + for (id in win_store) { + if (win_store.hasOwnProperty(id)) { + id_array.push(+id); // build array of numbers + if (win_store[id].window === my_win) { + my_id = +id; // cast as number to match against array + } + } + } + id_array.sort(function(a, b) { return a-b; }); // sort numerically + next_id = (id_array.indexOf(my_id) + offset); + if (next_id < 0) { + next_id += id_array.length; + } else { + next_id %= id_array.length; + } + win_store[id_array[next_id]].focus(); } +function raise_next(cid) { + walk_window_list(cid, 1); +} + +exports.raise_next = raise_next; + +function raise_prev(cid) { + walk_window_list(cid, -1); +} + +exports.raise_prev = raise_prev; + exports.raise_pd_window= gui_raise_pd_window; // Openpanel and Savepanel diff --git a/pd/nw/todo.txt b/pd/nw/todo.txt index ee3f75e8f..b63b94caf 100644 --- a/pd/nw/todo.txt +++ b/pd/nw/todo.txt @@ -325,6 +325,8 @@ Everything else: (A [x] means we've fixed it) that isn't true. Thus if we open many patches at a time, the getscroll call for the most recent window will cancel the old one, leaving the older window with the wrong viewport. +[ ] fix the Next Window/Previous Window keybindings. For some reason they + don't work. Crashers -------- -- GitLab