[epiphany/wip/gtkaction-to-gaction] Use GAction for Send To



commit 79ffc0a2e9c7b17a905f8fb78aec9a15c3949ec2
Author: Iulian Radu <iulian radu67 gmail com>
Date:   Fri Jul 1 18:05:08 2016 +0300

    Use GAction for Send To

 src/ephy-window.c     |   44 +++++++++-----------------
 src/window-commands.c |   84 +++++++++++++++++++++++++------------------------
 src/window-commands.h |    5 ++-
 3 files changed, 61 insertions(+), 72 deletions(-)
---
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 4875745..262bb72 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -75,11 +75,6 @@ static void ephy_window_view_popup_windows_cb (GtkAction  *action,
                                                EphyWindow *window);
 
 static const GtkActionEntry ephy_menu_entries [] = {
-  /* File actions. */
-
-  { "FileSendTo", NULL, N_("S_end Link by Email…"), NULL, NULL,
-    G_CALLBACK (window_cmd_file_send_to) },
-
   /* Go actions. */
 
   { "GoLocation", NULL, N_("_Location…"), "<control>L", NULL,
@@ -164,7 +159,6 @@ static const struct {
 #ifdef HAVE_X11_XF86KEYSYM_H
   { XF86XK_Go, 0, "GoLocation", FALSE },
   { XF86XK_OpenURL, 0, "GoLocation", FALSE },
-  { XF86XK_Send, 0, "FileSendTo", FALSE },
 #endif /* HAVE_X11_XF86KEYSYM_H */
 };
 
@@ -196,6 +190,8 @@ const struct {
 
   { "win.select-all", { "<Primary>A", NULL } },
 
+  { "win.send-to", { "Send", NULL } },
+
   /* Toggle actions */
   { "win.browse-with-caret", { "F7", NULL } },
   { "win.fullscreen", { "F11", NULL } },
@@ -963,6 +959,8 @@ static const GActionEntry window_entries [] =
 
   { "select-all", window_cmd_edit_select_all },
 
+  { "send-to", window_cmd_file_send_to },
+
   /* Toggle actions */
   { "browse-with-caret", activate_toggle, NULL, "false", window_cmd_change_browse_with_caret },
   { "fullscreen", activate_toggle, NULL, "false", window_cmd_change_fullscreen_state }
@@ -1062,37 +1060,25 @@ _ephy_window_set_default_actions_sensitive (EphyWindow *window,
                                             guint       flags,
                                             gboolean    set)
 {
-  GActionGroup *new_action_group;
-  GtkActionGroup *action_group;
+  GActionGroup *action_group;
   GtkAction *action;
   GAction *new_action;
   int i;
-  const char *action_group_actions[] = { "FileSendTo",
-                                         NULL };
 
-  const char *new_action_group_actions[] = { "save-as", "save-as-application",
+  const char *action_group_actions[] = { "save-as", "save-as-application",
                                          "zoom-in", "zoom-out", "print",
                                          "find", "find-prev", "find-next",
                                          "bookmark-page", "encoding", "page-source",
+                                         "send-to",
                                          NULL };
 
-  action_group = window->action_group;
-
-  /* Page menu */
-  for (i = 0; action_group_actions[i] != NULL; i++) {
-    action = gtk_action_group_get_action (action_group,
-                                          action_group_actions[i]);
-    ephy_action_change_sensitivity_flags (action,
-                                          flags, set);
-  }
-
-  new_action_group = gtk_widget_get_action_group (GTK_WIDGET (window),
+  action_group = gtk_widget_get_action_group (GTK_WIDGET (window),
                                               "win");
 
   /* Page menu */
-  for (i = 0; new_action_group_actions[i] != NULL; i++) {
-    new_action = g_action_map_lookup_action (G_ACTION_MAP (new_action_group),
-                                         new_action_group_actions[i]);
+  for (i = 0; action_group_actions[i] != NULL; i++) {
+    new_action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
+                                             action_group_actions[i]);
     new_ephy_action_change_sensitivity_flags (G_SIMPLE_ACTION (new_action),
                                           flags, set);
   }
@@ -1104,8 +1090,8 @@ _ephy_window_set_default_actions_sensitive (EphyWindow *window,
                                         flags, set);
 
   /* Toolbar */
-  new_action_group = gtk_widget_get_action_group (GTK_WIDGET (window), "toolbar");
-  new_action = g_action_map_lookup_action (G_ACTION_MAP (new_action_group),
+  action_group = gtk_widget_get_action_group (GTK_WIDGET (window), "toolbar");
+  new_action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
                                        "combined-stop-reload");
   new_ephy_action_change_sensitivity_flags (G_SIMPLE_ACTION (new_action),
                                         flags, set);
@@ -1810,8 +1796,8 @@ populate_context_menu (WebKitWebView       *web_view,
   if (is_document && !is_image && !is_media) {
     webkit_context_menu_append (context_menu,
                                 webkit_context_menu_item_new_separator ());
-    add_action_to_context_menu (context_menu,
-                                window->action_group, "FileSendTo");
+    new_add_action_to_context_menu (context_menu, window_action_group,
+                                    "send-to", window->toolbar);
   }
 
   webkit_context_menu_append (context_menu,
diff --git a/src/window-commands.c b/src/window-commands.c
index cceafe4..dcd39e9 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -231,47 +231,6 @@ window_cmd_undo_close_tab (GtkAction  *action,
 }
 
 void
-window_cmd_file_send_to (GtkAction  *action,
-                         EphyWindow *window)
-{
-  EphyEmbed *embed;
-  char *command, *subject, *body;
-  const char *location, *title;
-  GdkScreen *screen;
-  GError *error = NULL;
-
-  embed = ephy_embed_container_get_active_child
-            (EPHY_EMBED_CONTAINER (window));
-  g_return_if_fail (embed != NULL);
-
-  location = ephy_web_view_get_address (ephy_embed_get_web_view (embed));
-  title = ephy_embed_get_title (embed);
-
-  subject = g_uri_escape_string (title, NULL, TRUE);
-  body = g_uri_escape_string (location, NULL, TRUE);
-
-  command = g_strconcat ("mailto:";,
-                         "?Subject=", subject,
-                         "&Body=", body, NULL);
-
-  g_free (subject);
-  g_free (body);
-
-  if (window) {
-    screen = gtk_widget_get_screen (GTK_WIDGET (window));
-  } else {
-    screen = gdk_screen_get_default ();
-  }
-
-  if (!gtk_show_uri (screen, command, gtk_get_current_event_time (), &error)) {
-    g_warning ("Unable to send link by email: %s\n", error->message);
-    g_error_free (error);
-  }
-
-  g_free (command);
-}
-
-void
 window_cmd_go_location (GtkAction  *action,
                         EphyWindow *window)
 {
@@ -1679,6 +1638,49 @@ window_cmd_edit_select_all (GSimpleAction *action,
 }
 
 void
+window_cmd_file_send_to (GSimpleAction *action,
+                         GVariant      *value,
+                         gpointer       user_data)
+{
+  EphyWindow *window = EPHY_WINDOW (user_data);
+  EphyEmbed *embed;
+  char *command, *subject, *body;
+  const char *location, *title;
+  GdkScreen *screen;
+  GError *error = NULL;
+
+  embed = ephy_embed_container_get_active_child
+            (EPHY_EMBED_CONTAINER (window));
+  g_return_if_fail (embed != NULL);
+
+  location = ephy_web_view_get_address (ephy_embed_get_web_view (embed));
+  title = ephy_embed_get_title (embed);
+
+  subject = g_uri_escape_string (title, NULL, TRUE);
+  body = g_uri_escape_string (location, NULL, TRUE);
+
+  command = g_strconcat ("mailto:";,
+                         "?Subject=", subject,
+                         "&Body=", body, NULL);
+
+  g_free (subject);
+  g_free (body);
+
+  if (window) {
+    screen = gtk_widget_get_screen (GTK_WIDGET (window));
+  } else {
+    screen = gdk_screen_get_default ();
+  }
+
+  if (!gtk_show_uri (screen, command, gtk_get_current_event_time (), &error)) {
+    g_warning ("Unable to send link by email: %s\n", error->message);
+    g_error_free (error);
+  }
+
+  g_free (command);
+}
+
+void
 window_cmd_change_browse_with_caret (GSimpleAction *action,
                                      GVariant      *state,
                                      gpointer       user_data)
diff --git a/src/window-commands.h b/src/window-commands.h
index 53304b0..914b82e 100644
--- a/src/window-commands.h
+++ b/src/window-commands.h
@@ -43,8 +43,6 @@ void window_cmd_go_location               (GtkAction  *action,
                                            EphyWindow *window);
 void window_cmd_undo_close_tab            (GtkAction *action,
                                            EphyWindow *window);
-void window_cmd_file_send_to              (GtkAction  *action,
-                                           EphyWindow *window);
 void window_cmd_file_new_tab              (GSimpleAction *action,
                                            GVariant      *value,
                                            gpointer       user_data);
@@ -132,6 +130,9 @@ void window_cmd_edit_preferences          (GtkAction  *action,
 void window_cmd_edit_select_all           (GSimpleAction *action,
                                            GVariant      *value,
                                            gpointer       user_data);
+void window_cmd_file_send_to              (GSimpleAction *action,
+                                           GVariant      *value,
+                                           gpointer       user_data);
 void window_cmd_change_browse_with_caret  (GSimpleAction *action,
                                            GVariant      *state,
                                            gpointer       user_data);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]