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

[Script] Add new-selection option.

Allow you to select an entry (based on view, so might not work in combi
mode).

fixes: #1248
This commit is contained in:
Dave Davenport 2022-07-24 01:08:24 +02:00
parent d20926abab
commit f3064e0fee
2 changed files with 12 additions and 1 deletions

View file

@ -10,6 +10,7 @@ then
# Override the previously set prompt.
echo -en "\0theme\x1felement-text { background-color: "$@";}\n"
echo -en "\0keep-selection\x1ftrue\n"
echo -en "\0new-selection\x1f2\n"
echo "red"
echo "lightgreen"
echo "lightblue"

View file

@ -68,6 +68,7 @@ typedef struct {
char *data;
gboolean do_markup;
gboolean keep_selection;
int64_t new_selection;
char delim;
/** no custom */
gboolean no_custom;
@ -138,6 +139,8 @@ static void parse_header_entry(Mode *sw, char *line, ssize_t length) {
pd->use_hot_keys = (strcasecmp(value, "true") == 0);
} else if (strcasecmp(line, "keep-selection") == 0) {
pd->keep_selection = (strcasecmp(value, "true") == 0);
} else if (strcasecmp(line, "new-selection") == 0) {
pd->new_selection = (int64_t)g_ascii_strtoll(value, NULL, 0);
} else if (strcasecmp(line, "data") == 0) {
g_free(pd->data);
pd->data = g_strdup(value);
@ -160,7 +163,9 @@ static DmenuScriptEntry *execute_executor(Mode *sw, char *arg,
char **argv = NULL;
int argc = 0;
*length = 0;
// Reset these between runs.
pd->new_selection = -1;
pd->keep_selection = -1;
// Environment
char **env = g_get_environ();
@ -343,6 +348,11 @@ static ModeMode script_mode_result(Mode *sw, int mretv, char **input,
rmpd->cmd_list = new_list;
rmpd->cmd_list_length = new_length;
if (rmpd->keep_selection) {
if (rmpd->new_selection >= 0 &&
rmpd->new_selection < rmpd->cmd_list_length) {
rofi_view_set_selected_line(rofi_view_get_active(),
rmpd->new_selection);
}
retv = RELOAD_DIALOG;
} else {
retv = RESET_DIALOG;