better file globbing in load_file_dialog

This commit is contained in:
Stefan Frederik 2022-09-27 13:15:04 +02:00
parent d4b6986e24
commit 472751dfc0
7 changed files with 14 additions and 15 deletions

View File

@ -407,9 +407,9 @@ void saveas(const char *f, int type) /* changed name from ask_save_file to save
if( (p = strrchr(filename, '.')) && !strcmp(p, ".sch") ) { if( (p = strrchr(filename, '.')) && !strcmp(p, ".sch") ) {
my_strncpy(filename, add_ext(filename, ".sym"), S(filename)); my_strncpy(filename, add_ext(filename, ".sym"), S(filename));
} }
my_snprintf(name, S(name), "save_file_dialog {Save file} .sym.sch INITIALLOADDIR {%s}", filename); my_snprintf(name, S(name), "save_file_dialog {Save file} *.\\{sch,sym\\} INITIALLOADDIR {%s}", filename);
} else { } else {
my_snprintf(name, S(name), "save_file_dialog {Save file} .sch.sym INITIALLOADDIR {%s}", filename); my_snprintf(name, S(name), "save_file_dialog {Save file} *.\\{sch,sym\\} INITIALLOADDIR {%s}", filename);
} }
tcleval(name); tcleval(name);
@ -437,7 +437,7 @@ void ask_new_file(void)
if(xctx->modified) { if(xctx->modified) {
if(save(1) == -1 ) return; /* user cancels save, so do nothing. */ if(save(1) == -1 ) return; /* user cancels save, so do nothing. */
} }
tcleval("load_file_dialog {Load file} .sch.sym INITIALLOADDIR"); tcleval("load_file_dialog {Load file} *.\\{sch,sym\\} INITIALLOADDIR");
my_snprintf(f, S(f),"%s", tclresult()); my_snprintf(f, S(f),"%s", tclresult());
if(f[0]) { if(f[0]) {
char win_path[WINDOW_PATH_SIZE]; char win_path[WINDOW_PATH_SIZE];
@ -996,7 +996,7 @@ int place_symbol(int pos, const char *symbol_name, double x, double y, short rot
char *type; char *type;
int cond; int cond;
if(symbol_name==NULL) { if(symbol_name==NULL) {
tcleval("load_file_dialog {Choose symbol} .sym INITIALINSTDIR"); tcleval("load_file_dialog {Choose symbol} *.sym INITIALINSTDIR");
my_strncpy(name, tclresult(), S(name)); my_strncpy(name, tclresult(), S(name));
} else { } else {
my_strncpy(name, symbol_name, S(name)); my_strncpy(name, symbol_name, S(name));
@ -1243,7 +1243,7 @@ int descend_schematic(int instnumber)
char res[PATH_MAX]; char res[PATH_MAX];
my_strncpy(filename, xctx->sch[xctx->currsch], S(filename)); my_strncpy(filename, xctx->sch[xctx->currsch], S(filename));
my_snprintf(cmd, S(cmd), "save_file_dialog {Save file} .sch.sym INITIALLOADDIR {%s}", filename); my_snprintf(cmd, S(cmd), "save_file_dialog {Save file} *.\\{sch,sym\\} INITIALLOADDIR {%s}", filename);
tcleval(cmd); tcleval(cmd);
my_strncpy(res, tclresult(), S(res)); my_strncpy(res, tclresult(), S(res));
if(!res[0]) return 0; if(!res[0]) return 0;

View File

@ -1921,7 +1921,7 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key,
} }
if((key==XK_Insert && (state & ShiftMask)) || (key == 'i' && state == ControlMask)) /* insert sym */ if((key==XK_Insert && (state & ShiftMask)) || (key == 'i' && state == ControlMask)) /* insert sym */
{ {
tcleval("load_file_dialog {Insert symbol} .sym INITIALINSTDIR 2"); tcleval("load_file_dialog {Insert symbol} *.sym INITIALINSTDIR 2");
break; break;
} }
if(key==XK_Insert || (key == 'I' && state == ShiftMask) ) /* insert sym */ if(key==XK_Insert || (key == 'I' && state == ShiftMask) ) /* insert sym */

View File

@ -327,7 +327,7 @@ void merge_file(int selection_load, const char ext[])
if(selection_load==0) if(selection_load==0)
{ {
if(!strcmp(ext,"")) { if(!strcmp(ext,"")) {
my_snprintf(tmp, S(tmp), "load_file_dialog {Merge file} {.sch.sym} INITIALLOADDIR"); my_snprintf(tmp, S(tmp), "load_file_dialog {Merge file} *.\\{sch,sym\\} INITIALLOADDIR");
tcleval(tmp); tcleval(tmp);
if(!strcmp(tclresult(),"")) return; if(!strcmp(tclresult(),"")) return;
my_strncpy(name, (char *)tclresult(), S(name)); my_strncpy(name, (char *)tclresult(), S(name));

View File

@ -3182,7 +3182,7 @@ void make_schematic_symbol_from_sel(void)
char filename[PATH_MAX] = ""; char filename[PATH_MAX] = "";
char name[1024]; char name[1024];
my_snprintf(name, S(name), "save_file_dialog {Save file} .sch.sym INITIALLOADDIR"); my_snprintf(name, S(name), "save_file_dialog {Save file} *.\\{sch,sym\\} INITIALLOADDIR");
tcleval(name); tcleval(name);
my_strncpy(filename, tclresult(), S(filename)); my_strncpy(filename, tclresult(), S(filename));
if (!strcmp(filename, xctx->sch[xctx->currsch])) { if (!strcmp(filename, xctx->sch[xctx->currsch])) {

View File

@ -1719,7 +1719,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
if(argc>=3) { if(argc>=3) {
my_snprintf(fullname, S(fullname),"%s", argv[2]); my_snprintf(fullname, S(fullname),"%s", argv[2]);
} else { } else {
tcleval("load_file_dialog {Load file} .sch.sym INITIALLOADDIR"); tcleval("load_file_dialog {Load file} *.\\{sch,sym\\} INITIALLOADDIR");
my_snprintf(fullname, S(fullname),"%s", tclresult()); my_snprintf(fullname, S(fullname),"%s", tclresult());
} }
if( fullname[0] ) { if( fullname[0] ) {

View File

@ -677,7 +677,7 @@ int compare_schematics(const char *f)
/* set filename of schematic to compare */ /* set filename of schematic to compare */
if(f == NULL) { if(f == NULL) {
tcleval("load_file_dialog {Schematic to compare with} .sch.sym INITIALLOADDIR"); tcleval("load_file_dialog {Schematic to compare with} *.\\{sch,sym\\} INITIALLOADDIR");
if(tclresult()[0]) my_strncpy(xctx->sch_to_compare, tclresult(), S(xctx->sch_to_compare)); if(tclresult()[0]) my_strncpy(xctx->sch_to_compare, tclresult(), S(xctx->sch_to_compare));
else my_strncpy(xctx->sch_to_compare, "", S(xctx->sch_to_compare)); else my_strncpy(xctx->sch_to_compare, "", S(xctx->sch_to_compare));
} else if(f[0] != '\0') { } else if(f[0] != '\0') {

View File

@ -2358,7 +2358,7 @@ proc myload_getresult {loadfile confirm_overwrt} {
} else { } else {
return "$myload_dir1/$myload_retval" return "$myload_dir1/$myload_retval"
} }
} elseif { $myload_type ne {SYMBOL} && ($myload_ext eq {.sym}) } { } elseif { $myload_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?" \ tk_messageBox -message "$myload_dir1/$myload_retval does not seem to be a SYMBOL file...\nContinue?" \
-icon warning -parent [xschem get topwindow] -type yesno] -icon warning -parent [xschem get topwindow] -type yesno]
@ -2409,8 +2409,8 @@ proc load_file_dialog {{msg {}} {ext {}} {global_initdir {INITIALINSTDIR}}
} }
set myload_loadfile $loadfile set myload_loadfile $loadfile
set myload_ext $ext set myload_ext $ext
set globfilter $ext
set save_initialfile $initialf set save_initialfile $initialf
set globfilter *
set myload_retval {} set myload_retval {}
upvar #0 $global_initdir initdir upvar #0 $global_initdir initdir
if { $loadfile != 2} {xschem set semaphore [expr {[xschem get semaphore] +1}]} if { $loadfile != 2} {xschem set semaphore [expr {[xschem get semaphore] +1}]}
@ -2444,7 +2444,7 @@ proc load_file_dialog {{msg {}} {ext {}} {global_initdir {INITIALINSTDIR}}
if { $myload_sel ne {} } { if { $myload_sel ne {} } {
set myload_dir1 [abs_sym_path [.load.l.paneleft.list get $myload_sel]] set myload_dir1 [abs_sym_path [.load.l.paneleft.list get $myload_sel]]
set myload_index1 $myload_sel set myload_index1 $myload_sel
set globfilter * set globfilter $myload_ext
if {$save_initialfile eq {}} {.load.buttons_bot.entry delete 0 end} if {$save_initialfile eq {}} {.load.buttons_bot.entry delete 0 end}
setglob $myload_dir1 setglob $myload_dir1
myload_set_colors2 myload_set_colors2
@ -2635,7 +2635,6 @@ proc load_file_dialog {{msg {}} {ext {}} {global_initdir {INITIALINSTDIR}}
set myload_dir1 $myload_d set myload_dir1 $myload_d
# .load.buttons_bot.entry delete 0 end # .load.buttons_bot.entry delete 0 end
} else { } else {
set globfilter *
.load.buttons_bot.entry delete 0 end .load.buttons_bot.entry delete 0 end
.load.buttons_bot.entry insert 0 $myload_dir2 .load.buttons_bot.entry insert 0 $myload_dir2
myload_display_preview $myload_dir1/$myload_dir2 myload_display_preview $myload_dir1/$myload_dir2
@ -5179,7 +5178,7 @@ proc build_widgets { {topwin {} } } {
} }
$topwin.menubar.file.menu add command -label "Component browser" -accelerator {Shift-Ins, Ctrl-I} \ $topwin.menubar.file.menu add command -label "Component browser" -accelerator {Shift-Ins, Ctrl-I} \
-command { -command {
load_file_dialog {Insert symbol} .sym INITIALINSTDIR 2 load_file_dialog {Insert symbol} *.sym INITIALINSTDIR 2
} }
$topwin.menubar.file.menu add command -label "Open" -command "xschem load" -accelerator {Ctrl+O} $topwin.menubar.file.menu add command -label "Open" -command "xschem load" -accelerator {Ctrl+O}
$topwin.menubar.file.menu add cascade -label "Open recent" -menu $topwin.menubar.file.menu.recent $topwin.menubar.file.menu add cascade -label "Open recent" -menu $topwin.menubar.file.menu.recent