From 037016a6d4033a92156d985fa80e40bf2c9c7cd7 Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Thu, 1 Nov 2012 02:49:39 +0100 Subject: [PATCH] Auto clear input bar. No the inputbar will be cleared after some seconds a message was shown. --- src/command.c | 1 + src/main.c | 21 +++++++++++++++++---- src/setting.c | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/command.c b/src/command.c index 6c8bdba..c58cc54 100644 --- a/src/command.c +++ b/src/command.c @@ -77,6 +77,7 @@ gboolean command_run(const gchar* name, const gchar* param) Arg a; c = g_hash_table_lookup(vp.behave.commands, name); if (!c) { + vp_echo(VP_MSG_ERROR, "Command '%s' not found", name); return FALSE; } a.i = c->arg.i; diff --git a/src/main.c b/src/main.c index 142a396..baa0214 100644 --- a/src/main.c +++ b/src/main.c @@ -55,6 +55,7 @@ static void vp_set_cookie(SoupCookie* cookie); static const gchar* vp_get_cookies(SoupURI *uri); #endif static void vp_clean_up(void); +static gboolean vp_hide_message(void); static void vp_webview_load_status_cb(WebKitWebView* view, GParamSpec* pspec, gpointer user_data) { @@ -109,9 +110,6 @@ static void vp_inputbox_activate_cb(GtkEntry *entry, gpointer user_data) if (1 < length && ':' == text[0]) { success = vp_process_input((text + 1)); if (!success) { - /* print error message */ - vp_echo(VP_MSG_ERROR, "Command '%s' not found", (text + 1)); - /* switch to normal mode after running command */ Arg a = {VP_MODE_NORMAL}; vp_set_mode(&a); @@ -315,6 +313,19 @@ static void vp_clean_up(void) } } +static gboolean vp_hide_message(void) +{ + /* do not clean in command mode */ + if (vp.state.mode == VP_MODE_COMMAND) { + return FALSE; + } + const MessageType type = VP_MSG_NORMAL; + vp_set_widget_font(vp.gui.inputbox, inputbox_font[type], inputbox_bg[type], inputbox_fg[type]); + gtk_entry_set_text(GTK_ENTRY(vp.gui.inputbox), ""); + + return FALSE; +} + gboolean vp_view_source(const Arg* arg) { gboolean mode = webkit_web_view_get_view_source_mode(vp.gui.webview); @@ -415,9 +426,10 @@ gboolean vp_set(const Arg* arg) token = g_strsplit(line, "=", 2); g_free(line); - if (!token[0]) { + if (!token[1]) { /* TODO display current value */ g_strfreev(token); + vp_echo(VP_MSG_ERROR, "No param given"); return FALSE; } success = setting_run(token[0], token[1] ? token[1] : NULL); @@ -483,6 +495,7 @@ void vp_echo(const MessageType type, const char *error, ...) /* set the collors according to message type */ vp_set_widget_font(vp.gui.inputbox, inputbox_font[type], inputbox_bg[type], inputbox_fg[type]); gtk_entry_set_text(GTK_ENTRY(vp.gui.inputbox), message); + g_timeout_add_seconds(2, (GSourceFunc)vp_hide_message, NULL); } static void vp_print_version(void) diff --git a/src/setting.c b/src/setting.c index c888b2d..d7abc16 100644 --- a/src/setting.c +++ b/src/setting.c @@ -92,6 +92,7 @@ gboolean setting_run(const gchar* name, const gchar* param) gboolean result = FALSE; Setting* s = g_hash_table_lookup(settings, name); if (!s) { + vp_echo(VP_MSG_ERROR, "Config '%s' not found", name); return FALSE; } -- 2.20.1