[gedit] Update view centering in GeditWindow



commit a2b49a83e10e26ae29bff487d873582d9abf7842
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri Jun 26 12:51:13 2015 +0200

    Update view centering in GeditWindow
    
    The view centering was updated in GeditViewFrame (depending on whether
    the GtkWindow is in fullscreen mode). A class should not be aware of who
    contains it.
    
    This commit moves the code to GeditWindow. GeditViewFrame is thus more
    self-contained and more reusable. The fullscreen mode is an attribute of
    the window, so it's logical to put the code in GeditWindow (to keep
    related data and behavior together).
    
    The code in GeditWindow is also more straightforward, no need to
    disconnect/reconnect signals etc.

 gedit/gedit-view-frame.c |   61 ++++++----------------------------------------
 gedit/gedit-view-frame.h |   13 ++++++----
 gedit/gedit-window.c     |   22 ++++++++++++++++
 3 files changed, 38 insertions(+), 58 deletions(-)
---
diff --git a/gedit/gedit-view-frame.c b/gedit/gedit-view-frame.c
index f684962..3f64e61 100644
--- a/gedit/gedit-view-frame.c
+++ b/gedit/gedit-view-frame.c
@@ -98,10 +98,6 @@ struct _GeditViewFrame
         */
        gchar *search_text;
        gchar *old_search_text;
-
-       /* Track if the window is in fullscreen mode. */
-       GtkWindow *window;
-       gint window_state_changed_handler_id;
 };
 
 enum
@@ -153,13 +149,6 @@ gedit_view_frame_dispose (GObject *object)
                frame->remove_entry_tag_timeout_id = 0;
        }
 
-       if (frame->window_state_changed_handler_id != 0)
-       {
-               g_signal_handler_disconnect (frame->window,
-                                            frame->window_state_changed_handler_id);
-               frame->window_state_changed_handler_id = 0;
-       }
-
        if (buffer != NULL)
        {
                GtkSourceFile *file = gedit_document_get_file (GEDIT_DOCUMENT (buffer));
@@ -1485,43 +1474,6 @@ view_frame_mount_operation_factory (GtkSourceFile *file,
        return gtk_mount_operation_new (GTK_WINDOW (window));
 }
 
-static gboolean
-on_window_state_changed (GtkWidget           *widget,
-                         GdkEventWindowState *event,
-                         GeditViewFrame      *frame)
-{
-       gboolean fullscreen_state;
-
-       fullscreen_state = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
-
-       gedit_view_holder_set_centering (frame->view_holder, fullscreen_state);
-
-       return FALSE;
-}
-
-static void
-on_toplevel_window_changed (GtkWidget      *widget,
-                            GtkWidget      *previous_toplevel,
-                            GeditViewFrame *frame)
-{
-       if (frame->window_state_changed_handler_id != 0)
-       {
-               g_signal_handler_disconnect (frame->window,
-                                            frame->window_state_changed_handler_id);
-               frame->window_state_changed_handler_id = 0;
-       }
-
-       frame->window = GTK_WINDOW (gtk_widget_get_ancestor (GTK_WIDGET (frame), GTK_TYPE_WINDOW));
-
-       if (frame->window != NULL)
-       {
-               frame->window_state_changed_handler_id = g_signal_connect (frame->window,
-                                                                          "window-state-event",
-                                                                          G_CALLBACK 
(on_window_state_changed),
-                                                                          frame);
-       }
-}
-
 static void
 gedit_view_frame_init (GeditViewFrame *frame)
 {
@@ -1631,11 +1583,6 @@ gedit_view_frame_init (GeditViewFrame *frame)
                                  "clicked",
                                  G_CALLBACK (forward_search),
                                  frame);
-
-       g_signal_connect (frame,
-                         "hierarchy-changed",
-                         G_CALLBACK (on_toplevel_window_changed),
-                         frame);
 }
 
 GeditViewFrame *
@@ -1644,6 +1591,14 @@ gedit_view_frame_new (void)
        return g_object_new (GEDIT_TYPE_VIEW_FRAME, NULL);
 }
 
+GeditViewHolder *
+gedit_view_frame_get_view_holder (GeditViewFrame *frame)
+{
+       g_return_val_if_fail (GEDIT_IS_VIEW_FRAME (frame), NULL);
+
+       return frame->view_holder;
+}
+
 GeditView *
 gedit_view_frame_get_view (GeditViewFrame *frame)
 {
diff --git a/gedit/gedit-view-frame.h b/gedit/gedit-view-frame.h
index a01ee83..874ebf8 100644
--- a/gedit/gedit-view-frame.h
+++ b/gedit/gedit-view-frame.h
@@ -24,21 +24,24 @@
 #include <gtk/gtk.h>
 #include "gedit-document.h"
 #include "gedit-view.h"
+#include "gedit-view-holder.h"
 
 G_BEGIN_DECLS
 
 #define GEDIT_TYPE_VIEW_FRAME (gedit_view_frame_get_type ())
 G_DECLARE_FINAL_TYPE (GeditViewFrame, gedit_view_frame, GEDIT, VIEW_FRAME, GtkOverlay)
 
-GeditViewFrame *gedit_view_frame_new           (void);
+GeditViewFrame *gedit_view_frame_new                   (void);
 
-GeditView      *gedit_view_frame_get_view      (GeditViewFrame *frame);
+GeditViewHolder        *gedit_view_frame_get_view_holder       (GeditViewFrame *frame);
 
-void            gedit_view_frame_popup_search  (GeditViewFrame *frame);
+GeditView      *gedit_view_frame_get_view              (GeditViewFrame *frame);
 
-void            gedit_view_frame_popup_goto_line (GeditViewFrame *frame);
+void            gedit_view_frame_popup_search          (GeditViewFrame *frame);
 
-void            gedit_view_frame_clear_search  (GeditViewFrame *frame);
+void            gedit_view_frame_popup_goto_line       (GeditViewFrame *frame);
+
+void            gedit_view_frame_clear_search          (GeditViewFrame *frame);
 
 G_END_DECLS
 
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index a9bd648..44bd5e6 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -41,6 +41,8 @@
 #include "gedit-statusbar.h"
 #include "gedit-tab.h"
 #include "gedit-tab-private.h"
+#include "gedit-view-frame.h"
+#include "gedit-view-holder.h"
 #include "gedit-utils.h"
 #include "gedit-commands.h"
 #include "gedit-commands-private.h"
@@ -256,6 +258,22 @@ gedit_window_finalize (GObject *object)
        G_OBJECT_CLASS (gedit_window_parent_class)->finalize (object);
 }
 
+/* Center the view when the window is in fullscreen mode. */
+static void
+update_view_centering (GeditTab *tab,
+                      gpointer  user_data)
+{
+       GeditViewFrame *view_frame;
+       GeditViewHolder *view_holder;
+       gboolean is_fullscreen;
+
+       view_frame = _gedit_tab_get_view_frame (tab);
+       view_holder = gedit_view_frame_get_view_holder (view_frame);
+
+       is_fullscreen = GPOINTER_TO_BOOLEAN (user_data);
+       gedit_view_holder_set_centering (view_holder, is_fullscreen);
+}
+
 static void
 update_fullscreen (GeditWindow *window,
                    gboolean     is_fullscreen)
@@ -276,6 +294,10 @@ update_fullscreen (GeditWindow *window,
                }
        }
 
+       gedit_multi_notebook_foreach_tab (window->priv->multi_notebook,
+                                         (GtkCallback)update_view_centering,
+                                         GBOOLEAN_TO_POINTER (is_fullscreen));
+
 #ifndef OS_OSX
        if (is_fullscreen)
        {


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