1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

[FileBrowser] Allow command to be overwritten

This commit is contained in:
Dave Davenport 2023-01-11 00:20:57 +01:00
parent b02a9d552b
commit 82b2ce9435
3 changed files with 18 additions and 2 deletions

View file

@ -38,7 +38,7 @@ To show the \fB\fCdrun\fR dialog:
.RE
.PP
A very useful setup in minimalistic window managers is to combine \fB\fCdrun\fR, \fB\fCrun\fR
A useful setup in minimalistic window managers is to combine \fB\fCdrun\fR, \fB\fCrun\fR
with \fB\fCwindow\fR mode:
.PP
@ -1157,6 +1157,8 @@ configuration {
show-hidden: false;
/** return 1 on cancel. */
cancel-returns-1: true;
/** command */
command: "xdg-open";
}
}

View file

@ -712,6 +712,8 @@ configuration {
show-hidden: false;
/** return 1 on cancel. */
cancel-returns-1: true;
/** command */
command: "xdg-open";
}
}
```

View file

@ -50,6 +50,7 @@
#include "rofi-icon-fetcher.h"
#define FILEBROWSER_CACHE_FILE "rofi3.filebrowsercache"
#define DEFAULT_OPEN "xdg-open"
#if defined(__APPLE__)
#define st_atim st_atimespec
@ -97,6 +98,7 @@ typedef struct {
} FBFile;
typedef struct {
char *command;
GFile *current_dir;
FBFile *array;
unsigned int array_length;
@ -344,6 +346,7 @@ static void get_file_browser(Mode *sw) {
}
static void file_browser_mode_init_config(Mode *sw) {
FileBrowserModePrivateData * pd = (FileBrowserModePrivateData*)mode_get_private_data(sw);
char *msg = NULL;
gboolean found_error = FALSE;
@ -380,6 +383,14 @@ static void file_browser_mode_init_config(Mode *sw) {
file_browser_config.show_hidden = p->value.b;
}
p = rofi_theme_find_property(wid, P_STRING, "command", TRUE);
if ( p != NULL && p->type == P_STRING ) {
pd->command = g_strdup(p->value.s);
} else {
pd->command = g_strdup(DEFAULT_OPEN);
}
if (found_error) {
rofi_view_error_dialog(msg, FALSE);
@ -484,7 +495,7 @@ static ModeMode file_browser_mode_result(Mode *sw, int mretv, char **input,
(pd->array[selected_line].type == DIRECTORY &&
special_command)) {
char *d_esc = g_shell_quote(pd->array[selected_line].path);
char *cmd = g_strdup_printf("xdg-open %s", d_esc);
char *cmd = g_strdup_printf("%s %s",pd->command, d_esc);
g_free(d_esc);
char *cdir = g_file_get_path(pd->current_dir);
helper_execute_command(cdir, cmd, FALSE, NULL);
@ -546,6 +557,7 @@ static void file_browser_mode_destroy(Mode *sw) {
(FileBrowserModePrivateData *)mode_get_private_data(sw);
if (pd != NULL) {
g_object_unref(pd->current_dir);
g_free(pd->command);
free_list(pd);
g_free(pd);
mode_set_private_data(sw, NULL);