mirror of
https://github.com/davatorium/rofi.git
synced 2025-11-06 22:54:53 -05:00
[Helper] Allow selecting different matching modes for cycling at runtime.
This commit is contained in:
parent
e2e961ff12
commit
111f169e13
4 changed files with 67 additions and 25 deletions
|
|
@ -361,6 +361,9 @@ Currently, the following methods are supported:
|
|||
|
||||
Default: *normal*
|
||||
|
||||
Multiple sorting methods can be specified in a comma separated list.
|
||||
The matching up/down keybinding allows cycling through at runtime.
|
||||
|
||||
Note: glob matching might be slow for larger lists
|
||||
|
||||
`-tokenize`
|
||||
|
|
|
|||
|
|
@ -446,7 +446,15 @@ Property *rofi_theme_find_property(ConfigEntry *widget, PropertyType type,
|
|||
/**
|
||||
* @returns get a human readable string with the current matching method.
|
||||
*/
|
||||
const char * helper_get_matching_mode_str(void);
|
||||
const char *helper_get_matching_mode_str(void);
|
||||
/**
|
||||
* Switch to the next matching method.
|
||||
*/
|
||||
void helper_select_next_matching_mode(void);
|
||||
/**
|
||||
* Switch to the previous matching method.
|
||||
*/
|
||||
void helper_select_previous_matching_mode(void);
|
||||
G_END_DECLS
|
||||
|
||||
/**@} */
|
||||
|
|
|
|||
|
|
@ -57,6 +57,14 @@
|
|||
|
||||
const char *const MatchingMethodStr[MM_NUM_MATCHERS] = {
|
||||
"Normal", "Regex", "Glob", "Fuzzy", "Prefix"};
|
||||
|
||||
static int MatchingMethodEnabled[MM_NUM_MATCHERS] = {
|
||||
MM_NORMAL,
|
||||
-1,
|
||||
};
|
||||
static int NUMMatchingMethodEnabled = 1;
|
||||
static int CurrentMatchingMethod = 0;
|
||||
|
||||
/**
|
||||
* Textual description of positioning rofi.
|
||||
*/
|
||||
|
|
@ -73,6 +81,19 @@ char *helper_string_replace_if_exists_v(char *string, GHashTable *h);
|
|||
const char *helper_get_matching_mode_str(void) {
|
||||
return MatchingMethodStr[config.matching_method];
|
||||
}
|
||||
void helper_select_next_matching_mode(void) {
|
||||
|
||||
CurrentMatchingMethod++;
|
||||
CurrentMatchingMethod %= NUMMatchingMethodEnabled;
|
||||
config.matching_method = MatchingMethodEnabled[CurrentMatchingMethod];
|
||||
}
|
||||
void helper_select_previous_matching_mode(void) {
|
||||
CurrentMatchingMethod--;
|
||||
if (CurrentMatchingMethod < 0) {
|
||||
CurrentMatchingMethod = NUMMatchingMethodEnabled - 1;
|
||||
}
|
||||
config.matching_method = MatchingMethodEnabled[CurrentMatchingMethod];
|
||||
}
|
||||
|
||||
void cmd_set_arguments(int argc, char **argv) {
|
||||
stored_argc = argc;
|
||||
|
|
@ -671,24 +692,38 @@ int config_sanity_check(void) {
|
|||
}
|
||||
|
||||
if (config.matching) {
|
||||
if (g_strcmp0(config.matching, "regex") == 0) {
|
||||
config.matching_method = MM_REGEX;
|
||||
} else if (g_strcmp0(config.matching, "glob") == 0) {
|
||||
config.matching_method = MM_GLOB;
|
||||
} else if (g_strcmp0(config.matching, "fuzzy") == 0) {
|
||||
config.matching_method = MM_FUZZY;
|
||||
} else if (g_strcmp0(config.matching, "normal") == 0) {
|
||||
config.matching_method = MM_NORMAL;
|
||||
;
|
||||
} else if (g_strcmp0(config.matching, "prefix") == 0) {
|
||||
config.matching_method = MM_PREFIX;
|
||||
} else {
|
||||
g_string_append_printf(msg,
|
||||
"\t<b>config.matching</b>=%s is not a valid "
|
||||
"matching strategy.\nValid options are: glob, "
|
||||
"regex, fuzzy, prefix or normal.\n",
|
||||
config.matching);
|
||||
found_error = 1;
|
||||
char **strv = g_strsplit(config.matching, ",", 0);
|
||||
int index = 0;
|
||||
if (strv) {
|
||||
for (char **str = strv; *str && index < MM_NUM_MATCHERS; str++) {
|
||||
bool found = FALSE;
|
||||
for (unsigned i = 0; i < MM_NUM_MATCHERS && index < MM_NUM_MATCHERS;
|
||||
i++) {
|
||||
if (g_ascii_strcasecmp(*str, MatchingMethodStr[i]) == 0) {
|
||||
MatchingMethodEnabled[index] = i;
|
||||
index++;
|
||||
NUMMatchingMethodEnabled = index;
|
||||
if (index == MM_NUM_MATCHERS) {
|
||||
found_error = 1;
|
||||
g_string_append_printf(msg,
|
||||
"\t<b>config.matching</b> = %s to many "
|
||||
"matching options enabled.\n",
|
||||
config.matching);
|
||||
}
|
||||
found = TRUE;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
g_string_append_printf(msg,
|
||||
"\t<b>config.matching</b>=%s is not a valid "
|
||||
"matching strategy.\nValid options are: glob, "
|
||||
"regex, fuzzy, prefix or normal.\n",
|
||||
*str);
|
||||
found_error = 1;
|
||||
}
|
||||
}
|
||||
config.matching_method = MatchingMethodEnabled[0];
|
||||
g_strfreev(strv);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1984,16 +1984,12 @@ static void rofi_view_trigger_global_action(KeyBindingAction action) {
|
|||
break;
|
||||
}
|
||||
case MATCHER_UP:
|
||||
config.matching_method = (config.matching_method + 1) % MM_NUM_MATCHERS;
|
||||
helper_select_next_matching_mode();
|
||||
rofi_view_refilter(state);
|
||||
rofi_view_set_overlay_timeout(state, helper_get_matching_mode_str());
|
||||
break;
|
||||
case MATCHER_DOWN:
|
||||
if (config.matching_method == 0) {
|
||||
config.matching_method = MM_NUM_MATCHERS - 1;
|
||||
} else {
|
||||
config.matching_method = (config.matching_method - 1) % MM_NUM_MATCHERS;
|
||||
}
|
||||
helper_select_previous_matching_mode();
|
||||
rofi_view_refilter(state);
|
||||
rofi_view_set_overlay_timeout(state, helper_get_matching_mode_str());
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue