]> spindle.queued.net Git - midori/commitdiff
Revise and unitfy behavior modulating modifier handling
authorChristian Dywan <christian@twotoasts.de>
Fri, 22 Jan 2010 22:11:00 +0000 (23:11 +0100)
committerChristian Dywan <christian@twotoasts.de>
Sun, 24 Jan 2010 10:00:52 +0000 (11:00 +0100)
We define modfifier macros that indicate whether a modifier
indicates a new window, new tab, background tab or scrolling.

Modifier checks in the address entry, the search entry and view
now use the same consistent modifiers.

midori/midori-locationaction.c
midori/midori-searchaction.c
midori/midori-view.c
midori/sokoke.h

index 4813fab9d839c39e0a99740008dbb35e0cf8e723..b5434133d847f9479fc3016a3d01dd6031fe069c 100644 (file)
@@ -327,7 +327,7 @@ midori_location_action_treeview_button_press_cb (GtkWidget*            treeview,
         gtk_tree_model_get (action->completion_model, &iter, URI_COL, &uri, -1);
         gtk_entry_set_text (GTK_ENTRY (action->entry), uri);
         g_signal_emit (action, signals[SUBMIT_URI], 0, uri,
-                       (event->state & GDK_CONTROL_MASK) ? TRUE : FALSE);
+                       MIDORI_MOD_NEW_TAB (event->state));
         g_free (uri);
 
         return TRUE;
@@ -932,7 +932,7 @@ midori_location_action_key_press_event_cb (GtkEntry*    entry,
 
                 if (is_enter)
                     g_signal_emit (action, signals[SUBMIT_URI], 0, uri,
-                        (event->state & GDK_CONTROL_MASK) ? TRUE : FALSE);
+                                   MIDORI_MOD_NEW_TAB (event->state));
 
                 g_free (uri);
                 return TRUE;
@@ -942,7 +942,7 @@ midori_location_action_key_press_event_cb (GtkEntry*    entry,
         if (is_enter)
             if ((text = gtk_entry_get_text (entry)) && *text)
                 g_signal_emit (action, signals[SUBMIT_URI], 0, text,
-                    (event->state & GDK_CONTROL_MASK) ? TRUE : FALSE);
+                               MIDORI_MOD_NEW_TAB (event->state));
         break;
     case GDK_Escape:
     {
index 6fba4ba433e931296a3d31a4467b3ad3b6f7cb7d..e6d5de7917b43f24b98c1feec192614493f77e4f 100644 (file)
@@ -357,15 +357,15 @@ midori_search_action_key_press_event_cb (GtkWidget*          entry,
     case GDK_Return:
         text = gtk_entry_get_text (GTK_ENTRY (entry));
         g_signal_emit (search_action, signals[SUBMIT], 0, text,
-            (event->state & GDK_MOD1_MASK) ? TRUE : FALSE);
+                       MIDORI_MOD_NEW_TAB (event->state));
         search_action->last_proxy = entry;
         return TRUE;
     case GDK_Up:
-        if (event->state & GDK_CONTROL_MASK)
+        if (MIDORI_MOD_SCROLL (event->state))
             _midori_search_action_move_index (search_action, - 1);
         return TRUE;
     case GDK_Down:
-        if (event->state & GDK_CONTROL_MASK)
+        if (MIDORI_MOD_SCROLL (event->state))
             _midori_search_action_move_index (search_action, + 1);
         return TRUE;
     }
index b2415811b404bc6102fcd2bad6d34d7ee4d269a0..07213f39b0dc1b4a53f5e90e5873b93cda04aaed 100644 (file)
@@ -1237,47 +1237,33 @@ gtk_widget_button_press_event_cb (WebKitWebView*  web_view,
     case 1:
         if (!link_uri)
             return FALSE;
-        #if HAVE_OSX
-        /* FIXME: Test for Command key */
-        if (0)
-        #else
-        if (event->state & GDK_CONTROL_MASK)
-        #endif
+        if (MIDORI_MOD_NEW_TAB (event->state))
         {
             /* Open link in new tab */
             background = view->open_tabs_in_the_background;
-            if (event->state & GDK_SHIFT_MASK)
+            if (MIDORI_MOD_BACKGROUND (event->state))
                 background = !background;
             g_signal_emit (view, signals[NEW_TAB], 0, link_uri, background);
             return TRUE;
         }
-        else if (event->state & GDK_SHIFT_MASK)
+        else if (MIDORI_MOD_NEW_WINDOW (event->state))
         {
             /* Open link in new window */
             g_signal_emit (view, signals[NEW_WINDOW], 0, link_uri);
             return TRUE;
         }
-        else if (event->state & GDK_MOD1_MASK)
-        {
-            /* Open link in new tab */
-            background = view->open_tabs_in_the_background;
-            if (event->state & GDK_CONTROL_MASK)
-                background = !background;
-            g_signal_emit (view, signals[NEW_TAB], 0, link_uri, background);
-            return TRUE;
-        }
         break;
     case 2:
         if (link_uri)
         {
             /* Open link in new tab */
             background = view->open_tabs_in_the_background;
-            if (event->state & GDK_CONTROL_MASK)
+            if (MIDORI_MOD_BACKGROUND (event->state))
                 background = !background;
             g_signal_emit (view, signals[NEW_TAB], 0, link_uri, background);
             return TRUE;
         }
-        else if (event->state & GDK_CONTROL_MASK)
+        else if (MIDORI_MOD_SCROLL (event->state))
         {
             midori_view_set_zoom_level (MIDORI_VIEW (view), 1.0);
             return FALSE; /* Allow Ctrl + Middle click */
@@ -1304,36 +1290,43 @@ gtk_widget_button_press_event_cb (WebKitWebView*  web_view,
                 GDK_SELECTION_PRIMARY);
             if ((uri = gtk_clipboard_wait_for_text (clipboard)))
             {
-                KatzeArray* empty_array = katze_array_new (KATZE_TYPE_ITEM);
                 guint i = 0;
                 while (uri[i++] != '\0')
                     if (uri[i] == '\n' || uri[i] == '\r')
                         uri[i] = ' ';
-                new_uri = sokoke_magic_uri (g_strstrip (uri), empty_array, NULL);
-                g_object_unref (empty_array);
-                if (!new_uri)
+                g_strstrip (uri);
+
+                /* Hold Alt to search for the selected word */
+                if (event->state & GDK_MOD1_MASK)
                 {
-                    gchar* search;
-                    g_object_get (view->settings, "location-entry-search",
-                                  &search, NULL);
-                    new_uri = sokoke_search_uri (search, uri);
+                    KatzeArray* empty_array = katze_array_new (KATZE_TYPE_ITEM);
+                    new_uri = sokoke_magic_uri (uri, empty_array, NULL);
+                    g_object_unref (empty_array);
+                    if (!new_uri)
+                    {
+                        gchar* search;
+                        g_object_get (view->settings, "location-entry-search",
+                                      &search, NULL);
+                        new_uri = sokoke_search_uri (search, uri);
+                    }
+                    katze_assign (uri, new_uri);
                 }
-                if (event->state & GDK_CONTROL_MASK)
+
+                if (MIDORI_MOD_NEW_TAB (event->state))
                 {
                     background = view->open_tabs_in_the_background;
-                    if (event->state & GDK_CONTROL_MASK)
+                    if (MIDORI_MOD_BACKGROUND (event->state))
                         background = !background;
-                    g_signal_emit (view, signals[NEW_TAB], 0, new_uri, background);
+                    g_signal_emit (view, signals[NEW_TAB], 0, uri, background);
                 }
                 else
                 {
-                    midori_view_set_uri (MIDORI_VIEW (view), new_uri);
+                    midori_view_set_uri (MIDORI_VIEW (view), uri);
                     gtk_widget_grab_focus (GTK_WIDGET (view));
                 }
-                g_free (new_uri);
                 return TRUE;
-            }
             g_free (uri);
+            }
         }
         break;
     #if WEBKIT_CHECK_VERSION (1, 1, 15)
@@ -1409,7 +1402,7 @@ gtk_widget_scroll_event_cb (WebKitWebView*  web_view,
 {
     event->state = event->state & MIDORI_KEYS_MODIFIER_MASK;
 
-    if (event->state & GDK_CONTROL_MASK)
+    if (MIDORI_MOD_SCROLL (event->state))
     {
         if (event->direction == GDK_SCROLL_DOWN)
             midori_view_set_zoom_level (view,
index 37d1e46c8ea621fa2e28044461b1ef27f13e3658..a164230ddf11af3b7d29d13441d96348980220b0 100644 (file)
 #ifndef __SOKOKE_H__
 #define __SOKOKE_H__ 1
 
+/* Common behavior modifiers */
+#define MIDORI_MOD_NEW_WINDOW(state) (state & GDK_SHIFT_MASK)
+#define MIDORI_MOD_NEW_TAB(state) (state & GDK_CONTROL_MASK)
+#define MIDORI_MOD_BACKGROUND(state) (state & GDK_SHIFT_MASK)
+#define MIDORI_MOD_SCROLL(state) (state & GDK_CONTROL_MASK)
+
 #include <katze/katze.h>
 
 #include <webkit/webkit.h>