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



commit a0bc24723250e4833aaec3d0b2d4df6ba0b9f8a0
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 ac274fd..d276f7f 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -93,8 +93,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,
@@ -298,6 +296,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 } },
@@ -1052,8 +1051,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);
 
@@ -3075,15 +3072,15 @@ 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",
                                                        "FileBookmarkPage",
                                                        "EditBookmarks",
                                                        "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" };
@@ -3136,6 +3133,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 5b9bf1b..ad6a2df 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;
@@ -878,6 +857,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 364aa5d..9359053 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]