[gnome-notes/136-implement-the-list-row-pattern-in-main-view: 16/18] main-view: Replace GdMainView with BjbListView



commit 8fba9d6f99920ab85b478475c7f6e7ed988fca28
Author: Isaque Galdino <igaldino gmail com>
Date:   Sun Feb 16 21:28:25 2020 -0300

    main-view: Replace GdMainView with BjbListView

 src/bjb-controller.c        | 13 ++++++
 src/bjb-controller.h        | 11 +++--
 src/bjb-main-toolbar.c      | 12 +-----
 src/bjb-main-view.c         | 98 ++++++++++++++++++---------------------------
 src/bjb-selection-toolbar.c | 35 ++++++++--------
 src/bjb-selection-toolbar.h |  7 ++--
 6 files changed, 82 insertions(+), 94 deletions(-)
---
diff --git a/src/bjb-controller.c b/src/bjb-controller.c
index a4021ed..2a9d2c9 100644
--- a/src/bjb-controller.c
+++ b/src/bjb-controller.c
@@ -53,6 +53,8 @@ struct _BjbController
   gboolean        remaining_items;
   GMutex          mutex;
 
+  gboolean        selection_mode;
+
   gboolean        connected;
   gulong          manager_change;
 };
@@ -943,4 +945,15 @@ bjb_controller_unselect_all (BjbController *self)
   bjb_controller_set_all_selection (self, FALSE);
 }
 
+gboolean
+bjb_controller_get_selection_mode (BjbController *self)
+{
+  return self->selection_mode;
+}
 
+void
+bjb_controller_set_selection_mode (BjbController *self,
+                                   gboolean       selection_mode)
+{
+  self->selection_mode = selection_mode;
+}
diff --git a/src/bjb-controller.h b/src/bjb-controller.h
index 49e87d5..558cd06 100644
--- a/src/bjb-controller.h
+++ b/src/bjb-controller.h
@@ -73,10 +73,15 @@ void bjb_controller_show_more (BjbController *controller);
 
 gboolean bjb_controller_get_remaining_items (BjbController *self);
 
-GList *bjb_controller_get_selection (BjbController *self);
+gboolean  bjb_controller_get_selection_mode (BjbController *self);
 
-void   bjb_controller_select_all    (BjbController *self);
+void      bjb_controller_set_selection_mode (BjbController *self,
+                                             gboolean       selection_mode);
 
-void   bjb_controller_unselect_all  (BjbController *self);
+GList    *bjb_controller_get_selection      (BjbController *self);
+
+void      bjb_controller_select_all         (BjbController *self);
+
+void      bjb_controller_unselect_all       (BjbController *self);
 
 G_END_DECLS
diff --git a/src/bjb-main-toolbar.c b/src/bjb-main-toolbar.c
index 94f6f45..5c73445 100644
--- a/src/bjb-main-toolbar.c
+++ b/src/bjb-main-toolbar.c
@@ -170,21 +170,11 @@ static void
 on_selection_mode_clicked (BjbMainToolbar *self,
                            GtkWidget      *button)
 {
-  g_assert (BJB_IS_MAIN_TOOLBAR (self));
-  g_assert (GTK_IS_BUTTON (button));
-
   if (button == self->cancel_button)
-  {
     bjb_main_view_set_selection_mode (self->parent, FALSE);
-  }
-
-  /* Force refresh. We go to selection mode but nothing yet selected
-   * Thus no signal emited */
   else
-  {
     bjb_main_view_set_selection_mode (self->parent, TRUE);
-    on_view_selection_changed_cb (self);
-  }
+  on_view_selection_changed_cb (self);
 }
 
 static void
diff --git a/src/bjb-main-view.c b/src/bjb-main-view.c
index 4ef43ff..c606ea3 100644
--- a/src/bjb-main-view.c
+++ b/src/bjb-main-view.c
@@ -18,19 +18,20 @@
 #include <glib/gprintf.h>
 #include <gtk/gtk.h>
 #include <libbiji/libbiji.h>
-#include <libgd/gd-main-view.h>
 
 #include "bjb-application.h"
 #include "bjb-controller.h"
+#include "bjb-list-view.h"
+#include "bjb-list-view-row.h"
 #include "bjb-load-more-button.h"
 #include "bjb-main-toolbar.h"
-#include "bjb-utils.h"
 #include "bjb-main-view.h"
 #include "bjb-note-view.h"
 #include "bjb-organize-dialog.h"
 #include "bjb-search-toolbar.h"
 #include "bjb-selection-toolbar.h"
 #include "bjb-window-base.h"
+#include "bjb-utils.h"
 
 enum
 {
@@ -65,7 +66,7 @@ struct _BjbMainView
   BjbSelectionToolbar *select_bar;
 
   /* View Notes , model */
-  GdMainView          *view;
+  BjbListView         *view;
   BjbController       *controller;
   GtkWidget           *load_more;
 
@@ -230,12 +231,6 @@ switch_to_item (BjbMainView *self,
     }
 }
 
-static GList *
-get_selected_paths(BjbMainView *self)
-{
-  return gd_main_view_get_selection (self->view);
-}
-
 static gchar *
 get_note_url_from_tree_path(GtkTreePath *path,
                             BjbMainView *self)
@@ -258,8 +253,7 @@ bjb_main_view_get_selected_items (BjbMainView *self)
   GList    *l, *result = NULL;
   gchar    *url;
   BijiItem *item;
-  GList    *paths = get_selected_paths (self);
-
+  GList    *paths = bjb_controller_get_selection (self->controller);
 
   for (l = paths; l != NULL; l = l->next)
     {
@@ -277,15 +271,17 @@ bjb_main_view_get_selected_items (BjbMainView *self)
 }
 
 static void
-on_selection_mode_changed_cb (BjbMainView *self)
+on_selected_rows_changed_cb (GtkListBox  *box,
+                             BjbMainView *self)
 {
   /* Workaround if items are selected
    * but selection mode not really active (?) */
-  GList *select = gd_main_view_get_selection (self->view);
+  GList *select = bjb_controller_get_selection (self->controller);
+
   if (select)
     {
       g_list_free (select);
-      gd_main_view_set_selection_mode (self->view, TRUE);
+      bjb_controller_set_selection_mode (self->controller, TRUE);
     }
 
   /* Any case, tell */
@@ -305,17 +301,17 @@ on_key_press_event_cb (GtkWidget *widget,
     {
       case GDK_KEY_a:
       case GDK_KEY_A:
-        if (gd_main_view_get_selection_mode (self->view) && event->key.state & GDK_CONTROL_MASK)
+        if (bjb_controller_get_selection_mode (self->controller) && event->key.state & GDK_CONTROL_MASK)
           {
-            gd_main_view_select_all (self->view);
+            bjb_controller_select_all (self->controller);
             return TRUE;
           }
         break;
 
       case GDK_KEY_Escape:
-        if (gd_main_view_get_selection_mode (self->view))
+        if (bjb_controller_get_selection_mode (self->controller))
           {
-            gd_main_view_set_selection_mode (self->view, FALSE);
+            bjb_controller_set_selection_mode (self->controller, FALSE);
             return TRUE;
           }
 
@@ -326,34 +322,22 @@ on_key_press_event_cb (GtkWidget *widget,
   return FALSE;
 }
 
-static gboolean
-on_item_activated (GdMainView        *gd,
-                   const gchar       *id,
-                   const GtkTreePath *path,
-                   BjbMainView       *self)
+static void
+on_row_activated (GtkListBox     *view,
+                  BjbListViewRow *row,
+                  BjbMainView    *self)
 {
-  BijiManager  *manager;
-  BijiItem     *to_open;
-  GtkTreeIter   iter;
-  gchar        *item_path;
-  GtkTreeModel *model;
+  BijiManager *manager;
+  BijiItem    *to_open;
 
-  /* Get Item Path */
-  model = gd_main_view_get_model (gd);
-  gtk_tree_model_get_iter (model, &iter, (GtkTreePath *) path);
-  gtk_tree_model_get (model, &iter, BJB_MODEL_COLUMN_UUID, &item_path,-1);
-
-  g_return_val_if_fail (item_path != NULL, FALSE); // #709197
+  if (bjb_main_view_get_selection_mode (self))
+    return;
 
-  /* Switch to that item */
   manager = bjb_window_base_get_manager (self->window);
-  to_open = biji_manager_get_item_at_path (manager, item_path);
-  g_free (item_path);
+  to_open = biji_manager_get_item_at_path (manager, bjb_list_view_row_get_uuid (row));
 
   if (to_open)
     switch_to_item (self, to_open);
-
-  return FALSE ;
 }
 
 static GtkTargetEntry target_list[] = {
@@ -403,17 +387,23 @@ on_drag_data_received (GtkWidget        *widget,
 void
 bjb_main_view_connect_signals (BjbMainView *self)
 {
+  GtkListBox *list_box = bjb_list_view_get_list_box (self->view);
+
   if (self->view_selection_changed == 0)
-    self->view_selection_changed = g_signal_connect_swapped (self->view, "view-selection-changed",
-                                                             G_CALLBACK (on_selection_mode_changed_cb), 
self);
+    self->view_selection_changed = g_signal_connect (list_box,
+                                                     "selected-rows-changed",
+                                                     G_CALLBACK (on_selected_rows_changed_cb),
+                                                     self);
 
   if (self->key == 0)
     self->key = g_signal_connect (self->window, "key-press-event",
                                   G_CALLBACK (on_key_press_event_cb), self);
 
   if (self->activated == 0)
-    self->activated = g_signal_connect(self->view,"item-activated",
-                                       G_CALLBACK(on_item_activated),self);
+    self->activated = g_signal_connect (list_box,
+                                        "row-activated",
+                                        G_CALLBACK (on_row_activated),
+                                        self);
 
   if (self->data == 0)
     self->data = g_signal_connect (self->view, "drag-data-received",
@@ -472,14 +462,14 @@ bjb_main_view_constructed (GObject *o)
   self = BJB_MAIN_VIEW(o);
 
   gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_VERTICAL);
-  self->view = gd_main_view_new (GD_MAIN_VIEW_ICON);
+  self->view = bjb_list_view_new ();
   g_object_add_weak_pointer (G_OBJECT (self->view), (gpointer*) &(self->view));
 
   /* Main view */
-  gd_main_view_set_selection_mode (self->view, FALSE);
+  bjb_controller_set_selection_mode (self->controller, FALSE);
   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (self->view),
                                        GTK_SHADOW_NONE);
-  gd_main_view_set_model (self->view, bjb_controller_get_model(self->controller));
+  bjb_list_view_setup (self->view, self->controller);
   gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (self->view));
   gtk_widget_show (GTK_WIDGET (self->view));
 
@@ -582,28 +572,20 @@ void
 bjb_main_view_update_model (BjbMainView *self)
 {
   bjb_controller_update_view (self->controller);
-  gd_main_view_set_model (self->view, bjb_controller_get_model (self->controller));
+  bjb_list_view_update (self->view);
 }
 
-/* interface for notes view (GdMainView)
- * TODO - BjbMainView should rather be a GdMainView */
-
 gboolean
 bjb_main_view_get_selection_mode (BjbMainView *self)
 {
-  /* if self->view is NULL, that means the view was destroyed
-   * because the windows is being closed by an exit action, so it
-   * doesn't matter which SelectionMode we return.
-   */
-  if (self->view == NULL)
-    return FALSE;
-  return gd_main_view_get_selection_mode (self->view);
+  return bjb_controller_get_selection_mode (self->controller);
 }
 
 void
 bjb_main_view_set_selection_mode (BjbMainView *self,
                                   gboolean     mode)
 {
-  gd_main_view_set_selection_mode (self->view, mode);
+  bjb_controller_set_selection_mode (self->controller, mode);
+  bjb_list_view_set_selection_mode (self->view, mode);
 }
 
diff --git a/src/bjb-selection-toolbar.c b/src/bjb-selection-toolbar.c
index b72128e..4157c61 100644
--- a/src/bjb-selection-toolbar.c
+++ b/src/bjb-selection-toolbar.c
@@ -23,11 +23,11 @@
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
-#include <libgd/gd.h>
 
 #include "bjb-application.h"
 #include "bjb-color-button.h"
-#include "bjb-main-view.h"
+#include <bjb-list-view.h>
+#include <bjb-main-view.h>
 #include "bjb-organize-dialog.h"
 #include "bjb-selection-toolbar.h"
 #include "bjb-share.h"
@@ -43,25 +43,22 @@ enum
 
 static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
 
-
-
 struct _BjbSelectionToolbar
 {
   GtkRevealer parent_instance;
 
   BjbMainView *view;
-  GdMainView *selection;
+  BjbListView *selection;
 
-  GtkWidget *button_stack;
-  GtkWidget *notebook_button;
-  GtkWidget *detach_button;
-  GtkWidget *color_button;
-  GtkWidget *share_button;
+  GtkWidget   *button_stack;
+  GtkWidget   *notebook_button;
+  GtkWidget   *detach_button;
+  GtkWidget   *color_button;
+  GtkWidget   *share_button;
 };
 
 G_DEFINE_TYPE (BjbSelectionToolbar, bjb_selection_toolbar, GTK_TYPE_REVEALER)
 
-
 static void
 action_color_selected_items (GtkWidget           *w,
                              BjbSelectionToolbar *self)
@@ -288,14 +285,14 @@ bjb_selection_toolbar_fade_out (BjbSelectionToolbar *self)
 }
 
 static void
-bjb_selection_toolbar_selection_changed (GdMainView *view,
-                                         gpointer    user_data)
+on_selected_rows_changed_cb (BjbListView *view,
+                             gpointer     user_data)
 {
   BjbSelectionToolbar *self;
   GList *selection;
 
   self = BJB_SELECTION_TOOLBAR (user_data);
-  selection = gd_main_view_get_selection(view);
+  selection = bjb_main_view_get_selected_items (self->view);
 
   if (g_list_length (selection) > 0)
   {
@@ -365,9 +362,9 @@ bjb_selection_toolbar_constructed(GObject *obj)
 
   G_OBJECT_CLASS (bjb_selection_toolbar_parent_class)->constructed (obj);
 
-  g_signal_connect (self->selection,
-                    "view-selection-changed",
-                    G_CALLBACK (bjb_selection_toolbar_selection_changed),
+  g_signal_connect (bjb_list_view_get_list_box (self->selection),
+                    "selected-rows-changed",
+                    G_CALLBACK (on_selected_rows_changed_cb),
                     self);
 }
 
@@ -384,7 +381,7 @@ bjb_selection_toolbar_class_init (BjbSelectionToolbarClass *class)
   properties[PROP_BJB_SELECTION] = g_param_spec_object ("selection",
                                                         "Selection",
                                                         "SelectionController",
-                                                        GD_TYPE_MAIN_VIEW,
+                                                        BJB_TYPE_LIST_VIEW,
                                                         G_PARAM_READWRITE |
                                                         G_PARAM_CONSTRUCT |
                                                         G_PARAM_STATIC_STRINGS);
@@ -420,7 +417,7 @@ bjb_selection_toolbar_class_init (BjbSelectionToolbarClass *class)
 
 
 BjbSelectionToolbar *
-bjb_selection_toolbar_new (GdMainView   *selection,
+bjb_selection_toolbar_new (BjbListView  *selection,
                            BjbMainView  *bjb_main_view)
 {
   return g_object_new (BJB_TYPE_SELECTION_TOOLBAR,
diff --git a/src/bjb-selection-toolbar.h b/src/bjb-selection-toolbar.h
index fec2933..378ddb6 100644
--- a/src/bjb-selection-toolbar.h
+++ b/src/bjb-selection-toolbar.h
@@ -18,7 +18,8 @@
 
 #pragma once
 
-#include <libgd/gd.h>
+#include <bjb-list-view.h>
+#include <bjb-main-view.h>
 
 G_BEGIN_DECLS
 
@@ -26,7 +27,7 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (BjbSelectionToolbar, bjb_selection_toolbar, BJB, SELECTION_TOOLBAR, GtkRevealer)
 
-BjbSelectionToolbar * bjb_selection_toolbar_new (GdMainView   *selection,
-                                                 BjbMainView  *bjb_main_view);
+BjbSelectionToolbar *bjb_selection_toolbar_new (BjbListView *selection,
+                                                BjbMainView *bjb_main_view);
 
 G_END_DECLS


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