diff options
author | portix <portix@gmx.net> | 2012-01-03 11:23:30 +0100 |
---|---|---|
committer | portix <portix@gmx.net> | 2012-01-03 11:23:30 +0100 |
commit | f224f93a7e9bd6ece4d81ad81826566a8ef2da38 (patch) | |
tree | 2f8cb7a12f67522ebcc5b3b001698170113e6e65 | |
parent | abbe6267ef09fc0a78f677355a3ac4ce1d96c62a (diff) | |
download | dwb-f224f93a7e9bd6ece4d81ad81826566a8ef2da38.zip |
Complete urls in command mode
--HG--
branch : experimental
-rw-r--r-- | src/completion.c | 77 | ||||
-rw-r--r-- | src/dwb.h | 33 | ||||
-rw-r--r-- | src/util.c | 7 | ||||
-rw-r--r-- | src/util.h | 1 |
4 files changed, 93 insertions, 25 deletions
diff --git a/src/completion.c b/src/completion.c index 2908aba8..c2f960e4 100644 --- a/src/completion.c +++ b/src/completion.c @@ -32,6 +32,8 @@ typedef gboolean (*Match_Func)(char*, const char*); static char *_typed; static int _last_buf; static gboolean _leading0 = false; +static char *_current_command; +static int _command_len; /* GUI_FUNCTIONS {{{*/ /* completion_modify_completion_item(Completion *c, GdkColor *fg, GdkColor *bg, PangoFontDescription *fd) {{{*/ @@ -84,6 +86,10 @@ completion_init_completion(GList *store, GList *gl, gboolean word_beginnings, vo Navigation *n; const char *input = GET_TEXT(); _typed = g_strdup(input); + if (dwb.state.mode & COMMAND_MODE) + input = strchr(input, ' '); + if (input == NULL) + input = ""; Match_Func func = word_beginnings ? (Match_Func)g_str_has_prefix : (Match_Func)util_strcasestr; for (GList *l = gl; l; l=l->next) { @@ -109,7 +115,15 @@ completion_set_entry_text(Completion *c) { break; } - gtk_entry_set_text(GTK_ENTRY(dwb.gui.entry), text); + if (dwb.state.mode & COMMAND_MODE && _current_command) { + gtk_entry_set_text(GTK_ENTRY(dwb.gui.entry), _current_command); + int l = strlen(_current_command); + gtk_editable_insert_text(GTK_EDITABLE(dwb.gui.entry), " ", -1, &l); + gtk_editable_insert_text(GTK_EDITABLE(dwb.gui.entry), text, -1, &_command_len); + } + else { + gtk_entry_set_text(GTK_ENTRY(dwb.gui.entry), text); + } gtk_editable_set_position(GTK_EDITABLE(dwb.gui.entry), -1); }/*}}}*/ @@ -199,10 +213,12 @@ completion_clean_completion(gboolean set_text) { dwb.comps.active_comp = NULL; if (set_text && _typed != NULL) entry_set_text(_typed); - if (_typed != NULL) { - g_free(_typed); - _typed = NULL; - } + + FREE0(_current_command); + _command_len = 0; + + FREE0(_typed); + if (dwb.state.mode & COMPLETE_BUFFER) { _last_buf = 0; _leading0 = false; @@ -242,10 +258,12 @@ static GList * completion_get_normal_completion() { GList *list = NULL; - if (dwb.state.complete_userscripts) - list = completion_init_completion(list, dwb.misc.userscripts, false, NULL, "Userscript"); - if (dwb.state.complete_searchengines) - list = completion_init_completion(list, dwb.fc.se_completion, false, NULL, "Searchengine"); + if (!(dwb.state.mode & COMMAND_MODE) ) { + if (dwb.state.complete_userscripts) + list = completion_init_completion(list, dwb.misc.userscripts, false, NULL, "Userscript"); + if (dwb.state.complete_searchengines) + list = completion_init_completion(list, dwb.fc.se_completion, false, NULL, "Searchengine"); + } if (dwb.state.complete_bookmarks) list = completion_init_completion(list, dwb.fc.bookmarks, false, NULL, "Bookmark"); if (dwb.state.complete_history) @@ -428,11 +446,50 @@ completion_complete_buffer() { return list; }/*}}}*/ +static gboolean +completion_command_line() { + KeyMap *km = NULL; + gboolean ret = false; + + const char *text = GET_TEXT(); + while (g_ascii_isspace(*text)) + text++; + char **token = g_strsplit(text, " ", 2); + if (dwb.state.mode & COMMAND_MODE) { + for (GList *l = dwb.keymap; l; l=l->next) { + km = l->data; + if (! g_strcmp0(token[0], km->map->n.first) && km->map->entry & EP_COMP_DEFAULT) { + ret = true; + break; + } + } + } + if (ret) { + _command_len = util_strlen_trailing_space(text); + if (_command_len > 0 && g_ascii_isspace(text[_command_len-1])) { + _current_command = g_strdup(token[0]); + dwb.state.mode |= COMPLETE_COMMAND_MODE; + _command_len++; + } + else { + gtk_editable_insert_text(GTK_EDITABLE(dwb.gui.entry), " ", 1, &_command_len); + gtk_editable_set_position(GTK_EDITABLE(dwb.gui.entry), -1); + ret = false; + } + } + g_strfreev(token); + return ret; +} /* completion_complete {{{*/ DwbStatus completion_complete(CompletionType type, int back) { DwbStatus ret = STATUS_OK; - dwb.state.mode &= ~(COMPLETE_PATH | AUTO_COMPLETE); + if (dwb.state.mode & COMMAND_MODE) { + if (completion_command_line()) + type = COMP_NONE; + } + + dwb.state.mode &= ~(COMPLETE_PATH | AUTO_COMPLETE | COMPLETE_COMMAND_MODE); if ( !(dwb.state.mode & COMPLETION_MODE) ) { dwb.gui.compbox = gtk_vbox_new(true, 0); gtk_box_pack_start(GTK_BOX(dwb.gui.bottombox), dwb.gui.compbox, false, false, 0); @@ -115,6 +115,7 @@ #define STRCMP_FIRST_WORD(a, b) (strncmp((a), (b), MAX(strstr((a), " ") - a, strstr((b), " ") - b))) #define FREE(X) if ((X)) g_free((X)) +#define FREE0(X) ((X == NULL) ? NULL : (X = (g_free(X), NULL))) #define ALPHA(X) ((X->keyval >= GDK_KEY_A && X->keyval <= GDK_KEY_Z) || (X->keyval >= GDK_KEY_a && X->keyval <= GDK_KEY_z) || X->keyval == GDK_KEY_space) #define DIGIT(X) (X->keyval >= GDK_KEY_0 && X->keyval <= GDK_KEY_9) @@ -202,26 +203,27 @@ typedef DwbStatus (*S_Func)(void *, WebSettings *); typedef void *(*Content_Func)(void *); typedef enum { - COMP_NONE = 0x00, - COMP_BOOKMARK = 0x01, - COMP_HISTORY = 0x02, - COMP_SETTINGS = 0x03, - COMP_KEY = 0x04, - COMP_COMMAND = 0x05, - COMP_USERSCRIPT = 0x06, - COMP_SEARCH = 0x08, - COMP_PATH = 0x09, - COMP_CUR_HISTORY = 0x0a, - COMP_BUFFER = 0x0b, - COMP_QUICKMARK = 0x0c, + COMP_NONE = 1, + COMP_BOOKMARK, + COMP_HISTORY, + COMP_SETTINGS, + COMP_KEY, + COMP_COMMAND, + COMP_USERSCRIPT, + COMP_SEARCH, + COMP_PATH, + COMP_CUR_HISTORY, + COMP_BUFFER, + COMP_QUICKMARK, } CompletionType; enum { EP_NONE = 0, EP_ENTRY = 1<<0, EP_COMP_DEFAULT = 1<<1, - + EP_COMP_QUICKMARK = 1<<2, } EntryProp; +#define EP_COMPLETION (EP_COMP_DEFAULT | EP_COMP_QUICKMARK) typedef enum { @@ -276,8 +278,9 @@ typedef enum { COMPLETE_PATH = 1<<16, COMPLETE_BUFFER = 1<<17, COMPLETE_QUICKMARKS = 1<<18, - PASS_THROUGH = 1<<19, - CONFIRM = 1<<20, + COMPLETE_COMMAND_MODE = 1<<19, + PASS_THROUGH = 1<<20, + CONFIRM = 1<<21, } Mode; @@ -680,3 +680,10 @@ util_strcasestr(const char *haystack, const char *needle) { } return NULL; } +int +util_strlen_trailing_space(const char *str) { + int len; + for (len=0; *str != '\0'; str++, len++); + return len; + +} @@ -93,5 +93,6 @@ char * util_strcasestr(const char *haystack, const char *needle); int util_file_remove_line(const char *, const char *); Arg * util_arg_new(void); char * util_check_directory(char *); +int util_strlen_trailing_space(const char *str); #endif |