[epiphany/wip/gtkaction-to-gaction: 49/54] Port Open to GAction



commit fd58ae5341c43e2bbec7ed0c1b8fabd5340db597
Author: Iulian Radu <iulian radu67 gmail com>
Date:   Sat May 14 22:57:31 2016 +0300

    Port Open to GAction

 src/ephy-window.c             |   12 ++--
 src/resources/epiphany-ui.xml |    1 -
 src/resources/gtk/menus.ui    |    8 +-
 src/window-commands.c         |  126 +++++++++++++++++++++--------------------
 src/window-commands.h         |    5 +-
 5 files changed, 76 insertions(+), 76 deletions(-)
---
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 1ce93de..62f98e1 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -90,8 +90,6 @@ static const GtkActionEntry ephy_menu_entries [] = {
     G_CALLBACK (window_cmd_file_new_window) },
   { "FileNewWindowIncognito", NULL, N_("New _Incognito Window"), "<control><shift>N", NULL,
     G_CALLBACK (window_cmd_file_new_incognito_window) },
-  { "FileOpen", NULL, N_("_Open…"), "<control>O", NULL,
-    G_CALLBACK (window_cmd_file_open) },
   { "FileSendTo", NULL, N_("S_end Link by Email…"), NULL, NULL,
     G_CALLBACK (window_cmd_file_send_to) },
   { "FileQuit", NULL, N_("_Quit"), "<control>Q", NULL,
@@ -301,6 +299,7 @@ const struct {
   const gchar *action_and_target;
   const gchar *accelerators[5];
 } accels [] = {
+  { "win.open", { "<Primary>O", NULL } },
   { "win.save-as", { "<shift><Primary>S", "<Primary>S", NULL } },
   { "win.save-as-application", { "<shift><Primary>A", NULL } },
   { "win.undo", { "<Primary>Z", NULL } },
@@ -1055,8 +1054,6 @@ setup_ui_manager (EphyWindow *window)
   window->action_group = action_group;
   g_object_unref (action_group);
 
-  action = gtk_action_group_get_action (action_group, "FileOpen");
-  g_object_set (action, "short_label", _("Open"), NULL);
   action = gtk_action_group_get_action (action_group, "FileBookmarkPage");
   g_object_set (action, "short_label", _("Bookmark"), NULL);
 
@@ -3078,8 +3075,7 @@ setup_location_controller (EphyWindow  *window,
   return location_controller;
 }
 
-static const char *disabled_actions_for_app_mode[] = { "FileOpen",
-                                                       "FileNewWindow",
+static const char *disabled_actions_for_app_mode[] = { "FileNewWindow",
                                                        "FileNewWindowIncognito",
                                                        "ViewToggleInspector",
                                                        "FileBookmarkPage",
@@ -3087,7 +3083,8 @@ static const char *disabled_actions_for_app_mode[] = { "FileOpen",
                                                        "EditHistory",
                                                        "EditPreferences" };
 
-static const char *new_disabled_actions_for_app_mode[] = { "save-as",
+static const char *new_disabled_actions_for_app_mode[] = { "open",
+                                                       "save-as",
                                                        "save-as-application",
                                                        "encoding",
                                                        "page-source" };
@@ -3140,6 +3137,7 @@ ephy_window_toggle_visibility_for_app_menu (EphyWindow *window)
 static const GActionEntry new_ephy_page_menu_entries [] =
 {
   // { "new-tab", },
+  { "open", window_cmd_file_open },
   { "save-as", window_cmd_file_save_as },
   { "save-as-application", window_cmd_file_save_as_application },
   { "undo", window_cmd_edit_undo },
diff --git a/src/resources/epiphany-ui.xml b/src/resources/epiphany-ui.xml
index 289200f..91509a1 100644
--- a/src/resources/epiphany-ui.xml
+++ b/src/resources/epiphany-ui.xml
@@ -13,7 +13,6 @@
                 <menuitem name="FileNewWindowMenu" action="FileNewWindow"/>
                 <menuitem name="FileNewWindowIncognitoMenu" action="FileNewWindowIncognito"/>
                 <menuitem name="FileNewTabMenu" action="FileNewTab"/>
-                <menuitem name="FileOpenMenu" action="FileOpen"/>
                 <separator name="FileSep2"/>
                 <menuitem name="EditPreferencesMenu" action="EditPreferences"/>
                 <separator name="FileSep4"/>
diff --git a/src/resources/gtk/menus.ui b/src/resources/gtk/menus.ui
index 9a0a4dd..e237a70 100644
--- a/src/resources/gtk/menus.ui
+++ b/src/resources/gtk/menus.ui
@@ -2,16 +2,16 @@
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
   <menu id="page-menu">
-    <!-- <section>
-      <item>
+    <section>
+      <!-- <item>
         <attribute name="label" translatable="yes">New Tab</attribute>
         <attribute name="action">win.new-tab</attribute>
-      </item>
+      </item> -->
       <item>
         <attribute name="label" translatable="yes">_Open…</attribute>
         <attribute name="action">win.open</attribute>
       </item>
-    </section> -->
+    </section>
     <section>
       <item>
         <attribute name="label" translatable="yes">Save _As…</attribute>
diff --git a/src/window-commands.c b/src/window-commands.c
index 995ca79..fe27f72 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -189,68 +189,6 @@ window_cmd_file_bookmark_page (GtkAction  *action,
                                   ephy_embed_get_title (embed));
 }
 
-static void
-open_response_cb (GtkDialog *dialog, int response, EphyWindow *window)
-{
-  if (response == GTK_RESPONSE_ACCEPT) {
-    char *uri, *converted;
-
-    uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
-    if (uri != NULL) {
-      converted = g_filename_to_utf8 (uri, -1, NULL, NULL, NULL);
-
-      if (converted != NULL) {
-        ephy_window_load_url (window, converted);
-      }
-
-      g_free (converted);
-      g_free (uri);
-    }
-  }
-
-  gtk_widget_destroy (GTK_WIDGET (dialog));
-}
-
-static void
-save_response_cb (GtkDialog *dialog, int response, EphyEmbed *embed)
-{
-  if (response == GTK_RESPONSE_ACCEPT) {
-    char *uri, *converted;
-
-    uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
-    if (uri != NULL) {
-      converted = g_filename_to_utf8 (uri, -1, NULL, NULL, NULL);
-
-      if (converted != NULL) {
-        EphyWebView *web_view = ephy_embed_get_web_view (embed);
-        ephy_web_view_save (web_view, converted);
-      }
-
-      g_free (converted);
-      g_free (uri);
-    }
-  }
-
-  gtk_widget_destroy (GTK_WIDGET (dialog));
-}
-
-void
-window_cmd_file_open (GtkAction  *action,
-                      EphyWindow *window)
-{
-  EphyFileChooser *dialog;
-
-  dialog = ephy_file_chooser_new (_("Open"),
-                                  GTK_WIDGET (window),
-                                  GTK_FILE_CHOOSER_ACTION_OPEN,
-                                  EPHY_FILE_FILTER_ALL_SUPPORTED);
-
-  g_signal_connect (dialog, "response",
-                    G_CALLBACK (open_response_cb), window);
-
-  gtk_widget_show (GTK_WIDGET (dialog));
-}
-
 void
 window_cmd_file_quit (GtkAction  *action,
                       EphyWindow *window)
@@ -328,6 +266,47 @@ window_cmd_view_fullscreen (GtkAction  *action,
     gtk_window_unfullscreen (GTK_WINDOW (window));
 }
 
+static void
+open_response_cb (GtkDialog *dialog, int response, EphyWindow *window)
+{
+  if (response == GTK_RESPONSE_ACCEPT) {
+    char *uri, *converted;
+
+    uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
+    if (uri != NULL) {
+      converted = g_filename_to_utf8 (uri, -1, NULL, NULL, NULL);
+
+      if (converted != NULL) {
+        ephy_window_load_url (window, converted);
+      }
+
+      g_free (converted);
+      g_free (uri);
+    }
+  }
+
+  gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
+void
+window_cmd_file_open (GSimpleAction *action,
+                      GVariant      *value,
+                      gpointer       user_data)
+{
+  EphyWindow *window = user_data;
+  EphyFileChooser *dialog;
+
+  dialog = ephy_file_chooser_new (_("Open"),
+                                  GTK_WIDGET (window),
+                                  GTK_FILE_CHOOSER_ACTION_OPEN,
+                                  EPHY_FILE_FILTER_ALL_SUPPORTED);
+
+  g_signal_connect (dialog, "response",
+                    G_CALLBACK (open_response_cb), window);
+
+  gtk_widget_show (GTK_WIDGET (dialog));
+}
+
 typedef struct {
   EphyWebView *view;
   GtkWidget *image;
@@ -877,6 +856,29 @@ get_suggested_filename (EphyEmbed *embed)
   return suggested_filename;
 }
 
+static void
+save_response_cb (GtkDialog *dialog, int response, EphyEmbed *embed)
+{
+  if (response == GTK_RESPONSE_ACCEPT) {
+    char *uri, *converted;
+
+    uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
+    if (uri != NULL) {
+      converted = g_filename_to_utf8 (uri, -1, NULL, NULL, NULL);
+
+      if (converted != NULL) {
+        EphyWebView *web_view = ephy_embed_get_web_view (embed);
+        ephy_web_view_save (web_view, converted);
+      }
+
+      g_free (converted);
+      g_free (uri);
+    }
+  }
+
+  gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
 void
 window_cmd_file_save_as (GSimpleAction *action,
                          GVariant      *value,
diff --git a/src/window-commands.h b/src/window-commands.h
index a3cf1f2..5c7e229 100644
--- a/src/window-commands.h
+++ b/src/window-commands.h
@@ -32,14 +32,15 @@ void window_cmd_view_reload               (GtkAction  *action,
                                            EphyWindow *window);
 void window_cmd_file_bookmark_page        (GtkAction  *action,
                                            EphyWindow *window);
-void window_cmd_file_open                 (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_view_fullscreen           (GtkAction  *action,
                                            EphyWindow *window);
+void window_cmd_file_open                 (GSimpleAction *action,
+                                           GVariant      *value,
+                                           gpointer       user_data);
 void window_cmd_file_save_as              (GSimpleAction *action,
                                            GVariant      *value,
                                            gpointer       user_data);


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