# Auswahl- und Ausführungs-Menü für "Sonstige Programme"
#
# Copyright (C) 2000  G. Lamprecht, W. Lotz, R. Weibezahn; IWD, Bremen University

proc so  {} {

proc sosel1 {s} {# program selected
 global Wo vv sosep uttext utcmd utoptions utfreq utbackup ut_file utback ut_startdir utadir
 global main_file efile
 cd $ut_startdir
 soInit
 set uttext [concat [getvalue $s 0 $sosep]];  set utcmd [getvalue $s 1 $sosep]
 set utoptions [getvalue $s 2 $sosep];  set utfreq [getvalue $s 3 $sosep]
 global HOME; set utadir [eval concat [getvalue $s 6 $sosep]];# evaluation of $HOME,$main_file
 if {[getvalue $s 7 $sosep]==""} {set utbackup 1}
 if {$utfreq==""} {set utfreq "file"}; if {$utfreq=="nofile"} {set utbackup 0}
 if {($utcmd=="changecode")&&($utoptions=="-analyse")} {set utbackup 0}
 if {($utcmd=="xterm")&&([lindex $utoptions 0]=="-e")} {
   if {([lindex $utoptions 1]=="more")||([lindex $utoptions 1]=="pg")} {set utbackup 0}
 }
 if {[getvalue $s 7 $sosep]=="backup"} {set utbackup 1}
 if {[getvalue $s 7 $sosep]=="nobackup"} {set utbackup 0}
 progback utcmd utback;  writescr0 $Wo.d.tt "$vv(so3)  $utcmd $utback  $uttext\n"
 set ut_file ""
 if {$utfreq=="file"} {writescr $Wo.d.tt "\n*** $vv(so2)\n"; mybell 2}
 if {$utadir!=""} {writescr $Wo.d.tt "\n*** $vv(so11): $utadir\n"; mybell 2}
 if {($utadir!="")&&[catch {cd $utadir} m]!=0} \
      {writescr $Wo.d.tt "*** $vv(tvt2)\n$vv(tvt3)\n$m\n"; mybell 3; cd $ut_startdir} \
 else {writescr $Wo.d.tt "    $vv(so12)\n"}
 sosselffill [getvalue $s 5 $sosep] [getvalue $s 4 $sosep]
}

proc sosel2 {s} {# suffix selected
 global Wo vv kosuff dateiliste ut_file utcmd
 if {$utcmd==""} {writescr0 $Wo.d.tt $vv(so9); mybell 3; return}
 set kosuff $s
 writescr0 $Wo.d.tt "$vv(so4)  $kosuff"
 $Wo.c.3.f.f.li delete 0 end
 foreach ii $dateiliste \
     {if {[file isfile $ii]&&[string match "*$kosuff" $ii]} {$Wo.c.3.f.f.li insert end $ii}}
 set ut_file ""
 soanzeige
}

proc sosel3 {s} {# file selected
 global Wo vv ut_file utcmd
 if {$utcmd==""} {writescr0 $Wo.d.tt $vv(so9); mybell 3; return}
 if [file exists $s] {set ut_file $s; writescr0 $Wo.d.tt "$vv(so5) $ut_file"} \
 else {if {$s!=""} {writescr0 $Wo.d.tt "$vv(aus5) \"$s\" $vv(ea4)"};set ut_file ""}
 soanzeige
}

proc soanzeige {} {
 global vv Wo utcmd utback uttext ut_file utbackup utfreq kosuff ut_startdir utadir
 if {[string match "*$utcmd$utback*" "$uttext"]} {set c ""} else {set c "$utcmd$utback "}
 if {$ut_startdir==[pwd]} {set dt ""} else {set dt "($vv(in): $utadir)"}
 $Wo.b.ko configure -text "$vv(sobko)  $c $uttext  $dt"
 if {$utfreq=="nofile"} {set f "$vv(sobnf)"} \
 elseif {($utfreq=="optfile")&&($ut_file=="")} {set f "$vv(sobfi)  $vv(sobof)"} \
 else {set f "$vv(sobfi)  $ut_file"}
 $Wo.b.fi configure -text $f
 if {$utbackup==1} {set mo "$vv(sobba2)"} else {set mo "$vv(sobba22)"}
 $Wo.b.ba.2 configure -text "$mo"
 $Wo.c.3.f.l.t configure -text "$vv(soc21) ($kosuff)"
}

proc sosselffill {sufflist filesuff} {
 global Wo vv kosuff kosuffldef kosuffdef dateiliste
 if {($sufflist=="")||($filesuff=="")} {set l $kosuffldef; set kosuff $kosuffdef} \
	else {set l $sufflist; set kosuff $filesuff}
 $Wo.c.2.f.f.li delete 0 end;  foreach s $l {$Wo.c.2.f.f.li insert end $s}
 set dateiliste [DelWinNTFiles [lsort [glob -nocomplain -- *]]]
 $Wo.c.3.f.f.li delete 0 end;  foreach f $dateiliste \
	{if {[file isfile $f]&&[string match *$kosuff $f]} {$Wo.c.3.f.f.li insert end $f}}
 soanzeige
}

proc soExec {we wt} {
 global vv Wo utcmd utfreq ut_file ut_startdir
 if {$utcmd==""} {writescr0 $wt "***** $vv(so1)\n\n"; mybell 2} \
 elseif {($ut_file=="")&&($utfreq=="file")}  {writescr0 $wt "***** $vv(so2)\n\n"; mybell 2} \
 else {
   $we configure -state disabled; update idletasks; writescr0 $wt ""
   utility $wt austext; cd $ut_startdir
   if [winfo exists $Wo] \
   {$we configure -state normal; update idletasks; soInit; soanzeige; writescr $wt "$austext"}
 }
}

proc soWobba2 {} {
 global Wo utbackup utfreq
 if {$utbackup==0} {set utbackup 1;if {$utfreq=="nofile"} {set utbackup 0}} {set utbackup 0}
 soanzeige; writescr0 $Wo.d.tt ""
}

proc soInit {} {
 global utcmd utback uttext utoptions utfreq ut_file utbackup
 set utcmd ""; set utback ""; set uttext ""; set utoptions ""; set utfreq "file"
 set ut_file ""; set utbackup 1
}

proc soWoae {} {global Wo ut_startdir; destros $Wo; unlock_list; cd $ut_startdir}


global vv Wo dateiliste utcmd sosep kosuff kosuffl kosuffldef kosuffdef ut_startdir

toplevel_init $Wo "$vv(sovor)" 0 0;  set tyh 18;  set dir [pwd]

soInit; set ut_startdir [pwd]


# Bereich a für erste Buttons

frame $Wo.a; pack configure $Wo.a -anchor w -fill x
frame $Wo.a.b; pack configure $Wo.a.b -side right -anchor ne -pady 6 -ipadx 10

insertTopButtons $Wo.a so_h soWoae $Wo.d.tt

button $Wo.a.b.e -text "$vv(soa2e)" -command {soExec $Wo.a.b.e $Wo.d.tt}
Bind3HF $Wo.a.b.e so_exec $Wo.d.tt
pack configure $Wo.a.b.e -side left


# Bereich b für Anzeigen Einstellungen

frame $Wo.b; pack configure $Wo.b -pady 3 -anchor w

label $Wo.b.ko -width 95 -anchor w
Bind3HF $Wo.b.ko so_kommando $Wo.d.tt
label $Wo.b.fi -width 90 -anchor w
Bind3HF $Wo.b.fi so_datei $Wo.d.tt
frame $Wo.b.ba
pack configure $Wo.b.ko $Wo.b.fi $Wo.b.ba -anchor w

label  $Wo.b.ba.1 -text "$vv(sobba1)" -anchor w -padx 1
Bind3HF $Wo.b.ba.1 so_back $Wo.d.tt
button $Wo.b.ba.2 -text "$vv(sobba2)" -width 7 -command {soWobba2}
Bind3HF $Wo.b.ba.2 so_back $Wo.d.tt
label  $Wo.b.ba.3 -text "$vv(sobba3)" -anchor w
Bind3HF $Wo.b.ba.3 so_back $Wo.d.tt
pack configure $Wo.b.ba.1 $Wo.b.ba.2 $Wo.b.ba.3 -side left


# Bereich c fuer Wechsel

frame $Wo.c; pack configure $Wo.c -anchor w -fill x
frame $Wo.c.1; frame $Wo.c.d -width 5; frame $Wo.c.2; frame $Wo.c.3
pack configure $Wo.c.1 $Wo.c.d $Wo.c.2 -side left -anchor n
pack configure $Wo.c.3 -side left -anchor n -fill x -expand yes

# Bereich c.1 für Programmauswahl 
CreateLSBox $Wo.c.1 $vv(soc1fl) top 50 12 2 so_komsel $Wo.d.tt "" "" sosel1 sel ""
set sosep [fillboxsep $Wo.c.1.f.f.li utility.vst]

# Bereich c.2 für Dateisuffix und Dateiauswahl
CreateLSBox $Wo.c.2 " " top 6 10 2 so_suffsel $Wo.d.tt "" "" sosel2 sel ""
CreateLSBox $Wo.c.3 $vv(soc21) top 30 12 2 so_filesel $Wo.d.tt "" "" sosel3 sel ""
set kosuffldef "* "
set f [open_vst texsuffix.vst]; while {[getscl $f e]>0} {lappend kosuffldef $e}; close $f
set kosuff [lindex $kosuffldef 1]; set kosuffdef [lindex $kosuffldef 1]
set dateiliste [DelWinNTFiles [lsort [glob -nocomplain -- *]]]
sosselffill "$kosuffldef" "$kosuff"


InsertTextFrame $Wo $tyh "" "" ""
}
