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

Add methods for completer to modes.

This commit is contained in:
Dave Davenport 2023-06-04 14:36:14 +02:00
parent 7972420c30
commit 722f07a803
3 changed files with 8 additions and 39 deletions

View file

@ -232,12 +232,12 @@ struct rofi_mode {
/** /**
* Create mode. * Create mode.
*/ */
_mode_create create; _mode_create _create;
/** /**
* If this mode is used as completer. * If this mode is used as completer.
*/ */
_mode_completer_result completer_result; _mode_completer_result _completer_result;
/** Extra fields for script */ /** Extra fields for script */
void *ed; void *ed;

View file

@ -727,6 +727,8 @@ Mode file_browser_mode = {
._get_message = _get_message, ._get_message = _get_message,
._get_completion = _get_completion, ._get_completion = _get_completion,
._preprocess_input = NULL, ._preprocess_input = NULL,
._create = create_new_file_browser,
._completer_result = file_browser_mode_completer,
.private_data = NULL, .private_data = NULL,
.free = NULL, .free = NULL,
.type = MODE_TYPE_SWITCHER|MODE_TYPE_COMPLETER .type = MODE_TYPE_SWITCHER|MODE_TYPE_COMPLETER

View file

@ -487,7 +487,7 @@ Mode *create_new_recursive_browser(void) {
return sw; return sw;
} }
#if 0 #if 1
ModeMode recursive_browser_mode_completer(Mode *sw, int mretv, char **input, ModeMode recursive_browser_mode_completer(Mode *sw, int mretv, char **input,
unsigned int selected_line, unsigned int selected_line,
char **path) { char **path) {
@ -502,49 +502,15 @@ ModeMode recursive_browser_mode_completer(Mode *sw, int mretv, char **input,
retv = (mretv & MENU_LOWER_MASK); retv = (mretv & MENU_LOWER_MASK);
} else if ((mretv & MENU_OK)) { } else if ((mretv & MENU_OK)) {
if (selected_line < pd->array_length) { if (selected_line < pd->array_length) {
if (pd->array[selected_line].type == UP) { if (pd->array[selected_line].type == RFILE) {
GFile *new = g_file_get_parent(pd->current_dir);
if (new) {
g_object_unref(pd->current_dir);
pd->current_dir = new;
free_list(pd);
get_recursive_browser(sw, pd->current_dir);
return RESET_DIALOG;
}
} else if (pd->array[selected_line].type == DIRECTORY) {
GFile *new = g_file_new_for_path(pd->array[selected_line].path);
g_object_unref(pd->current_dir);
pd->current_dir = new;
free_list(pd);
get_recursive_browser(sw, pd->current_dir);
return RESET_DIALOG;
} else if (pd->array[selected_line].type == RFILE) {
*path = g_strescape(pd->array[selected_line].path, NULL); *path = g_strescape(pd->array[selected_line].path, NULL);
return MODE_EXIT; return MODE_EXIT;
} }
} }
retv = RELOAD_DIALOG; retv = RELOAD_DIALOG;
} else if ((mretv & MENU_CUSTOM_INPUT) && *input) { } else if ((mretv & MENU_CUSTOM_INPUT) && *input) {
char *p = rofi_expand_path(*input);
char *dir = g_filename_from_utf8(p, -1, NULL, NULL, NULL);
g_free(p);
if (g_file_test(dir, G_FILE_TEST_EXISTS)) {
if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
g_object_unref(pd->current_dir);
pd->current_dir = g_file_new_for_path(dir);
g_free(dir);
free_list(pd);
get_recursive_browser(sw, pd->current_dir);
return RESET_DIALOG;
}
}
g_free(dir);
retv = RELOAD_DIALOG; retv = RELOAD_DIALOG;
} else if ((mretv & MENU_ENTRY_DELETE) == MENU_ENTRY_DELETE) { } else if ((mretv & MENU_ENTRY_DELETE) == MENU_ENTRY_DELETE) {
recursive_browser_config.show_hidden =
!recursive_browser_config.show_hidden;
free_list(pd);
get_recursive_browser(sw, pd->current_dir);
retv = RELOAD_DIALOG; retv = RELOAD_DIALOG;
} }
return retv; return retv;
@ -566,8 +532,9 @@ Mode recursive_browser_mode = {
._get_message = _get_message, ._get_message = _get_message,
._get_completion = _get_completion, ._get_completion = _get_completion,
._preprocess_input = NULL, ._preprocess_input = NULL,
._create = create_new_recursive_browser,
._completer_result = recursive_browser_mode_completer,
.private_data = NULL, .private_data = NULL,
.free = NULL, .free = NULL,
.create = create_new_recursive_browser,
.type = MODE_TYPE_SWITCHER|MODE_TYPE_COMPLETER .type = MODE_TYPE_SWITCHER|MODE_TYPE_COMPLETER
}; };