summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorportix <none@none>2013-02-19 22:59:56 +0100
committerportix <none@none>2013-02-19 22:59:56 +0100
commitdfb9b624d3520e514f328fff7ecd1d4031c8286d (patch)
treeb3028aee0dc70b3657a8cc002f8cc0c55f76418e
parentf614ebb8fe343a2ef3ee14c68ee3317fa3f968b6 (diff)
downloaddwb-dfb9b624d3520e514f328fff7ecd1d4031c8286d.zip
Filter command/search/navigation history
-rw-r--r--src/commands.c2
-rw-r--r--src/completion.c2
-rw-r--r--src/dwb.c14
-rw-r--r--src/dwb.h1
-rw-r--r--src/entry.c62
-rw-r--r--src/entry.h2
6 files changed, 63 insertions, 20 deletions
diff --git a/src/commands.c b/src/commands.c
index 27dc3d84..50ed6d35 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -64,7 +64,7 @@ commands_simple_command(KeyMap *km, const char *argument)
dwb_set_normal_message(dwb.state.fview, false, "%s:", km->map->n.second);
else if (km->map->hide == ALWAYS_SM)
{
- gtk_widget_hide(dwb.gui.entry);
+ entry_hide();
CLEAR_COMMAND_TEXT();
}
break;
diff --git a/src/completion.c b/src/completion.c
index 9074d3c8..c3a29052 100644
--- a/src/completion.c
+++ b/src/completion.c
@@ -765,7 +765,7 @@ completion_init_autocompletion(GList *gl)
}
}
gtk_box_pack_start(GTK_BOX(dwb.gui.status_hbox), dwb.gui.autocompletion, true, true, 10);
- gtk_widget_hide(dwb.gui.entry);
+ entry_hide();
gtk_widget_hide(dwb.gui.rstatus);
gtk_widget_hide(dwb.gui.urilabel);
gtk_widget_show(dwb.gui.autocompletion);
diff --git a/src/dwb.c b/src/dwb.c
index 519a450a..0f70a858 100644
--- a/src/dwb.c
+++ b/src/dwb.c
@@ -663,7 +663,7 @@ dwb_set_error_message(GList *gl, const char *error, ...)
webkit_dom_html_element_set_inner_text(WEBKIT_DOM_HTML_ELEMENT(VIEW(gl)->status_element), message, NULL);
}
dwb.state.message_id = g_timeout_add_seconds(dwb.misc.message_delay, (GSourceFunc)dwb_hide_message, NULL);
- gtk_widget_hide(dwb.gui.entry);
+ entry_hide();
}/*}}}*/
static gboolean
@@ -1646,7 +1646,7 @@ dwb_focus_scroll(GList *gl)
gtk_widget_set_can_focus(v->web, true);
gtk_widget_grab_focus(v->web);
- gtk_widget_hide(dwb.gui.entry);
+ entry_hide();
}/*}}}*/
/* dwb_handle_mail(const char *uri) return: true if it is a mail-address{{{*/
@@ -2348,9 +2348,6 @@ dwb_update_layout()
void
dwb_focus(GList *gl)
{
- if (dwb.gui.entry)
- gtk_widget_hide(dwb.gui.entry);
-
dwb.state.fview = gl;
view_set_active_style(gl);
dwb_focus_scroll(gl);
@@ -2826,6 +2823,9 @@ dwb_eval_override_key(GdkEventKey *e, CommandProperty prop)
gboolean isprint;
gboolean ret = false;
+ if (gtk_widget_has_focus(dwb.gui.entry) && e->keyval == GDK_KEY_BackSpace)
+ entry_clear_history();
+
if (CLEAN_STATE(e) && (key = dwb_get_key(e, &mod, &isprint)) != NULL)
{
for (GList *l = dwb.override_keys; l; l=l->next)
@@ -4424,6 +4424,10 @@ dwb_init_vars(void)
dwb.misc.bar_height = 0;
dwb.state.last_tab = 0;
+
+ dwb.state.last_com_history = NULL;
+ dwb.state.last_nav_history = NULL;
+ dwb.state.last_find_history = NULL;
}
diff --git a/src/dwb.h b/src/dwb.h
index 4767d377..045ca83f 100644
--- a/src/dwb.h
+++ b/src/dwb.h
@@ -128,6 +128,7 @@
#define STRCMP_FIRST_WORD(a, b) (strncmp((a), (b), MAX(strstr((a), " ") - a, strstr((b), " ") - b)))
#define FREE0(X) ((X == NULL) ? NULL : (X = (g_free(X), NULL)))
+#define GLIST_FREE0(X) ((X == NULL) ? NULL : (X = (g_list_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)
diff --git a/src/entry.c b/src/entry.c
index 52f8794c..19175ccb 100644
--- a/src/entry.c
+++ b/src/entry.c
@@ -16,19 +16,28 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+
+#include <string.h>
#include "dwb.h"
#include "entry.h"
static char *s_store;
+static GList *s_filterlist;
/* dwb_entry_history_forward {{{*/
DwbStatus
entry_history_forward(GList **last)
{
+ if (s_filterlist == NULL)
+ return STATUS_ERROR;
+
const char *text = NULL;
GList *prev = NULL;
if (*last != NULL)
{
if ((*last)->prev == NULL)
+ {
text = s_store;
+ GLIST_FREE0(s_filterlist);
+ }
else
{
prev = (*last)->prev;
@@ -53,9 +62,22 @@ entry_history_back(GList **list, GList **last)
GList *next;
if (*last == NULL)
{
- next = *list;
- g_free(s_store);
- s_store = g_strdup(GET_TEXT());
+ const char *text = GET_TEXT();
+ if (text && *text) {
+ for (GList *l = *list; l; l=l->next)
+ {
+ if (strstr(l->data, text)) {
+ s_filterlist = g_list_prepend(s_filterlist, l->data);
+ }
+ }
+ if (s_filterlist)
+ s_filterlist = g_list_reverse(s_filterlist);
+ }
+ else
+ s_filterlist = g_list_copy(*list);
+
+ next = s_filterlist;
+ s_store = g_strdup(text);
}
else if ((*last)->next != NULL)
next = (*last)->next;
@@ -74,19 +96,33 @@ entry_history_back(GList **list, GList **last)
/* entry_focus() {{{*/
void
-entry_focus() {
- if (! (dwb.state.bar_visible & BAR_VIS_STATUS))
- gtk_widget_show_all(dwb.gui.bottombox);
+entry_focus()
+{
+ if (! (dwb.state.bar_visible & BAR_VIS_STATUS))
+ gtk_widget_show_all(dwb.gui.bottombox);
- gtk_widget_show(dwb.gui.entry);
- gtk_widget_grab_focus(dwb.gui.entry);
- gtk_widget_set_can_focus(CURRENT_WEBVIEW_WIDGET(), false);
- gtk_editable_delete_text(GTK_EDITABLE(dwb.gui.entry), 0, -1);
- dwb.state.last_com_history = NULL;
- dwb.state.last_nav_history = NULL;
- dwb.state.last_find_history = NULL;
+ gtk_widget_show(dwb.gui.entry);
+ gtk_widget_grab_focus(dwb.gui.entry);
+ gtk_widget_set_can_focus(CURRENT_WEBVIEW_WIDGET(), false);
+ gtk_editable_delete_text(GTK_EDITABLE(dwb.gui.entry), 0, -1);
}/*}}}*/
+void
+entry_clear_history()
+{
+ dwb.state.last_com_history = NULL;
+ dwb.state.last_nav_history = NULL;
+ dwb.state.last_find_history = NULL;
+ FREE0(s_store);
+ GLIST_FREE0(s_filterlist);
+}
+void
+entry_hide()
+{
+ gtk_widget_hide(dwb.gui.entry);
+ entry_clear_history();
+}
+
/* entry_insert_text(const char *) {{{*/
void
entry_insert_text(const char *text)
diff --git a/src/entry.h b/src/entry.h
index 74d21b8d..1e5c6197 100644
--- a/src/entry.h
+++ b/src/entry.h
@@ -21,6 +21,8 @@
DwbStatus entry_history_forward(GList **last);
DwbStatus entry_history_back(GList **list, GList **last);
void entry_focus();
+void entry_hide();
+void entry_clear_history();
void entry_set_text(const char *text);
void entry_insert_text(const char *text);
void entry_move_cursor_step(GtkMovementStep step, int stepcount, gboolean del);