diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2021-03-01 16:36:52 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2021-03-01 16:37:33 +0300 |
commit | 3649b5b6dfff8c02637648773165efe5f94aeecf (patch) | |
tree | dddeaa4a9b76343494904ed4ca7e43b2d413f088 | |
parent | e06f5f64aeac914c17cfc267b1335869d0f24309 (diff) |
Add `--open-last` CLI argument that opens the most recent file
Add a CLI argument `--open-last` that opens the most recent file,
effectively doing the same as {key Ctrl Shift O}, {key Enter} after
starting Blender.
When there are no known recent files, print a warning and do nothing,
showing the startup file instead.
Note that this does not try to be smart about restoring the last Blender
session. It just opens the file from disk, as if the user had typed
`blender $(head -n1 ~/.config/blender/2.93/config/recent-files.txt)`.
There is also no smartness when that file cannot be opened; it behaves
exactly the same as typing the most recent filename on the CLI.
Reviewed by: mont29, campbellbarton
Differential Revision: https://developer.blender.org/D10563
-rw-r--r-- | source/creator/creator_args.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/source/creator/creator_args.c b/source/creator/creator_args.c index e31be24ec7b..9133b259a13 100644 --- a/source/creator/creator_args.c +++ b/source/creator/creator_args.c @@ -84,6 +84,8 @@ # include "DEG_depsgraph_build.h" # include "DEG_depsgraph_debug.h" +# include "WM_types.h" + # include "creator_intern.h" /* own include */ /* -------------------------------------------------------------------- */ @@ -1994,6 +1996,21 @@ static int arg_handle_load_file(int UNUSED(argc), const char **argv, void *data) return 0; } +static const char arg_handle_load_last_file_doc[] = + "\n\t" + "Open the most recently opened blend file, instead of the default startup file."; +static int arg_handle_load_last_file(int UNUSED(argc), const char **UNUSED(argv), void *data) +{ + if (BLI_listbase_is_empty(&G.recent_files)) { + printf("Warning: no recent files known, opening default startup file instead.\n"); + return -1; + } + + const RecentFile *recent_file = G.recent_files.first; + const char *fake_argv[] = {recent_file->filepath}; + return arg_handle_load_file(1, fake_argv, data); +} + void main_args_setup(bContext *C, bArgs *ba) { @@ -2217,6 +2234,8 @@ void main_args_setup(bContext *C, bArgs *ba) BLI_args_add(ba, "-F", "--render-format", CB(arg_handle_image_type_set), C); BLI_args_add(ba, "-x", "--use-extension", CB(arg_handle_extension_set), C); + BLI_args_add(ba, NULL, "--open-last", CB(arg_handle_load_last_file), C); + # undef CB # undef CB_EX } |