[epiphany/wip/gtkaction-to-gaction: 48/54] Port Encoding, Page Source and Close to GAction



commit 79444befec517ebd15bd80869d728d969133ebc4
Author: Iulian Radu <iulian radu67 gmail com>
Date:   Sat May 14 22:33:51 2016 +0300

    Port Encoding, Page Source and Close to GAction

 src/ephy-window.c             |   60 ++++++++++++++-------------------
 src/resources/epiphany-ui.xml |    5 +--
 src/resources/gtk/menus.ui    |    8 ++---
 src/window-commands.c         |   74 ++++++++++++++++++++++-------------------
 src/window-commands.h         |   15 +++++---
 5 files changed, 79 insertions(+), 83 deletions(-)
---
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 0090993..1ce93de 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -94,8 +94,6 @@ static const GtkActionEntry ephy_menu_entries [] = {
     G_CALLBACK (window_cmd_file_open) },
   { "FileSendTo", NULL, N_("S_end Link by Email…"), NULL, NULL,
     G_CALLBACK (window_cmd_file_send_to) },
-  { "FileCloseTab", NULL, N_("_Close"), "<control>W", NULL,
-    G_CALLBACK (window_cmd_file_close_window) },
   { "FileQuit", NULL, N_("_Quit"), "<control>Q", NULL,
     G_CALLBACK (window_cmd_file_quit) },
 
@@ -115,10 +113,6 @@ static const GtkActionEntry ephy_menu_entries [] = {
     NULL, G_CALLBACK (window_cmd_view_stop) },
   { "ViewReload", NULL, N_("_Reload"), "<control>R", NULL,
     G_CALLBACK (window_cmd_view_reload) },
-  { "ViewEncoding", NULL, N_("Text _Encoding"), NULL, NULL,
-    G_CALLBACK (window_cmd_view_encoding) },
-  { "ViewPageSource", NULL, N_("_Page Source"), "<control>U", NULL,
-    G_CALLBACK (window_cmd_view_page_source) },
   { "ViewToggleInspector", NULL, N_("_Toggle Inspector"), "<shift><control>I", NULL,
     G_CALLBACK (window_cmd_view_toggle_inspector) },
 
@@ -307,7 +301,7 @@ const struct {
   const gchar *action_and_target;
   const gchar *accelerators[5];
 } accels [] = {
-  { "win.save-as", { "<shift><Primary>S", "<Primary>s", NULL } },
+  { "win.save-as", { "<shift><Primary>S", "<Primary>S", NULL } },
   { "win.save-as-application", { "<shift><Primary>A", NULL } },
   { "win.undo", { "<Primary>Z", NULL } },
   { "win.redo", { "<shift><Primary>Z", NULL } },
@@ -320,8 +314,11 @@ const struct {
   { "win.zoom-normal", { "<Primary>0", "<Primary>KP_0", NULL } },
   { "win.print", { "<Primary>P", NULL } },
   { "win.find", { "<Primary>F", "Search", NULL } },
-  { "win.find-prev", { "<shift><Primary>G", "Search", NULL } },
-  { "win.find-next", { "<Primary>G", NULL } }
+  { "win.find-prev", { "<shift><Primary>G", NULL } },
+  { "win.find-next", { "<Primary>G", NULL } },
+  { "win.encoding", { NULL } },
+  { "win.page-source", { "<Primary>U", NULL } },
+  { "win.close", { "<Primary>W", NULL } }
 };
 
 #define SETTINGS_CONNECTION_DATA_KEY    "EphyWindowSettings"
@@ -1063,9 +1060,6 @@ setup_ui_manager (EphyWindow *window)
   action = gtk_action_group_get_action (action_group, "FileBookmarkPage");
   g_object_set (action, "short_label", _("Bookmark"), NULL);
 
-  action = gtk_action_group_get_action (action_group, "ViewEncoding");
-  g_object_set (action, "short_label", _("Encodings…"), NULL);
-
   action_group = gtk_action_group_new ("PopupsActions");
   gtk_action_group_set_translation_domain (action_group, NULL);
   gtk_action_group_add_actions (action_group, ephy_popups_entries,
@@ -1165,12 +1159,12 @@ _ephy_window_set_default_actions_sensitive (EphyWindow *window,
   GAction *new_action;
   int i;
   const char *action_group_actions[] = { "FileSendTo", "FileBookmarkPage",
-                                         "ViewEncoding", "ViewPageSource",
                                          NULL };
 
   const char *new_action_group_actions[] = { "save-as", "save-as-application",
                                          "zoom-in", "zoom-out", "print",
                                          "find", "find-prev", "find-next",
+                                         "encoding", "page-source",
                                          NULL };
 
   action_group = window->action_group;
@@ -1262,9 +1256,7 @@ sync_tab_document_type (EphyWebView *view,
                         GParamSpec  *pspec,
                         EphyWindow  *window)
 {
-  GtkActionGroup *action_group = window->action_group;
-  GtkAction *action;
-  GAction *new_action;
+  GAction *action;
   EphyWebViewDocumentType type;
   gboolean can_find, disable, is_image;
 
@@ -1278,16 +1270,16 @@ sync_tab_document_type (EphyWebView *view,
   is_image = type == EPHY_WEB_VIEW_DOCUMENT_IMAGE;
   disable = (type != EPHY_WEB_VIEW_DOCUMENT_HTML);
 
-  action = gtk_action_group_get_action (action_group, "ViewEncoding");
-  ephy_action_change_sensitivity_flags (action, SENS_FLAG_DOCUMENT, disable);
-  action = gtk_action_group_get_action (action_group, "ViewPageSource");
-  ephy_action_change_sensitivity_flags (action, SENS_FLAG_DOCUMENT, is_image);
-  new_action = g_action_map_lookup_action (G_ACTION_MAP (window), "find");
-  new_ephy_action_change_sensitivity_flags (G_SIMPLE_ACTION (new_action), SENS_FLAG_DOCUMENT, !can_find);
-  new_action = g_action_map_lookup_action (G_ACTION_MAP (window), "find-prev");
-  new_ephy_action_change_sensitivity_flags (G_SIMPLE_ACTION (new_action), SENS_FLAG_DOCUMENT, !can_find);
-  new_action = g_action_map_lookup_action (G_ACTION_MAP (window), "find-next");
-  new_ephy_action_change_sensitivity_flags (G_SIMPLE_ACTION (new_action), SENS_FLAG_DOCUMENT, !can_find);
+  action = g_action_map_lookup_action (G_ACTION_MAP (window), "encoding");
+  new_ephy_action_change_sensitivity_flags (G_SIMPLE_ACTION (action), SENS_FLAG_DOCUMENT, disable);
+  action = g_action_map_lookup_action (G_ACTION_MAP (window), "page-source");
+  new_ephy_action_change_sensitivity_flags (G_SIMPLE_ACTION (action), SENS_FLAG_DOCUMENT, is_image);
+  action = g_action_map_lookup_action (G_ACTION_MAP (window), "find");
+  new_ephy_action_change_sensitivity_flags (G_SIMPLE_ACTION (action), SENS_FLAG_DOCUMENT, !can_find);
+  action = g_action_map_lookup_action (G_ACTION_MAP (window), "find-prev");
+  new_ephy_action_change_sensitivity_flags (G_SIMPLE_ACTION (action), SENS_FLAG_DOCUMENT, !can_find);
+  action = g_action_map_lookup_action (G_ACTION_MAP (window), "find-next");
+  new_ephy_action_change_sensitivity_flags (G_SIMPLE_ACTION (action), SENS_FLAG_DOCUMENT, !can_find);
 
   if (!can_find) {
     ephy_find_toolbar_request_close (ephy_embed_get_find_toolbar (window->active_embed));
@@ -3089,8 +3081,6 @@ setup_location_controller (EphyWindow  *window,
 static const char *disabled_actions_for_app_mode[] = { "FileOpen",
                                                        "FileNewWindow",
                                                        "FileNewWindowIncognito",
-                                                       "ViewEncoding",
-                                                       "ViewPageSource",
                                                        "ViewToggleInspector",
                                                        "FileBookmarkPage",
                                                        "EditBookmarks",
@@ -3098,7 +3088,9 @@ static const char *disabled_actions_for_app_mode[] = { "FileOpen",
                                                        "EditPreferences" };
 
 static const char *new_disabled_actions_for_app_mode[] = { "save-as",
-                                                       "save-as-application" };
+                                                       "save-as-application",
+                                                       "encoding",
+                                                       "page-source" };
 
 static void
 parse_css_error (GtkCssProvider *provider,
@@ -3165,11 +3157,11 @@ static const GActionEntry new_ephy_page_menu_entries [] =
   { "find", window_cmd_edit_find },
   { "find-prev", window_cmd_edit_find_prev },
   { "find-next", window_cmd_edit_find_next },
-  { "bookmarks", },
-  { "bookmark-page", },
-  { "view-encoding", },
-  { "view-page-source", },
-  { "close-tab", }
+  // { "bookmarks", },
+  // { "bookmark-page", },
+  { "encoding", window_cmd_view_encoding },
+  { "page-source", window_cmd_view_page_source },
+  { "close-tab", window_cmd_file_close_window }
 };
 
 static GObject *
diff --git a/src/resources/epiphany-ui.xml b/src/resources/epiphany-ui.xml
index d62d7a1..289200f 100644
--- a/src/resources/epiphany-ui.xml
+++ b/src/resources/epiphany-ui.xml
@@ -5,7 +5,7 @@
                        <menuitem name="TabMoveRightENP" action="TabsMoveRight"/>
                </placeholder>
                <menuitem name="TabDuplicateENP" action="TabsDuplicate"/>
-               <menuitem name="TabCloseENP" action="FileCloseTab"/>
+               <!-- <menuitem name="TabCloseENP" action="FileCloseTab"/> -->
                <!-- <menuitem name="TabDetachENP" action="TabsDetach"/> -->
        </popup>
 
@@ -24,12 +24,9 @@
                        <separator name="BookmarksSep1"/>
                </menu>
                 <separator name="FileSep5"/>
-                <menuitem name="ViewEncodingMenu" action="ViewEncoding"/>
-                <menuitem name="ViewPageSourceMenu" action="ViewPageSource"/>
                 <separator name="FileSep6"/>
                 <menuitem name="HelpContentsMenu" action="HelpContents"/>
                 <menuitem name="HelpAboutMenu" action="HelpAbout"/>
-                <menuitem name="FileCloseWindowMenu" action="FileCloseTab"/>
                 <menuitem name="FileQuitMenu" action="FileQuit"/>
        </popup>
 
diff --git a/src/resources/gtk/menus.ui b/src/resources/gtk/menus.ui
index bbbc983..9a0a4dd 100644
--- a/src/resources/gtk/menus.ui
+++ b/src/resources/gtk/menus.ui
@@ -16,12 +16,10 @@
       <item>
         <attribute name="label" translatable="yes">Save _As…</attribute>
         <attribute name="action">win.save-as</attribute>
-        <attribute name="hidden-when">action-disabled</attribute>
       </item>
       <item>
         <attribute name="label" translatable="yes">Save As _Web Application…</attribute>
         <attribute name="action">win.save-as-application</attribute>
-        <attribute name="hidden-when">action-disabled</attribute>
       </item>
     </section>
     <section>
@@ -79,13 +77,13 @@
         <attribute name="label" translatable="yes">Edit _Bookmarks</attribute>
         <attribute name="action">win.bookmarks</attribute>
       </item>
-      <submenu id="bookmarkks-menu">
+      <submenu id="bookmarks-menu">
         <item>
           <attribute name="label" translatable="yes">_Add Bookmark…</attribute>
           <attribute name="action">win.bookmark-page</attribute>
         </item>
       </submenu>
-    </section>
+    </section> -->
     <section>
       <item>
         <attribute name="label" translatable="yes">Text _Encoding</attribute>
@@ -101,6 +99,6 @@
         <attribute name="label" translatable="yes">_Close</attribute>
         <attribute name="action">win.close-tab</attribute>
       </item>
-    </section> -->
+    </section>
   </menu>
 </interface>
diff --git a/src/window-commands.c b/src/window-commands.c
index db77ffc..995ca79 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -252,27 +252,6 @@ window_cmd_file_open (GtkAction  *action,
 }
 
 void
-window_cmd_file_close_window (GtkAction  *action,
-                              EphyWindow *window)
-{
-  GtkWidget *notebook;
-  EphyEmbed *embed;
-
-  notebook = ephy_window_get_notebook (window);
-
-  if (g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN,
-                              EPHY_PREFS_LOCKDOWN_QUIT) &&
-      gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)) == 1) {
-    return;
-  }
-
-  embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
-  g_return_if_fail (embed != NULL);
-
-  g_signal_emit_by_name (notebook, "tab-close-request", embed);
-}
-
-void
 window_cmd_file_quit (GtkAction  *action,
                       EphyWindow *window)
 {
@@ -1162,6 +1141,19 @@ window_cmd_view_zoom_normal (GSimpleAction *action,
   ephy_window_set_zoom (window, 1.0);
 }
 
+void
+window_cmd_view_encoding (GSimpleAction *action,
+                          GVariant      *value,
+                          gpointer       user_data)
+{
+  EphyWindow *window = user_data;
+  EphyEncodingDialog *dialog;
+
+  dialog = ephy_encoding_dialog_new (window);
+  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window));
+  gtk_dialog_run (GTK_DIALOG (dialog));
+}
+
 static void
 view_source_embedded (const char *uri, EphyEmbed *embed)
 {
@@ -1352,9 +1344,11 @@ save_temp_source (EphyEmbed *embed,
 }
 
 void
-window_cmd_view_page_source (GtkAction  *action,
-                             EphyWindow *window)
+window_cmd_view_page_source (GSimpleAction *action,
+                             GVariant      *value,
+                             gpointer       user_data)
 {
+  EphyWindow *window = user_data;
   EphyEmbed *embed;
   const char *address;
   guint32 user_time;
@@ -1415,6 +1409,29 @@ window_cmd_view_toggle_inspector (GtkAction  *action,
 }
 
 void
+window_cmd_file_close_window (GSimpleAction *action,
+                              GVariant      *value,
+                              gpointer       user_data)
+{
+  EphyWindow *window = user_data;
+  GtkWidget *notebook;
+  EphyEmbed *embed;
+
+  notebook = ephy_window_get_notebook (window);
+
+  if (g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN,
+                              EPHY_PREFS_LOCKDOWN_QUIT) &&
+      gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)) == 1) {
+    return;
+  }
+
+  embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
+  g_return_if_fail (embed != NULL);
+
+  g_signal_emit_by_name (notebook, "tab-close-request", embed);
+}
+
+void
 window_cmd_help_contents (GtkAction *action,
                           GtkWidget *window)
 {
@@ -1708,14 +1725,3 @@ window_cmd_browse_with_caret (GtkAction  *action,
   g_settings_set_boolean (EPHY_SETTINGS_MAIN,
                           EPHY_PREFS_ENABLE_CARET_BROWSING, active);
 }
-
-void
-window_cmd_view_encoding (GtkAction  *action,
-                          EphyWindow *window)
-{
-  EphyEncodingDialog *dialog;
-
-  dialog = ephy_encoding_dialog_new (window);
-  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window));
-  gtk_dialog_run (GTK_DIALOG (dialog));
-}
diff --git a/src/window-commands.h b/src/window-commands.h
index bcd2cf7..a3cf1f2 100644
--- a/src/window-commands.h
+++ b/src/window-commands.h
@@ -38,10 +38,6 @@ void window_cmd_undo_close_tab            (GtkAction *action,
                                            EphyWindow *window);
 void window_cmd_file_send_to              (GtkAction  *action,
                                            EphyWindow *window);
-void window_cmd_file_close_window         (GtkAction  *action,
-                                           EphyWindow *window);
-void window_cmd_view_encoding             (GtkAction  *action,
-                                           EphyWindow *window);
 void window_cmd_view_fullscreen           (GtkAction  *action,
                                            EphyWindow *window);
 void window_cmd_file_save_as              (GSimpleAction *action,
@@ -92,10 +88,17 @@ void window_cmd_view_zoom_out             (GSimpleAction *action,
 void window_cmd_view_zoom_normal          (GSimpleAction *action,
                                            GVariant      *value,
                                            gpointer       user_data);
-void window_cmd_view_page_source          (GtkAction  *action,
-                                           EphyWindow *window);
 void window_cmd_view_toggle_inspector     (GtkAction  *action,
                                            EphyWindow *window);
+void window_cmd_view_encoding             (GSimpleAction *action,
+                                           GVariant      *value,
+                                           gpointer       user_data);
+void window_cmd_view_page_source          (GSimpleAction *action,
+                                           GVariant      *value,
+                                           gpointer       user_data);
+void window_cmd_file_close_window         (GSimpleAction *action,
+                                           GVariant      *value,
+                                           gpointer       user_data);
 void window_cmd_help_contents             (GtkAction  *action,
                                            GtkWidget  *window);
 void window_cmd_help_about                (GtkAction  *action,


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