summaryrefslogtreecommitdiffstats
path: root/source/dialogs
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2016-05-26 08:39:33 +0200
committerDave Davenport <qball@gmpclient.org>2016-05-26 08:39:33 +0200
commit0e86050db8d3e20a93fada37724d9c8d59386c55 (patch)
tree835d1e58c9652b8d708a17074c6c922c74f60025 /source/dialogs
parent7aff2ae243f4d15875a5a6d567112400a727e642 (diff)
Fix combi mode 'bang' behaviour, improve levenshtein with combi
Diffstat (limited to 'source/dialogs')
-rw-r--r--source/dialogs/combi.c50
-rw-r--r--source/dialogs/dmenu.c5
-rw-r--r--source/dialogs/drun.c9
-rw-r--r--source/dialogs/run.c3
-rw-r--r--source/dialogs/script.c1
-rw-r--r--source/dialogs/ssh.c1
-rw-r--r--source/dialogs/window.c11
7 files changed, 43 insertions, 37 deletions
diff --git a/source/dialogs/combi.c b/source/dialogs/combi.c
index 89c634b8..7cba5200 100644
--- a/source/dialogs/combi.c
+++ b/source/dialogs/combi.c
@@ -45,6 +45,7 @@ typedef struct
// List of switchers to combine.
unsigned int num_switchers;
Mode **switchers;
+ Mode *current;
} CombiModePrivateData;
static void combi_mode_parse_switchers ( Mode *sw )
@@ -178,34 +179,14 @@ static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned
static int combi_mode_match ( const Mode *sw, GRegex **tokens, unsigned int index )
{
CombiModePrivateData *pd = mode_get_private_data ( sw );
-// if ( config.regex || config.glob ) {
- // Bang support only works in text mode.
- for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
- if ( index >= pd->starts[i] && index < ( pd->starts[i] + pd->lengths[i] ) ) {
- return mode_token_match ( pd->switchers[i], tokens, index - pd->starts[i] );
- }
+ for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
+ if ( pd->current != NULL && pd->switchers[i] != pd->current ) {
+ continue;
}
- /* @TODO fix this
- }
- else{
- for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
- if ( index >= pd->starts[i] && index < ( pd->starts[i] + pd->lengths[i] ) ) {
- if ( tokens && tokens[0][0] == '!' ) {
- if ( tokens[0][1] == mode_get_name ( pd->switchers[i] )[0] ) {
- return mode_token_match ( pd->switchers[i], &tokens[1], not_ascii, case_sensitive,
- index - pd->starts[i] );
- }
- return 0;
- }
- else {
- return mode_token_match ( pd->switchers[i], tokens, not_ascii, case_sensitive,
- index - pd->starts[i] );
- }
- }
+ if ( index >= pd->starts[i] && index < ( pd->starts[i] + pd->lengths[i] ) ) {
+ return mode_token_match ( pd->switchers[i], tokens, index - pd->starts[i] );
}
}
- */
- abort ();
return 0;
}
static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *state, int get_entry )
@@ -247,6 +228,24 @@ static char * combi_get_completion ( const Mode *sw, unsigned int index )
return NULL;
}
+static char * combi_preprocess_input ( Mode *sw, const char *input )
+{
+ CombiModePrivateData *pd = mode_get_private_data ( sw );
+ pd->current = NULL;
+ if ( input != NULL && input[0] == '!' && strlen ( input ) > 1 ) {
+ for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
+ if ( input[1] == mode_get_name ( pd->switchers[i] )[0] ) {
+ pd->current = pd->switchers[i];
+ if ( input[2] == '\0' ) {
+ return NULL;
+ }
+ return g_strdup ( &input[2] );
+ }
+ }
+ }
+ return g_strdup ( input );
+}
+
#include "mode-private.h"
Mode combi_mode =
{
@@ -259,6 +258,7 @@ Mode combi_mode =
._token_match = combi_mode_match,
._get_completion = combi_get_completion,
._get_display_value = combi_mgrv,
+ ._preprocess_input = combi_preprocess_input,
.private_data = NULL,
.free = NULL
};
diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c
index 4d4cdbbc..c7b016aa 100644
--- a/source/dialogs/dmenu.c
+++ b/source/dialogs/dmenu.c
@@ -350,6 +350,7 @@ Mode dmenu_mode =
._token_match = dmenu_token_match,
._get_display_value = get_display_data,
._get_completion = NULL,
+ ._preprocess_input = NULL,
.private_data = NULL,
.free = NULL
};
@@ -509,7 +510,7 @@ int dmenu_switcher_dialog ( void )
char *select = NULL;
find_arg_str ( "-select", &select );
if ( select != NULL ) {
- GRegex **tokens = tokenize ( select, config.case_sensitive );
+ GRegex **tokens = tokenize ( select, config.case_sensitive );
unsigned int i = 0;
for ( i = 0; i < cmd_list_length; i++ ) {
if ( token_match ( tokens, cmd_list[i] ) ) {
@@ -520,7 +521,7 @@ int dmenu_switcher_dialog ( void )
tokenize_free ( tokens );
}
if ( find_arg ( "-dump" ) >= 0 ) {
- GRegex **tokens = tokenize ( config.filter ? config.filter : "", config.case_sensitive );
+ GRegex **tokens = tokenize ( config.filter ? config.filter : "", config.case_sensitive );
unsigned int i = 0;
for ( i = 0; i < cmd_list_length; i++ ) {
if ( token_match ( tokens, cmd_list[i] ) ) {
diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c
index 39fee13f..fcab4f0e 100644
--- a/source/dialogs/drun.c
+++ b/source/dialogs/drun.c
@@ -378,24 +378,24 @@ static char *drun_get_completion ( const Mode *sw, unsigned int index )
}
}
-static int drun_token_match ( const Mode *data, GRegex **tokens, unsigned int index)
+static int drun_token_match ( const Mode *data, GRegex **tokens, unsigned int index )
{
DRunModePrivateData *rmpd = (DRunModePrivateData *) mode_get_private_data ( data );
int match = 1;
if ( tokens ) {
for ( int j = 0; match && tokens != NULL && tokens[j] != NULL; j++ ) {
- int test = 0;
+ int test = 0;
GRegex *ftokens[2] = { tokens[j], NULL };
if ( !test && rmpd->entry_list[index].name &&
token_match ( ftokens, rmpd->entry_list[index].name ) ) {
test = 1;
}
if ( !test && rmpd->entry_list[index].generic_name &&
- token_match ( ftokens, rmpd->entry_list[index].generic_name) ) {
+ token_match ( ftokens, rmpd->entry_list[index].generic_name ) ) {
test = 1;
}
- if ( !test && token_match ( ftokens, rmpd->entry_list[index].exec) ) {
+ if ( !test && token_match ( ftokens, rmpd->entry_list[index].exec ) ) {
test = 1;
}
if ( test == 0 ) {
@@ -423,6 +423,7 @@ Mode drun_mode =
._token_match = drun_token_match,
._get_completion = drun_get_completion,
._get_display_value = _get_display_value,
+ ._preprocess_input = NULL,
.private_data = NULL,
.free = NULL
};
diff --git a/source/dialogs/run.c b/source/dialogs/run.c
index 51db25d9..523a0b4e 100644
--- a/source/dialogs/run.c
+++ b/source/dialogs/run.c
@@ -421,7 +421,7 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_
static int run_token_match ( const Mode *sw, GRegex **tokens, unsigned int index )
{
const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data;
- return token_match ( tokens, rmpd->cmd_list[index]);
+ return token_match ( tokens, rmpd->cmd_list[index] );
}
#include "mode-private.h"
@@ -436,6 +436,7 @@ Mode run_mode =
._token_match = run_token_match,
._get_display_value = _get_display_value,
._get_completion = NULL,
+ ._preprocess_input = NULL,
.private_data = NULL,
.free = NULL
};
diff --git a/source/dialogs/script.c b/source/dialogs/script.c
index 3abb2aba..bac6e1b8 100644
--- a/source/dialogs/script.c
+++ b/source/dialogs/script.c
@@ -200,6 +200,7 @@ Mode *script_switcher_parse_setup ( const char *str )
sw->_destroy = script_mode_destroy;
sw->_token_match = script_token_match;
sw->_get_completion = NULL,
+ sw->_preprocess_input = NULL,
sw->_get_display_value = _get_display_value;
return sw;
diff --git a/source/dialogs/ssh.c b/source/dialogs/ssh.c
index 3bf38f8e..331e5431 100644
--- a/source/dialogs/ssh.c
+++ b/source/dialogs/ssh.c
@@ -498,6 +498,7 @@ Mode ssh_mode =
._token_match = ssh_token_match,
._get_display_value = _get_display_value,
._get_completion = NULL,
+ ._preprocess_input = NULL,
.private_data = NULL,
.free = NULL
};
diff --git a/source/dialogs/window.c b/source/dialogs/window.c
index a2918bb7..56ff8d01 100644
--- a/source/dialogs/window.c
+++ b/source/dialogs/window.c
@@ -338,19 +338,19 @@ static int window_match ( const Mode *sw, GRegex **tokens, unsigned int index )
// e.g. when searching 'title element' and 'class element'
GRegex *ftokens[2] = { tokens[j], NULL };
if ( !test && c->title != NULL && c->title[0] != '\0' ) {
- test = token_match ( ftokens, c->title);
+ test = token_match ( ftokens, c->title );
}
if ( !test && c->class != NULL && c->class[0] != '\0' ) {
- test = token_match ( ftokens, c->class);
+ test = token_match ( ftokens, c->class );
}
if ( !test && c->role != NULL && c->role[0] != '\0' ) {
- test = token_match ( ftokens, c->role);
+ test = token_match ( ftokens, c->role );
}
if ( !test && c->name != NULL && c->name[0] != '\0' ) {
- test = token_match ( ftokens, c->name);
+ test = token_match ( ftokens, c->name );
}
if ( test == 0 ) {
@@ -653,7 +653,6 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, in
return get_entry ? g_strdup ( rmpd->cmd_list[selected_line] ) : NULL;
}
-
#include "mode-private.h"
Mode window_mode =
{
@@ -666,6 +665,7 @@ Mode window_mode =
._token_match = window_match,
._get_display_value = _get_display_value,
._get_completion = NULL,
+ ._preprocess_input = NULL,
.private_data = NULL,
.free = NULL
};
@@ -680,6 +680,7 @@ Mode window_mode_cd =
._token_match = window_match,
._get_display_value = _get_display_value,
._get_completion = NULL,
+ ._preprocess_input = NULL,
.private_data = NULL,
.free = NULL
};