[gnome-notes/implement-select-all: 1/2] Implement "Select All"




commit 4fc11db1042dca3556d9ecfd3b3ffc8c3277209f
Author: Isaque Galdino <igaldino gmail com>
Date:   Tue Aug 4 10:13:06 2020 -0300

    Implement "Select All"

 src/bjb-controller.c    | 10 ++++++++++
 src/bjb-controller.h    |  2 ++
 src/bjb-list-view-row.c | 29 ++++++++++++++++++++++-------
 src/bjb-list-view.c     |  2 --
 src/bjb-main-view.c     |  5 ++++-
 5 files changed, 38 insertions(+), 10 deletions(-)
---
diff --git a/src/bjb-controller.c b/src/bjb-controller.c
index 0bb5cdf8..7f766063 100644
--- a/src/bjb-controller.c
+++ b/src/bjb-controller.c
@@ -959,6 +959,8 @@ bjb_controller_set_all_selection (BjbController *self,
   gtk_tree_model_foreach (self->model,
                           bjb_controller_set_selection_foreach,
                           GINT_TO_POINTER (selection));
+
+  notify_displayed_items_changed (self);
 }
 
 void
@@ -1009,3 +1011,11 @@ bjb_controller_set_selection_mode (BjbController *self,
       bjb_controller_unselect_all (self);
     }
 }
+
+gboolean
+bjb_controller_is_all_selected (BjbController *self)
+{
+  g_autoptr (GList) selection_list = bjb_controller_get_selection (self);
+  return g_list_length (selection_list) == g_list_length (self->items_to_show);
+}
+
diff --git a/src/bjb-controller.h b/src/bjb-controller.h
index 975e9dec..7113df84 100644
--- a/src/bjb-controller.h
+++ b/src/bjb-controller.h
@@ -91,4 +91,6 @@ void      bjb_controller_select_all         (BjbController *self);
 
 void      bjb_controller_unselect_all       (BjbController *self);
 
+gboolean  bjb_controller_is_all_selected    (BjbController *self);
+
 G_END_DECLS
diff --git a/src/bjb-list-view-row.c b/src/bjb-list-view-row.c
index 2c36735a..872dc0e0 100644
--- a/src/bjb-list-view-row.c
+++ b/src/bjb-list-view-row.c
@@ -74,6 +74,9 @@ bjb_list_view_row_setup (BjbListViewRow *self,
   char            *color;
   gint64           mtime;
   GdkRGBA          rgba;
+  gboolean         selected;
+  BjbController   *controller;
+  GtkListBox      *list_box;
   g_auto (GStrv)   lines        = NULL;
   g_autofree char *one_line     = NULL;
   g_autofree char *preview      = NULL;
@@ -81,19 +84,22 @@ bjb_list_view_row_setup (BjbListViewRow *self,
   g_autofree char *css_style    = NULL;
 
   self->view = view;
+  list_box = bjb_list_view_get_list_box (view);
+  controller = bjb_list_view_get_controller (view);
 
-  model = bjb_controller_get_model (bjb_list_view_get_controller (self->view));
+  model = bjb_controller_get_model (controller);
   if (!gtk_tree_model_get_iter_from_string (model, &iter, model_iter))
     return;
   self->model_iter = g_strdup (model_iter);
 
   gtk_tree_model_get (model,
                       &iter,
-                      BJB_MODEL_COLUMN_UUID,  &uuid,
-                      BJB_MODEL_COLUMN_TITLE, &title,
-                      BJB_MODEL_COLUMN_TEXT,  &text,
-                      BJB_MODEL_COLUMN_MTIME, &mtime,
-                      BJB_MODEL_COLUMN_COLOR, &color,
+                      BJB_MODEL_COLUMN_UUID,     &uuid,
+                      BJB_MODEL_COLUMN_TITLE,    &title,
+                      BJB_MODEL_COLUMN_TEXT,     &text,
+                      BJB_MODEL_COLUMN_MTIME,    &mtime,
+                      BJB_MODEL_COLUMN_COLOR,    &color,
+                      BJB_MODEL_COLUMN_SELECTED, &selected,
                       -1);
 
   updated_time = bjb_utils_get_human_time (mtime);
@@ -122,6 +128,16 @@ bjb_list_view_row_setup (BjbListViewRow *self,
                                       GTK_STYLE_PROVIDER (self->css_provider),
                                       GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
     }
+
+  gtk_widget_set_visible (GTK_WIDGET (self->select_button),
+                          bjb_controller_get_selection_mode (controller));
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->select_button),
+                                selected);
+  if (selected)
+    gtk_list_box_select_row (list_box, GTK_LIST_BOX_ROW (self));
+  else
+    gtk_list_box_unselect_row (list_box, GTK_LIST_BOX_ROW (self));
+
 }
 
 void
@@ -129,7 +145,6 @@ bjb_list_view_row_show_select_button (BjbListViewRow *self,
                                       gboolean        show)
 {
   gtk_widget_set_visible (GTK_WIDGET (self->select_button), show);
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->select_button), FALSE);
 }
 
 const char *
diff --git a/src/bjb-list-view.c b/src/bjb-list-view.c
index d06656ee..f8bf99c7 100644
--- a/src/bjb-list-view.c
+++ b/src/bjb-list-view.c
@@ -169,8 +169,6 @@ void
 bjb_list_view_set_selection_mode (BjbListView *self,
                                   gboolean     mode)
 {
-  gtk_list_box_unselect_all (self->list_box);
-
   gtk_container_foreach (GTK_CONTAINER (self->list_box),
                          bjb_list_view_show_select_button_cb,
                          GINT_TO_POINTER (mode));
diff --git a/src/bjb-main-view.c b/src/bjb-main-view.c
index ac27aff9..02c4b7cb 100644
--- a/src/bjb-main-view.c
+++ b/src/bjb-main-view.c
@@ -246,7 +246,10 @@ on_key_press_event_cb (BjbMainView *self,
       case GDK_KEY_A:
         if (bjb_controller_get_selection_mode (self->controller) && event->key.state & GDK_CONTROL_MASK)
           {
-            bjb_controller_select_all (self->controller);
+            if (bjb_controller_is_all_selected (self->controller))
+              bjb_controller_unselect_all (self->controller);
+            else
+              bjb_controller_select_all (self->controller);
             return TRUE;
           }
         break;


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