[epiphany] Cleanup context menus



commit 9d10f81c4765cb279df6439a11b302767f0a63b1
Author: William Jon McCann <william jon mccann gmail com>
Date:   Sun Dec 15 09:17:42 2013 -0500

    Cleanup context menus
    
    https://bugzilla.gnome.org/show_bug.cgi?id=690062

 src/ephy-lockdown.c  |    4 +-
 src/ephy-window.c    |   61 +++++++++------------
 src/popup-commands.c |  148 +++-----------------------------------------------
 src/popup-commands.h |    8 +---
 4 files changed, 38 insertions(+), 183 deletions(-)
---
diff --git a/src/ephy-lockdown.c b/src/ephy-lockdown.c
index 56a4900..0acaba6 100644
--- a/src/ephy-lockdown.c
+++ b/src/ephy-lockdown.c
@@ -107,11 +107,9 @@ static const BindAction window_actions[] = {
 };
 
 static const BindAction popup_actions[] = {
-  { EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "DownloadLink", "sensitive" },
   { EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "DownloadLinkAs", "sensitive" },
   { EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "SaveImageAs", "sensitive" },
-  { EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "OpenImage", "sensitive" },
-  { EPHY_PREFS_LOCKDOWN_BOOKMARK_EDITING, "BookmarkLink", "sensitive" }
+  { EPHY_PREFS_LOCKDOWN_BOOKMARK_EDITING, "ContextBookmarkPage", "sensitive" }
 };
 
 static const BindAction special_toolbar_actions[] = {
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 146466d..ebb439b 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -217,18 +217,12 @@ static const GtkActionEntry ephy_popups_entries [] = {
        
        /* Links. */
 
-       { "OpenLink", NULL, N_("_Open Link"), NULL, NULL,
-         G_CALLBACK (popup_cmd_open_link) },
        { "OpenLinkInNewWindow", NULL, N_("Open Link in New _Window"), NULL, NULL,
          G_CALLBACK (popup_cmd_link_in_new_window) },
        { "OpenLinkInNewTab", NULL, N_("Open Link in New _Tab"), NULL, NULL,
          G_CALLBACK (popup_cmd_link_in_new_tab) },
-       { "DownloadLink", NULL, N_("_Download Link"), NULL,
-         NULL, G_CALLBACK (popup_cmd_download_link) },
        { "DownloadLinkAs", NULL, N_("_Save Link As…"), NULL, NULL,
          G_CALLBACK (popup_cmd_download_link_as) },
-       { "BookmarkLink", NULL, N_("_Bookmark Link…"),
-         NULL, NULL, G_CALLBACK (popup_cmd_bookmark_link) },
        { "CopyLinkAddress", NULL, N_("_Copy Link Address"), NULL,
          NULL, G_CALLBACK (popup_cmd_copy_link_address) },
        { "CopyEmailAddress", NULL, N_("_Copy E-mail Address"), NULL,
@@ -236,14 +230,14 @@ static const GtkActionEntry ephy_popups_entries [] = {
 
        /* Images. */
 
-       { "OpenImage", NULL, N_("Open _Image"), NULL,
-         NULL, G_CALLBACK (popup_cmd_open_image) },
+       { "ViewImage", NULL, N_("View _Image"), NULL,
+         NULL, G_CALLBACK (popup_cmd_view_image_in_new_tab) },
+       { "CopyImageLocation", NULL, N_("Copy I_mage Address"), NULL,
+         NULL, G_CALLBACK (popup_cmd_copy_image_location) },
        { "SaveImageAs", NULL, N_("_Save Image As…"), NULL,
          NULL, G_CALLBACK (popup_cmd_save_image_as) },
-       { "SetImageAsBackground", NULL, N_("_Use Image As Background"), NULL,
+       { "SetImageAsBackground", NULL, N_("Set as _Wallpaper"), NULL,
          NULL, G_CALLBACK (popup_cmd_set_image_as_background) },
-       { "CopyImageLocation", NULL, N_("Copy I_mage Address"), NULL,
-         NULL, G_CALLBACK (popup_cmd_copy_image_location) },
        { "StartImageAnimation", NULL, N_("St_art Animation"), NULL,
          NULL, NULL },
        { "StopImageAnimation", NULL, N_("St_op Animation"), NULL,
@@ -1690,6 +1684,9 @@ populate_context_menu (WebKitWebView *web_view,
        EphyEmbedEvent *embed_event;
        gboolean is_document = FALSE;
        gboolean app_mode;
+       gboolean is_image;
+
+       is_image = webkit_hit_test_result_context_is_image (hit_test_result);
 
        if (webkit_hit_test_result_context_is_editable (hit_test_result)) {
                input_methods_item = find_item_in_context_menu (context_menu, 
WEBKIT_CONTEXT_MENU_ACTION_INPUT_METHODS);
@@ -1721,8 +1718,6 @@ populate_context_menu (WebKitWebView *web_view,
                if (!app_mode)
                {
                        add_action_to_context_menu (context_menu,
-                                                   priv->popups_action_group, "OpenLink");
-                       add_action_to_context_menu (context_menu,
                                                    priv->popups_action_group, "OpenLinkInNewTab");
                        add_action_to_context_menu (context_menu,
                                                    priv->popups_action_group, "OpenLinkInNewWindow");
@@ -1734,14 +1729,7 @@ populate_context_menu (WebKitWebView *web_view,
                webkit_context_menu_append (context_menu,
                                            webkit_context_menu_item_new_separator ());
                add_action_to_context_menu (context_menu,
-                                           priv->popups_action_group, "DownloadLink");
-               add_action_to_context_menu (context_menu,
                                            priv->popups_action_group, "DownloadLinkAs");
-               if (!app_mode)
-               {
-                       add_action_to_context_menu (context_menu,
-                                                   priv->popups_action_group, "BookmarkLink");
-               }
 
                if (g_str_has_prefix (uri, "mailto:";))
                {
@@ -1814,17 +1802,22 @@ populate_context_menu (WebKitWebView *web_view,
 
                update_edit_actions_sensitivity (window, TRUE);
 
-               add_action_to_context_menu (context_menu,
-                                           priv->toolbar_action_group, "NavigationBack");
-               add_action_to_context_menu (context_menu,
-                                           priv->toolbar_action_group, "NavigationForward");
-               add_action_to_context_menu (context_menu,
-                                           priv->action_group, "ViewReload");
-               webkit_context_menu_append (context_menu,
-                                           webkit_context_menu_item_new_separator ());
+               if (!is_image)
+               {
+                       add_action_to_context_menu (context_menu,
+                                                   priv->toolbar_action_group, "NavigationBack");
+                       add_action_to_context_menu (context_menu,
+                                                   priv->toolbar_action_group, "NavigationForward");
+                       add_action_to_context_menu (context_menu,
+                                                   priv->action_group, "ViewReload");
+                       webkit_context_menu_append (context_menu,
+                                                   webkit_context_menu_item_new_separator ());
+               }
+
                add_action_to_context_menu (context_menu,
                                            priv->action_group, "EditCopy");
-               if (!app_mode)
+
+               if (!app_mode && !is_image)
                {
                        webkit_context_menu_append (context_menu,
                                                    webkit_context_menu_item_new_separator ());
@@ -1833,18 +1826,18 @@ populate_context_menu (WebKitWebView *web_view,
                }
        }
 
-       if (webkit_hit_test_result_context_is_image (hit_test_result))
+       if (is_image)
        {
                webkit_context_menu_append (context_menu,
                                            webkit_context_menu_item_new_separator ());
                add_action_to_context_menu (context_menu,
-                                           priv->popups_action_group, "OpenImage");
-               add_action_to_context_menu (context_menu,
                                            priv->popups_action_group, "SaveImageAs");
                add_action_to_context_menu (context_menu,
-                                           priv->popups_action_group, "SetImageAsBackground");
-               add_action_to_context_menu (context_menu,
                                            priv->popups_action_group, "CopyImageLocation");
+               add_action_to_context_menu (context_menu,
+                                           priv->popups_action_group, "ViewImage");
+               add_action_to_context_menu (context_menu,
+                                           priv->popups_action_group, "SetImageAsBackground");
        }
 
        if (is_document)
diff --git a/src/popup-commands.c b/src/popup-commands.c
index 102fe5e..391a988 100644
--- a/src/popup-commands.c
+++ b/src/popup-commands.c
@@ -232,34 +232,6 @@ save_property_url (GtkAction *action,
 }
 
 void
-popup_cmd_open_link (GtkAction *action,
-                    EphyWindow *window)
-{
-       EphyEmbedEvent *event;
-       const char *location;
-       GValue value = { 0, };
-       EphyEmbed *embed;
-
-       embed = ephy_embed_container_get_active_child 
-               (EPHY_EMBED_CONTAINER (window));
-       g_return_if_fail (embed != NULL);
-
-       event = ephy_window_get_context_event (window);
-       ephy_embed_event_get_property (event, "link-uri", &value);
-       location = g_value_get_string (&value);
-       ephy_web_view_load_url (ephy_embed_get_web_view (embed), location);
-       g_value_unset (&value);
-}
-
-void
-popup_cmd_download_link (GtkAction *action,
-                        EphyWindow *window)
-{
-       save_property_url (action, _("Download Link"), window, 
-                          FALSE, "link-uri");
-}
-
-void
 popup_cmd_download_link_as (GtkAction *action,
                            EphyWindow *window)
 {
@@ -339,130 +311,28 @@ popup_cmd_copy_image_location (GtkAction *action,
        g_value_unset (&value);
 }
 
-/* Opens an image URI using its associated handler. Or, if that
- * doesn't work, fallback to open the URI in a new browser window.
- */
-static void
-image_open_uri (GFile *file,
-                const char *remote_address,
-               guint32 user_time)
-{
-       gboolean success;
-
-       success = ephy_file_launch_handler (NULL, file, user_time);
-
-       if (!success)
-       {
-               ephy_shell_new_tab (ephy_shell_get_default (),
-                                   NULL, NULL, remote_address,
-                                   EPHY_NEW_TAB_OPEN_PAGE |
-                                   EPHY_NEW_TAB_IN_NEW_WINDOW);
-       }
-
-       if (strcmp (remote_address, g_file_get_uri (file)) != 0)
-       {
-               if (success)
-                       ephy_file_delete_on_exit (file);
-               else
-                       g_file_delete (file, NULL, NULL);
-       }
-}
-
-static void
-save_source_completed_cb (EphyDownload *download)
-{
-       const char *dest;
-       const char *source;
-       guint32 user_time;
-       GFile *file;
-
-       user_time = ephy_download_get_start_time (download);
-       dest = ephy_download_get_destination_uri (download);
-       source = ephy_download_get_source_uri (download);
-       g_return_if_fail (dest != NULL);
-       
-       file = g_file_new_for_uri (dest);
-
-       image_open_uri (file, source, user_time);
-       g_object_unref (file);
-}
-
-static void
-save_temp_source (const char *address)
-{
-       EphyDownload *download;
-       const char *static_temp_dir;
-       char *base, *tmp_name, *tmp_path, *dest, *dest_uri;
-
-       if (address == NULL) return;
-
-       static_temp_dir = ephy_file_tmp_dir ();
-       if (static_temp_dir == NULL) return;
-
-       base = g_path_get_basename (address);
-       tmp_name = g_strconcat (base, ".XXXXXX", NULL);
-       g_free (base);
-
-       tmp_path = g_build_filename (static_temp_dir, tmp_name, NULL);
-       g_free (tmp_name);
-
-       dest = ephy_file_tmp_filename (tmp_path, NULL);
-       g_free (tmp_path);
-
-       if (dest == NULL) return;
-
-       dest_uri = g_filename_to_uri (dest, NULL, NULL);
-       download = ephy_download_new_for_uri (address, NULL);
-       ephy_download_set_destination_uri (download, dest_uri);
-
-       g_signal_connect (download, "completed",
-                         G_CALLBACK (save_source_completed_cb), NULL);
-
-       ephy_download_start (download);
-
-       g_free (dest);
-       g_free (dest_uri);
-}
-
 void
-popup_cmd_open_image (GtkAction *action,
-                     EphyWindow *window)
+popup_cmd_view_image_in_new_tab (GtkAction *action,
+                                EphyWindow *window)
 {
        EphyEmbedEvent *event;
-       const char *address;
-       char *scheme = NULL;
        GValue value = { 0, };
        EphyEmbed *embed;
 
        event = ephy_window_get_context_event (window);
        g_return_if_fail (event != NULL);
 
-       embed = ephy_embed_container_get_active_child 
-               (EPHY_EMBED_CONTAINER (window));
+       embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
        g_return_if_fail (embed != NULL);
 
        ephy_embed_event_get_property (event, "image-uri", &value);
-       address = g_value_get_string (&value);
-
-       scheme = g_uri_parse_scheme (address);
-       if (scheme == NULL) goto out;
 
-       if (strcmp (scheme, "file") == 0)
-       {
-               GFile *file;
-               
-               file = g_file_new_for_uri (address);
-               image_open_uri (file, address,
-                               gtk_get_current_event_time ());
-               g_object_unref (file);
-       }
-       else
-       {
-               save_temp_source (address);
-       }
-
- out:
+       ephy_shell_new_tab (ephy_shell_get_default (),
+                           window, embed,
+                           g_value_get_string (&value),
+                           EPHY_NEW_TAB_OPEN_PAGE |
+                           EPHY_NEW_TAB_IN_EXISTING_WINDOW |
+                           EPHY_NEW_TAB_APPEND_AFTER);
        g_value_unset (&value);
-       g_free (scheme);
 }
 
diff --git a/src/popup-commands.h b/src/popup-commands.h
index 4301ef3..e07f2d5 100644
--- a/src/popup-commands.h
+++ b/src/popup-commands.h
@@ -39,12 +39,6 @@ void popup_cmd_copy_link_address     (GtkAction *action,
 void popup_cmd_copy_link_location       (GtkAction *action,
                                         EphyWindow *window);
 
-void popup_cmd_open_link               (GtkAction *action,
-                                        EphyWindow *window);
-
-void popup_cmd_download_link           (GtkAction *action,
-                                        EphyWindow *window);
-
 void popup_cmd_download_link_as                (GtkAction *action,
                                         EphyWindow *window);
 
@@ -54,7 +48,7 @@ void popup_cmd_set_image_as_background  (GtkAction *action,
 void popup_cmd_copy_image_location     (GtkAction *action,
                                         EphyWindow *window);
 
-void popup_cmd_open_image              (GtkAction *action,
+void popup_cmd_view_image_in_new_tab   (GtkAction *action,
                                         EphyWindow *window);
 
 void popup_cmd_download_link           (GtkAction *action,


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