Support RETURN-FROM in DEF%TR forms
[maxima.git] / interfaces / xmaxima / Tkmaxima / Menu.tcl
blob6e0bdb86ccd9c6cbbe92df7c3c14d172ddc6f5f7
1 ############################################################
2 # Menu.tcl #
3 # Copyright (C) 1998 William F. Schelter #
4 # For distribution under GNU public License. See COPYING. #
5 # #
6 # Modified by Jaime E. Villate #
7 # Time-stamp: "2021-04-04 12:05:13 villate" #
8 ############################################################
10 proc zoomConsole {f} {
11 global maxima_default maxima_priv
12 set ffamily [lindex $maxima_default(ConsoleFont) 0]
13 set fsize [lindex $maxima_default(ConsoleFont) 1]
14 set fsize [expr round($fsize*pow(1.2,$f))]
15 font configure ConsoleFont -family $ffamily -size $fsize
16 set text $maxima_priv(cConsoleText)
17 resizeSubPlotWindows $text [winfo width $text] [winfo height $text]
18 resizeMaxima $text [winfo width $text] [winfo height $text]
19 set maxima_default(ConsoleFont) [list $ffamily $fsize]
22 proc pMAXSaveTexToFile {text} {
23 set file [tide_savefile [M [mc "Save to a file"]] "" *.out]
24 if {$file != ""} {
25 set contents [$text get 1.0 end]
26 set fd [open $file w]
27 if {[catch {puts $fd $contents} err]} {
28 tide_failure [M [mc "Error writing to file:\n%s"] $err]
30 catch {close $fd}
34 proc vMAXAddBrowserMenu {win} {
35 global maxima_priv maxima_default
36 global tcl_platform env
38 if {[winfo exists .browser.menu]} {destroy .browser.menu}
39 set bm .browser.menu
40 menu $bm
41 .browser configure -menu .browser.menu
42 foreach m {file edit options help} {
43 $bm add cascade -label [string totitle $m] -underline 0 \
44 -menu [menu $bm.$m -tearoff 0]
46 $bm.file add command -label [mc Reload] -underline 0 \
47 -command "OpenMathOpenUrl \[oget \[omPanel $win\] location\] -reload 1 \
48 -commandpanel \[omPanel $win\]"
49 $bm.file add command -label [mc Interrupt] -underline 0 \
50 -command "omDoInterrupt \[oget \[omPanel $win\] textwin\]"
51 $bm.file add command -label [mc Abort] -underline 0 \
52 -command "omDoAbort \[oget \[omPanel $win\] textwin\]"
53 $bm.file add command -label [mc Stop] -underline 1 \
54 -command "omDoStop \[oget \[omPanel $win\] textwin\]"
55 $bm.file add command -label [mc Forget] -underline 0 \
56 -command "forgetCurrent \[omPanel $win\]"
57 $bm.file add command -label [mc Save] -underline 0\
58 -command "pMAXSaveTexToFile \[oget \[omPanel $win\] textwin\]"
59 $bm.file add separator
60 $bm.file add command -label [mc {Close}] -underline 0 \
61 -command "destroy $win"
62 $bm.options add command -label [mc {Fonts}] -underline 0 \
63 -command {fontDialog .fontdialog}
66 proc vMAXAddSystemMenu {fr text} {
67 global maxima_priv maxima_default
68 global tcl_platform env
69 set win $fr.textcommands
71 # Build a menubar
72 if {[winfo exists .menu]} {destroy .menu}
73 menu .menu
74 . configure -menu .menu
76 # Add a File menu
77 set m [menu .menu.file -tearoff 0]
78 .menu add cascade -label [mc "File"] -menu $m -underline 0
79 $m add command -underline 0 \
80 -accel {Alt+b} \
81 -label [set label [M [mc "Batch File"]]] \
82 -command [set command [cIDECreateEvent $text $label {
83 set file [tide_openfile [M [mc "Open a file to Batch"]] "" *.mac]
84 if {$file != ""} {
85 sendMaxima $maxima_priv(cConsoleText) "batch(\"$file\")\$\n"
86 gui status [concat [mc "Batched File "] "$file"]
88 }]]
89 bind $text <Alt-Key-b> $command
90 $m add command -underline 11 \
91 -accel {Alt+o} \
92 -label [set label [M [mc "Batch File Silently"]]] \
93 -command [set command [cIDECreateEvent $text $label {
94 set file [tide_openfile [M [mc "Open a file to Batch Silently"]] "" *.mac]
95 if {$file != ""} {
96 sendMaxima $maxima_priv(cConsoleText) "batchload(\"$file\")\$\n"
97 gui status [concat [mc "Batched File "] "$file"]
99 }]]
100 bind $text <Alt-Key-o> $command
102 $m add command -underline 11 \
103 -accel {Alt+i} \
104 -label [set label [M [mc "Restore Maxima State"]]] \
105 -command [set command [cIDECreateEvent $text $label {
106 set file [tide_openfile [M [mc "Open a file to Restore State"]] "" *.lisp]
107 if {$file != ""} {
108 sendMaxima $maxima_priv(cConsoleText) ":lisp-quiet (prog2 (mfuncall '\$load \"$file\") nil)\n"
109 gui status [concat [mc "Maxima State Restored from "] "$file"]
112 bind $text <Alt-Key-i> $command
114 $m add separator
115 $m add command -underline 0 \
116 -label [set label [mc "Save Maxima State to File"]] \
117 -accel {Ctrl+s} \
118 -command [set command [cIDECreateEvent $text $label {
119 set file [tide_savefile [M [mc "Save to a file"]] "" *.lisp]
120 if {$file != ""} {
121 sendMaxima $maxima_priv(cConsoleText) ":lisp-quiet (prog2 (mfuncall '\$save \"$file\" '\$all) nil)\n"
122 gui status [concat [mc "Maxima State Saved to "] "$file"]
125 bind $text <Control-Key-s> $command
127 $m add command -underline 1 \
128 -label [set label [mc "Save Maxima Input to File"]] \
129 -accel {Ctrl+a} \
130 -command [set command [cIDECreateEvent $text $label {
131 set file [tide_savefile [M [mc "Save to a file"]] "" *.mac]
132 if {$file != ""} {
133 sendMaxima $maxima_priv(cConsoleText) ":lisp-quiet (prog2 (mfuncall '\$stringout \"$file\" '\$input) nil)\n"
134 gui status [concat [mc "Maxima Input Saved to "] "$file"]
137 bind $text <Control-Key-a> $command
138 $m add sep
139 $m add command -underline 0 \
140 -label [mc "Interrupt"] \
141 -accel {Ctrl+g} \
142 -command [list event generate $text <Control-Key-g>]
143 $m add command -underline 0 \
144 -label [mc "Restart"] \
145 -command [list runOneMaxima $text]
146 $m add command -underline 0 \
147 -label [mc "Input prompt"] \
148 -accel {Alt+s} \
149 -command [list event generate $text <Alt-Key-s>]
151 $m add separator
152 $m add command -underline 1 \
153 -label [mc "Exit"] \
154 -command [list tkmaxima exit $text]
156 # Add an Edit menubutton
157 set m [menu .menu.edit -tearoff 0]
158 .menu add cascade -label [mc "Edit"] -menu $m -underline 0
159 $m add command -underline 2 \
160 -label [mc "Cut"] \
161 -accel {Ctrl+x} \
162 -command [list event generate $text <Control-Key-x>]
163 $m add command -underline 0 \
164 -label [mc "Copy"] \
165 -accel {Ctrl+c} \
166 -command [list event generate $text <Control-Key-c>]
167 $m add command -underline 0 \
168 -label [mc "Paste"] \
169 -accel {Ctrl+v} \
170 -command [list event generate $text <Control-Key-v>]
171 #mike distinguish from Cut/Copy/Past and Kill/Yank
172 $m add separator
173 $m add command -underline 0 \
174 -label [mc "Kill"] \
175 -accel {Ctrl+k} \
176 -command [list event generate $text <Control-Key-k>]
177 $m add command -underline 0 \
178 -label [mc "Yank"] \
179 -accel {Ctrl+y} \
180 -command [list event generate $text <Control-Key-y>]
181 $m add separator
182 #mike FIXME: use event generate
183 $m add command -underline 0 \
184 -label [mc "Previous Input"] \
185 -accel {Alt-p} \
186 -command [list CNpreviousInput $text -1]
187 $m add command -underline 0 \
188 -label [mc "Next Input"] \
189 -accel {Alt-n} \
190 -command [list CNpreviousInput $text 1]
191 $m add command -underline 9 -label [mc "Clear input"] \
192 -accel {Ctrl+u} \
193 -command [list CNclearinput $text]
194 $m add separator
195 $m add command -underline 0 -label [mc "Save Console to File"] \
196 -command [list pMAXSaveTexToFile $maxima_priv(cConsoleText)]
198 # Add a Options menubutton
199 set m [menu .menu.options -tearoff 0]
200 .menu add cascade -label [mc "Options"] -menu $m -underline 0
201 $m add separator
202 set pm [menu $m.plot]
203 $m add cascade -label [mc "Plot Windows"] -menu $pm
204 foreach elt { embedded separate multiple } {
205 $pm add radio -label [mc [string totit $elt]] \
206 -variable maxima_default(plotwindow) \
207 -value $elt -command [list SetPlotFormat $text ]
209 # $m add separator
210 # $m add command -underline 0 \
211 # -label [mc "Preferences"] \
212 # -command {fontDialog .preferences}
213 if {[info commands console] == "console" } {
214 $m add sep
215 $m add command -underline 0 -label [mc "Show Tcl Console"] \
216 -command [list console show]
219 # Add a Maxima menubutton
220 set m [menu .menu.maxima -tearoff 0]
221 .menu add cascade -label "Maxima" -menu $m -underline 0
222 set km [menu $m.kill]
223 $m add cascade -label [mc "Clear Memory"] -menu $km
224 $km add command -label [mc "Kill All"] \
225 -command [list sendMaxima $text "kill(all)\$\n"]
226 $km add separator
227 foreach elt {labels values functions macros arrays \
228 myoptions props aliases rules gradefs \
229 dependencies let_rule_packages} {
230 $km add command -label [mc [string totit $elt]] \
231 -command [list sendMaxima $text "kill($elt)\$\n"]
233 $m add separator
234 set dir $maxima_priv(pTestsDir)
235 if {[file isdir $dir]} {
236 set state normal
237 } else {
238 set state disabled
240 $m add command -underline 0 \
241 -state $state \
242 -label [mc "Run Tests"] \
243 -command [list sendMaxima $text "run_testsuite()\$\n"]
244 $m add command -underline 0 \
245 -state $state \
246 -label [mc "About Maxima"] \
247 -command [list sendMaxima $text "build_info();\n"]
249 # Add a Help menubutton
250 set m [menu .menu.help -tearoff 0]
251 .menu add cascade -label [mc "Help"] -menu $m -underline 0
253 # Xmaxima manual
254 set xmaximahelpfile [file join $maxima_priv(maxima_verpkgdatadir) xmaxima html xmaxima.html]
255 set xmaximahelpfile [file normalize $xmaximahelpfile]
256 if {[file isfile $xmaximahelpfile]} {
257 set xstate normal
258 } else {
259 set xstate disabled
261 # Maxima manual
262 set file $maxima_priv(pReferenceToc)
263 if {[file isfile $file]} {
264 set state normal
265 if {$tcl_platform(platform) == "windows"} {
266 # decodeURL is broken and needs fixing
267 # This is a workaround
268 set file [file attrib $file -shortname]
270 } else {
271 set state disabled
273 if {$tcl_platform(platform) == "windows"} {
274 if {[string match *maxima.chm* $file]} {
275 $m add command -underline 1 -label [mc "Maxima Manual"] \
276 -state $state \
277 -command [list exec hh.exe $file & ]
278 } else {
279 $m add command -underline 1 -label [mc "Maxima Manual (xmaxima browser)"] \
280 -state $state \
281 -command "OpenMathOpenUrl \"file:/$file\""
283 $m add command -underline 4 -label [mc "Xmaxima Manual (xmaxima browser)"] \
284 -state $xstate \
285 -command "OpenMathOpenUrl \"file:/$xmaximahelpfile\""
286 } else {
287 $m add command -underline 1 -label [mc "Maxima Manual (xmaxima browser)"] \
288 -state $state \
289 -command "OpenMathOpenUrl \"file:/$file\""
290 $m add command -underline 4 -label [mc "Xmaxima Manual (xmaxima browser)"] \
291 -state $xstate \
292 -command "OpenMathOpenUrl \"file:/$xmaximahelpfile\""
294 set browse {exec}
296 # FIXME: get a browser object
297 if {$tcl_platform(platform) == "windows"} {
298 if {$tcl_platform(os) == "Windows 95"} {
299 # Windows 95/98/ME
300 lappend browse start
301 } else {
302 # Windows NT / 2000
303 lappend browse cmd.exe /c start
305 } else {
306 set selectedbrowser xdg-open
307 foreach b { xdg-open htmlview firefox chromium-browser google-chrome konqueror epiphany galeon amaya opera } {
308 if { ! [catch {exec which $b} ] } {
309 set selectedbrowser $b
310 break
313 lappend browse $selectedbrowser
315 $m add separator
316 if {$tcl_platform(platform) != "windows"} {
317 $m add command -underline 0 -label [mc "Maxima Manual (web browser)"] \
318 -command [list eval $browse "file://$file" &]
320 $m add command -underline 0 -label [mc "Xmaxima Manual (web browser)"] \
321 -command [list eval $browse "file://$xmaximahelpfile" &]
322 $m add separator
323 $m add command -underline 7 -label [mc "Maxima Homepage"] \
324 -command [list eval $browse http://maxima.sourceforge.net &]
325 $m add command -underline 0 -label [mc "Project Page"] \
326 -command [list eval $browse https://sourceforge.net/projects/maxima/ &]
327 $m add command -underline 0 -label [mc "Bug Reports"] \
328 -command [list eval $browse https://sourceforge.net/p/maxima/bugs/ &]
329 rename vMAXAddSystemMenu ""
330 # vMAXSystemMenuHandlers $text $event
331 # Backwards compatibility
332 return $win
335 proc vMAXAddSystemBar {} {
336 set tb [frame .toolbar -borderwidth 1]
337 pack $tb -side top -fill x
338 button $tb.zoomin -image ::img::zoom-in -text [mc "Zoom in"] \
339 -command "zoomConsole 1" -relief flat -width 30 -height 30
340 button $tb.zoomout -image ::img::zoom-out -text [mc "Zoom out"] \
341 -command "zoomConsole -1" -relief flat -width 30 -height 30
342 pack $tb.zoomin $tb.zoomout -side left
345 proc SetPlotFormat { text } {
346 global maxima_default
347 if { $maxima_default(plotwindow) == "embedded" } {
348 sendMaxima $text ":lisp-quiet (prog2 (\$set_plot_option '((mlist simp) \$plot_format \$xmaxima)) nil) \n"