[epiphany/wip/gtkaction-to-gaction: 43/54] Port Print and Find to GAction



commit b5fc965928edeec39b764bce24e4837fc623b379
Author: Iulian Radu <iulian radu67 gmail com>
Date:   Fri May 13 18:57:57 2016 +0300

    Port Print and Find to GAction

 src/ephy-lockdown.c           |   66 ++++++++++++++++++++++++-
 src/ephy-window.c             |   60 +++++++++-------------
 src/resources/epiphany-ui.xml |    2 -
 src/resources/gtk/menus.ui    |    6 +-
 src/window-commands.c         |  109 +++++++++++++++++++++++------------------
 src/window-commands.h         |   20 +++++---
 6 files changed, 164 insertions(+), 99 deletions(-)
---
diff --git a/src/ephy-lockdown.c b/src/ephy-lockdown.c
index 3589385..a886240 100644
--- a/src/ephy-lockdown.c
+++ b/src/ephy-lockdown.c
@@ -99,8 +99,6 @@ typedef struct {
 } BindAction;
 
 static const BindAction window_actions[] = {
-  { EPHY_PREFS_LOCKDOWN_PRINTING, "FilePrint", "sensitive" },
-
   { EPHY_PREFS_LOCKDOWN_BOOKMARK_EDITING, "FileBookmarkPage", "sensitive" },
 
   { EPHY_PREFS_LOCKDOWN_ARBITRARY_URL, "GoLocation", "sensitive" },
@@ -112,6 +110,10 @@ static const BindAction window_actions[] = {
   { EPHY_PREFS_LOCKDOWN_FULLSCREEN, "FileNewWindowIncognito", "sensitive" }
 };
 
+static const BindAction new_window_actions[] = {
+  { EPHY_PREFS_LOCKDOWN_PRINTING, "print", "enabled" }
+};
+
 static const BindAction popup_actions[] = {
   { EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "DownloadLinkAs", "sensitive" },
   { EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "SaveImageAs", "sensitive" },
@@ -149,6 +151,28 @@ sensitive_get_mapping (GValue   *value,
   return TRUE;
 }
 
+static gboolean
+new_sensitive_get_mapping (GValue   *value,
+                       GVariant *variant,
+                       gpointer  data)
+{
+  GAction *action;
+  gboolean active, before, after;
+
+  action = G_ACTION (data);
+  active = g_variant_get_boolean (variant);
+
+  before = g_action_get_enabled (action);
+  new_ephy_action_change_sensitivity_flags (G_SIMPLE_ACTION (action), LOCKDOWN_FLAG, active);
+  after = g_action_get_enabled (action);
+
+  /* Set (GAction::enabled) to the value in GSettings _only if_
+   * the LOCKDOWN_FLAG had some real effect in the GtkAction */
+  g_value_set_boolean (value, (before != after) ? after : before);
+
+  return TRUE;
+}
+
 static void
 bind_settings_and_actions (GSettings        *settings,
                            GtkActionGroup   *action_group,
@@ -184,6 +208,40 @@ bind_settings_and_actions (GSettings        *settings,
 }
 
 static void
+new_bind_settings_and_actions (GSettings        *settings,
+                           GActionGroup     *action_group,
+                           const BindAction *actions,
+                           int               actions_n)
+{
+  int i;
+
+  for (i = 0; i < actions_n; i++) {
+    GAction *action;
+
+    action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
+                                         actions[i].action);
+
+    if (g_strcmp0 (actions[i].prop, "visible") == 0) {
+      g_settings_bind (settings, actions[i].key,
+                       action, actions[i].prop,
+                       G_SETTINGS_BIND_GET |
+                       G_SETTINGS_BIND_INVERT_BOOLEAN);
+    } else {
+      /* We need a custom get_mapping for 'sensitive'
+       * properties, see usage of
+       * ephy_action_change_sensitivity_flags in
+       * ephy-window.c. */
+      g_settings_bind_with_mapping (settings, actions[i].key,
+                                    action, actions[i].prop,
+                                    G_SETTINGS_BIND_GET,
+                                    new_sensitive_get_mapping,
+                                    NULL,
+                                    action, NULL);
+    }
+  }
+}
+
+static void
 bind_location_controller (GSettings              *settings,
                           EphyLocationController *controller)
 {
@@ -227,6 +285,10 @@ window_added_cb (GtkApplication *application,
                              action_group, window_actions,
                              G_N_ELEMENTS (window_actions));
 
+  new_bind_settings_and_actions (EPHY_SETTINGS_LOCKDOWN,
+                             G_ACTION_GROUP (window), new_window_actions,
+                             G_N_ELEMENTS (new_window_actions));
+
   action_group = find_action_group (manager, "PopupsActions");
   bind_settings_and_actions (EPHY_SETTINGS_LOCKDOWN,
                              action_group, popup_actions,
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 45a04fb..6272520 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -96,8 +96,6 @@ static const GtkActionEntry ephy_menu_entries [] = {
     G_CALLBACK (window_cmd_file_save_as) },
   { "FileSaveAsApplication", NULL, N_("Save As _Web Application…"), "<shift><control>A", NULL,
     G_CALLBACK (window_cmd_file_save_as_application) },
-  { "FilePrint", NULL, N_("_Print…"), "<control>P", NULL,
-    G_CALLBACK (window_cmd_file_print) },
   { "FileSendTo", NULL, N_("S_end Link by Email…"), NULL, NULL,
     G_CALLBACK (window_cmd_file_send_to) },
   { "FileCloseTab", NULL, N_("_Close"), "<control>W", NULL,
@@ -121,12 +119,6 @@ static const GtkActionEntry ephy_menu_entries [] = {
     G_CALLBACK (window_cmd_edit_delete) },
   { "EditSelectAll", NULL, N_("Select _All"), "<control>A", NULL,
     G_CALLBACK (window_cmd_edit_select_all) },
-  { "EditFind", NULL, N_("_Find…"), "<control>F", NULL,
-    G_CALLBACK (window_cmd_edit_find) },
-  { "EditFindNext", NULL, N_("Find Ne_xt"), "<control>G", NULL,
-    G_CALLBACK (window_cmd_edit_find_next) },
-  { "EditFindPrev", NULL, N_("Find Pre_vious"), "<shift><control>G", NULL,
-    G_CALLBACK (window_cmd_edit_find_prev) },
   { "EditBookmarks", NULL, N_("Edit _Bookmarks"), "<control>B", NULL,
     G_CALLBACK (window_cmd_edit_bookmarks) },
   { "EditHistory", NULL, N_("_History"), "<control>H", NULL,
@@ -266,9 +258,6 @@ static const struct {
   { GDK_KEY_Home, GDK_MOD1_MASK, "FileHome", TRUE },
   /* FIXME: these are not in any menu for now, so add them here. */
   { GDK_KEY_F11, 0, "ViewFullscreen", FALSE },
-  { GDK_KEY_g, GDK_CONTROL_MASK, "EditFindNext", FALSE },
-  { GDK_KEY_G, GDK_CONTROL_MASK |
-    GDK_SHIFT_MASK, "EditFindPrev", FALSE },
 
   { GDK_KEY_s, GDK_CONTROL_MASK, "FileSaveAs", FALSE },
   { GDK_KEY_r, GDK_CONTROL_MASK, "ViewReload", FALSE },
@@ -318,7 +307,6 @@ static const struct {
   { XF86XK_AddFavorite, 0, "FileBookmarkPage", FALSE },
   { XF86XK_Refresh, 0, "ViewReload", FALSE },
   { XF86XK_Reload, 0, "ViewReload", FALSE },
-  { XF86XK_Search, 0, "EditFind", FALSE },
   { XF86XK_Send, 0, "FileSendTo", FALSE },
   { XF86XK_Stop, 0, "ViewStop", FALSE },
   /* FIXME: what about ScrollUp, ScrollDown, Menu*, Option, LogOff, Save,.. any others? */
@@ -341,7 +329,11 @@ const struct {
 } accels [] = {
   { "win.zoom-in", { "<control>plus", "<control>KP_Add", "<control>equal", "ZoomIn", NULL } },
   { "win.zoom-out", { "<control>minus", "<control>KP_Subtract", "ZoomOut", NULL } },
-  { "win.zoom-normal", { "<control>0", "<control>KP_0", NULL } }
+  { "win.zoom-normal", { "<control>0", "<control>KP_0", NULL } },
+  { "win.print", { "<control>P", NULL } },
+  { "win.find", { "<control>F", "Search", NULL } },
+  { "win.find-prev", { "<shift><control>G", "Search", NULL } },
+  { "win.find-next", { "<control>G", NULL } }
 };
 
 #define SETTINGS_CONNECTION_DATA_KEY    "EphyWindowSettings"
@@ -681,6 +673,7 @@ sync_tab_load_status (EphyWebView    *view,
 {
   GtkActionGroup *action_group = window->action_group;
   GtkAction *action;
+  GAction *new_action;
   gboolean loading;
 
   if (window->closing) return;
@@ -691,8 +684,8 @@ sync_tab_load_status (EphyWebView    *view,
   gtk_action_set_sensitive (action, loading);
 
   /* disable print while loading, see bug #116344 */
-  action = gtk_action_group_get_action (action_group, "FilePrint");
-  ephy_action_change_sensitivity_flags (action, SENS_FLAG_LOADING, loading);
+  new_action = g_action_map_lookup_action (G_ACTION_MAP (window), "print");
+  new_ephy_action_change_sensitivity_flags (G_SIMPLE_ACTION (new_action), SENS_FLAG_LOADING, loading);
 
   action = gtk_action_group_get_action (window->toolbar_action_group,
                                         "ViewCombinedStopReload");
@@ -1089,15 +1082,8 @@ setup_ui_manager (EphyWindow *window)
   g_object_set (action, "short_label", _("Save As"), NULL);
   action = gtk_action_group_get_action (action_group, "FileSaveAsApplication");
   g_object_set (action, "short_label", _("Save As Application"), NULL);
-  action = gtk_action_group_get_action (action_group, "FilePrint");
-  g_object_set (action, "short_label", _("Print"), NULL);
   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, "EditFind");
-  g_object_set (action, "short_label", _("Find"), NULL);
-
-  action = gtk_action_group_get_action (action_group, "EditFind");
-  g_object_set (action, "is_important", TRUE, NULL);
 
   action = gtk_action_group_get_action (action_group, "ViewEncoding");
   g_object_set (action, "short_label", _("Encodings…"), NULL);
@@ -1200,13 +1186,12 @@ _ephy_window_set_default_actions_sensitive (EphyWindow *window,
   GtkAction *action;
   GAction *new_action;
   int i;
-  const char *action_group_actions[] = { "FileSaveAs", "FileSaveAsApplication", "FilePrint",
-                                         "FileSendTo", "FileBookmarkPage", "EditFind",
-                                         "EditFindPrev", "EditFindNext", "ViewEncoding",
-                                         "ViewPageSource",
+  const char *action_group_actions[] = { "FileSaveAs", "FileSaveAsApplication", "FileSendTo",
+                                         "FileBookmarkPage", "ViewEncoding", "ViewPageSource",
                                          NULL };
 
-  const char *new_action_group_actions[] = { "zoom-in", "zoom-out",
+  const char *new_action_group_actions[] = { "zoom-in", "zoom-out", "print",
+                                         "find", "find-prev", "find-next",
                                          NULL };
 
   action_group = window->action_group;
@@ -1300,6 +1285,7 @@ sync_tab_document_type (EphyWebView *view,
 {
   GtkActionGroup *action_group = window->action_group;
   GtkAction *action;
+  GAction *new_action;
   EphyWebViewDocumentType type;
   gboolean can_find, disable, is_image;
 
@@ -1317,12 +1303,12 @@ sync_tab_document_type (EphyWebView *view,
   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);
-  action = gtk_action_group_get_action (action_group, "EditFind");
-  ephy_action_change_sensitivity_flags (action, SENS_FLAG_DOCUMENT, !can_find);
-  action = gtk_action_group_get_action (action_group, "EditFindNext");
-  ephy_action_change_sensitivity_flags (action, SENS_FLAG_DOCUMENT, !can_find);
-  action = gtk_action_group_get_action (action_group, "EditFindPrev");
-  ephy_action_change_sensitivity_flags (action, SENS_FLAG_DOCUMENT, !can_find);
+  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);
 
   if (!can_find) {
     ephy_find_toolbar_request_close (ephy_embed_get_find_toolbar (window->active_embed));
@@ -3117,9 +3103,11 @@ static const GActionEntry new_ephy_page_menu_entries [] =
   { "zoom-in", window_cmd_view_zoom_in },
   { "zoom-out", window_cmd_view_zoom_out },
   { "zoom-normal", window_cmd_view_zoom_normal },
-  { "zoom", NULL, "d", "1.0", zoom_to_level_cb }
-  // { "print", },
-  // { "find", },
+  { "zoom", NULL, "d", "1.0", zoom_to_level_cb },
+  { "print", window_cmd_file_print },
+  { "find", window_cmd_edit_find },
+  { "find-prev", window_cmd_edit_find_prev },
+  { "find-next", window_cmd_edit_find_next }
   // { "bookmarks", },
   // { "bookmark-page", },
   // { "view-encoding", },
diff --git a/src/resources/epiphany-ui.xml b/src/resources/epiphany-ui.xml
index aa3e324..85e94ad 100644
--- a/src/resources/epiphany-ui.xml
+++ b/src/resources/epiphany-ui.xml
@@ -25,8 +25,6 @@
                 <menuitem name="EditCopyMenu" action="EditCopy"/>
                 <menuitem name="EditPasteMenu" action="EditPaste"/>
                 <separator name="EditSep3"/> 
-                <menuitem name="FilePrintMenu" action="FilePrint"/>
-                <menuitem name="EditFindMenu" action="EditFind"/>
                 <menuitem name="EditPreferencesMenu" action="EditPreferences"/>
                 <separator name="FileSep4"/>
                 <menuitem name="HistoryEditMenu" action="EditHistory"/>
diff --git a/src/resources/gtk/menus.ui b/src/resources/gtk/menus.ui
index 86165ea..a8a4dd8 100644
--- a/src/resources/gtk/menus.ui
+++ b/src/resources/gtk/menus.ui
@@ -52,17 +52,17 @@
         <attribute name="action">win.zoom-out</attribute>
       </item>
     </section>
-<!--     <section>
+    <section>
       <item>
         <attribute name="label" translatable="yes">Print…</attribute>
-        <attribute name="action">win.file-print</attribute>
+        <attribute name="action">win.print</attribute>
       </item>
       <item>
         <attribute name="label" translatable="yes">_Find…</attribute>
         <attribute name="action">win.find</attribute>
       </item>
     </section>
-    <section>
+    <!-- <section>
       <item>
         <attribute name="label" translatable="yes">Edit _Bookmarks</attribute>
         <attribute name="action">win.bookmarks</attribute>
diff --git a/src/window-commands.c b/src/window-commands.c
index 3e0856c..942c210 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -62,21 +62,6 @@
 #define FAVICON_SIZE 16
 
 void
-window_cmd_file_print (GtkAction  *action,
-                       EphyWindow *window)
-{
-  EphyEmbed *embed;
-  EphyWebView *view;
-
-  embed = ephy_embed_container_get_active_child
-            (EPHY_EMBED_CONTAINER (window));
-  g_return_if_fail (EPHY_IS_EMBED (embed));
-  view = ephy_embed_get_web_view (embed);
-
-  ephy_web_view_print (view);
-}
-
-void
 window_cmd_undo_close_tab (GtkAction  *action,
                            EphyWindow *window)
 {
@@ -1028,36 +1013,6 @@ window_cmd_edit_select_all (GtkAction  *action,
 }
 
 void
-window_cmd_edit_find (GtkAction  *action,
-                      EphyWindow *window)
-{
-  EphyFindToolbar *toolbar;
-
-  toolbar = EPHY_FIND_TOOLBAR (ephy_window_get_current_find_toolbar (window));
-  ephy_find_toolbar_toggle_state (toolbar);
-}
-
-void
-window_cmd_edit_find_next (GtkAction  *action,
-                           EphyWindow *window)
-{
-  EphyFindToolbar *toolbar;
-
-  toolbar = EPHY_FIND_TOOLBAR (ephy_window_get_current_find_toolbar (window));
-  ephy_find_toolbar_find_next (toolbar);
-}
-
-void
-window_cmd_edit_find_prev (GtkAction  *action,
-                           EphyWindow *window)
-{
-  EphyFindToolbar *toolbar;
-
-  toolbar = EPHY_FIND_TOOLBAR (ephy_window_get_current_find_toolbar (window));
-  ephy_find_toolbar_find_previous (toolbar);
-}
-
-void
 window_cmd_edit_bookmarks (GtkAction  *action,
                            EphyWindow *window)
 {
@@ -1107,11 +1062,66 @@ window_cmd_view_fullscreen (GtkAction  *action,
 }
 
 void
+window_cmd_file_print (GSimpleAction *action,
+                       GVariant      *value,
+                       gpointer       user_data)
+{
+  EphyWindow *window = user_data;
+  EphyEmbed *embed;
+  EphyWebView *view;
+
+  embed = ephy_embed_container_get_active_child
+            (EPHY_EMBED_CONTAINER (window));
+  g_return_if_fail (EPHY_IS_EMBED (embed));
+  view = ephy_embed_get_web_view (embed);
+
+  ephy_web_view_print (view);
+}
+
+void
+window_cmd_edit_find (GSimpleAction *action,
+                      GVariant      *value,
+                      gpointer       user_data)
+{
+  EphyWindow *window = user_data;
+  EphyFindToolbar *toolbar;
+
+  toolbar = EPHY_FIND_TOOLBAR (ephy_window_get_current_find_toolbar (window));
+  ephy_find_toolbar_toggle_state (toolbar);
+}
+
+void
+window_cmd_edit_find_prev (GSimpleAction *action,
+                           GVariant      *value,
+                           gpointer       user_data)
+{
+  EphyWindow *window = user_data;
+  EphyFindToolbar *toolbar;
+
+  toolbar = EPHY_FIND_TOOLBAR (ephy_window_get_current_find_toolbar (window));
+  ephy_find_toolbar_find_previous (toolbar);
+}
+
+void
+window_cmd_edit_find_next (GSimpleAction *action,
+                           GVariant      *value,
+                           gpointer       user_data)
+{
+  EphyWindow *window = user_data;
+  EphyFindToolbar *toolbar;
+
+  toolbar = EPHY_FIND_TOOLBAR (ephy_window_get_current_find_toolbar (window));
+  ephy_find_toolbar_find_next (toolbar);
+}
+
+void
 window_cmd_view_zoom_in (GSimpleAction *action,
                          GVariant      *value,
                          gpointer       user_data)
 {
-  ephy_window_set_zoom (EPHY_WINDOW (user_data), ZOOM_IN);
+  EphyWindow *window = user_data;
+
+  ephy_window_set_zoom (window, ZOOM_IN);
 }
 
 void
@@ -1119,7 +1129,9 @@ window_cmd_view_zoom_out (GSimpleAction *action,
                           GVariant      *value,
                           gpointer       user_data)
 {
-  ephy_window_set_zoom (EPHY_WINDOW (user_data), ZOOM_OUT);
+  EphyWindow *window = user_data;
+
+  ephy_window_set_zoom (window, ZOOM_OUT);
 }
 
 void
@@ -1127,7 +1139,8 @@ window_cmd_view_zoom_normal (GSimpleAction *action,
                              GVariant      *value,
                              gpointer       user_data)
 {
-  ephy_window_set_zoom (EPHY_WINDOW (user_data), 1.0);
+  EphyWindow *window = user_data;
+  ephy_window_set_zoom (window, 1.0);
 }
 
 static void
diff --git a/src/window-commands.h b/src/window-commands.h
index 1626ab1..ba8e608 100644
--- a/src/window-commands.h
+++ b/src/window-commands.h
@@ -24,8 +24,6 @@
 
 G_BEGIN_DECLS
 
-void window_cmd_edit_find                 (GtkAction  *action,
-                                           EphyWindow *window);
 void window_cmd_view_stop                 (GtkAction  *action,
                                            EphyWindow *window);
 void window_cmd_go_location               (GtkAction  *action,
@@ -40,8 +38,6 @@ void window_cmd_file_save_as              (GtkAction  *action,
                                            EphyWindow *window);
 void window_cmd_file_save_as_application  (GtkAction  *action,
                                            EphyWindow *window);
-void window_cmd_file_print                (GtkAction  *action,
-                                           EphyWindow *window);
 void window_cmd_undo_close_tab            (GtkAction *action,
                                            EphyWindow *window);
 void window_cmd_file_send_to              (GtkAction  *action,
@@ -62,14 +58,22 @@ void window_cmd_edit_delete               (GtkAction  *action,
                                            EphyWindow *window);
 void window_cmd_edit_select_all           (GtkAction  *action,
                                            EphyWindow *window);
-void window_cmd_edit_find_next            (GtkAction  *action,
-                                           EphyWindow *window);
-void window_cmd_edit_find_prev            (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_print                (GSimpleAction *action,
+                                           GVariant      *value,
+                                           gpointer       user_data);
+void window_cmd_edit_find                 (GSimpleAction *action,
+                                           GVariant      *value,
+                                           gpointer       user_data);
+void window_cmd_edit_find_prev            (GSimpleAction *action,
+                                           GVariant      *value,
+                                           gpointer       user_data);
+void window_cmd_edit_find_next            (GSimpleAction *action,
+                                           GVariant      *value,
+                                           gpointer       user_data);
 void window_cmd_view_zoom_in              (GSimpleAction *action,
                                            GVariant      *value,
                                            gpointer       user_data);


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