pdcanvas.html 25.9 KB
Newer Older
Jonathan Wilkes's avatar
Jonathan Wilkes committed
1
2
3
4
<!DOCTYPE html>
<html>
  <head>
  <link rel="stylesheet" type="text/css" href="pdcanvas.css">
5
  </head>
Jonathan Wilkes's avatar
Jonathan Wilkes committed
6
7
8
  <body>
  <input style="display:none;" id="fileDialog" type="file" multiple />
  <input style="display:none;" id="saveDialog" type="file" nwsaveas nwworkingdir accept=".pd" />
9
10
11
12
13

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


Jonathan Wilkes's avatar
Jonathan Wilkes committed
14
15
16
17
18
19
20
21
  <svg xmlns="http://www.w3.org/2000/svg" version="1.1" id="patchsvg" height="1000" width="1000" class="noselect">
  <rect/>
  </svg>
  <script>
    'use strict';
    var nw = require('nw.gui'); 
    var pdgui = require('./pdgui.js');

22
    //var name = pdgui.last_loaded();
Jonathan Wilkes's avatar
Jonathan Wilkes committed
23
24
25
26
27
28
29
30
    
    console.log("my working dire 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());

31
32
33
34
35
36
37
38
39
40
41
42
43
    var last_keydown = "";

    // 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) {
console.log("fuck you");
        create_popup_menu(cid);
        add_events(cid);
        nw_create_patch_window_menus(cid);
        pdgui.canvas_map(cid);
    }

Jonathan Wilkes's avatar
Jonathan Wilkes committed
44
45


46
47
48
49
50
51
52
53
// 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;
}

function create_popup_menu(name) {
Jonathan Wilkes's avatar
Jonathan Wilkes committed
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
    // The right-click popup menu
    var popup_menu = new nw.Menu();
    pdgui.add_popup(name, popup_menu);

    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);
        }
    }));
76
}
Jonathan Wilkes's avatar
Jonathan Wilkes committed
77

78
function add_events(name) {
Jonathan Wilkes's avatar
Jonathan Wilkes committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
    document.querySelector("#saveDialog").addEventListener("change", function(evt) {
        pdgui.saveas_callback(name, this.value);
        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);

93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
    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
    );

Jonathan Wilkes's avatar
Jonathan Wilkes committed
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213

    document.addEventListener("mousemove", function(evt) {
        //pdgui.gui_post("x: " + evt.pageX + " y: " + evt.pageY +
        //    " modifier: " + (evt.shiftKey + (evt.ctrlKey << 1)));
        pdgui.pdsend(name + " motion " + evt.pageX + " " + evt.pageY + " " +
            (evt.shiftKey + (evt.ctrlKey << 1)));
        evt.stopPropagation();
//        evt.preventDefault();
        return false;
    });

    document.addEventListener("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;

            // Need to handle Control key, Alt

            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);
        }
        pdgui.gui_post("keydown time: keycode is " + evt.keyCode);
        last_keydown = evt.keyCode;
        evt.stopPropagation();
    });

    document.addEventListener("keypress", function(evt) {
        pdgui.gui_canvas_sendkey(name, 1, evt, evt.charCode);
        pdgui.set_keymap(last_keydown, evt.charCode);
        pdgui.gui_post("keypress time: charcode is " + evt.charCode);
        // Don't do things like scrolling on space, arrow keys, etc.
        evt.stopPropagation();
        evt.preventDefault();
    });

    document.addEventListener("keyup", function(evt) {
        var my_char_code = pdgui.get_char_code(evt.keyCode);
        pdgui.gui_canvas_sendkey(name, 0, evt, my_char_code);
        pdgui.gui_post("keyup time: charcode is: " + my_char_code);
    });

    // just left-clicks for the moment
    document.onmousedown = function(evt) {
        //pdgui.gui_post("mousedown: x: " + evt.pageX + " y: " + evt.pageY +
        //    " button: " + (evt.button + 1) + " modifier: " + (evt.shiftKey + (evt.ctrlKey << 1)));
        // tk events are one greater than html5...
        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)); 
        }
        pdgui.pdsend(name + " mouse " + evt.pageX + " " + evt.pageY + " " +
            b + " " + mod);
        evt.stopPropagation();
        evt.preventDefault();
    }

    document.onmouseup = function(evt) {
        //pdgui.gui_post("mouseup: x: " + evt.pageX + " y: " + evt.pageY +
        //    " button: " + (evt.button + 1));
        pdgui.pdsend(name + " mouseup " + evt.pageX + " " + evt.pageY + " " +
            (evt.button + 1));
    }




    // let's handle some events for this window...

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


214
215
}

Jonathan Wilkes's avatar
Jonathan Wilkes committed
216
217
218



219
220
221


//nw_create_patch_window_menus(name);
Jonathan Wilkes's avatar
Jonathan Wilkes committed
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299

        function menu_generic () {
            alert("Please implement this");
        }

        function pdmenu_copy () {
            alert("Please implement pdmenu_copy"); 
        }

        function pdmenu_selectall () {
            alert("Please implement pdmenu_selectall"); 
        }

        function pdmenu_preferences () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_next_win () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_previous_win () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_parent_win () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_console_win () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_audio_on () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_audio_off () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_test_audio () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_load_meter () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_about_pd () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_manual () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_help_browser () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_l2ork_mailinglist () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_pd_mailinglists () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_forums () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_irc () {
            alert("Please implement pdmenu_preferences"); 
        }

// Menus for the Patch window
300
function nw_create_patch_window_menus (name) {
Jonathan Wilkes's avatar
Jonathan Wilkes committed
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327

    // 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: 'File',
        submenu: fileMenu
    }));

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

    fileMenu.append(new nw.MenuItem({
        label: 'Open',
        key: 'o',
        modifiers: "ctrl",
328
        click: function() {
Jonathan Wilkes's avatar
Jonathan Wilkes committed
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
            var chooser = document.querySelector('#fileDialog');
            chooser.click();
        }
    }));

    if (pdgui.k12_mode == 1) {
        fileMenu.append(new nw.MenuItem({
        label: 'K12 Demos',
        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: 'Save',
        click: function () {
            pdgui.menu_save(name);
        },
        key: 's',
        modifiers: "ctrl"
    }));

    fileMenu.append(new nw.MenuItem({
        label: 'Save as...',
        click: function (){
            pdgui.menu_saveas(name);
        },
        key: 's',
        modifiers: "ctrl+shift"
    }));

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

    fileMenu.append(new nw.MenuItem({
        label: 'Message...',
        click: pdgui.menu_send,
        key: 'm',
        modifiers: "ctrl"
    }));

    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: 'Close',
        click: function() {
            pdgui.menu_close(name);
        }
    }));

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


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

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

    // Edit sub-entries
    editMenu.append(new nw.MenuItem({
        label: 'Undo',
        click: menu_generic,
        key: 'c',
        modifiers: "ctrl"
    }));

    editMenu.append(new nw.MenuItem({
        label: 'Redo',
        click: menu_generic,
        key: 'a',
        modifiers: "ctrl"
    }));

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

    editMenu.append(new nw.MenuItem({
        label: 'Cut',
433
434
435
        click: function () {
            pdgui.pdsend(name + " cut");
        },
Jonathan Wilkes's avatar
Jonathan Wilkes committed
436
437
438
439
440
441
        key: 'c',
        modifiers: "ctrl"
    }));

    editMenu.append(new nw.MenuItem({
        label: 'Copy',
442
443
444
445
        click: function () {
            pdgui.pdsend(name + " copy");
        },
        key: 'x',
Jonathan Wilkes's avatar
Jonathan Wilkes committed
446
447
448
449
450
        modifiers: "ctrl"
    }));

    editMenu.append(new nw.MenuItem({
        label: 'Paste',
451
452
453
454
        click: function () {
            pdgui.pdsend(name + " paste");
        },
        key: 'v',
Jonathan Wilkes's avatar
Jonathan Wilkes committed
455
456
457
458
459
460
        modifiers: "ctrl"
    }));


    editMenu.append(new nw.MenuItem({
        label: 'Duplicate',
461
462
463
464
        click: function () {
            pdgui.pdsend(name + " duplicate");
        },
        key: 'd',
Jonathan Wilkes's avatar
Jonathan Wilkes committed
465
466
467
468
469
        modifiers: "ctrl"
    }));

    editMenu.append(new nw.MenuItem({
        label: 'Select All',
470
471
472
        click: function () {
            pdgui.pdsend(name + " selectall");
        },
Jonathan Wilkes's avatar
Jonathan Wilkes committed
473
474
475
476
477
478
        key: 'a',
        modifiers: "ctrl"
    }));

    editMenu.append(new nw.MenuItem({
        label: 'Reselect',
479
480
481
482
483
484
485
486
        // 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 () {
            pdgui.pdsend(name + " reselect");
        },
        key: String.fromCharCode(10),
Jonathan Wilkes's avatar
Jonathan Wilkes committed
487
488
489
490
491
492
493
494
495
496
        modifiers: "ctrl"
    }));

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

    editMenu.append(new nw.MenuItem({
        label: 'Zoom In',
        click: function () {
497
498
499
            var z = nw.Window.get().zoomLevel;
            if (z < 8) { z++; }
            nw.Window.get().zoomLevel = z;
Jonathan Wilkes's avatar
Jonathan Wilkes committed
500
501
502
503
504
505
506
507
508
            pdgui.gui_post("zoom level is " + nw.Window.get().zoomLevel);
        },
        key: '=',
        modifiers: "ctrl"
    }));

    editMenu.append(new nw.MenuItem({
        label: 'Zoom Out',
        click: function () {
509
510
511
            var z = nw.Window.get().zoomLevel;
            if (z > -7) { z--; } 
            nw.Window.get().zoomLevel = z;
Jonathan Wilkes's avatar
Jonathan Wilkes committed
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
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
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
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
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
            pdgui.gui_post("zoom level is " + nw.Window.get().zoomLevel);
        },
        key: '-',
        modifiers: "ctrl"
    }));




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

    editMenu.append(new nw.MenuItem({
        label: 'Tidy Up',
        click: menu_generic,
        key: 'a',
        modifiers: "ctrl"
    }));

    editMenu.append(new nw.MenuItem({
        label: 'Bring to Front',
        click: menu_generic,
        key: 'a',
        modifiers: "ctrl"
    }));

    editMenu.append(new nw.MenuItem({
        label: 'Send to Back',
        click: menu_generic,
        key: 'a',
        modifiers: "ctrl"
    }));

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

    editMenu.append(new nw.MenuItem({
        label: 'Font',
        click: menu_generic,
        key: 'a',
        modifiers: "ctrl"
    }));

    editMenu.append(new nw.MenuItem({
        label: 'Cord Inspector',
        click: function() {
            pdgui.pdsend(name + " magicglass 0");
        },
        key: 'a',
        modifiers: "ctrl"
    }));

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

    editMenu.append(new nw.MenuItem({
        label: 'Find',
        click: menu_generic,
        key: 'a',
        modifiers: "ctrl"
    }));

    editMenu.append(new nw.MenuItem({
        label: 'Find Again',
        click: menu_generic,
        key: 'a',
        modifiers: "ctrl"
    }));

    editMenu.append(new nw.MenuItem({
        label: 'Find Last Error',
        click: menu_generic,
        key: 'a',
        modifiers: "ctrl"
    }));

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

    editMenu.append(new nw.MenuItem({
        label: 'Autotips',
        click: menu_generic,
        key: 'a',
        modifiers: "ctrl"
    }));

    editMenu.append(new nw.MenuItem({
        label: 'Editmode',
        click: function() { pdgui.pdsend(name + " editmode 0"); },
        key: 'e',
        modifiers: "ctrl"
    }));

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

    editMenu.append(new nw.MenuItem({
        label: 'Preferences...',
        click: menu_generic,
        key: 'a',
        modifiers: "ctrl"
    }));

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

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

    // Put menu sub-entries
    putMenu.append(new nw.MenuItem({
        label: 'Object',
        click: function() {
                   pdgui.pdsend(name + " dirty 1");
                   pdgui.pdsend(name + " obj 0");
        },
        key: '1',
        modifiers: "ctrl"
    }));

/*

proc menu_floatatom {name accel} {
	pd [concat $name dirty 1 \;]
    pd [concat $name floatatom $accel \;]
}

proc menu_symbolatom {name accel} {
	pd [concat $name dirty 1 \;]
    pd [concat $name symbolatom $accel \;]
}

proc menu_comment {name accel} {
	pd [concat $name dirty 1 \;]
    pd [concat $name text $accel \;]
}

proc menu_graph {name} {
	pd [concat $name dirty 1 \;]
	set xdraw [expr int([$name.c canvasx 0])]
	set ydraw [expr int([$name.c canvasy 0])]
    pd [concat $name graph NULL 0 0 0 0 [expr $xdraw+30] [expr $ydraw+30] 0 [expr $ydraw+30]\;]
    #pd [concat $name graph \;]
}

proc menu_array {name} {
	pd [concat $name dirty 1 \;]
    pd [concat $name menuarray \;]
}


*/

    putMenu.append(new nw.MenuItem({
        label: 'Message',
        click: function() {
                   pdgui.pdsend(name + " dirty 1");
                   pdgui.pdsend(name + " msg 0");
        },
        key: '2',
        modifiers: "ctrl"
    }));

    putMenu.append(new nw.MenuItem({
        label: 'Number',
        click: function() { 
                   pdgui.pdsend(name + " dirty 1");
                   pdgui.pdsend(name + " floatatom 0");
        },
        key: '3',
        modifiers: "ctrl"
    }));

    putMenu.append(new nw.MenuItem({
        label: 'Symbol',
        click: function() {
                   pdgui.pdsend(name + " dirty 1");
                   pdgui.pdsend(name + " symbolatom 0");
        },
        key: '4',
        modifiers: "ctrl"
    }));

    putMenu.append(new nw.MenuItem({
        label: 'Comment',
        click: function() {
                   pdgui.pdsend(name + " dirty 1");
                   pdgui.pdsend(name + " text 0");
        },
        key: '5',
        modifiers: "ctrl"
    }));

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

    putMenu.append(new nw.MenuItem({
        label: 'Bang',
        click: function(e) {
                   pdgui.pdsend(name + " dirty 1");
                   pdgui.pdsend(name + " bng 0");
        },
        key: 'b',
        modifiers: "ctrl-shift"
    }));

    putMenu.append(new nw.MenuItem({
        label: 'Toggle',
        click: function() {
                   pdgui.pdsend(name + " dirty 1");
                   pdgui.pdsend(name + " toggle 0");
        },
        key: 't',
        modifiers: "ctrl-shift"
    }));

    putMenu.append(new nw.MenuItem({
        label: 'Number2',
        click: function() {
                   pdgui.pdsend(name + " dirty 1");
                   pdgui.pdsend(name + " numbox 0");
        },
        key: 'n',
        modifiers: "ctrl-shift"
    }));

    putMenu.append(new nw.MenuItem({
        label: 'Vslider',
        click: function() {
                   pdgui.pdsend(name + " dirty 1");
                   pdgui.pdsend(name + " vslider 0");
        },
        key: 'v',
        modifiers: "ctrl-shift"
    }));

    putMenu.append(new nw.MenuItem({
        label: 'Hslider',
        click: function() {
                   pdgui.pdsend(name + " dirty 1");
                   pdgui.pdsend(name + " hslider 0");
        },
        key: 'h',
        modifiers: "ctrl-shift"
    }));

    putMenu.append(new nw.MenuItem({
        label: 'Vradio',
        click: function() {
                   pdgui.pdsend(name + " dirty 1");
                   pdgui.pdsend(name + " vradio 0");
        },
        key: 'd',
        modifiers: "ctrl"
    }));

    putMenu.append(new nw.MenuItem({
        label: 'Hradio',
        click: function() {
                   pdgui.pdsend(name + " dirty 1");
                   pdgui.pdsend(name + " hradio 0");
        },
        key: 'i',
        modifiers: "ctrl"
    }));

    putMenu.append(new nw.MenuItem({
        label: 'VU',
        click: function() {
                   pdgui.pdsend(name + " dirty 1");
                   pdgui.pdsend(name + " vumeter 0");
        },
        key: 'u',
        modifiers: "ctrl"
    }));

    putMenu.append(new nw.MenuItem({
        label: 'Canvas',
        click: function() {
                   pdgui.pdsend(name + " dirty 1");
                   pdgui.pdsend(name + " mycnv 0");
        },
        key: 'c',
        modifiers: "ctrl"
    }));

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

    putMenu.append(new nw.MenuItem({
        label: 'Graph',
        click: function() {
            pdgui.pdsend(name + " dirty 1");
            // leaving out some placement logic... see pd.tk menu_graph
            pdgui.pdsend(name + " graph NULL 0 0 0 0 30 30 0 30");
        },
        key: 'a',
        modifiers: "ctrl"
    }));

    putMenu.append(new nw.MenuItem({
        label: 'Array',
        click: menu_generic,
        key: 'a',
        modifiers: "ctrl"
    }));


    // Windows menu... call it "winman" (i.e., window management) to avoid confusion
    var winmanMenu = new nw.Menu();

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

    // Winman sub-entries
    winmanMenu.append(new nw.MenuItem({
        label: 'Next Window',
        click: menu_generic,
        key: 'c',
        modifiers: "ctrl"
    }));

    winmanMenu.append(new nw.MenuItem({
        label: 'Previous Window',
        click: menu_generic,
        key: 'a',
        modifiers: "ctrl"
    }));

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

    winmanMenu.append(new nw.MenuItem({
        label: 'Parent Window',
        click: menu_generic,
        key: 'a',
        modifiers: "ctrl"
    }));

    winmanMenu.append(new nw.MenuItem({
        label: 'Pd & Console',
        click: menu_generic,
        key: 'a',
        modifiers: "ctrl"
    }));

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

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

    // Media sub-entries
    mediaMenu.append(new nw.MenuItem({
        label: 'Audio On',
        click: menu_generic,
        key: 'c',
        modifiers: "ctrl"
    }));

    mediaMenu.append(new nw.MenuItem({
        label: 'Audio Off',
        click: menu_generic,
        key: 'a',
        modifiers: "ctrl"
    }));

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

    mediaMenu.append(new nw.MenuItem({
        label: 'Test Audio and Midi',
        click: menu_generic,
        key: 'a',
        modifiers: "ctrl"
    }));

    mediaMenu.append(new nw.MenuItem({
        label: 'Load Meter',
        click: menu_generic,
        key: 'a',
        modifiers: "ctrl"
    }));

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

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

    // Help sub-entries
    helpMenu.append(new nw.MenuItem({
        label: 'About Pd-L2ork',
        click: menu_generic,
        key: 'c',
        modifiers: "ctrl"
    }));

    helpMenu.append(new nw.MenuItem({
        label: 'Manual',
        click: menu_generic,
        key: 'a',
        modifiers: "ctrl"
    }));

    helpMenu.append(new nw.MenuItem({
        label: 'Help Browser',
        click: menu_generic,
        key: 'a',
        modifiers: "ctrl"
    }));

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

    helpMenu.append(new nw.MenuItem({
        label: 'Pd-L2ork Mailing List',
        click: menu_generic,
        key: 'a',
        modifiers: "ctrl"
    }));

    helpMenu.append(new nw.MenuItem({
        label: 'Pure Data Mailing Lists',
        click: menu_generic,
        key: 'a',
        modifiers: "ctrl"
    }));

    helpMenu.append(new nw.MenuItem({
        label: 'Forums',
        click: menu_generic,
        key: 'a',
        modifiers: "ctrl"
    }));

    helpMenu.append(new nw.MenuItem({
        label: 'IRC Chat',
        click: menu_generic,
        key: 'a',
        modifiers: "ctrl"
    }));

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

}



/*
function nw_create_canvas_window_menus(name) {
	// Window menu
	var windowMenu = new nw.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: 'File',
	    submenu: fileMenu
	}));

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

	fileMenu.append(new nw.MenuItem({
	    label: 'Open',
	    key: 'o',
	    modifiers: "ctrl",
	    click: function (){
		var chooser = document.querySelector('#fileDialog');
		chooser.click();
		chooser.addEventListener("change", function(evt) {
		    menu_open(this.value);
		    console.log("tried to open something");
		}, false);
	    }
	}));

	if (pdgui.k12_mode == 1) {
	    fileMenu.append(new nw.MenuItem({
		label: 'K12 Demos',
		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: 'Save',
	    click: function (){
		pdgui.menu_save(name);
	    },
	    key: 's',
	    modifiers: "ctrl"
	}));

	fileMenu.append(new nw.MenuItem({
	    label: 'Save as...',
	    click: function (){
		pdgui.menu_saveas(name);
	    },
	    key: 'S',
	    modifiers: "ctrl"
	}));

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

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

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