pd_canvas.html 35.6 KB
Newer Older
1
2
3
<!DOCTYPE html>
<html>
  <head>
4
  <link id="page_style" rel="stylesheet" type="text/css" href="css/default.css">
5
  </head>
6
  <body id="patch_body">
7
8
9
10
11
12
  <input style="display:none;" id="fileDialog" type="file" multiple />
  <input style="display:none;" id="saveDialog" type="file" nwsaveas nwworkingdir accept=".pd" />

  <input style="display:none;" id="openpanel_dialog" type="file" />
  <input style="display:none;" id="savepanel_dialog" type="file" nwsaveas nwworkingdir />

13
  <svg xmlns="http://www.w3.org/2000/svg" version="1.1" id="patchsvg" overflow="visible" class="noselect">
14
15
  </svg>
  <script>
user's avatar
user committed
16
17
18
'use strict';
var nw = require('nw.gui'); 
var pdgui = require('./pdgui.js');
19

user's avatar
user committed
20
21
// Apply gui preset to this canvas
pdgui.skin.apply(this);
22

user's avatar
user committed
23
24
25
//var name = pdgui.last_loaded();
   
var l = pdgui.get_local_string;
26

user's avatar
user committed
27
28
29
30
31
32
33
console.log("my working dir is " + pdgui.get_pwd());
document.getElementById("saveDialog")
    .setAttribute("nwworkingdir", pdgui.get_pwd());
document.getElementById("fileDialog")
    .setAttribute("nwworkingdir", pdgui.get_pwd());
document.getElementById("fileDialog").setAttribute("accept",
    Object.keys(pdgui.pd_filetypes).toString());
34

user's avatar
user committed
35
var last_keydown = "";
36
37
38
39
40
41
42
43

// This could probably be in pdgui.js
function add_keymods(key, evt) {
    var shift = evt.shiftKey ? "Shift" : "";
    var ctrl = evt.ctrlKey ? "Ctrl" : "";
    return shift + ctrl + key;
}

44
45
46
47
48
49
function text_to_fudi(text) {
    text = text.trim();
    text = text.replace(/(\$[0-9]+)/g, '\\$1');    // escape dollar signs
    text = text.replace(/(?!\\)(,|;)/g, ' \\$1 '); // escape ',' and ';'
    text = text.replace(/\{|\}/g, '');             // filter '{' and '}'
    text = text.replace(/\s+/g, ' ');              // filter consecutive /s
user's avatar
user committed
50

51
52
53
    return text;
}

54
55
var canvas_events = (function() {
    var name,
56
        state,
57
        svg_view = document.getElementById('patchsvg').viewBox.baseVal,
58
59
        textbox = function () {
            return document.getElementById('new_object_textentry');
60
        },
61
62
63
64
        events = {
            mousemove: function(evt) {
                //pdgui.gui_post("x: " + evt.pageX + " y: " + evt.pageY +
                //    " modifier: " + (evt.shiftKey + (evt.ctrlKey << 1)));
65
66
67
68
69
                pdgui.pdsend(name, "motion",
                    (evt.pageX + svg_view.x),
                    (evt.pageY + svg_view.y),
                    (evt.shiftKey + (evt.ctrlKey << 1))
                );
70
71
72
73
74
                evt.stopPropagation();
                evt.preventDefault();
                return false;
            },
            mousedown: function(evt) {
75
                // tk events (and, therefore, Pd evnets) are one greater than html5...
76
77
78
79
80
81
82
83
84
85
                var b = evt.button + 1;
                var mod;
                // For some reason right-click sends a modifier value of "8",
                // and canvas_doclick in g_editor.c depends on that value to
                // do the right thing.  So let's hack...
                if (b === 3) { // right-click
                    mod = 8;
                } else {
                    mod = (evt.shiftKey + (evt.ctrlKey << 1)); 
                }
86
87
88
89
90
                pdgui.pdsend(name, "mouse",
                    (evt.pageX + svg_view.x),
                    (evt.pageY + svg_view.y),
                    b, mod
                );
91
92
93
94
95
96
97
                //evt.stopPropagation();
                evt.preventDefault();
            },
            mouseup: function(evt) {
                //pdgui.gui_post("mouseup: x: " +
                //    evt.pageX + " y: " + evt.pageY +
                //    " button: " + (evt.button + 1));
98
99
100
101
102
                pdgui.pdsend(name, "mouseup",
                    (evt.pageX + svg_view.x),
                    (evt.pageY + svg_view.y),
                    (evt.button + 1)
                );
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
                evt.stopPropagation();
                evt.preventDefault();
            },
            keydown: function(evt) {
                var key_code = evt.keyCode; 
                var hack = null; // hack for unprintable ascii codes
                switch(key_code) {
                    case 8:
                    case 9:
                    case 10:
                    case 27:
                    //case 32:
                    case 127: hack = key_code; break;
                    case 37: hack = add_keymods('Left', evt); break;
                    case 38: hack = add_keymods('Up', evt); break;
                    case 39: hack = add_keymods('Right', evt); break;
                    case 40: hack = add_keymods('Down', evt); break;
                    case 33: hack = add_keymods('Prior', evt); break;
                    case 34: hack = add_keymods('Next', evt); break;
                    case 35: hack = add_keymods('End', evt); break;
                    case 36: hack = add_keymods('Home', evt); break;
124

125
126
127
128
129
130
131
132
133
134
135
136
137
138
                    // These may be different on Safari...
                    case 112: hack = add_keymods('F1', evt); break;
                    case 113: hack = add_keymods('F2', evt); break;
                    case 114: hack = add_keymods('F3', evt); break;
                    case 115: hack = add_keymods('F4', evt); break;
                    case 116: hack = add_keymods('F5', evt); break;
                    case 117: hack = add_keymods('F6', evt); break;
                    case 118: hack = add_keymods('F7', evt); break;
                    case 119: hack = add_keymods('F8', evt); break;
                    case 120: hack = add_keymods('F9', evt); break;
                    case 121: hack = add_keymods('F10', evt); break;
                    case 122: hack = add_keymods('F11', evt); break;
                    case 123: hack = add_keymods('F12', evt); break;

139
140
141
142
143
                    // Handle weird behavior for clipboard shortcuts
                    // Which don't fire a keypress for some odd reason

                    case 65:
                        if (evt.ctrlKey === true) {
144
                            pdgui.pdsend(name, "selectall");
145
146
147
148
149
                            hack = 0; // not sure what to report here...
                        }
                        break;
                    case 88:
                        if (evt.ctrlKey === true) {
150
                            pdgui.pdsend(name, "cut");
151
152
153
154
155
                            hack = 0; // not sure what to report here...
                        }
                        break;
                    case 67:
                        if (evt.ctrlKey === true) {
156
                            pdgui.pdsend(name, "copy");
157
158
159
160
161
                            hack = 0; // not sure what to report here...
                        }
                        break;
                    case 86:
                        if (evt.ctrlKey === true) {
162
                            pdgui.pdsend(name, "paste");
163
164
165
166
                            hack = 0; // not sure what to report here...
                        }
                        break;

167
                    // Need to handle Control key, Alt
168

169
170
171
172
173
174
175
176
                    case 16: hack = 'Shift'; break;
                    case 17: hack = 'Control'; break;
                    case 18: hack = 'Alt'; break;
                }
                if (hack !== null) {
                    pdgui.gui_canvas_sendkey(name, 1, evt, hack);
                    pdgui.set_keymap(key_code, hack);
                }
177
//                pdgui.gui_post("keydown time: keycode is " + evt.keyCode);
178
179
180
181
182
                last_keydown = evt.keyCode;
                //evt.stopPropagation();
                //evt.preventDefault();
            },
            keypress: function(evt) {
183
184
185
186
                // Hack to handle undo/redo shortcuts
                if (evt.charCode === 26) {
                    if (evt.ctrlKey === true) {
                        if (evt.shiftKey === true) { // ctrl-Shift-z
187
                            pdgui.pdsend(name, "redo");
188
                        } else { // ctrl-z
189
                            pdgui.pdsend(name, "undo");
190
191
192
193
194
                        }
                        return;
                    }
                }

195
196
                pdgui.gui_canvas_sendkey(name, 1, evt, evt.charCode);
                pdgui.set_keymap(last_keydown, evt.charCode);
197
//                pdgui.gui_post("keypress time: charcode is " + evt.charCode);
198
199
200
201
202
203
204
                // Don't do things like scrolling on space, arrow keys, etc.
                //evt.stopPropagation();
                evt.preventDefault();
            },
            keyup: function(evt) {
                var my_char_code = pdgui.get_char_code(evt.keyCode);
                pdgui.gui_canvas_sendkey(name, 0, evt, my_char_code);
205
//                pdgui.gui_post("keyup time: charcode is: " + my_char_code);
206
                if (evt.keyCode === 13 && evt.ctrlKey) {
207
                    pdgui.pdsend(name, "reselect");
208
                }
209
210
211
                evt.stopPropagation();
                evt.preventDefault();
            },
212
            text_mousemove: function(evt) {
213
214
215
216
217
218
                evt.stopPropagation();    
                //evt.preventDefault();
                return false;
            },
            text_mousedown: function(evt) {
                if (textbox() !== evt.target) {
user's avatar
user committed
219
220
221
222
                    // Yes: I _really_ want .innerText and NOT .textContent
                    // here.  I want those newlines: although that isn't
                    // standard in Pd-Vanilla, Pd-l2ork uses and preserves
                    // them inside comments
223
224
                    utils.create_obj();
//                    var fudi_msg = text_to_fudi(textbox().innerText);
225
//                    pdgui.pdsend(name, "createobj", fudi_msg);
226
//                    pdgui.gui_post("formatted content is " + fudi_msg);
227
228
229
230
231
232
233
234
235
236
                    events.mousedown(evt);
                    canvas_events.normal();
                }
                evt.stopPropagation();    
                //evt.preventDefault();
                return false;
            },
            text_mouseup: function(evt) {
                pdgui.gui_post("mouseup target is " +
                    evt.target + " and textbox is " + textbox());
user's avatar
user committed
237
                //evt.stopPropagation();    
238
239
240
241
242
243
244
245
246
247
248
                //evt.preventDefault();
                return false;
            },
            text_keydown: function(evt) {
                evt.stopPropagation();    
                //evt.preventDefault();
                return false;
            },
            text_keyup: function(evt) {
                evt.stopPropagation();    
                //evt.preventDefault();
249
250
251
                // ctrl-Enter to reselect
                if (evt.keyCode === 13 && evt.ctrlKey) {
                    canvas_events.set_obj();
252
                    pdgui.pdsend(name, "reselect");
253
                }
254
255
256
257
258
259
260
261
                return false;
            },
            text_keypress: function(evt) {
                evt.stopPropagation();    
                //evt.preventDefault();
                return false;
            },
            floating_text_click: function(evt) {
262
                //pdgui.gui_post("leaving floating mode");
263
264
265
266
267
268
                canvas_events.text();
                evt.stopPropagation();
                evt.preventDefault();
                return false;
            },
            floating_text_keypress: function(evt) {
269
                //pdgui.gui_post("leaving floating mode");
270
                canvas_events.text();
user's avatar
user committed
271
272
273
                //evt.stopPropagation();
                //evt.preventDefault();
                //return false;
274
            }
275
276
277
278
        },
        utils = {
            create_obj: function() {
                var fudi_msg = text_to_fudi(textbox().innerText);
279
                pdgui.pdsend(name, "createobj", fudi_msg);
280
                //pdgui.gui_post("formatted content is " + fudi_msg);
281
282
283
            },
            set_obj: function() {
                var fudi_msg = text_to_fudi(textbox().innerText);
284
                pdgui.pdsend(name, "setobj", fudi_msg);
285
                //pdgui.gui_post("formatted content is " + fudi_msg);
286
            }
287
        }
288
    ;
289

290
291
292
293
    // Dialog events
    document.querySelector("#saveDialog").addEventListener("change",
        function(evt) {
            pdgui.saveas_callback(name, this.value);
294
295
            // reset value so that we can open the same file twice
            this.value = null;
296
297
298
299
300
301
302
303
304
305
306
307
            console.log("tried to open something");
        }, false
    );
    document.querySelector("#fileDialog").addEventListener("change",
        function(evt) {
            var file_array = this.value;
            // reset value so that we can open the same file twice
            this.value = null;
            pdgui.menu_open(file_array);
            console.log("tried to open something");
        }, false
    );
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
    document.querySelector("#openpanel_dialog").addEventListener("change",
        function(evt) {
            var file_string = this.value;
            // reset value so that we can open the same file twice
            this.value = null;
            pdgui.file_dialog_callback(file_string);
            console.log("tried to openpanel something");
        }, false
    );
    document.querySelector("#savepanel_dialog").addEventListener("change",
        function(evt) {
            var file_string = this.value;
            // reset value so that we can open the same file twice
            this.value = null;
            pdgui.file_dialog_callback(file_string);
            console.log("tried to savepanel something");
        }, false
    );

327
328
329
    // closing the Window
    // this isn't actually closing the window yet
    nw.Window.get().on("close", function() {
330
        pdgui.pdsend(name, "menuclose 0");
331
332
    });

333
    return {
334
335
        none: function() {
            var name;
336
            state = 'none';
337
338
339
340
341
342
343
344
            for (var prop in events) {
                if (events.hasOwnProperty(prop)) {
                    name = prop.split('_');
                    name = name[name.length -1];
                    document.removeEventListener(name, events[prop], false);
                }
            }
        },
345
        normal: function() {
346
            //pdgui.gui_post("resetting to normal...");
347
            this.none();
348

349
350
351
352
353
354
            document.addEventListener("mousemove", events.mousemove, false);
            document.addEventListener("keydown", events.keydown, false);
            document.addEventListener("keypress", events.keypress, false);
            document.addEventListener("keyup", events.keyup, false);
            document.addEventListener("mousedown", events.mousedown, false);
            document.addEventListener("mouseup", events.mouseup, false);
355
356
            state = 'normal';
            set_edit_menu_modals(true);
357
358
        },
        text: function() {
359
360
361
362
363
364
365
366
            this.none();

            document.addEventListener("mousemove", events.text_mousemove, false);
            document.addEventListener("keydown", events.text_keydown, false);
            document.addEventListener("keypress", events.text_keypress, false);
            document.addEventListener("keyup", events.text_keyup, false);
            document.addEventListener("mousedown", events.text_mousedown, false);
            document.addEventListener("mouseup", events.text_mouseup, false);
367
368
            state = 'text';
            set_edit_menu_modals(false);
369
370
371
372
373
374
375
        },
        floating_text: function() {
            this.none();
            this.text();
            document.removeEventListener("mousedown", events.text_mousedown, false);
            document.removeEventListener("mouseup", events.text_mouseup, false);
            document.removeEventListener("keypress", events.text_keypress, false);
376
            document.removeEventListener("mousemove", events.text_mousemove, false);
377
378
379
            document.addEventListener("click", events.floating_text_click, false);
            document.addEventListener("keypress", events.floating_text_keypress, false);
            document.addEventListener("mousemove", events.mousemove, false);
380
381
            state = 'floating_text';
            set_edit_menu_modals(false);
382
383
384
        },
        register: function(n) {
            name = n;
385
386
387
        },
        get_state: function() {
            return state;
388
389
390
        },
        set_obj: function() {
            utils.set_obj();
391
392
        }
    }
393
}());
394

user's avatar
user committed
395
396
397
398
399
400
401
402
403
404
405
// This gets called from the nw_create_window function in index.html
// It provides us with our canvas id from the C side.  Once we have it
// we can create the menu and register event callbacks
function register_canvas_id(cid) {
    name = cid; // hack
    create_popup_menu(cid);
    canvas_events.register(cid);
    canvas_events.normal();
    nw_create_patch_window_menus(cid);
    pdgui.canvas_map(cid);
}
406

407
408
409
410
function create_popup_menu(name) {
    // The right-click popup menu
    var popup_menu = new nw.Menu();
    pdgui.add_popup(name, popup_menu);
411

412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
    popup_menu.append(new nw.MenuItem({
        label: 'Properties',
        click: function() {
            pdgui.popup_action(name, 0);
        }
    }));
    popup_menu.append(new nw.MenuItem({
        label: 'Open',
        click: function() {
            pdgui.popup_action(name, 1);
        }
    }));
    popup_menu.append(new nw.MenuItem({
        label: 'Help',
        click: function() {
            pdgui.popup_action(name, 2);
        }
    }));
430
431
}

user's avatar
user committed
432
433
434
435
// stop-gap
function menu_generic () {
    alert("Please implement this");
}
436

437
438
439
440
441
442
443
444
445
446
447
448
var modals = {}; // Edit menu items that should be disabled when editing
                 // an object box

function set_edit_menu_modals(state) {
    var item;
    for (item in modals) {
        if (modals.hasOwnProperty(item)) {
            modals[item].enabled = state; 
        }
    }
}

user's avatar
user committed
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
function nw_undo_menu(undo_text, redo_text) {
    if (undo_text === 'no') {
        modals.undo.enabled = false;
    } else {
        modals.undo.enabled = true;
        modals.undo.label = l('menu.undo') + " " + undo_text;
    }
    if (redo_text === 'no') {
        modals.redo.enabled = false;
    } else {
        modals.redo.enabled = true;
        modals.redo.label = l('menu.redo') + " " + redo_text;
    }
}

464
465
466
467
468
469
470
function check_box_for_text() {
    var state = canvas_events.get_state();
    if (state === 'text' || state === 'floating_text') {
        canvas_events.set_obj();
    }
}

471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
// Menus for the Patch window
function nw_create_patch_window_menus (name) {

    // Window menu
    var windowMenu = new nw.Menu({
        type: 'menubar'
    });

    // File menu
    var fileMenu = new nw.Menu();

    // Add to window menu
    windowMenu.append(new nw.MenuItem({
        label: l('menu.file'),
        submenu: fileMenu
    }));

    // File sub-entries
    fileMenu.append(new nw.MenuItem({
        label: l('menu.new'),
        click: pdgui.menu_new,
        key: 'n',
        modifiers: "ctrl",
        tooltip: l('menu.new_tt')
    }));

    fileMenu.append(new nw.MenuItem({
        label: l('menu.open'),
        key: 'o',
        modifiers: "ctrl",
        tooltip: l('menu.open_tt'),
        click: function() {
            var chooser = document.querySelector('#fileDialog');
            chooser.click();
        }
    }));

    if (pdgui.k12_mode == 1) {
        fileMenu.append(new nw.MenuItem({
        label: l('menu.k12_demos'),
        tooltip: l('menu.k12_demos_tt'),
        click: pdgui.menu_k12_open_demos
        }));
    }

    fileMenu.append(new nw.MenuItem({
        type: 'separator'
    }));

    // Note: this must be different for the main Pd window
    fileMenu.append(new nw.MenuItem({
        label: l('menu.save'),
        click: function () {
524
            pdgui.canvas_check_geometry(name);
525
526
527
528
529
530
531
532
533
534
            pdgui.menu_save(name);
        },
        key: 's',
        modifiers: "ctrl",
        tooltip: l('menu.save_tt')
    }));

    fileMenu.append(new nw.MenuItem({
        label: l('menu.saveas'),
        click: function (){
535
            pdgui.canvas_check_geometry(name);
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
            pdgui.menu_saveas(name);
        },
        key: 's',
        modifiers: "ctrl+shift",
        tooltip: l('menu.saveas_tt')
    }));

    if (pdgui.k12_mode == 0) {
        fileMenu.append(new nw.MenuItem({
            type: 'separator'
        }));
    }

    fileMenu.append(new nw.MenuItem({
        label: l('menu.message'),
        click: pdgui.menu_send,
        key: 'm',
        modifiers: "ctrl",
        tooltip: l('menu.message_tt')
    }));

    if (pdgui.k12_mode == 0) {
        fileMenu.append(new nw.MenuItem({
            type: 'separator'
        }));
    }

    // recent files go here

    // anther separator goes here if there are any recent files

    fileMenu.append(new nw.MenuItem({
        label: l('menu.close'),
        tooltip: l('menu.close_tt'),
        click: function() {
            pdgui.menu_close(name);
572
573
574
        },
        key: 'w',
        modifiers: "ctrl"
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
    }));

    // Quit Pd
    fileMenu.append(new nw.MenuItem({
        label: l('menu.quit'),
        click: pdgui.menu_quit,
        key: 'q',
        modifiers: "ctrl",
        tooltip: l('menu.quit_tt')
    }));

    // Edit menu
    var editMenu = new nw.Menu();

    // Add to window menu
    windowMenu.append(new nw.MenuItem({
    label: l('menu.edit'),
    submenu: editMenu
    }));

    // Edit sub-entries
596
    editMenu.append(modals.undo = new nw.MenuItem({
597
        label: l('menu.undo'),
user's avatar
user committed
598
        click: function () {
599
            pdgui.pdsend(name, "undo");
user's avatar
user committed
600
        },
601
        tooltip: l('menu.undo_tt'),
602
603
    }));

604
    editMenu.append(modals.redo = new nw.MenuItem({
605
        label: l('menu.redo'),
user's avatar
user committed
606
        click: function () {
607
            pdgui.pdsend(name, "redo");
user's avatar
user committed
608
        },
609
        tooltip: l('menu.redo_tt'),
610
611
612
613
614
615
    }));

    editMenu.append(new nw.MenuItem({
        type: 'separator'
    }));

616
    editMenu.append(modals.cut = new nw.MenuItem({
617
618
        label: l('menu.cut'),
        click: function () {
619
            pdgui.pdsend(name, "cut");
620
        },
621
        tooltip: l('menu.cut_tt'),
622
623
    }));

624
    editMenu.append(modals.copy = new nw.MenuItem({
625
626
        label: l('menu.copy'),
        click: function () {
627
            pdgui.pdsend(name, "copy");
628
        },
629
        tooltip: l('menu.copy_tt'),
630
631
    }));

632
    editMenu.append(modals.paste = new nw.MenuItem({
633
634
        label: l('menu.paste'),
        click: function () {
635
            pdgui.pdsend(name, "paste");
636
        },
637
        tooltip: l('menu.paste_tt'),
638
639
640
641
642
    }));

    editMenu.append(new nw.MenuItem({
        label:  l('menu.duplicate'),
        click: function () {
643
            pdgui.pdsend(name, "duplicate");
644
645
646
647
648
649
        },
        key: 'd',
        modifiers: "ctrl",
        tooltip: l('menu.duplicate_tt')
    }));

650
    editMenu.append(modals.selectall = new nw.MenuItem({
651
        label: l('menu.selectall'),
652
653
        click: function (evt) {
            if (canvas_events.get_state() === 'normal') {
654
                pdgui.pdsend(name, "selectall");
655
            }
656
657
658
659
660
661
662
663
664
665
666
        },
        tooltip: l('menu.selectall_tt'),
    }));

    editMenu.append(new nw.MenuItem({
        label: l('menu.reselect'),
        // Unfortunately nw.js doesn't allow
        // key: "Return" or key: "Enter", so we
        // can't bind to ctrl-Enter here. (Even
        // tried fromCharCode...)
        click: function () {
667
            pdgui.pdsend(name, "reselect");
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
        },
        key: String.fromCharCode(10),
        modifiers: "ctrl",
        tooltip: l('menu.reselect_tt')
    }));

    editMenu.append(new nw.MenuItem({
        type: 'separator'
    }));

    editMenu.append(new nw.MenuItem({
        label: l('menu.zoomin'),
        click: function () {
            var z = nw.Window.get().zoomLevel;
            if (z < 8) { z++; }
            nw.Window.get().zoomLevel = z;
            pdgui.gui_post("zoom level is " + nw.Window.get().zoomLevel);
        },
        key: '=',
        modifiers: "ctrl",
        tooltip: l('menu.zoomin')
    }));

    editMenu.append(new nw.MenuItem({
        label: l('menu.zoomout'),
        click: function () {
            var z = nw.Window.get().zoomLevel;
            if (z > -7) { z--; } 
            nw.Window.get().zoomLevel = z;
            pdgui.gui_post("zoom level is " + nw.Window.get().zoomLevel);
        },
        key: '-',
        modifiers: "ctrl",
        tooltip: l('menu.zoomout_tt'),
    }));

    editMenu.append(new nw.MenuItem({
        type: 'separator'
    }));

    editMenu.append(new nw.MenuItem({
        label: l('menu.tidyup'),
710
        click: function() {
711
            pdgui.pdsend(name, "tidy");
712
713
        },
        key: 'y',
714
715
716
717
718
719
        modifiers: "ctrl",
        tooltip: l('menu.tidyup_tt')
    }));

    editMenu.append(new nw.MenuItem({
        label: l('menu.tofront'),
720
721
722
        click: function() {
            pdgui.popup_action(name, 3);
        },
723
724
725
726
727
        tooltip: l('menu.tofront_tt'),
    }));

    editMenu.append(new nw.MenuItem({
        label: l('menu.toback'),
728
729
730
        click: function() {
            pdgui.popup_action(name, 4);
        },
731
732
733
734
735
736
737
738
739
        tooltip: l('menu.toback_tt'),
    }));

    editMenu.append(new nw.MenuItem({
        type: 'separator'
    }));

    editMenu.append(new nw.MenuItem({
        label: l('menu.font'),
user's avatar
user committed
740
        click: function () {
741
            pdgui.pdsend(name, "menufont");
user's avatar
user committed
742
        },
743
744
745
746
747
748
        tooltip: l('menu.font_tt'),
    }));

    editMenu.append(new nw.MenuItem({
        label: l('menu.cordinspector'),
        click: function() {
749
            pdgui.pdsend(name, "magicglass 0");
750
        },
pokergaming's avatar
pokergaming committed
751
        key: 'r',
752
753
754
755
756
757
758
759
760
761
762
        modifiers: "ctrl",
        tooltip: l('menu.cordinspector_tt'),
    }));

    editMenu.append(new nw.MenuItem({
        type: 'separator'
    }));

    editMenu.append(new nw.MenuItem({
        label: l('menu.find'),
        click: menu_generic,
user's avatar
user committed
763
764
        key: 'f',
        modifiers: "ctrl",
765
766
767
768
769
770
        tooltip: l('menu.find_tt'),
    }));

    editMenu.append(new nw.MenuItem({
        label: l('menu.findagain'),
        click: menu_generic,
user's avatar
user committed
771
772
        key: 'g',
        modifiers: "ctrl",
773
774
775
776
777
        tooltip: l('menu.findagain')
    }));

    editMenu.append(new nw.MenuItem({
        label: l('menu.finderror'),
pokergaming's avatar
pokergaming committed
778
779
780
        click: function() {
            pdgui.pdsend("pd finderror");
        },
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
        tooltip: l('menu.finderror_tt'),
    }));

    editMenu.append(new nw.MenuItem({
        type: 'separator'
    }));

    editMenu.append(new nw.MenuItem({
        label: l('menu.autotips'),
        click: menu_generic,
        tooltip: l('menu.autotips_tt'),
    }));

    editMenu.append(new nw.MenuItem({
        label: l('menu.editmode'),
796
797
        click: function() {
            check_box_for_text();
798
            pdgui.pdsend(name, "editmode 0");
799
        },
800
801
802
803
804
805
806
807
808
809
810
        key: 'e',
        modifiers: "ctrl",
        tooltip: l('menu.editmode_tt')
    }));

    editMenu.append(new nw.MenuItem({
        type: 'separator'
    }));

    editMenu.append(new nw.MenuItem({
        label: l('menu.preferences'),
pokergaming's avatar
pokergaming committed
811
812
        click: pdgui.open_prefs,
        key: 'p',
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
        modifiers: "ctrl",
        tooltip: l('menu.preferences_tt')
    }));

    // Put menu
    var putMenu = new nw.Menu();

    // Add to window menu
    windowMenu.append(new nw.MenuItem({
    label: l('menu.put'),
    submenu: putMenu
    }));

    // Put menu sub-entries
    putMenu.append(new nw.MenuItem({
        label: l('menu.object'),
        click: function() {
830
            check_box_for_text();
831
832
            pdgui.pdsend(name, "dirty 1");
            pdgui.pdsend(name, "obj 0");
833
834
835
836
837
838
839
840
841
        },
        key: '1',
        modifiers: "ctrl",
        tooltip: l('menu.object_tt'),
    }));

    putMenu.append(new nw.MenuItem({
        label: l('menu.msgbox'),
        click: function() {
842
            check_box_for_text();
843
844
            pdgui.pdsend(name, "dirty 1");
            pdgui.pdsend(name, "msg 0");
845
846
847
848
849
850
851
852
853
        },
        key: '2',
        modifiers: "ctrl",
        tooltip: l('menu.msgbox_tt'),
    }));

    putMenu.append(new nw.MenuItem({
        label: l('menu.number'),
        click: function() { 
854
            check_box_for_text();
855
856
            pdgui.pdsend(name, "dirty 1");
            pdgui.pdsend(name, "floatatom 0");
857
858
859
860
861
862
863
864
865
        },
        key: '3',
        modifiers: "ctrl",
        tooltip: l('menu.number_tt')
    }));

    putMenu.append(new nw.MenuItem({
        label: l('menu.symbol'),
        click: function() {
866
            check_box_for_text();
867
868
            pdgui.pdsend(name, "dirty 1");
            pdgui.pdsend(name, "symbolatom 0");
869
870
871
872
873
874
875
876
877
        },
        key: '4',
        modifiers: "ctrl",
        tooltip: l('menu.symbol_tt')
    }));

    putMenu.append(new nw.MenuItem({
        label: l('menu.comment'),
        click: function() {
878
            check_box_for_text();
879
880
            pdgui.pdsend(name, "dirty 1");
            pdgui.pdsend(name, "text 0");
881
882
883
884
885
886
887
888
889
890
891
892
893
        },
        key: '5',
        modifiers: "ctrl",
        tooltip: l('menu.comment_tt')
    }));

    putMenu.append(new nw.MenuItem({
        type: 'separator'
    }));

    putMenu.append(new nw.MenuItem({
        label: l('menu.bang'),
        click: function(e) {
894
            check_box_for_text();
895
896
            pdgui.pdsend(name, "dirty 1");
            pdgui.pdsend(name, "bng 0");
897
898
899
900
901
902
903
904
905
        },
        key: 'b',
        modifiers: "ctrl-shift",
        tooltip: l('menu.bang_tt')
    }));

    putMenu.append(new nw.MenuItem({
        label: l('menu.toggle'),
        click: function() {
906
            check_box_for_text();
907
908
            pdgui.pdsend(name, "dirty 1");
            pdgui.pdsend(name, "toggle 0");
909
910
911
912
913
914
915
916
917
        },
        key: 't',
        modifiers: "ctrl-shift",
        tooltip: l('menu.toggle_tt')
    }));

    putMenu.append(new nw.MenuItem({
        label: l('menu.number2'),
        click: function() {
918
            check_box_for_text();
919
920
            pdgui.pdsend(name, "dirty 1");
            pdgui.pdsend(name, "numbox 0");
921
922
923
924
925
926
927
928
929
        },
        key: 'n',
        modifiers: "ctrl-shift",
        tooltip: l('menu.number2')
    }));

    putMenu.append(new nw.MenuItem({
        label: l('menu.vslider'),
        click: function() {
930
            check_box_for_text();
931
932
            pdgui.pdsend(name, "dirty 1");
            pdgui.pdsend(name, "vslider 0");
933
934
935
936
937
938
939
940
941
        },
        key: 'v',
        modifiers: "ctrl-shift",
        tooltip: l('menu.vslider_tt'),
    }));

    putMenu.append(new nw.MenuItem({
        label: l('menu.hslider'),
        click: function() {
942
            check_box_for_text();
943
944
            pdgui.pdsend(name, "dirty 1");
            pdgui.pdsend(name, "hslider 0");
945
946
947
948
949
950
951
952
953
        },
        key: 'h',
        modifiers: "ctrl-shift",
        tooltip: l('menu.hslider_tt'),
    }));

    putMenu.append(new nw.MenuItem({
        label: l('menu.vradio'),
        click: function() {
954
            check_box_for_text();
955
956
            pdgui.pdsend(name, "dirty 1");
            pdgui.pdsend(name, "vradio 0");
957
958
959
960
961
962
963
964
965
        },
        key: 'd',
        modifiers: "ctrl-shift",
        tooltip: l('menu.vradio_tt'),
    }));

    putMenu.append(new nw.MenuItem({
        label: l('menu.hradio'),
        click: function() {
966
            check_box_for_text();
967
968
            pdgui.pdsend(name, "dirty 1");
            pdgui.pdsend(name, "hradio 0");
969
970
971
972
973
974
975
976
977
        },
        key: 'i',
        modifiers: "ctrl",
        tooltip: l('menu.hradio_tt'),
    }));

    putMenu.append(new nw.MenuItem({
        label: l('menu.vu'),
        click: function() {
978
            check_box_for_text();
979
980
            pdgui.pdsend(name, "dirty 1");
            pdgui.pdsend(name, "vumeter 0");
981
982
983
984
985
986
987
988
989
        },
        key: 'u',
        modifiers: "ctrl",
        tooltip: l('menu.vu_tt'),
    }));

    putMenu.append(new nw.MenuItem({
        label: l('menu.cnv'),
        click: function() {
990
            check_box_for_text();
991
992
            pdgui.pdsend(name, "dirty 1");
            pdgui.pdsend(name, "mycnv 0");
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
        },
        key: 'c',
        modifiers: "ctrl-shift",
        tooltip: l('menu.cnv_tt')
    }));

    putMenu.append(new nw.MenuItem({
        type: 'separator'
    }));

    putMenu.append(new nw.MenuItem({
        label: l('menu.graph'),
        click: function() {
1006
            check_box_for_text();
1007
            pdgui.pdsend(name, "dirty 1");
1008
            // leaving out some placement logic... see pd.tk menu_graph
1009
            pdgui.pdsend(name, "graph NULL 0 0 0 0 30 30 0 30");
1010
1011
1012
1013
1014
1015
        },
        tooltip: l('menu.graph_tt'),
    }));

    putMenu.append(new nw.MenuItem({
        label: l('menu.array'),
1016
        click: function() {
1017
                check_box_for_text();
1018
1019
                pdgui.pdsend(name, "dirty 1");
                pdgui.pdsend(name, "menuarray");
1020
            },
1021
1022
1023
1024
        tooltip: l('menu.array_tt'),
    }));


user's avatar
user committed
1025
1026
    // Windows menu... call it "winman" (i.e., window management)
    // to avoid confusion
1027
1028
1029
1030
1031
1032
1033
1034
1035
    var winmanMenu = new nw.Menu();

    // Add to windows menu
    windowMenu.append(new nw.MenuItem({
    label: l('menu.windows'),
    submenu: winmanMenu
    }));

    // Winman sub-entries
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
    winmanMenu.append(new nw.MenuItem({
        label: l('menu.fullscreen'),
        click: function() {
            var win = nw.Window.get();
            var fullscreen = win.isFullscreen;
            win.isFullscreen = !fullscreen;
            pdgui.gui_post("fullscreen is " + fullscreen);
        },
        key: "f11",
        //modifiers: "ctrl",
        tooltip: l('menu.nextwin_tt'),
    }));

1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
    winmanMenu.append(new nw.MenuItem({
        label: l('menu.nextwin'),
        click: menu_generic,
        key: String.fromCharCode(12), // Page down
        modifiers: "ctrl",
        tooltip: l('menu.nextwin_tt'),
    }));

    winmanMenu.append(new nw.MenuItem({
        label: l('menu.prevwin'),
        click: menu_generic,
        key: String.fromCharCode(11), // Page up
        modifiers: "ctrl",
        tooltip: l('menu.prevwin_tt'),
    }));

    winmanMenu.append(new nw.MenuItem({
        type: 'separator'
    }));

    winmanMenu.append(new nw.MenuItem({
        label: l('menu.parentwin'),
        click: menu_generic,
        tooltip: l('menu.parentwin_tt'),
    }));

    winmanMenu.append(new nw.MenuItem({
        label: l('menu.pdwin'),
        click: menu_generic,
        tooltip: l('menu.pdwin_tt'),
    }));

    // Media menu
    var mediaMenu = new nw.Menu();

    // Add to window menu
    windowMenu.append(new nw.MenuItem({
    label: l('menu.media'),
    submenu: mediaMenu
    }));

    // Media sub-entries
    mediaMenu.append(new nw.MenuItem({
        label: l('menu.audio_on'),
1093
1094
1095
        click: function() {
            pdgui.pdsend("pd dsp 1");
        },
1096
1097
1098
1099
1100
1101
1102
        key: '/',
        modifiers: "ctrl",
        tooltip: l('menu.audio_on_tt'),
    }));

    mediaMenu.append(new nw.MenuItem({
        label: l('menu.audio_off'),
1103
1104
1105
1106
        click: function() {
            pdgui.pdsend("pd dsp 0");
        },
        key: '.',
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
        modifiers: "ctrl",
        tooltip: l('menu.audio_off_tt'),
    }));

    mediaMenu.append(new nw.MenuItem({
        type: 'separator'
    }));

    mediaMenu.append(new nw.MenuItem({
        label: l('menu.test'),
        click: menu_generic,
        tooltip: l('menu.test_tt'),
    }));

    mediaMenu.append(new nw.MenuItem({
        label: l('menu.loadmeter'),
        click: menu_generic,
        tooltip: l('menu.loadmeter_tt'),
    }));

    // Help menu
    var helpMenu = new nw.Menu();

    // Add to window menu
    windowMenu.append(new nw.MenuItem({
    label: l('menu.help'),
    submenu: helpMenu
    }));

    // Help sub-entries
    helpMenu.append(new nw.MenuItem({
        label: l('menu.about'),
        click: menu_generic,
        //key: 'c',
        //modifiers: "ctrl",
        tooltip: l('menu.about_tt'),
    }));

    helpMenu.append(new nw.MenuItem({
        label: l('menu.manual'),
        click: menu_generic,
        tooltip: l('menu.manual'),
    }));

    helpMenu.append(new nw.MenuItem({
        label: l('menu.browser'),
        click: menu_generic,
        tooltip: l('menu.browser_tt'),
    }));

    helpMenu.append(new nw.MenuItem({
        type: 'separator'
    }));

    helpMenu.append(new nw.MenuItem({
        label: l('menu.l2ork_list'),
        click: menu_generic,
        tooltip: l('menu.l2ork_list_tt'),
    }));

    helpMenu.append(new nw.MenuItem({
        label: l('menu.pd_list'),
        click: menu_generic,
        tooltip: l('menu.pd_list_tt'),
    }));

    helpMenu.append(new nw.MenuItem({
        label: l('menu.forums'),
        click: menu_generic,
        tooltip: l('menu.forums_tt'),
    }));

    helpMenu.append(new nw.MenuItem({
        label: l('menu.irc'),
        click: menu_generic,
        tooltip: l('menu.irc_tt'),
    }));

    // Assign to window
    nw.Window.get().menu = windowMenu;

}

  </script>
  </body>
</html>