when placing symbols user can also type file name (with full path also) inside File/search box instead of clicking in the list box. web URLs will be returned as they are with no further interpretation

This commit is contained in:
Stefan Frederik 2022-11-12 12:16:21 +01:00
parent ca8ffafe8a
commit 94247770ce
1 changed files with 60 additions and 27 deletions

View File

@ -2260,6 +2260,8 @@ proc save_file_dialog { msg ext global_initdir {initialf {}} {overwrt 1} } {
} }
proc is_xschem_file {f} { proc is_xschem_file {f} {
if { ![file exists $f] } { return 0
} elseif { [file isdirectory $f] } { return 0 }
set a [catch {open "$f" r} fd] set a [catch {open "$f" r} fd]
set ret 0 set ret 0
set score 0 set score 0
@ -2494,49 +2496,53 @@ proc load_file_dialog_up {dir} {
proc myload_getresult {loadfile confirm_overwrt} { proc myload_getresult {loadfile confirm_overwrt} {
global myload_dir1 myload_retval myload_ext global myload_dir1 myload_retval myload_ext
if { $myload_retval ne {}} { if { $myload_retval ne {}} {
if {![file exists "$myload_dir1/$myload_retval"] } { if { [regexp {^http[s]?://} $myload_retval] } {
return "$myload_dir1/$myload_retval" set fname $myload_retval
} elseif { [regexp {^/} $myload_retval]} {
set fname $myload_retval
} else {
set fname "$myload_dir1/$myload_retval"
}
if {![file exists "$fname"] } {
return "$fname"
} }
if { $loadfile == 0 } { if { $loadfile == 0 } {
if {[file exists "$myload_dir1/$myload_retval"]} { if {[file exists "$fname"]} {
if {$confirm_overwrt == 1 } { if {$confirm_overwrt == 1 } {
set answer [tk_messageBox -message "Overwrite $myload_dir1/${myload_retval}?" \ set answer [alert_ "Overwrite $fname?" {} 0 1]
-icon warning -parent [xschem get topwindow] -type okcancel]
} else { } else {
set answer ok set answer 1
} }
if {$answer eq {ok}} { if {$answer eq {1}} {
return "$myload_dir1/$myload_retval" return "$fname"
} else { } else {
set myload_retval {}
return {} return {}
} }
} }
} }
set type [is_xschem_file "$myload_dir1/$myload_retval"] set type [is_xschem_file "$fname"]
if { $type eq {0} } { if { $type eq {0} } {
set answer [ set answer [
tk_messageBox -message "$myload_dir1/$myload_retval does not seem to be an xschem file...\nContinue?" \ alert_ "$fname does not seem to be an xschem file...\nContinue?" {} 0 1]
-icon warning -parent [xschem get topwindow] -type yesno] if { $answer eq {0}} {
if { $answer eq "no"} {
set myload_retval {} set myload_retval {}
return {} return {}
} else { } else {
return "$myload_dir1/$myload_retval" return "$fname"
} }
} elseif { $type ne {SYMBOL} && ($myload_ext eq {*.sym}) } { } elseif { $type ne {SYMBOL} && ($myload_ext eq {*.sym}) } {
set answer [ set answer [
tk_messageBox -message "$myload_dir1/$myload_retval does not seem to be a SYMBOL file...\nContinue?" \ alert_ "$fname does not seem to be a SYMBOL file...\nContinue?" {} 0 1]
-icon warning -parent [xschem get topwindow] -type yesno] if { $answer eq {0}} {
if { $answer eq "no"} {
set myload_retval {} set myload_retval {}
return {} return {}
} else { } else {
return "$myload_dir1/$myload_retval" return "$fname"
} }
} else { } else {
return "$myload_dir1/$myload_retval" return "$fname"
} }
} else { } else {
return {} return {}
@ -2551,7 +2557,6 @@ proc myload_display_preview {f} {
.load.l.paneright.draw configure -background {} .load.l.paneright.draw configure -background {}
xschem preview_window draw .load.l.paneright.draw "$f" xschem preview_window draw .load.l.paneright.draw "$f"
bind .load.l.paneright.draw <Expose> [subst {xschem preview_window draw .load.l.paneright.draw "$f"}] bind .load.l.paneright.draw <Expose> [subst {xschem preview_window draw .load.l.paneright.draw "$f"}]
} }
} else { } else {
bind .load.l.paneright.draw <Expose> {} bind .load.l.paneright.draw <Expose> {}
@ -2765,6 +2770,19 @@ proc load_file_dialog {{msg {}} {ext {}} {global_initdir {INITIALINSTDIR}}
setglob $myload_dir1 setglob $myload_dir1
myload_set_colors2 myload_set_colors2
if {$myload_loadfile == 2} {
bind .load.buttons_bot.entry <Leave> {
set myload_retval [.load.buttons_bot.entry get]
set r [myload_getresult 2 0]
# puts "r=$r myload_dir1=$myload_dir1 myload_dir2=$myload_dir2"
xschem abort_operation
if {$r ne {}} {
xschem place_symbol "$r"
}
}
}
bind .load.l.paneright.list <ButtonPress> { bind .load.l.paneright.list <ButtonPress> {
set myload_yview [.load.l.paneright.list yview] set myload_yview [.load.l.paneright.list yview]
} }
@ -2814,7 +2832,7 @@ proc load_file_dialog {{msg {}} {ext {}} {global_initdir {INITIALINSTDIR}}
# puts "r=$r myload_dir1=$myload_dir1 myload_dir2=$myload_dir2" # puts "r=$r myload_dir1=$myload_dir1 myload_dir2=$myload_dir2"
xschem abort_operation xschem abort_operation
if {$r ne {}} { if {$r ne {}} {
xschem place_symbol "$myload_dir1/$myload_dir2" xschem place_symbol "$r"
} }
} }
};# bind .load.l.paneright.list <<ListboxSelect>> };# bind .load.l.paneright.list <<ListboxSelect>>
@ -4135,8 +4153,9 @@ proc text_line {txtlabel clear {preserve_disabled disabled} } {
return $rcode return $rcode
} }
proc alert_ {txtlabel {position +200+300} {nowait {0}}} { proc alert_ {txtlabel {position +200+300} {nowait {0}} {yesno 0}} {
global has_x global has_x rcode
set recode 1
if {![info exists has_x] } {return} if {![info exists has_x] } {return}
toplevel .alert -class Dialog toplevel .alert -class Dialog
wm title .alert {Alert} wm title .alert {Alert}
@ -4148,12 +4167,27 @@ proc alert_ {txtlabel {position +200+300} {nowait {0}}} {
wm geometry .alert "+$X+$Y" wm geometry .alert "+$X+$Y"
} }
label .alert.l1 -text $txtlabel -wraplength 700 label .alert.l1 -text $txtlabel -wraplength 700
button .alert.b1 -text "OK" -command \ if { $yesno} {
set oktxt Yes
} else {
set oktxt OK
}
button .alert.b1 -text $oktxt -command \
{ {
set rcode 1
destroy .alert destroy .alert
} }
if {$yesno} {
button .alert.b2 -text "No" -command \
{
set rcode 0
destroy .alert
}
}
pack .alert.l1 -side top -fill x pack .alert.l1 -side top -fill x
pack .alert.b1 -side top -fill x pack .alert.b1 -side left -fill x
if {$yesno} {pack .alert.b2 -side left -fill x}
tkwait visibility .alert tkwait visibility .alert
grab set .alert grab set .alert
focus .alert.b1 focus .alert.b1
@ -4169,9 +4203,8 @@ proc alert_ {txtlabel {position +200+300} {nowait {0}}} {
} }
} }
if {!$nowait} {tkwait window .alert} if {!$nowait} {tkwait window .alert}
return {} return $rcode
} }
proc show_infotext {} { proc show_infotext {} {