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



commit d993f415c56526a4d6eacebe317991ed906fa620
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-view.c         | 56 ++++++++++++++++-----------------------------
 src/bjb-selection-toolbar.c | 29 +++++++++++------------
 src/bjb-selection-toolbar.h |  7 +++---
 5 files changed, 58 insertions(+), 58 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-view.c b/src/bjb-main-view.c
index 4ef43ff..02668b0 100644
--- a/src/bjb-main-view.c
+++ b/src/bjb-main-view.c
@@ -18,19 +18,19 @@
 #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-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 +65,7 @@ struct _BjbMainView
   BjbSelectionToolbar *select_bar;
 
   /* View Notes , model */
-  GdMainView          *view;
+  BjbListView         *view;
   BjbController       *controller;
   GtkWidget           *load_more;
 
@@ -230,12 +230,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 +252,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)
     {
@@ -281,11 +274,11 @@ on_selection_mode_changed_cb (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 +298,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;
           }
 
@@ -327,7 +320,7 @@ on_key_press_event_cb (GtkWidget *widget,
 }
 
 static gboolean
-on_item_activated (GdMainView        *gd,
+on_item_activated (BjbListView       *view,
                    const gchar       *id,
                    const GtkTreePath *path,
                    BjbMainView       *self)
@@ -339,7 +332,7 @@ on_item_activated (GdMainView        *gd,
   GtkTreeModel *model;
 
   /* Get Item Path */
-  model = gd_main_view_get_model (gd);
+  model = bjb_controller_get_model (self->controller);
   gtk_tree_model_get_iter (model, &iter, (GtkTreePath *) path);
   gtk_tree_model_get (model, &iter, BJB_MODEL_COLUMN_UUID, &item_path,-1);
 
@@ -412,8 +405,8 @@ bjb_main_view_connect_signals (BjbMainView *self)
                                   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 (self->view, "item-activated",
+                                       G_CALLBACK (on_item_activated), self);
 
   if (self->data == 0)
     self->data = g_signal_connect (self->view, "drag-data-received",
@@ -472,14 +465,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 +575,19 @@ 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);
 }
 
diff --git a/src/bjb-selection-toolbar.c b/src/bjb-selection-toolbar.c
index b72128e..ad5ca47 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)
+bjb_selection_toolbar_selection_changed (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)
   {
@@ -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]