Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FileBrowser] Allow setting startup directory #1325

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
13 changes: 13 additions & 0 deletions doc/rofi.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions doc/rofi.1.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
3 changes: 3 additions & 0 deletions include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
49 changes: 34 additions & 15 deletions source/dialogs/filebrowser.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "mode-private.h"
#include "dialogs/filebrowser.h"
#include "rofi.h"
#include "settings.h"
#include "history.h"

#include <stdint.h>
Expand Down Expand Up @@ -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, &current_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 )
{
/**
Expand All @@ -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 );
}
Expand Down
3 changes: 3 additions & 0 deletions source/xrmoptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down