add cli options --lastclosed and --lastopened, as well as gui commands Shift-Backspace and Ctrl-Backspace to load last closed or last opened schematic respectively

This commit is contained in:
stefan schippers 2025-09-28 23:47:45 +02:00
parent 94a0a6a2f9
commit bdd09f2db2
13 changed files with 68 additions and 12 deletions

View File

@ -116,6 +116,8 @@ LeftButton Double click Terminate Polygon placement
XSCHEM KEY BINDINGS
----------------------------------------------------------------------
- BackSpace Back to parent schematic
shift BackSpace Open last closed schematic
ctrl BackSpace Open last opened or saved schematic
- Delete Delete selected objects
- Insert Insert element from library
shift Insert Open persistent insert symbol dialog box

View File

@ -83,6 +83,8 @@ Options:
--plotfile <file> Use <file> as output for plot (png, svg, ps).
--rcfile <file> Use <file> as a rc file for startup instead of the
default xschemrc.
--lastclosed Open last closed file
--lastopened Open last opened or saved file
-p --postscript
--pdf Export pdf schematic.
--png Export png schematic.

View File

@ -605,7 +605,7 @@ void saveas(const char *f, int type) /* changed name from ask_save_file to save
return;
}
void ask_new_file(int in_new_window)
void ask_new_file(int in_new_window, char *filename)
{
char f[PATH_MAX]; /* overflow safe 20161125 */
@ -613,8 +613,12 @@ void ask_new_file(int in_new_window)
if(!(in_new_window || tclgetboolvar("open_in_new_window")) && xctx->modified) {
if(save(1, 0) == -1 ) return; /* user cancels save, so do nothing. */
}
tcleval("load_file_dialog {Load file} *.\\{sch,sym,tcl\\} INITIALLOADDIR");
my_snprintf(f, S(f),"%s", tclresult());
if(!filename || !filename[0]) {
tcleval("load_file_dialog {Load file} *.\\{sch,sym,tcl\\} INITIALLOADDIR");
my_snprintf(f, S(f),"%s", tclresult());
} else {
my_strncpy(f, filename, S(f));
}
if(f[0]) {
char win_path[WINDOW_PATH_SIZE];
int skip = 0;

View File

@ -3200,7 +3200,7 @@ static void handle_key_press(int event, KeySym key, int state, int rstate, int m
case 'o':
if(EQUAL_MODMASK) { /* load in new tab/window */
xctx->semaphore--;
ask_new_file(1);
ask_new_file(1, NULL);
tcleval("load_additional_files");
xctx->semaphore++;
}
@ -3212,7 +3212,7 @@ static void handle_key_press(int event, KeySym key, int state, int rstate, int m
);
} else {
xctx->semaphore--;
ask_new_file(0);
ask_new_file(0, NULL);
tcleval("load_additional_files");
xctx->semaphore++;
}
@ -3924,9 +3924,20 @@ static void handle_key_press(int event, KeySym key, int state, int rstate, int m
redraw_w_a_l_r_p_z_rubbers(1);
break;
case XK_BackSpace: /* back */
case XK_BackSpace:
if(xctx->semaphore >= 2) break;
go_back(1);
if(state == 0) go_back(1); /* go up in hierarchy */
else if(state == ShiftMask) {
/* load last closed file */
char f[PATH_MAX];
my_strncpy(f, tcleval("get_lastclosed"), S(f));
ask_new_file(0, f);
} else if(state == ControlMask) {
/* load last opened file */
char f[PATH_MAX];
my_strncpy(f, tcleval("lindex $tctx::recentfile 0"), S(f));
ask_new_file(0, f);
}
break;
#if defined(__unix__) && HAS_CAIRO==1

View File

@ -213,6 +213,8 @@ char *cli_opt_preinit_command = NULL; /* tcl command given on command line with
* this commands will be executed before loading xschemrc */
char *cli_opt_tcl_post_command = NULL; /* tcl command given on command line with --command <script> */
int cli_opt_do_print=0;
int cli_opt_lastclosed=0;
int cli_opt_lastopened=0;
int cli_opt_do_netlist=0; /* set by process_options if user wants netllist from cmdline */
int cli_opt_do_simulation=0;
int cli_opt_do_waves=0;

View File

@ -57,6 +57,8 @@ LeftButton Double click Terminate Polygon placement
XSCHEM KEY BINDINGS
----------------------------------------------------------------------
- BackSpace Back to parent schematic
shift BackSpace Open last closed schematic
ctrl BackSpace Open last opened or saved schematic
- Delete Delete selected objects
- Insert Insert element from library
shift Insert Open persistent insert symbol dialog box

View File

@ -68,6 +68,14 @@ static void check_opt(char *opt, char *optval, int type)
dbg(1, "process_options(): user rcfile specified: %s\n", optval ? optval : "<NULL>");
if(optval) my_strncpy(cli_opt_rcfile, optval, S(cli_opt_rcfile));
} else if( (type == LONG && !strcmp("lastclosed", opt)) ) {
dbg(1, "process_options(): lastclosed specified\n");
cli_opt_lastclosed = 1;
} else if( (type == LONG && !strcmp("lastopened", opt)) ) {
dbg(1, "process_options(): lastopened specified\n");
cli_opt_lastopened = 1;
} else if( (type == LONG && !strcmp("png", opt)) ) {
dbg(1, "process_options(): will print png\n");
cli_opt_do_print = 2;

View File

@ -3017,7 +3017,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
"insert_symbol $new_file_browser_paths $new_file_browser_depth $new_file_browser_ext load"
);
} else {
ask_new_file(0);
ask_new_file(0, NULL);
tcleval("load_additional_files");
}
} else

View File

@ -3107,6 +3107,14 @@ int Tcl_AppInit(Tcl_Interp *inter)
/* */
tcleval("eval_postinit_commands");
if(cli_opt_lastclosed) {
my_strncpy(cli_opt_filename, tcleval("get_lastclosed"), S(cli_opt_filename));
}
if(cli_opt_lastopened) {
my_strncpy(cli_opt_filename, tcleval("lindex $tctx::recentfile 0"), S(cli_opt_filename));
}
if(cli_opt_filename[0]) {
int file_loaded = 1;
/* check if local_netlist_dir is set and set netlist_dir accordingly

View File

@ -1252,6 +1252,8 @@ extern char *cli_opt_tcl_command;
extern char *cli_opt_preinit_command;
extern char *cli_opt_tcl_post_command;
extern int cli_opt_do_print;
extern int cli_opt_lastclosed;
extern int cli_opt_lastopened;
extern int cli_opt_do_netlist;
extern int cli_opt_do_simulation;
extern int cli_opt_do_waves;
@ -1329,7 +1331,7 @@ extern int copy_hierarchy_data(const char *from_win_path, const char *to_win_pat
extern int schematic_in_new_window(int new_process, int dr, int force);
extern void symbol_in_new_window(int new_process);
extern void new_xschem_process(const char *cell, int symbol);
extern void ask_new_file(int in_new_window);
extern void ask_new_file(int in_new_window, char *filename);
extern void saveas(const char *f, int type);
extern const char *get_file_path(char *f);
extern int save(int confirm, int fast);

View File

@ -37,6 +37,8 @@ Options:
--plotfile <file> Use <file> as output for plot (png, svg, ps).
--rcfile <file> Use <file> as a rc file for startup instead of the
default xschemrc.
--lastclosed Open last closed file
--lastopened Open last opened or saved file
-p --postscript
--pdf Export pdf schematic.
--png Export png schematic.

View File

@ -8598,6 +8598,19 @@ proc set_geom {win {filename {}}} {
update
}
proc get_lastclosed {} {
global USER_CONF_DIR
set ret {}
if {[file exists $USER_CONF_DIR/geometry]} {
set ret [lindex [read_data $USER_CONF_DIR/geometry] 0]
if {$ret eq [abs_sym_path untitled.sch]} {
set ret {}
}
}
return $ret
}
proc quit_xschem { {force {}}} {
global tabbed_interface
@ -8712,7 +8725,7 @@ set tctx::global_list {
show_hidden_texts show_infowindow show_infowindow_after_netlist simconf_default_geometry
simconf_vpos simulate_bg snap_cursor snap_cursor_size spiceprefix split_files svg_colors
svg_font_name sym_txt symbol symbol_width tabstop tclcmd_txt tclstop
tctx::colors tctx::delay_flag tctx::hsize tctx::recentfil
tctx::colors tctx::delay_flag tctx::hsize tctx::recentfile
tctx::selected_mode tctx::old_selected_mode tctx::old_selected_tok tctx::selected_tok
tctx::rcode tctx::vsize tctx::tctx::retval tctx::retval_orig
text_line_default_geometry text_replace_selection text_tabs_setting

View File

@ -400,8 +400,6 @@ T {-} 412.5 -23.75 0 0 0.18 0.18 {layer=12}
T {Toggle manhattan drawing / pan schematic} 412.5 -12.5 0 0 0.18 0.18 {}
T {-} 412.5 -46.25 0 0 0.18 0.18 {layer=7}
T {-} 412.5 -57.5 0 0 0.18 0.18 {layer=6}
T {-} 1042.5 -355 0 0 0.18 0.18 {layer=4}
T {-} 1042.5 -343.75 0 0 0.18 0.18 {layer=12}
T {Back to parent} 1042.5 -332.5 0 0 0.18 0.18 {}
T {-} 1042.5 -366.25 0 0 0.18 0.18 {layer=7}
T {-} 1042.5 -377.5 0 0 0.18 0.18 {layer=6}
@ -473,3 +471,5 @@ T {Move down} 1302.5 -12.5 0 0 0.18 0.18 {}
T {Move up} 1302.5 -92.5 0 0 0.18 0.18 {}
T {Open last file} 762.5 -297.5 0 0 0.18 0.18 {layer=6}
T {Previous Tab} 2.5 -275 0 0 0.18 0.18 {layer=4}
T {Load last opened file} 1042.5 -355 0 0 0.18 0.18 {layer=4}
T {Load last closed file} 1042.5 -343.75 0 0 0.18 0.18 {layer=12}