Simplified the usage of vp_set_model().
authorDaniel Carl <danielcarl@gmx.de>
Sun, 25 Nov 2012 13:27:39 +0000 (14:27 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Sun, 25 Nov 2012 13:27:39 +0000 (14:27 +0100)
src/command.c
src/dom.c
src/keybind.c
src/main.c
src/main.h

index 41c7547..b09e368 100644 (file)
@@ -140,8 +140,7 @@ gboolean command_input(const Arg* arg)
 
     gtk_editable_set_position(GTK_EDITABLE(vp.gui.inputbox), -1);
 
-    Arg a = {VP_MODE_COMMAND};
-    return vp_set_mode(&a);
+    return vp_set_mode(VP_MODE_COMMAND, FALSE);
 }
 
 gboolean command_close(const Arg* arg)
index 903ef4f..2769238 100644 (file)
--- a/src/dom.c
+++ b/src/dom.c
@@ -44,8 +44,7 @@ void dom_check_auto_insert(void)
 static gboolean dom_auto_insert(WebKitDOMElement* element)
 {
     if (dom_is_editable(element)) {
-        Arg a = {VP_MODE_INSERT};
-        vp_set_mode(&a);
+        vp_set_mode(VP_MODE_INSERT, FALSE);
         return TRUE;
     }
     return FALSE;
index 4f2cef3..7f7b9dc 100644 (file)
@@ -206,10 +206,8 @@ static gboolean keybind_keypress_callback(WebKitWebView* webview, GdkEventKey* e
 
     /* check for escape or modkeys or counts */
     if (IS_ESCAPE_KEY(keyval, state)) {
-        completion_clean();
         /* switch to normal mode and clear the input box */
-        Arg a = {VP_MODE_NORMAL, ""};
-        vp_set_mode(&a);
+        vp_set_mode(VP_MODE_NORMAL, TRUE);
 
         return TRUE;
     }
index 250471d..e160e38 100644 (file)
@@ -65,11 +65,8 @@ static void vp_webview_load_status_cb(WebKitWebView* view, GParamSpec* pspec, gp
             break;
 
         case WEBKIT_LOAD_COMMITTED:
-            {
-                Arg a = {VP_MODE_NORMAL};
-                vp_set_mode(&a);
-            }
             /* status bar is updated by vp_set_mode */
+            vp_set_mode(VP_MODE_NORMAL , FALSE);
             vp_update_urlbar(uri);
             break;
 
@@ -113,8 +110,7 @@ static void vp_inputbox_activate_cb(GtkEntry *entry, gpointer user_data)
             /* switch to normal mode after running command without success the
              * mode after success is set by command_run to the value defined
              * for the command */
-            Arg a = {VP_MODE_NORMAL};
-            vp_set_mode(&a);
+            vp_set_mode(VP_MODE_NORMAL , FALSE);
         }
     }
 }
@@ -212,8 +208,7 @@ gboolean vp_load_uri(const Arg* arg)
     g_free(uri);
 
     /* change state to normal mode */
-    Arg a = {VP_MODE_NORMAL};
-    vp_set_mode(&a);
+    vp_set_mode(VP_MODE_NORMAL, FALSE);
 
     return TRUE;
 }
@@ -271,12 +266,15 @@ static gboolean vp_hide_message(void)
  * Set the base modes. All other mode flags like completion can be set directly
  * to vp.state.mode.
  */
-gboolean vp_set_mode(const Arg* arg)
+gboolean vp_set_mode(Mode mode, gboolean clean)
 {
-    vp.state.mode = arg->i;
+    if (vp.state.mode & VP_MODE_COMPLETE) {
+        completion_clean();
+    }
+    vp.state.mode = mode;
     vp.state.modkey = vp.state.count  = 0;
 
-    switch (CLEAN_MODE(arg->i)) {
+    switch (CLEAN_MODE(mode)) {
         case VP_MODE_NORMAL:
             gtk_widget_grab_focus(GTK_WIDGET(vp.gui.webview));
             break;
@@ -296,8 +294,8 @@ gboolean vp_set_mode(const Arg* arg)
     }
 
     /* echo message if given */
-    if (arg->s) {
-        vp_echo(VP_MSG_NORMAL, FALSE, arg->s);
+    if (clean) {
+        vp_echo(VP_MSG_NORMAL, FALSE, "");
     }
 
     vp_update_statusbar();
@@ -555,8 +553,7 @@ static gboolean vp_notify_event_cb(GtkWidget* widget, GdkEvent* event, gpointer
         result = webkit_web_view_get_hit_test_result(vp.gui.webview, (GdkEventButton*)event);
         g_object_get(result, "context", &context, NULL);
         if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE) {
-            Arg a = {VP_MODE_INSERT};
-            vp_set_mode(&a);
+            vp_set_mode(VP_MODE_INSERT, FALSE);
         }
     }
 
index 8bd5093..bac04d6 100644 (file)
@@ -233,7 +233,7 @@ extern VpCore vp;
 void vp_update_statusbar(void);
 void vp_update_urlbar(const gchar* uri);
 void vp_echo(const MessageType type, gboolean hide, const char *error, ...);
-gboolean vp_set_mode(const Arg* arg);
+gboolean vp_set_mode(Mode mode, gboolean clean);
 void vp_set_widget_font(GtkWidget* widget, const VpColor* fg, const VpColor* bg, PangoFontDescription* font);
 gboolean vp_load_uri(const Arg* arg);
 void vp_clean_up(void);