diff options
author | Dave Davenport <qball@gmpclient.org> | 2020-10-16 21:30:27 +0200 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2020-10-16 21:33:02 +0200 |
commit | e00ef7d99365ed400be1d6957666e15d510d73ea (patch) | |
tree | 1dee9b6520157f94a7760d54411c35564b08c012 | |
parent | 10678e55d831d6da0861c9b7cd318ae340e54352 (diff) |
[FileBrowser] Save last directory.
-rw-r--r-- | source/dialogs/filebrowser.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/source/dialogs/filebrowser.c b/source/dialogs/filebrowser.c index 26b870d9..37ec7725 100644 --- a/source/dialogs/filebrowser.c +++ b/source/dialogs/filebrowser.c @@ -39,11 +39,16 @@ #include "helper.h" #include "mode-private.h" #include "dialogs/filebrowser.h" +#include "rofi.h" +#include "history.h" #include <stdint.h> #include "rofi-icon-fetcher.h" + +#define FILEBROWSER_CACHE_FILE "rofi3.filebrowsercache" + /** * The internal data structure holding the private data of the TEST Mode. */ @@ -194,7 +199,21 @@ static int file_browser_mode_init ( Mode *sw ) if ( mode_get_private_data ( sw ) == NULL ) { FileBrowserModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) ); mode_set_private_data ( sw, (void *) pd ); - pd->current_dir = g_file_new_for_path(g_get_home_dir () ); + { + char *path = g_build_filename ( cache_dir, FILEBROWSER_CACHE_FILE, NULL ); + char *file = NULL; + if ( g_file_get_contents (path, &file, NULL, NULL ) ) { + if ( g_file_test ( file, G_FILE_TEST_IS_DIR ) ){ + pd->current_dir = g_file_new_for_path( file ); + } + g_free ( file ); + } + // Store it based on the unique identifiers (desktop_id). + g_free ( path ); + if ( pd->current_dir == NULL ) { + pd->current_dir = g_file_new_for_path(g_get_home_dir () ); + } + } // Load content. get_file_browser ( sw ); } @@ -229,6 +248,9 @@ static ModeMode file_browser_mode_result ( Mode *sw, int mretv, char **input, un return RESET_DIALOG; } } else if ( pd->array[selected_line].type == DIRECTORY ) { + char *path = g_build_filename ( cache_dir, FILEBROWSER_CACHE_FILE, NULL ); + g_file_set_contents (path, pd->array[selected_line].path, -1, NULL ); + g_free(path); GFile *new = g_file_new_for_path ( pd->array[selected_line].path ); g_object_unref ( pd->current_dir ); pd->current_dir = new; |