Merge branch 'master' into bug-4403-remove-polyfill
[maxima.git] / interfaces / xmaxima / Tkmaxima / Menu.tcl
blobad210a9c1e8483ab33636b34da5e1b9019df9e26
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: "2024-03-26 17:08:40 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 fileType {type} {
23 switch -exact -- $type output {
24 return [list {"Output Files" .out} {"All Files" *}]
25 } lisp {
26 return [list {"Lisp Files" {.lisp}} {"All Files" *}]
27 } maxima {
28 return [list {"Maxima Files" {.mac .mc .dem}} {"All Files" *}]
29 } all - default {
30 return [list {"All Files" *}]}}
32 proc getOpenFile {title {type "all"}} {
33 global maxima_default
34 set types [fileType $type]
35 set file $maxima_default(OpenFile)
36 if {$file ne ""} {set dir [file dir $file]} {set dir ""}
37 set proc tk_getOpenFile
38 set list [list $proc -title $title -filetypes $types]
39 if {$dir ne ""} {lappend list -initialdir [file native $dir]}
40 if {[catch {eval $list} retval]} {
41 global errorInfo
42 tk_messageBox -title Error -icon error -message \
43 [mc "Error opening file:\n%s" $errorInfo]
44 return ""}
45 if {$retval ne ""} { set maxima_default(OpenFile) $retval }
46 return $retval}
48 proc getSaveFile {title {type "all"}} {
49 global maxima_default
50 set types [fileType $type]
51 set file $maxima_default(SaveFile)
52 if {$file ne ""} {set dir [file dir $file]} {set dir ""}
53 set proc tk_getSaveFile
54 set list [list $proc -title $title -filetypes $types]
55 if {$dir ne ""} {lappend list -initialdir [file native $dir]}
56 if {[catch {eval $list} retval]} {
57 global errorInfo
58 tk_messageBox -title Error -icon error -message \
59 [mc "Error saving file:\n%s" $errorInfo]
60 return ""}
61 if {$retval ne ""} { set maxima_default(SaveFile) $retval }
62 return $retval}
64 proc cIDECreateEvent {text label code} {
65 set z [winfo toplevel $text]
66 set event "<<[join $label -]>>"
67 bind $text $event $code
68 return [list event generate $text $event]
71 proc pMAXSaveTexToFile {text} {
72 set file [getSaveFile [mc "Save to a file"] output]
73 if {$file != ""} {
74 set contents [$text get 1.0 end]
75 set fd [open $file w]
76 if {[catch {puts $fd $contents} err]} {
77 tk_messageBox -title Error -icon error -message \
78 [mc "Error writing to file:\n%s" $err]
80 catch {close $fd}
84 proc vMAXAddBrowserMenu {win} {
85 global maxima_priv maxima_default
86 global tcl_platform env
88 if {[winfo exists .browser.menu]} {destroy .browser.menu}
89 set bm .browser.menu
90 menu $bm
91 .browser configure -menu .browser.menu
92 foreach m {file edit options help} {
93 $bm add cascade -label [string totitle $m] -underline 0 \
94 -menu [menu $bm.$m -tearoff 0]
96 $bm.file add command -label [mc Reload] -underline 0 \
97 -command "OpenMathOpenUrl \[oget \[omPanel $win\] location\] -reload 1 \
98 -commandpanel \[omPanel $win\]"
99 $bm.file add command -label [mc Interrupt] -underline 0 \
100 -command "omDoInterrupt \[oget \[omPanel $win\] textwin\]"
101 $bm.file add command -label [mc Abort] -underline 0 \
102 -command "omDoAbort \[oget \[omPanel $win\] textwin\]"
103 $bm.file add command -label [mc Stop] -underline 1 \
104 -command "omDoStop \[oget \[omPanel $win\] textwin\]"
105 $bm.file add command -label [mc Forget] -underline 0 \
106 -command "forgetCurrent \[omPanel $win\]"
107 $bm.file add command -label [mc Save] -underline 0\
108 -command "pMAXSaveTexToFile \[oget \[omPanel $win\] textwin\]"
109 $bm.file add separator
110 $bm.file add command -label [mc {Close}] -underline 0 \
111 -command "destroy $win"
112 $bm.options add command -label [mc {Fonts}] -underline 0 \
113 -command {fontDialog .fontdialog}
116 proc vMAXAddSystemMenu {fr text} {
117 global maxima_priv maxima_default
118 global tcl_platform env
119 set win $fr.textcommands
121 # Build a menubar
122 if {[winfo exists .menu]} {destroy .menu}
123 menu .menu
124 . configure -menu .menu
126 # Add a File menu
127 set m [menu .menu.file -tearoff 0]
128 .menu add cascade -label [mc "File"] -menu $m -underline 0
129 $m add command -underline 0 \
130 -accel {Alt+b} \
131 -label [set label [mc "Batch File"]] \
132 -command [set command [cIDECreateEvent $text $label {
133 set file [getOpenFile [mc "Open a file to Batch"] maxima]
134 if {$file != ""} {
135 sendMaxima $maxima_priv(cConsoleText) "batch(\"$file\")\$\n"
136 maxStatus [concat [mc "Batched File "] "$file"]
139 bind $text <Alt-Key-b> $command
140 $m add command -underline 11 \
141 -accel {Alt+o} \
142 -label [set label [mc "Batch File Silently"]] \
143 -command [set command [cIDECreateEvent $text $label {
144 set file [getOpenFile [mc "Open a file to Batch Silently"] maxima]
145 if {$file != ""} {
146 sendMaxima $maxima_priv(cConsoleText) "batchload(\"$file\")\$\n"
147 maxStatus [concat [mc "Batched File "] "$file"]
150 bind $text <Alt-Key-o> $command
152 $m add command -underline 11 \
153 -accel {Alt+i} \
154 -label [set label [mc "Restore Maxima State"]] \
155 -command [set command [cIDECreateEvent $text $label {
156 set file [getOpenFile [mc "Open a file to Restore State"] lisp]
157 if {$file != ""} {
158 sendMaxima $maxima_priv(cConsoleText) ":lisp-quiet (prog2 (mfuncall '\$load \"$file\") nil)\n"
159 maxStatus [concat [mc "Maxima State Restored from "] "$file"]
162 bind $text <Alt-Key-i> $command
164 $m add separator
165 $m add command -underline 0 \
166 -label [set label [mc "Save Maxima State to File"]] \
167 -accel {Ctrl+s} \
168 -command [set command [cIDECreateEvent $text $label {
169 set file [getSaveFile [mc "Save to a file"] lisp]
170 if {$file != ""} {
171 sendMaxima $maxima_priv(cConsoleText) ":lisp-quiet (prog2 (mfuncall '\$save \"$file\" '\$all) nil)\n"
172 maxStatus [concat [mc "Maxima State Saved to "] "$file"]
175 bind $text <Control-Key-s> $command
177 $m add command -underline 1 \
178 -label [set label [mc "Save Maxima Input to File"]] \
179 -accel {Ctrl+a} \
180 -command [set command [cIDECreateEvent $text $label {
181 set file [getSaveFile [mc "Save to a file"] maxima]
182 if {$file != ""} {
183 sendMaxima $maxima_priv(cConsoleText) ":lisp-quiet (prog2 (mfuncall '\$stringout \"$file\" '\$input) nil)\n"
184 maxStatus [concat [mc "Maxima Input Saved to "] "$file"]
187 bind $text <Control-Key-a> $command
188 $m add sep
189 $m add command -underline 0 \
190 -label [mc "Interrupt"] \
191 -accel {Ctrl+g} \
192 -command [list event generate $text <Control-Key-g>]
193 $m add command -underline 0 \
194 -label [mc "Restart"] \
195 -command [list runOneMaxima $text]
196 $m add command -underline 0 \
197 -label [mc "Input prompt"] \
198 -accel {Alt+s} \
199 -command [list event generate $text <Alt-Key-s>]
201 $m add separator
202 $m add command -underline 1 -label [mc "Exit"] \
203 -command [list maxExit $text]
205 # Add an Edit menubutton
206 set m [menu .menu.edit -tearoff 0]
207 .menu add cascade -label [mc "Edit"] -menu $m -underline 0
208 $m add command -underline 2 \
209 -label [mc "Cut"] \
210 -accel {Ctrl+x} \
211 -command [list event generate $text <Control-Key-x>]
212 $m add command -underline 0 \
213 -label [mc "Copy"] \
214 -accel {Ctrl+c} \
215 -command [list event generate $text <Control-Key-c>]
216 $m add command -underline 0 \
217 -label [mc "Paste"] \
218 -accel {Ctrl+v} \
219 -command [list event generate $text <Control-Key-v>]
220 #mike distinguish from Cut/Copy/Past and Kill/Yank
221 $m add separator
222 $m add command -underline 0 \
223 -label [mc "Kill"] \
224 -accel {Ctrl+k} \
225 -command [list event generate $text <Control-Key-k>]
226 $m add command -underline 0 \
227 -label [mc "Yank"] \
228 -accel {Ctrl+y} \
229 -command [list event generate $text <Control-Key-y>]
230 $m add separator
231 #mike FIXME: use event generate
232 $m add command -underline 0 \
233 -label [mc "Previous Input"] \
234 -accel {Alt-p} \
235 -command [list CNpreviousInput $text -1]
236 $m add command -underline 0 \
237 -label [mc "Next Input"] \
238 -accel {Alt-n} \
239 -command [list CNpreviousInput $text 1]
240 $m add command -underline 9 -label [mc "Clear input"] \
241 -accel {Ctrl+u} \
242 -command [list CNclearinput $text]
243 $m add separator
244 $m add command -underline 0 -label [mc "Save Console to File"] \
245 -command [list pMAXSaveTexToFile $maxima_priv(cConsoleText)]
247 # Add an Options menubutton
248 set m [menu .menu.options -tearoff 0]
249 .menu add cascade -label [mc "Options"] -menu $m -underline 0
250 $m add separator
251 $m add command -label [mc "Open the Browser"] \
252 -command [list createBrowser .browser]
253 set pm [menu $m.plot]
254 $m add cascade -label [mc "Plot Windows"] -menu $pm
255 foreach elt { embedded separate multiple } {
256 $pm add radio -label [mc [string totit $elt]] \
257 -variable maxima_default(plotwindow) \
258 -value $elt -command [list SetPlotFormat $text ]
260 # $m add separator
261 # $m add command -underline 0 \
262 # -label [mc "Preferences"] \
263 # -command {fontDialog .preferences}
264 if {[info commands console] == "console" } {
265 $m add sep
266 $m add command -underline 0 -label [mc "Show Tcl Console"] \
267 -command [list console show]
270 # Add a Maxima menubutton
271 set m [menu .menu.maxima -tearoff 0]
272 .menu add cascade -label "Maxima" -menu $m -underline 0
273 set km [menu $m.kill]
274 $m add cascade -label [mc "Clear Memory"] -menu $km
275 $km add command -label [mc "Kill All"] \
276 -command [list sendMaxima $text "kill(all)\$\n"]
277 $km add separator
278 foreach elt {labels values functions macros arrays \
279 myoptions props aliases rules gradefs \
280 dependencies let_rule_packages} {
281 $km add command -label [mc [string totit $elt]] \
282 -command [list sendMaxima $text "kill($elt)\$\n"]
284 $m add separator
285 set dir $maxima_priv(pTestsDir)
286 if {[file isdir $dir]} {
287 set state normal
288 } else {
289 set state disabled
291 $m add command -underline 0 \
292 -state $state \
293 -label [mc "Run Tests"] \
294 -command [list sendMaxima $text "run_testsuite()\$\n"]
295 $m add command -underline 0 \
296 -state $state \
297 -label [mc "About Maxima"] \
298 -command [list sendMaxima $text "build_info();\n"]
300 # Add a Help menubutton
301 set m [menu .menu.help -tearoff 0]
302 .menu add cascade -label [mc "Help"] -menu $m -underline 0
304 # Xmaxima manual
305 set xmaximahelpfile [file join $maxima_priv(maxima_verpkgdatadir) xmaxima html index.html]
306 set xmaximahelpfile [file normalize $xmaximahelpfile]
307 if {[file isfile $xmaximahelpfile]} {
308 set xstate normal
309 } else {
310 set xstate disabled
312 # Maxima manual
313 set file $maxima_priv(pReferenceToc)
314 if {[file isfile $file]} {
315 set state normal
316 if {$tcl_platform(platform) == "windows"} {
317 # decodeURL is broken and needs fixing
318 # This is a workaround
319 set file [file attrib $file -shortname]
321 } else {
322 set state disabled
324 if {$tcl_platform(platform) == "windows"} {
325 if {[string match *maxima.chm* $file]} {
326 $m add command -underline 1 -label [mc "Maxima Manual"] \
327 -state $state \
328 -command [list exec hh.exe $file & ]
329 } else {
330 $m add command -underline 1 -label [mc "Maxima Manual (xmaxima browser)"] \
331 -state $state \
332 -command "OpenMathOpenUrl \"file:/$file\""
334 $m add command -underline 4 -label [mc "Xmaxima Manual (xmaxima browser)"] \
335 -state $xstate \
336 -command "OpenMathOpenUrl \"file:/$xmaximahelpfile\""
337 } else {
338 $m add command -underline 1 -label [mc "Maxima Manual (xmaxima browser)"] \
339 -state $state \
340 -command "OpenMathOpenUrl \"file:/$file\""
341 $m add command -underline 4 -label [mc "Xmaxima Manual (xmaxima browser)"] \
342 -state $xstate \
343 -command "OpenMathOpenUrl \"file:/$xmaximahelpfile\""
345 set browse {exec}
347 # FIXME: get a browser object
348 if {$tcl_platform(platform) == "windows"} {
349 if {$tcl_platform(os) == "Windows 95"} {
350 # Windows 95/98/ME
351 lappend browse start
352 } else {
353 # Windows NT / 2000
354 lappend browse cmd.exe /c start
356 } else {
357 set selectedbrowser xdg-open
358 foreach b { xdg-open htmlview firefox chromium-browser google-chrome konqueror epiphany galeon amaya opera } {
359 if { ! [catch {exec which $b} ] } {
360 set selectedbrowser $b
361 break
364 lappend browse $selectedbrowser
366 $m add separator
367 if {$tcl_platform(platform) != "windows"} {
368 $m add command -underline 0 -label [mc "Maxima Manual (web browser)"] \
369 -command [list eval $browse "file://$file" &]
371 $m add command -underline 0 -label [mc "Xmaxima Manual (web browser)"] \
372 -command [list eval $browse "file://$xmaximahelpfile" &]
373 $m add separator
374 $m add command -underline 7 -label [mc "Maxima Homepage"] \
375 -command [list eval $browse http://maxima.sourceforge.net &]
376 $m add command -underline 0 -label [mc "Project Page"] \
377 -command [list eval $browse https://sourceforge.net/projects/maxima/ &]
378 $m add command -underline 0 -label [mc "Bug Reports"] \
379 -command [list eval $browse https://sourceforge.net/p/maxima/bugs/ &]
380 rename vMAXAddSystemMenu ""
381 # vMAXSystemMenuHandlers $text $event
382 # Backwards compatibility
383 return $win
386 proc vMAXAddSystemBar {} {
387 set tb [frame .toolbar -borderwidth 1]
388 pack $tb -side top -fill x
389 button $tb.zoomin -image ::img::zoom-in -text [mc "Zoom in"] \
390 -command "zoomConsole 1" -relief flat -width 30 -height 30
391 button $tb.zoomout -image ::img::zoom-out -text [mc "Zoom out"] \
392 -command "zoomConsole -1" -relief flat -width 30 -height 30
393 pack $tb.zoomin $tb.zoomout -side left
396 proc SetPlotFormat { text } {
397 global maxima_default
398 if { $maxima_default(plotwindow) == "embedded" } {
399 sendMaxima $text ":lisp-quiet (prog2 (\$set_plot_option '((mlist simp) \$plot_format \$xmaxima)) nil) \n"