Auto clear input bar.
authorDaniel Carl <danielcarl@gmx.de>
Thu, 1 Nov 2012 01:49:39 +0000 (02:49 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Sat, 10 Nov 2012 13:43:03 +0000 (14:43 +0100)
No the inputbar will be cleared after some seconds a message was shown.

src/command.c
src/main.c
src/setting.c

index 6c8bdba..c58cc54 100644 (file)
@@ -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;
index 142a396..baa0214 100644 (file)
@@ -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)
index c888b2d..d7abc16 100644 (file)
@@ -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;
     }