aboutsummaryrefslogtreecommitdiff
path: root/pd/tcl/pd_menus.tcl
blob: f8dc24691cc8f4bab8e279b8a24ff9f983aae739 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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
214
215
216
217
218
219
220
221
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
300
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
328
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
# Copyright (c) 1997-2009 Miller Puckette.
#(c) 2008 WordTech Communications LLC. License: standard Tcl license, http://www.tcl.tk/software/tcltk/license.html

package provide pd_menus 0.1

package require pd_menucommands
package require Tk
#package require tile
## replace Tk widgets with Ttk widgets on 8.5
#namespace import -force ttk::*

# TODO figure out Undo/Redo/Cut/Copy/Paste/DSP state changes for menus
# TODO figure out parent window/window list for Window menu
# TODO what is the Tcl package constructor or init()?

    

# ------------------------------------------------------------------------------
# global variables

# TODO this should properly be inside the pd_menus namespace, now it is global
namespace import ::pd_menucommands::* 

namespace eval ::pd_menus:: {
    variable accelerator
    
    namespace export create_menubar
    namespace export configure_pdwindow

    # turn off tearoff menus globally
    option add *tearOff 0
}

# ------------------------------------------------------------------------------
# 
proc ::pd_menus::create_menubar {mymenubar mytoplevel} {
    variable accelerator
    if {$::windowingsystem eq "aqua"} {
        set accelerator "Cmd"
    } else {
        set accelerator "Ctrl"
    }
    menu $mymenubar
    set menulist "file edit put find media window help"
    if { $::windowingsystem eq "aqua" } {create_apple_menu $mymenubar}
#TODO figure out why this took my menubars out? -msp
#    if { $::windowingsystem eq "win32" } {create_system_menu $mymenubar}
    foreach mymenu $menulist {  
        menu $mymenubar.$mymenu
        $mymenubar add cascade -label [_ [string totitle $mymenu]] \
            -menu $mymenubar.$mymenu
        [format build_%s_menu $mymenu] $mymenubar.$mymenu $mytoplevel
        if {$::windowingsystem eq "win32"} {
            # fix menu font size on Windows with tk scaling = 1
            $mymenubar.$mymenu configure -font menufont
        }
    }
}

proc ::pd_menus::configure_pdwindow {mymenubar} {
    # these are meaningless for the Pd window, so disable them
    set file_items_to_disable {"Save" "Save As..." "Print..." "Close"}
    foreach menuitem $file_items_to_disable {
        $mymenubar.file entryconfigure [_ $menuitem] -state disabled
    }
    set edit_items_to_disable {"Undo" "Redo" "Duplicate" "Tidy Up" "Edit Mode"}
    foreach menuitem $edit_items_to_disable {
        $mymenubar.edit entryconfigure [_ $menuitem] -state disabled
    }
    # disable everything on the Put menu
    for {set i 0} {$i <= [$mymenubar.put index end]} {incr i} {
        # catch errors by trying to disable separators
        catch {$mymenubar.put entryconfigure $i -state disabled }
    }
}

# ------------------------------------------------------------------------------
# menu building functions
proc ::pd_menus::build_file_menu {mymenu mytoplevel} {
    [format build_file_menu_%s $::windowingsystem] $mymenu
    $mymenu entryconfigure [_ "New"]        -command "menu_new"
    $mymenu entryconfigure [_ "Open"]       -command "menu_open"
    $mymenu entryconfigure [_ "Save"]       -command "pdsend \"$mytoplevel menusave\""
    $mymenu entryconfigure [_ "Save As..."] -command "pdsend \"$mytoplevel menusaveas\""
    #   $mymenu entryconfigure "Revert*"    -command "menu_revert $mytoplevel"
    $mymenu entryconfigure [_ "Close"]      -command "pdsend \"$mytoplevel menuclose 0\""
    $mymenu entryconfigure [_ "Message"]    -command "menu_message_panel"
    $mymenu entryconfigure [_ "Print..."]   -command "menu_print $mytoplevel"
}

proc ::pd_menus::build_edit_menu {mymenu mytoplevel} {
    variable accelerator
    $mymenu add command -label [_ "Undo"]       -accelerator "$accelerator+Z" \
        -command "menu_undo $mytoplevel"
    $mymenu add command -label [_ "Redo"]       -accelerator "Shift+$accelerator+Z" \
        -command "menu_redo $mytoplevel"
    $mymenu add  separator
    $mymenu add command -label [_ "Cut"]        -accelerator "$accelerator+X" \
        -command "pdsend \"$mytoplevel cut\""
    $mymenu add command -label [_ "Copy"]       -accelerator "$accelerator+C" \
        -command "pdsend \"$mytoplevel copy\""
    $mymenu add command -label [_ "Paste"]      -accelerator "$accelerator+V" \
        -command "pdsend \"$mytoplevel paste\""
    $mymenu add command -label [_ "Duplicate"]  -accelerator "$accelerator+D" \
        -command "pdsend \"$mytoplevel duplicate\""
    $mymenu add command -label [_ "Select All"] -accelerator "$accelerator+A" \
        -command "pdsend \"$mytoplevel selectall\""
    $mymenu add  separator
    if {$::windowingsystem eq "aqua"} {
        $mymenu add command -label [_ "Text Editor"] \
            -command "menu_texteditor $mytoplevel"
        $mymenu add command -label [_ "Font"]  -accelerator "$accelerator+T" \
            -command "menu_dialog_font $mytoplevel"
    } else {
        $mymenu add command -label [_ "Text Editor"] -accelerator "$accelerator+T"\
            -command "menu_texteditor $mytoplevel"
        $mymenu add command -label [_ "Font"] \
            -command "menu_dialog_font $mytoplevel"
    }
    $mymenu add command -label [_ "Tidy Up"] \
        -command "pdsend \"$mytoplevel tidy\""
    # $mymenu add command -label [_ "Toggle Console"] -accelerator "Shift+$accelerator+R" \
    #   -command {.controls.switches.console invoke}
    # $mymenu add command -label [_ "Clear Console"] -accelerator "Shift+$accelerator+L" \
    #   -command "menu_clear_console"
    $mymenu add  separator
    $mymenu add radiobutton -label [_ "Edit Mode"] -accelerator "$accelerator+E" \
        -indicatoron true -selectcolor grey85 \
        -command "pdsend \"$mytoplevel editmode 0\""
    #    if { $editable == 0 } {
    #        $mymenu entryconfigure "Edit Mode" -indicatoron false 
    #    }

    #if { ! [catch {console hide}]} { 
    # TODO set up menu item to show/hide the Tcl/Tk console, if it available
    #}

    if {$::windowingsystem ne "aqua"} {
        $mymenu add  separator
        $mymenu add command -label [_ "Path..."] \
            -command "menu_path_panel"
        $mymenu add command -label [_ "Startup..."] \
            -command "menu_startup_panel"
    }
}

proc ::pd_menus::build_put_menu {mymenu mytoplevel} {
    variable accelerator
    $mymenu add command -label [_ "Object"] -accelerator "$accelerator+1" \
        -command "pdsend \"$mytoplevel obj 0\"" 
    $mymenu add command -label [_ "Message"] -accelerator "$accelerator+2" \
        -command "pdsend \"$mytoplevel msg 0\""
    $mymenu add command -label [_ "Number"] -accelerator "$accelerator+3" \
        -command "pdsend \"$mytoplevel floatatom  0\""
    $mymenu add command -label [_ "Symbol"] -accelerator "$accelerator+4" \
        -command "pdsend \"$mytoplevel symbolatom  0\""
    $mymenu add command -label [_ "Comment"] -accelerator "$accelerator+5" \
        -command "pdsend \"$mytoplevel text  0\""
    $mymenu add  separator
    $mymenu add command -label [_ "Bang"]    -accelerator "Shift+$accelerator+B" \
        -command "pdsend \"$mytoplevel bng  0\""
    $mymenu add command -label [_ "Toggle"]  -accelerator "Shift+$accelerator+T" \
        -command "pdsend \"$mytoplevel toggle  0\""
    $mymenu add command -label [_ "Number2"] -accelerator "Shift+$accelerator+N" \
        -command "pdsend \"$mytoplevel numbox  0\""
    $mymenu add command -label [_ "Vslider"] -accelerator "Shift+$accelerator+V" \
        -command "pdsend \"$mytoplevel vslider  0\""
    $mymenu add command -label [_ "Hslider"] -accelerator "Shift+$accelerator+H" \
        -command "pdsend \"$mytoplevel hslider  0\""
    $mymenu add command -label [_ "Vradio"]  -accelerator "Shift+$accelerator+D" \
        -command "pdsend \"$mytoplevel vradio  0\""
    $mymenu add command -label [_ "Hradio"]  -accelerator "Shift+$accelerator+I" \
        -command "pdsend \"$mytoplevel hradio  0\""
    $mymenu add command -label [_ "VU Meter"] -accelerator "Shift+$accelerator+U"\
        -command "pdsend \"$mytoplevel vumeter  0\""
    $mymenu add command -label [_ "Canvas"]  -accelerator "Shift+$accelerator+C" \
        -command "pdsend \"$mytoplevel mycnv  0\""
    $mymenu add  separator
    $mymenu add command -label Graph -command "pdsend \"$mytoplevel graph\"" 
    $mymenu add command -label Array -command "pdsend \"$mytoplevel menuarray\""
}

proc ::pd_menus::build_find_menu {mymenu mytoplevel} {
    variable accelerator
    $mymenu add command -label [_ "Find..."]    -accelerator "$accelerator+F" \
        -command "::dialog_find::menu_dialog_find $mytoplevel"
    $mymenu add command -label [_ "Find Again"] -accelerator "$accelerator+G" \
        -command "pdsend \"$mytoplevel findagain\""
    $mymenu add command -label [_ "Find Last Error"] \
        -command "pdsend \"$mytoplevel finderror\"" 
}

proc ::pd_menus::build_media_menu {mymenu mytoplevel} {
    variable accelerator
    $mymenu add radiobutton -label [_ "Audio ON"] -accelerator "$accelerator+/" \
        -command "pdsend \"pd dsp 1\""
    $mymenu add radiobutton -label [_ "Audio OFF"] -accelerator "$accelerator+." \
        -command "pdsend \"pd dsp 0\"" -indicatoron true 
    $mymenu add  separator    
    $mymenu add command -label [_ "Audio settings..."] \
        -command "pdsend \"pd audio-properties\"" 
    $mymenu add command -label [_ "MIDI settings..."] \
        -command "pdsend \"pd midi-properties\"" 
    $mymenu add  separator    
    $mymenu add command -label [_ "Test Audio and MIDI..."] \
        -command "menu_doc_open doc/7.stuff/tools testtone.pd" 
    $mymenu add command -label [_ "Load Meter"] \
        -command "menu_doc_open doc/7.stuff/tools load-meter.pd" 
}

proc ::pd_menus::build_window_menu {mymenu mytoplevel} {
    variable accelerator
    if {$::windowingsystem eq "aqua"} {
        $mymenu add command -label [_ "Minimize"] -command "menu_minimize ." \
            -accelerator "$accelerator+M"
        $mymenu add command -label [_ "Zoom"] -command "menu_zoom ."
        $mymenu add  separator
    }
    $mymenu add command -label [_ "Parent Window"] \
        -command "pdsend \"$mytoplevel findparent\""
    $mymenu add command -label [_ "Pd window"] -command "menu_raise_pdwindow" \
        -accelerator "$accelerator+R"
    $mymenu add  separator
    if {$::windowingsystem eq "aqua"} {
        $mymenu add command -label [_ "Bring All to Front"] \
            -command "menu_bringalltofront"
        $mymenu add  separator
    }
}

proc ::pd_menus::build_help_menu {mymenu mytoplevel} {
    if {$::windowingsystem ne "aqua"} {
        $mymenu add command -label {About Pd} \
            -command "placeholder menu_doc_open doc/1.manual 1.introduction.txt" 
    }
    $mymenu add command -label {HTML ...} \
        -command "placeholder menu_doc_open doc/1.manual index.htm"
    $mymenu add command -label {Browser ...} \
        -command "placeholder menu_helpbrowser \$help_top_directory" 
}

# ------------------------------------------------------------------------------
# menu building functions for Mac OS X/aqua

# for Mac OS X only
proc ::pd_menus::create_apple_menu {mymenu} {
    puts stderr BUILD_APPLE_MENU
    # TODO this should open a Pd patch called about.pd
    menu $mymenu.apple
    $mymenu.apple add command -label [_ "About Pd"] \
        -command "menu_doc_open doc/1.manual 1.introduction.txt" 
    $mymenu add cascade -label "Apple" -menu $mymenu.apple
    $mymenu.apple add  separator
    # starting in 8.4.14, this is created automatically
    set patchlevel [split [info patchlevel] .]
    if {[lindex $patchlevel 1] < 5 && [lindex $patchlevel 2] < 14} {
        $mymenu.apple add command -label [_ "Preferences..."] \
            -command "menu_preferences_panel" -accelerator "Cmd+,"
    }
}

proc ::pd_menus::build_file_menu_aqua {mymenu} {
    variable accelerator
    $mymenu add command -label [_ "New"]       -accelerator "$accelerator+N"
    $mymenu add command -label [_ "Open"]      -accelerator "$accelerator+O"
    $mymenu add cascade -label [_ "Open Recent"]
    $mymenu add  separator
    $mymenu add command -label [_ "Close"]     -accelerator "$accelerator+W"
    $mymenu add command -label [_ "Save"]      -accelerator "$accelerator+S"
    $mymenu add command -label [_ "Save As..."] -accelerator "$accelerator+Shift+S"
    #$mymenu add command -label [_ "Save All"]
    #$mymenu add command -label [_ "Revert to Saved"]
    $mymenu add  separator
    $mymenu add command -label [_ "Message"]
    $mymenu add  separator
    $mymenu add command -label [_ "Print..."]   -accelerator "$accelerator+P"
}

# the "Edit", "Put", and "Find" menus do not have cross-platform differences

proc ::pd_menus::build_media_menu_aqua {mymenu} {
}

proc ::pd_menus::build_window_menu_aqua {mymenu} {
}

# the "Help" does not have cross-platform differences
 
# ------------------------------------------------------------------------------
# menu building functions for UNIX/X11

proc ::pd_menus::build_file_menu_x11 {mymenu} {
    variable accelerator
    $mymenu add command -label [_ "New"]        -accelerator "$accelerator+N"
    $mymenu add command -label [_ "Open"]       -accelerator "$accelerator+O"
    $mymenu add  separator
    $mymenu add command -label [_ "Save"]       -accelerator "$accelerator+S"
    $mymenu add command -label [_ "Save As..."] -accelerator "Shift+$accelerator+S"
    #   $mymenu add command -label "Revert"
    $mymenu add  separator
    $mymenu add command -label [_ "Message"]    -accelerator "$accelerator+M"
    $mymenu add command -label [_ "Print..."]   -accelerator "$accelerator+P"
    $mymenu add  separator
    $mymenu add command -label [_ "Close"]      -accelerator "$accelerator+W"
    $mymenu add command -label [_ "Quit"]       -accelerator "$accelerator+Q" \
        -command "pdsend \"pd verifyquit\""
}

# the "Edit", "Put", and "Find" menus do not have cross-platform differences

proc ::pd_menus::build_media_menu_x11 {mymenu} {
}

proc ::pd_menus::build_window_menu_x11 {mymenu} {
}

# the "Help" does not have cross-platform differences

# ------------------------------------------------------------------------------
# menu building functions for Windows/Win32

# for Windows only
proc ::pd_menus::create_system_menu {mymenu} {
    $mymenu add cascade -menu [menu $mymenu.system]
    # TODO add Close, Minimize, etc and whatever else is on the little menu
    # that is on the top left corner of the window frame
}

proc ::pd_menus::build_file_menu_win32 {mymenu} {
    variable accelerator
    $mymenu add command -label [_ "New"]      -accelerator "$accelerator+N"
    $mymenu add command -label [_ "Open"]     -accelerator "$accelerator+O"
    $mymenu add  separator
    $mymenu add command -label [_ "Save"]      -accelerator "$accelerator+S"
    $mymenu add command -label [_ "Save As..."] -accelerator "Shift+$accelerator+S"
    #   $mymenu add command -label "Revert"
    $mymenu add  separator
    $mymenu add command -label [_ "Message"]  -accelerator "$accelerator+M"
    $mymenu add command -label [_ "Print..."] -accelerator "$accelerator+P"
    $mymenu add  separator
    $mymenu add command -label [_ "Close"]    -accelerator "$accelerator+W"
    $mymenu add command -label [_ "Quit"]     -accelerator "$accelerator+Q"\
        -command "pdsend \"pd verifyquit\""
}

# the "Edit", "Put", and "Find" menus do not have cross-platform differences

proc ::pd_menus::build_media_menu_win32 {mymenu} {
}

proc ::pd_menus::build_window_menu_win32 {mymenu} {
}

# the "Help" does not have cross-platform differences