new_file_browser: "search all" does no more open a new dialog, use existing file listbox.

This commit is contained in:
stefan schippers 2026-05-08 14:50:51 +02:00
parent aaaa0e6b59
commit 4961ee437e
1 changed files with 35 additions and 255 deletions

View File

@ -5194,7 +5194,7 @@ proc file_chooser_draw_preview {f} {
## preview window draw causes a save / restore context.
## restore_ctx writes XSCHEM_LIBRARY_PATH --> set_paths --> .ins.top4.upd invoke
## restore_ctx writes XSCHEM_LIBRARY_PATH --> set_paths --> .ins.top4.reset invoke
## this rewrites the file_chooser(dirtails) list variable and list loses selection...
# .ins.center.leftdir.l selection set [.ins.center.leftdir.l index active]
@ -5284,21 +5284,25 @@ proc file_chooser_dirlist {} {
#### fill list of files matching pattern
proc file_chooser_filelist {} {
global file_chooser new_file_browser_ext
global file_chooser new_file_browser_ext new_file_browser_depth
if {![info exists file_chooser(dirs)]} {return}
set sel [lindex [.ins.center.leftdir.l curselection] 0]
if {$sel eq {}} { return }
set file_chooser(dirindex) $sel
set path [lindex $file_chooser(dirs) $sel]
set file_chooser(abs_filename) $path
set file_chooser(rel_filename) {}
# check if regex is valid
set regex $file_chooser(regex)
set err [catch {regexp $regex {12345}} res]
if {$err} {set regex {}}
set f {}
if {$path ne {} } {
set f [match_file $regex [list $path] 0 $file_chooser(fullpath)]
if {$file_chooser(searchall) == 0} {
set f [match_file $regex [list $path] 0 $file_chooser(fullpath)]
} else {
set f [match_file $regex {} $new_file_browser_depth $file_chooser(fullpath)]
}
}
set filelist {}
set file_chooser(fullpathlist) {}
@ -5315,7 +5319,11 @@ proc file_chooser_filelist {} {
set err [catch {regexp $nfbe {12345}} res1]
if {$err} {set nfbe {}}
foreach i $f {
set fname [file tail $i]
if {$file_chooser(searchall) == 0} {
set fname [file tail $i]
} else {
set fname $i
}
set err [catch {regexp $nfbe $fname} type]
if {!$err && $type} {
lappend filelist $fname
@ -5388,7 +5396,11 @@ proc file_chooser_select {f} {
global file_chooser
if {$f ne {} && [info exists file_chooser(dirs)] && [info exists file_chooser(files)]} {
set dir [file dirname $f]
set file [file tail $f]
if {$file_chooser(searchall) == 0} {
set file [file tail $f]
} else {
set file $f
}
# puts "file=$file"
# puts " dir=$dir"
set dirindex [lsearch -exact $file_chooser(dirs) $dir]
@ -5412,236 +5424,6 @@ proc file_chooser_select {f} {
}
}
#### Display preview of selected symbol and start sym placement
proc file_chooser_search_all_draw_preview {f} {
global file_chooser
# puts "file_chooser_draw_preview"
if {[winfo exists .ins]} {
.ins.center.right configure -bg {}
xschem preview_window create .ins.center.right {}
xschem preview_window draw .ins.center.right "$f"
## preview window draw causes a save / restore context.
## restore_ctx writes XSCHEM_LIBRARY_PATH --> set_paths --> .ins.top4.upd invoke
## this rewrites the file_chooser(dirtails) list variable and list loses selection...
# .ins.center.leftdir.l selection set [.ins.center.leftdir.l index active]
bind .ins.center.right <Expose> "xschem preview_window draw .ins.center.right {$f}"
bind .ins.center.right <Configure> "xschem preview_window draw .ins.center.right {$f}"
if {$file_chooser(action) eq {symbol}} {
file_chooser_search_all_place symbol
}
if {$file_chooser(action) eq {symbol1}} {
set file_chooser(action) {load}
file_chooser_search_all_place symbol
}
}
}
proc file_chooser_search_all_preview {} {
# puts "file_chooser_preview"
global file_chooser
if {[info exists file_chooser(f)]} {
after cancel ".ins.center.right configure -bg white"
after cancel "file_chooser_draw_preview {$file_chooser(f)}"
unset file_chooser(f)
}
xschem preview_window close .ins.center.right {}
bind .ins.center.right <Expose> {}
bind .ins.center.right <Configure> {}
set sel [lindex [.searchall.c.lb curselection] 0]
if {$sel ne {} && [info exists file_chooser(searchall)]} {
# puts "set fileindex=$sel"
set f [lindex $file_chooser(searchall) $sel]
# puts "file_chooser_preview: f=$f"
if {$f ne {}} {
set file_chooser(f) $f
set type [is_xschem_file $f]
if {$type ne {0}} {
set dir [rel_sym_path $f]
set file_chooser(abs_filename) $f
set file_chooser(rel_filename) $dir
# global used to cancel delayed script
after 200 "file_chooser_search_all_draw_preview {$f}"
} else {
after 200 {.ins.center.right configure -bg white}
}
}
}
}
proc file_chooser_search_all_place {action} {
# puts file_chooser_place
global file_chooser open_in_new_window
if {[xschem get semaphore] > 0} {return}
set sel [.searchall.c.lb index active]
if {$sel ne {}} {
set f [lindex $file_chooser(searchall) $sel]
if {$f ne {}} {
set type [is_xschem_file $f]
# puts "file_chooser_place: file=$f, type=$type"
if {$type ne {0}} {
if { [xschem get ui_state] & 8192 } {
xschem abort_operation
}
if {$action eq {symbol}} {
xschem place_symbol $f
} elseif {$action eq {load}} {
if {$open_in_new_window} {
xschem load_new_window $f
} else {
xschem load -gui $f
}
} elseif {$action eq {load_new_win}} {
xschem load_new_window $f
}
}
}
}
}
# called when double clicking a file item in the file_chooser search all listbox
proc file_chooser_search_all_open {{shift 0}} {
global file_chooser
if {[xschem get semaphore] > 0} {return}
set sel [.searchall.c.lb index active]
if {$sel ne {}} {
set f [lindex $file_chooser(searchall) $sel]
if {$f ne {}} {
set type [is_xschem_file $f]
if {$type eq {SCHEMATIC}} {
if {$shift == 0} {
file_chooser_search_all_place load
} else {
file_chooser_search_all_place load_new_win
}
} elseif {$type eq {SYMBOL}} {
if {$shift == 0} {
set file_chooser(action) {symbol1} ;# only one time insert symbol
file_chooser_search_all_preview
} else {
file_chooser_search_all_place load_new_win
}
}
}
}
}
proc file_chooser_search_all {} {
global file_chooser new_file_browser_depth new_file_browser_ext USER_CONF_DIR
# just check if pattern is a valid regexp
set file_chooser(searchall) {}
set nfbe $new_file_browser_ext
set err [catch {regexp $nfbe {12345}} res1]
if {$err} {set nfbe {}}
set regex $file_chooser(regex)
# check if regex is valid
set err [catch {regexp $regex {12345}} res1]
if {$err} {set regex {}}
set nth 0
set f {}
if {$file_chooser(dirs) ne {} } {
set allfiles [
match_file $regex {} $new_file_browser_depth $file_chooser(fullpath)
]
puts ""
foreach i $allfiles {
set err [catch {regexp $nfbe $i} type]
if {!$err && $type} {
lappend file_chooser(searchall) $i
}
}
}
if {[winfo exists .searchall]} {return}
toplevel .searchall
frame .searchall.t
frame .searchall.c
frame .searchall.b
listbox .searchall.c.lb -width 70 -height 28 -listvariable file_chooser(searchall) -selectmode single \
-yscrollcommand ".searchall.c.yscroll set" \
-xscrollcommand ".searchall.c.xscroll set"
scrollbar .searchall.c.yscroll -command ".searchall.c.lb yview"
scrollbar .searchall.c.xscroll -orient horiz -command ".searchall.c.lb xview"
pack .searchall.c.yscroll -side right -fill y
pack .searchall.c.xscroll -side bottom -fill x
pack .searchall.c.lb -side bottom -fill both -expand true
pack .searchall.t -fill x -expand true
pack .searchall.c -fill both -expand true
pack .searchall.b -fill x -expand true
bind .searchall.c.lb <Double-Button-1> {file_chooser_search_all_open 0}
bind .searchall.c.lb <Shift-Double-Button-1> {file_chooser_search_all_open r10}
bind .searchall.c.lb <<ListboxSelect>> {
if {[.searchall.c.lb curselection] ne {}} {
if { [xschem get ui_state] & 8192 } {
xschem abort_operation
}
file_chooser_search_all_preview
}
}
if { [info exists file_chooser(search_all_geometry)]} {
wm geometry .searchall "${file_chooser(search_all_geometry)}"
} elseif {[file exists $USER_CONF_DIR/file_chooser_search_all_geometry]} {
source $USER_CONF_DIR/file_chooser_search_all_geometry
set valid 0
set xmax [winfo screenwidth .]
set ymax [winfo screenheight .]
if {[info exists file_chooser(geometry)]} {
set n [scan $file_chooser(search_all_geometry) {%dx%d+%d+%d} x y dx dy]
if {$n == 4} {
# puts "xmax=$xmax, ymax=$ymax, x=$x, y=$y dx=$dx dy=$dy"
# off screen. do not use.
set valid 1
if { $dx > $xmax - 100 || $dy > $ymax - 100} {
set valid 0
}
}
}
if {$valid} {wm geometry .searchall "${file_chooser(search_all_geometry)}"}
} else {
# wm geometry .searchall 800x300
}
bind .searchall <Configure> {
set file_chooser(search_all_geometry) [wm geometry .searchall]
write_data [string cat \
"set file_chooser(search_all_geometry) $file_chooser(search_all_geometry)\n" \
] $USER_CONF_DIR/file_chooser_search_all_geometry
}
button .searchall.b.dismiss -takefocus 0 -text Dismiss -command {
if { [xschem get ui_state] & 8192 } {
xschem abort_operation
} else {
destroy .searchall
}
}
button .searchall.b.load -takefocus 0 -text {Open} -command {
file_chooser_search_all_place load
}
button .searchall.b.load_new_win -takefocus 0 -text {Open in new Window / Tab} -command {
file_chooser_search_all_place load_new_win
}
button .searchall.b.sym -text {Place symbol} -takefocus 0 \
-command {
set file_chooser(action) {symbol1} ;# only one time insert symbol
file_chooser_search_all_preview
}
pack .searchall.b.dismiss .searchall.b.load .searchall.b.load_new_win .searchall.b.sym -side left
wm protocol .searchall WM_DELETE_WINDOW {.searchall.b.dismiss invoke}
bind .searchall <KeyPress-Escape> {.searchall.b.dismiss invoke}
return {}
}
proc file_chooser_search {{current {}}} {
global file_chooser new_file_browser_depth new_file_browser_ext
# just check if pattern is a valid regexp
@ -5686,8 +5468,9 @@ proc file_chooser_search {{current {}}} {
}
}
if {$f ne {}} {
file_chooser_select $f
file_chooser_select $f ;# calls file_chooser_filelist
} else {
file_chooser_filelist
if {$file_chooser(nth) > 0} {
incr file_chooser(nth) -1
} else {
@ -5750,7 +5533,7 @@ proc file_chooser_edit_paths {} {
set tctx::rcode 1
set tctx::retval [.editpaths.center.paths get 1.0 {end - 1 chars}]
file_chooser_set_paths
.ins.top4.upd invoke
.ins.top4.reset invoke
destroy .editpaths
}
@ -5758,7 +5541,7 @@ proc file_chooser_edit_paths {} {
set tctx::rcode 1
set tctx::retval [.editpaths.center.paths get 1.0 {end - 1 chars}]
file_chooser_set_paths
.ins.top4.upd invoke
.ins.top4.reset invoke
}
button .editpaths.bottom.dismiss -text Dismiss -command {
destroy .editpaths
@ -5771,7 +5554,7 @@ proc file_chooser_edit_paths {} {
set tctx::rcode 1
set tctx::retval [.editpaths.center.paths get 1.0 {end - 1 chars}]
file_chooser_set_paths
.ins.top4.upd invoke
.ins.top4.reset invoke
if {[winfo exists .editdata]} {destroy .editdata}
editdata "set XSCHEM_LIBRARY_PATH {$XSCHEM_LIBRARY_PATH}" {XSCHEM_LIBRARY_PATH} char 0
}
@ -6048,13 +5831,8 @@ proc file_chooser {} {
fuzzy_chooser_inline [.ins.top3.fzf_e get]
}
button .ins.top4.select_current -takefocus 0 -text {Select current} -command {
button .ins.top4.reset -takefocus 0 -text "Reset" -command {
set file_chooser(regex) {}
file_chooser_select [xschem get schname]
}
balloon .ins.top4.select_current "Select directory and file name\nof current active xschem window"
button .ins.top4.upd -takefocus 0 -text "Reload" -command {
set file_chooser(abs_filename) {}
set file_chooser(rel_filename) {}
set file_chooser(fullpathlist) {}
@ -6064,16 +5842,18 @@ proc file_chooser {} {
.ins.center.right configure -bg white
file_chooser_dirlist
file_chooser_filelist
file_chooser_select [xschem get schname]
}
balloon .ins.top4.upd "Reset and reload list of files"
balloon .ins.top4.reset "Reset and re-reads list of files"
button .ins.top4.search_curr -takefocus 0 -text {Search curr. dir.} -activebackground red -command {
file_chooser_search current
}
balloon .ins.top4.search_curr "Show and select match\n in current directory"
button .ins.top4.search_all -takefocus 0 -text {Search all} -activebackground red -command {
file_chooser_search_all
}
checkbutton .ins.top4.search_all -takefocus 0 -variable file_chooser(searchall) -text {Search all} \
-activebackground red -command {
file_chooser_search
}
balloon .ins.top4.search_all "Show all matches in all directories"
button .ins.top4.search -takefocus 0 -text {Search first} -activebackground red -command {
set file_chooser(nth) 1
@ -6205,8 +5985,7 @@ proc file_chooser {} {
pack .ins.top2.dir_e -side left -fill x -expand 1
pack .ins.top2.delete -side left
pack .ins.top2.save -side left
pack .ins.top4.select_current -side left
pack .ins.top4.upd -side left
pack .ins.top4.reset -side left
pack .ins.top3.pat_l -side left
pack .ins.top3.pat_e -side left
pack .ins.top4.clear -side left
@ -6273,6 +6052,7 @@ proc file_chooser {} {
set file_chooser(files) {}
set file_chooser(fullpathlist) {}
set file_chooser(nitems) 0
set file_chooser(searchall) 0
file_chooser_dirlist
file_chooser_filelist
set file_chooser(old_dirs) $file_chooser(dirs)
@ -11111,7 +10891,7 @@ proc trace_set_vars {varname idxname op} {
$file_chooser(old_new_file_browser_ext) ne $new_file_browser_ext} {
set file_chooser(old_new_file_browser_ext) $new_file_browser_ext
if {[winfo exists .ins]} {
.ins.top4.upd invoke
.ins.top4.reset invoke
}
}
}
@ -11121,7 +10901,7 @@ proc trace_set_vars {varname idxname op} {
$file_chooser(old_new_file_browser_depth) ne $new_file_browser_depth} {
set file_chooser(old_new_file_browser_depth) $new_file_browser_depth
if {[winfo exists .ins]} {
.ins.top4.upd invoke
.ins.top4.reset invoke
}
}
}
@ -11131,7 +10911,7 @@ proc trace_set_vars {varname idxname op} {
$file_chooser(old_dirs) ne $file_chooser(dirs)} {
set file_chooser(old_dirs) $file_chooser(dirs)
if {[winfo exists .ins]} {
.ins.top4.upd invoke
.ins.top4.reset invoke
}
}
}