mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
[FileBrowser] Allow setting startup directory (#1325)
This commit is contained in:
parent
12b2b38578
commit
c1244b066f
6 changed files with 62 additions and 15 deletions
|
@ -128,6 +128,9 @@ Settings config = {
|
|||
/** Desktop Link launch command */
|
||||
.drun_url_launcher = "xdg-open",
|
||||
|
||||
/** Directory the file browser starts in */
|
||||
.file_browser_directory = NULL,
|
||||
|
||||
/** Window fields to match in window mode*/
|
||||
.window_match_fields = "all",
|
||||
/** Monitor */
|
||||
|
|
13
doc/rofi.1
13
doc/rofi.1
|
@ -1181,6 +1181,19 @@ Set ellipsize mode to start. So end of string is visible.
|
|||
Pops up a message dialog (used internally for showing errors) with \fImessage\fP\&.
|
||||
Message can be multi\-line.
|
||||
|
||||
.SS File browser settings
|
||||
.PP
|
||||
\fB\fC\-file\-browser\-directory\fR \fIdirectory\fP
|
||||
|
||||
.PP
|
||||
Directory the file browser starts in.
|
||||
|
||||
.PP
|
||||
.RS
|
||||
|
||||
.fi
|
||||
.RE
|
||||
|
||||
.SS Other
|
||||
.PP
|
||||
\fB\fC\-drun\-use\-desktop\-cache\fR
|
||||
|
|
|
@ -721,6 +721,12 @@ Set ellipsize mode to start. So end of string is visible.
|
|||
Pops up a message dialog (used internally for showing errors) with *message*.
|
||||
Message can be multi-line.
|
||||
|
||||
### File browser settings
|
||||
|
||||
`-file-browser-directory` *directory*
|
||||
|
||||
Directory the file browser starts in.
|
||||
|
||||
### Other
|
||||
|
||||
`-drun-use-desktop-cache`
|
||||
|
|
|
@ -132,6 +132,9 @@ typedef struct
|
|||
/** Desktop Link launch command */
|
||||
char * drun_url_launcher;
|
||||
|
||||
/** Directory the file browser starts in */
|
||||
char * file_browser_directory;
|
||||
|
||||
/** Search case sensitivity */
|
||||
unsigned int case_sensitive;
|
||||
/** Cycle through in the element list */
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "mode-private.h"
|
||||
#include "dialogs/filebrowser.h"
|
||||
#include "rofi.h"
|
||||
#include "settings.h"
|
||||
#include "history.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
@ -193,6 +194,36 @@ static void get_file_browser ( Mode *sw )
|
|||
g_qsort_with_data ( pd->array, pd->array_length, sizeof ( FBFile ), compare, NULL );
|
||||
}
|
||||
|
||||
static void file_browser_mode_init_current_dir ( Mode *sw ) {
|
||||
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
|
||||
|
||||
gboolean config_has_valid_dir = config.file_browser_directory != NULL
|
||||
&& g_file_test ( config.file_browser_directory, G_FILE_TEST_IS_DIR );
|
||||
|
||||
if ( config_has_valid_dir ) {
|
||||
pd->current_dir = g_file_new_for_path ( config.file_browser_directory );
|
||||
} else {
|
||||
char *current_dir = NULL;
|
||||
char *cache_file = g_build_filename ( cache_dir, FILEBROWSER_CACHE_FILE, NULL );
|
||||
|
||||
if ( g_file_get_contents ( cache_file, ¤t_dir, NULL, NULL ) ) {
|
||||
if ( g_file_test ( current_dir, G_FILE_TEST_IS_DIR ) ) {
|
||||
pd->current_dir = g_file_new_for_path ( current_dir );
|
||||
}
|
||||
|
||||
g_free ( current_dir );
|
||||
}
|
||||
|
||||
// Store it based on the unique identifiers (desktop_id).
|
||||
g_free ( cache_file );
|
||||
}
|
||||
|
||||
|
||||
if ( pd->current_dir == NULL ) {
|
||||
pd->current_dir = g_file_new_for_path ( g_get_home_dir () );
|
||||
}
|
||||
}
|
||||
|
||||
static int file_browser_mode_init ( Mode *sw )
|
||||
{
|
||||
/**
|
||||
|
@ -201,21 +232,9 @@ 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 );
|
||||
{
|
||||
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 () );
|
||||
}
|
||||
}
|
||||
|
||||
file_browser_mode_init_current_dir ( sw );
|
||||
|
||||
// Load content.
|
||||
get_file_browser ( sw );
|
||||
}
|
||||
|
|
|
@ -145,6 +145,9 @@ static XrmOption xrmOptions[] = {
|
|||
{ xrm_String, "drun-url-launcher", { .str = &config.drun_url_launcher }, NULL,
|
||||
"Command to open an Desktop Entry that is a Link.", CONFIG_DEFAULT },
|
||||
|
||||
{ xrm_String, "file-browser-directory", { .str = &config.file_browser_directory }, NULL,
|
||||
"Directory the file browser starts in", CONFIG_DEFAULT },
|
||||
|
||||
{ xrm_Boolean, "disable-history", { .num = &config.disable_history }, NULL,
|
||||
"Disable history in run/ssh", CONFIG_DEFAULT },
|
||||
{ xrm_String, "ignored-prefixes", { .str = &config.ignored_prefixes }, NULL,
|
||||
|
|
Loading…
Reference in a new issue