1 ############################################################
3 # Copyright (C) 1998 William F. Schelter #
4 # For distribution under GNU public License. See COPYING. #
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" *}]
26 return [list {"Lisp Files" {.lisp
}} {"All Files" *}]
28 return [list {"Maxima Files" {.mac .mc .dem
}} {"All Files" *}]
30 return [list {"All Files" *}]}}
32 proc getOpenFile
{title
{type
"all"}} {
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
]} {
42 tk_messageBox -title Error
-icon error -message \
43 [mc
"Error opening file:\n%s" $errorInfo]
45 if {$retval ne
""} { set maxima_default
(OpenFile
) $retval }
48 proc getSaveFile
{title
{type
"all"}} {
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
]} {
58 tk_messageBox -title Error
-icon error -message \
59 [mc
"Error saving file:\n%s" $errorInfo]
61 if {$retval ne
""} { set maxima_default
(SaveFile
) $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
]
74 set contents
[$text get
1.0 end
]
76 if {[catch {puts $fd $contents} err
]} {
77 tk_messageBox -title Error
-icon error -message \
78 [mc
"Error writing to file:\n%s" $err]
84 proc vMAXAddBrowserMenu
{win
} {
85 global maxima_priv maxima_default
86 global tcl_platform env
88 if {[winfo exists .browser.
menu]} {destroy .browser.
menu}
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
122 if {[winfo exists .
menu]} {destroy .
menu}
124 . configure
-menu .
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 \
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
]
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 \
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
]
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 \
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
]
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
165 $m add command
-underline 0 \
166 -label [set label [mc
"Save Maxima State to File"]] \
168 -command [set command
[cIDECreateEvent
$text $label {
169 set file [getSaveFile
[mc
"Save to a file"] lisp
]
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"]] \
180 -command [set command
[cIDECreateEvent
$text $label {
181 set file [getSaveFile
[mc
"Save to a file"] maxima
]
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
189 $m add command
-underline 0 \
190 -label [mc
"Interrupt"] \
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"] \
199 -command [list event generate
$text <Alt-Key-s
>]
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 \
211 -command [list event generate
$text <Control-Key-x
>]
212 $m add command
-underline 0 \
215 -command [list event generate
$text <Control-Key-c
>]
216 $m add command
-underline 0 \
217 -label [mc
"Paste"] \
219 -command [list event generate
$text <Control-Key-v
>]
220 #mike distinguish from Cut/Copy/Past and Kill/Yank
222 $m add command
-underline 0 \
225 -command [list event generate
$text <Control-Key-k
>]
226 $m add command
-underline 0 \
229 -command [list event generate
$text <Control-Key-y
>]
231 #mike FIXME: use event generate
232 $m add command
-underline 0 \
233 -label [mc
"Previous Input"] \
235 -command [list CNpreviousInput
$text -1]
236 $m add command
-underline 0 \
237 -label [mc
"Next Input"] \
239 -command [list CNpreviousInput
$text 1]
240 $m add command
-underline 9 -label [mc
"Clear input"] \
242 -command [list CNclearinput
$text]
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
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 ]
261 # $m add command -underline 0 \
262 # -label [mc "Preferences"] \
263 # -command {fontDialog .preferences}
264 if {[info commands
console] == "console" } {
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"]
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"]
285 set dir
$maxima_priv(pTestsDir
)
286 if {[file isdir
$dir]} {
291 $m add command
-underline 0 \
293 -label [mc
"Run Tests"] \
294 -command [list sendMaxima
$text "run_testsuite()\$\n"]
295 $m add command
-underline 0 \
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
305 set xmaximahelpfile
[file join $maxima_priv(maxima_verpkgdatadir
) xmaxima html index.html
]
306 set xmaximahelpfile
[file normalize
$xmaximahelpfile]
307 if {[file isfile
$xmaximahelpfile]} {
313 set file $maxima_priv(pReferenceToc
)
314 if {[file isfile
$file]} {
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]
324 if {$tcl_platform(platform
) == "windows"} {
325 if {[string match
*maxima.chm
* $file]} {
326 $m add command
-underline 1 -label [mc
"Maxima Manual"] \
328 -command [list exec hh.exe
$file & ]
330 $m add command
-underline 1 -label [mc
"Maxima Manual (xmaxima browser)"] \
332 -command "OpenMathOpenUrl \"file:/$file\""
334 $m add command
-underline 4 -label [mc
"Xmaxima Manual (xmaxima browser)"] \
336 -command "OpenMathOpenUrl \"file:/$xmaximahelpfile\""
338 $m add command
-underline 1 -label [mc
"Maxima Manual (xmaxima browser)"] \
340 -command "OpenMathOpenUrl \"file:/$file\""
341 $m add command
-underline 4 -label [mc
"Xmaxima Manual (xmaxima browser)"] \
343 -command "OpenMathOpenUrl \"file:/$xmaximahelpfile\""
347 # FIXME: get a browser object
348 if {$tcl_platform(platform
) == "windows"} {
349 if {$tcl_platform(os
) == "Windows 95"} {
354 lappend browse cmd.exe
/c start
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
364 lappend browse
$selectedbrowser
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" &]
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
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"