From: Daniel Carl Date: Sun, 25 Nov 2012 13:27:39 +0000 (+0100) Subject: Simplified the usage of vp_set_model(). X-Git-Url: https://git.owens.tech/about.html/about.html/git?a=commitdiff_plain;h=024f0ddcdf12830ded443f20cebbf6f388aa3245;p=vimb.git Simplified the usage of vp_set_model(). --- diff --git a/src/command.c b/src/command.c index 41c7547..b09e368 100644 --- a/src/command.c +++ b/src/command.c @@ -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) diff --git a/src/dom.c b/src/dom.c index 903ef4f..2769238 100644 --- 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; diff --git a/src/keybind.c b/src/keybind.c index 4f2cef3..7f7b9dc 100644 --- a/src/keybind.c +++ b/src/keybind.c @@ -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; } diff --git a/src/main.c b/src/main.c index 250471d..e160e38 100644 --- a/src/main.c +++ b/src/main.c @@ -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); } } diff --git a/src/main.h b/src/main.h index 8bd5093..bac04d6 100644 --- a/src/main.h +++ b/src/main.h @@ -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);