[gnome-notes/67-replace-load-more] Replace "Load More" button with edge hit detection




commit df6ee0d1316b569c53149273e1fcf515971032c7
Author: Isaque Galdino <igaldino gmail com>
Date:   Wed Aug 5 15:47:46 2020 -0300

    Replace "Load More" button with edge hit detection
    
    Backport and adapt change from commit 446703bc

 src/bjb-load-more-button.c | 250 ---------------------------------------------
 src/bjb-load-more-button.h |  46 ---------
 src/bjb-main-view.c        | 107 ++-----------------
 src/bjb-main-view.h        |   4 -
 src/bjb-window-base.c      |   1 -
 src/meson.build            |   1 -
 6 files changed, 10 insertions(+), 399 deletions(-)
---
diff --git a/src/bjb-main-view.c b/src/bjb-main-view.c
index 02a2e95a..caf68676 100644
--- a/src/bjb-main-view.c
+++ b/src/bjb-main-view.c
@@ -22,7 +22,6 @@
 
 #include "bjb-application.h"
 #include "bjb-controller.h"
-#include "bjb-load-more-button.h"
 #include "bjb-main-toolbar.h"
 #include "bjb-utils.h"
 #include "bjb-main-view.h"
@@ -67,7 +66,6 @@ struct _BjbMainView
   /* View Notes , model */
   GdMainView       *view;
   BjbController    *controller;
-  GtkWidget        *load_more;
 
   /* Signals */
   gulong key;
@@ -76,39 +74,13 @@ struct _BjbMainView
   gulong view_selection_changed;
 };
 
-
 G_DEFINE_TYPE (BjbMainView, bjb_main_view, GTK_TYPE_GRID)
 
-
-static void bjb_main_view_view_changed (BjbMainView *self);
-
-
 static void
 bjb_main_view_init (BjbMainView *self)
 {
 }
 
-
-
-void
-bjb_main_view_disconnect_scrolled_window (BjbMainView *self)
-{
-  GtkAdjustment *vadjustment;
-  GtkWidget *vscrollbar;
-
-  if (self->view == NULL ||
-      !GTK_IS_SCROLLED_WINDOW (self->view))
-    return;
-
-  vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (self->view));
-  vscrollbar = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (self->view));
-
-  g_signal_handlers_disconnect_by_func (vadjustment, bjb_main_view_view_changed, self);
-  g_signal_handlers_disconnect_by_func (vscrollbar, bjb_main_view_view_changed, self);
-}
-
-
-
 static void
 bjb_main_view_disconnect_handlers (BjbMainView *self)
 {
@@ -127,13 +99,10 @@ bjb_main_view_disconnect_handlers (BjbMainView *self)
   self->view_selection_changed =0;
 }
 
-
-
 static void
 bjb_main_view_dispose (GObject *object)
 {
   bjb_main_view_disconnect_handlers (BJB_MAIN_VIEW (object));
-  bjb_main_view_disconnect_scrolled_window (BJB_MAIN_VIEW (object));
   G_OBJECT_CLASS (bjb_main_view_parent_class)->dispose (object);
 }
 
@@ -549,56 +518,21 @@ add_list_renderers (BjbMainView *self)
 
 }
 
-
-
 static void
-bjb_main_view_view_changed (BjbMainView *self)
+on_show_more_cb (BjbMainView     *self,
+                 GtkPositionType  pos)
 {
-  GtkAdjustment *vadjustment;
-  GtkWidget *vscrollbar;
-  gboolean end;
-  gdouble page_size;
-  gdouble upper;
-  gdouble value;
-  gint reveal_area_height;
-
-  reveal_area_height = 32;
-  end = FALSE;
-  if (self->view == NULL)
-    return;
-
-  vscrollbar = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (self->view));
+  if (pos == GTK_POS_BOTTOM)
+    bjb_controller_show_more (self->controller);
 
-  if (vscrollbar == NULL || !gtk_widget_get_visible (GTK_WIDGET (vscrollbar)))
-  {
-    bjb_load_more_button_set_block (BJB_LOAD_MORE_BUTTON (self->load_more), TRUE);
-    return;
-  }
-
-  vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (self->view));
-  page_size = gtk_adjustment_get_page_size (vadjustment);
-  upper = gtk_adjustment_get_upper (vadjustment);
-  value = gtk_adjustment_get_value (vadjustment);
-
-  /* Special case these values which happen at construction */
-  if ((gint) value == 0 && (gint) upper == 1 && (gint) page_size == 1)
-    end = FALSE;
-  else
-    end = !(value < (upper - page_size - reveal_area_height));
-
-  bjb_load_more_button_set_block (BJB_LOAD_MORE_BUTTON (self->load_more), !end);
 }
 
-
 static void
 bjb_main_view_constructed(GObject *o)
 {
-  BjbMainView          *self;
-  GtkAdjustment        *vadjustment;
-  GtkWidget            *vscrollbar;
-  GtkWidget            *button;
-  BjbSettings *settings;
-  GdMainViewType type;
+  BjbMainView    *self;
+  BjbSettings    *settings;
+  GdMainViewType  type;
 
   G_OBJECT_CLASS (bjb_main_view_parent_class)->constructed(G_OBJECT(o));
 
@@ -621,32 +555,11 @@ bjb_main_view_constructed(GObject *o)
   gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (self->view));
   gtk_widget_show (GTK_WIDGET (self->view));
 
-  vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (self->view));
-
-  g_signal_connect_object (vadjustment,
-                           "changed",
-                           G_CALLBACK (bjb_main_view_view_changed),
+  g_signal_connect_object (GTK_SCROLLED_WINDOW (self->view),
+                           "edge-overshot",
+                           G_CALLBACK (on_show_more_cb),
                            self,
                            G_CONNECT_SWAPPED);
-  g_signal_connect_object (vadjustment,
-                           "value-changed",
-                           G_CALLBACK (bjb_main_view_view_changed),
-                           self,
-                           G_CONNECT_SWAPPED);
-
-  vscrollbar = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (self->view));
-  g_signal_connect_object (vscrollbar,
-                           "notify::visible",
-                           G_CALLBACK (bjb_main_view_view_changed),
-                           self,
-                           G_CONNECT_SWAPPED);
-
-  /* Load more */
-  self->load_more = bjb_load_more_button_new (self->controller);
-  button = bjb_load_more_button_get_revealer (BJB_LOAD_MORE_BUTTON (self->load_more));
-  gtk_container_add (GTK_CONTAINER (self), button);
-  bjb_main_view_view_changed (self);
-
 
   /* Selection Panel */
   self->select_bar = bjb_selection_toolbar_new (self->view, self);
diff --git a/src/bjb-main-view.h b/src/bjb-main-view.h
index f4816542..416aadd5 100644
--- a/src/bjb-main-view.h
+++ b/src/bjb-main-view.h
@@ -63,8 +63,4 @@ GdMainViewType bjb_main_view_get_view_type (BjbMainView *view);
 
 void bjb_main_view_set_view_type (BjbMainView *view, GdMainViewType type);
 
-
-void bjb_main_view_disconnect_scrolled_window (BjbMainView *self);
-
-
 G_END_DECLS
diff --git a/src/bjb-window-base.c b/src/bjb-window-base.c
index c52aef8d..c51c4702 100644
--- a/src/bjb-window-base.c
+++ b/src/bjb-window-base.c
@@ -308,7 +308,6 @@ bjb_window_base_load_geometry (BjbWindowBase *self)
 static void
 bjb_window_base_destroy (gpointer a, BjbWindowBase * self)
 {
-  bjb_main_view_disconnect_scrolled_window (self->view);
   bjb_controller_disconnect (self->controller);
   bjb_window_base_save_geometry (self);
 }
diff --git a/src/meson.build b/src/meson.build
index 27d5b3aa..0300a02e 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -7,7 +7,6 @@ sources = files(
   'bjb-editor-toolbar.c',
   'bjb-empty-results-box.c',
   'bjb-import-dialog.c',
-  'bjb-load-more-button.c',
   'bjb-main.c',
   'bjb-main-toolbar.c',
   'bjb-main-view.c',


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