[gnome-notes/136-implement-the-list-row-pattern-in-main-view: 6/13] view-type: Fix toolbar and main view



commit 2c11d4902fbc1c78686f2b441ec867d5e11b5da6
Author: Isaque Galdino <igaldino@gmail>
Date:   Fri Dec 27 02:21:39 2019 -0300

    view-type: Fix toolbar and main view
    
    In our effort to implement the new UI, we need to replace GdMainView by
    GtkListBox. That will also cause the removal of libgd as we only use it
    because of GdMainView.
    
    This first step is to remove the view-type feature from BjbMainView and
    their related buttons from BjbMainToolbar.

 data/resources/main-toolbar.ui |  47 +------------
 src/bjb-controller.c           |  13 +---
 src/bjb-main-toolbar.c         |  82 ++---------------------
 src/bjb-main-view.c            | 148 +----------------------------------------
 src/bjb-main-view.h            |   5 --
 5 files changed, 8 insertions(+), 287 deletions(-)
---
diff --git a/data/resources/main-toolbar.ui b/data/resources/main-toolbar.ui
index eea8d52..6728e51 100644
--- a/data/resources/main-toolbar.ui
+++ b/data/resources/main-toolbar.ui
@@ -95,56 +95,11 @@
           </object>
         </child>
       </object>
-      <packing>
-        <property name="position">3</property>
-        <property name="pack-type">end</property>
-      </packing>
-    </child>
-
-    <child>
-      <object class="GtkStack" id="style_buttons">
-        <property name="visible">1</property>
-        <child>
-          <object class="GtkButton" id="grid_button">
-            <property name="visible">1</property>
-            <signal name="clicked" handler="on_view_mode_clicked" swapped="yes"/>
-            <style>
-             <class name="image-button"/>
-            </style>
-            <child>
-              <object class="GtkImage">
-                <property name="visible">1</property>
-                <property name="icon-name">view-grid-symbolic</property>
-                <property name="icon-size">1</property>
-                <property name="tooltip-text" translatable="yes">View notes and notebooks in a 
grid</property>
-              </object>
-            </child>
-          </object>
-        </child>
-
-        <child>
-          <object class="GtkButton" id="list_button">
-            <property name="visible" bind-source="grid_button" bind-property="visible" 
bind-flags="default|bidirectional|invert-boolean"/>
-            <signal name="clicked" handler="on_view_mode_clicked" swapped="yes"/>
-            <style>
-             <class name="image-button"/>
-            </style>
-            <child>
-              <object class="GtkImage">
-                <property name="visible">1</property>
-                <property name="icon-name">view-list-symbolic</property>
-                <property name="icon-size">1</property>
-                <property name="tooltip-text" translatable="yes">View notes and notebooks in a 
list</property>
-              </object>
-            </child>
-          </object>
-        </child>
-      </object>
       <packing>
         <property name="position">2</property>
         <property name="pack-type">end</property>
       </packing>
-    </child> <!-- /GtkStack style_buttons -->
+    </child>
 
     <child>
       <object class="GtkButton" id="select_button">
diff --git a/src/bjb-controller.c b/src/bjb-controller.c
index c8b55bc..7aca0d2 100644
--- a/src/bjb-controller.c
+++ b/src/bjb-controller.c
@@ -259,20 +259,9 @@ bjb_controller_add_item (BjbController *self,
   else
     gtk_list_store_append (store, &iter);
 
-
-  /* First , if there is a gd main view , and if gd main view
-   * is a list, then load the smaller emblem */
   win = self->window;
   scale = gtk_widget_get_scale_factor (GTK_WIDGET (win));
-
-  if (bjb_window_base_get_main_view (win)
-      && bjb_main_view_get_view_type
-                (bjb_window_base_get_main_view (win)) == GD_MAIN_VIEW_LIST)
-    surface = biji_item_get_emblem (item, scale);
-
-  /* Else, load the icon */
-  if (!surface)
-    surface = biji_item_get_icon (item, scale);
+  surface = biji_item_get_icon (item, scale);
 
   /* Appart from pixbuf, both icon & list view types
    * currently use the same model */
diff --git a/src/bjb-main-toolbar.c b/src/bjb-main-toolbar.c
index 18fdd6b..ed5ca35 100644
--- a/src/bjb-main-toolbar.c
+++ b/src/bjb-main-toolbar.c
@@ -19,7 +19,6 @@
 #include "config.h"
 
 #include <glib/gi18n.h>
-#include <libgd/gd.h>
 
 #include "bjb-application.h"
 #include "bjb-color-button.h"
@@ -32,11 +31,9 @@
 typedef enum
 {
   BJB_TOOLBAR_0,
-  BJB_TOOLBAR_STD_LIST,
-  BJB_TOOLBAR_STD_ICON,
+  BJB_TOOLBAR_LIST,
   BJB_TOOLBAR_SELECT,
   BJB_TOOLBAR_TRASH_LIST,
-  BJB_TOOLBAR_TRASH_ICON,
   BJB_TOOLBAR_TRASH_SELECT,
   BJB_TOOLBAR_NOTE_VIEW
 } BjbToolbarType;
@@ -58,12 +55,9 @@ struct _BjbMainToolbar
   GtkWidget *new_button;
   GtkWidget *back_button;
   GtkWidget *title_entry;
-  GtkWidget *list_button;
-  GtkWidget *grid_button;
   GtkWidget *select_button;
   GtkWidget *cancel_button;
   GtkWidget *search_button;
-  GtkWidget *style_buttons;
   GtkWidget *empty_button;
   GtkWidget *color_button;
   GtkWidget *button_stack;
@@ -193,42 +187,12 @@ on_selection_mode_clicked (BjbMainToolbar *self,
   }
 }
 
-static gboolean
-on_view_mode_clicked (BjbMainToolbar *self,
-                      GtkWidget      *button)
-{
-  GdMainViewType current;
-
-  g_assert (BJB_IS_MAIN_TOOLBAR (self));
-  g_assert (GTK_IS_BUTTON (button));
-
-  current = bjb_main_view_get_view_type (self->parent);
-
-  switch ( current )
-  {
-    case GD_MAIN_VIEW_ICON :
-      bjb_main_view_set_view_type (self->parent, GD_MAIN_VIEW_LIST);
-      break ;
-    case GD_MAIN_VIEW_LIST :
-      bjb_main_view_set_view_type (self->parent, GD_MAIN_VIEW_ICON);
-      break ;
-    default:
-      bjb_main_view_set_view_type (self->parent, GD_MAIN_VIEW_ICON);
-  }
-
-  bjb_main_view_update_model (self->parent);
-  gtk_widget_hide (button);
-  return TRUE;
-}
-
 static void
 update_selection_buttons (BjbController *controller,
                           gboolean some_item_is_visible,
                           gboolean remaining,
                           BjbMainToolbar *self)
 {
-  gtk_widget_set_sensitive (self->grid_button, some_item_is_visible);
-  gtk_widget_set_sensitive (self->list_button, some_item_is_visible);
   gtk_widget_set_sensitive (self->empty_button, some_item_is_visible);
   gtk_widget_set_sensitive (self->search_button, some_item_is_visible);
   gtk_widget_set_sensitive (self->select_button, some_item_is_visible);
@@ -251,7 +215,6 @@ populate_bar_for_selection (BjbMainToolbar *self)
   gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (self), FALSE);
   gtk_widget_hide (self->select_button);
   gtk_widget_hide (self->button_stack);
-  gtk_widget_hide (self->style_buttons);
   gtk_widget_hide (self->main_button);
   gtk_widget_show (self->cancel_button);
 
@@ -462,7 +425,6 @@ populate_bar_for_note_view (BjbMainToolbar *self)
   gtk_header_bar_set_custom_title (GTK_HEADER_BAR (self), self->title_entry);
 
   gtk_widget_hide (self->new_button);
-  gtk_widget_hide (self->style_buttons);
   gtk_widget_hide (self->search_button);
   gtk_widget_hide (self->select_button);
   gtk_widget_hide (self->main_button);
@@ -513,7 +475,6 @@ bjb_main_toolbar_reset (BjbMainToolbar *self)
   gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (self), TRUE);
 
   gtk_widget_show (self->button_stack);
-  gtk_widget_show (self->style_buttons);
   gtk_widget_show (self->select_button);
   gtk_widget_show (self->search_button);
   gtk_widget_show (self->new_button);
@@ -539,31 +500,18 @@ populate_bar_switch (BjbMainToolbar *self)
       populate_bar_for_selection (self);
       break;
 
-    case BJB_TOOLBAR_STD_ICON:
+    case BJB_TOOLBAR_LIST:
       populate_bar_for_standard(self);
-      gtk_widget_show (self->list_button);
       update_selection_buttons (self->controller,
                                 bjb_controller_shows_item (self->controller),
                                 TRUE,
                                 self);
       break;
 
-    case BJB_TOOLBAR_STD_LIST:
-      populate_bar_for_standard(self);
-      gtk_widget_show (self->grid_button);
-      update_selection_buttons (self->controller,
-                                bjb_controller_shows_item (self->controller),
-                                TRUE,
-                                self);
-      break;
-
-
-    case BJB_TOOLBAR_TRASH_ICON:
     case BJB_TOOLBAR_TRASH_LIST:
       populate_bar_for_trash (self);
       break;
 
-
     case BJB_TOOLBAR_NOTE_VIEW:
       populate_bar_for_note_view (self);
       break;
@@ -592,35 +540,19 @@ populate_main_toolbar(BjbMainToolbar *self)
     case BJB_WINDOW_BASE_NO_NOTE:
     case BJB_WINDOW_BASE_NO_RESULT:
     case BJB_WINDOW_BASE_MAIN_VIEW:
-
       if (bjb_main_view_get_selection_mode (self->parent) == TRUE)
         to_be = BJB_TOOLBAR_SELECT;
-
-      else if (bjb_main_view_get_view_type (self->parent) == GD_MAIN_VIEW_ICON)
-        to_be = BJB_TOOLBAR_STD_ICON;
-
-      else if (bjb_main_view_get_view_type (self->parent) == GD_MAIN_VIEW_LIST)
-        to_be = BJB_TOOLBAR_STD_LIST;
-
+      else
+        to_be = BJB_TOOLBAR_LIST;
       break;
 
-
     case BJB_WINDOW_BASE_ARCHIVE_VIEW:
-
       if (bjb_main_view_get_selection_mode (self->parent) == TRUE)
         to_be = BJB_TOOLBAR_TRASH_SELECT;
-
-      else if (bjb_main_view_get_view_type (self->parent) == GD_MAIN_VIEW_ICON)
-        to_be = BJB_TOOLBAR_TRASH_ICON;
-
-      else if (bjb_main_view_get_view_type (self->parent) == GD_MAIN_VIEW_LIST)
+      else
         to_be = BJB_TOOLBAR_TRASH_LIST;
-
-
       break;
 
-
-
     /* Not really a toolbar,
      * still used for Spinner */
     case BJB_WINDOW_BASE_SPINNER_VIEW:
@@ -796,11 +728,8 @@ bjb_main_toolbar_class_init (BjbMainToolbarClass *klass)
   gtk_widget_class_bind_template_child (widget_class, BjbMainToolbar, new_button);
   gtk_widget_class_bind_template_child (widget_class, BjbMainToolbar, back_button);
   gtk_widget_class_bind_template_child (widget_class, BjbMainToolbar, title_entry);
-  gtk_widget_class_bind_template_child (widget_class, BjbMainToolbar, list_button);
-  gtk_widget_class_bind_template_child (widget_class, BjbMainToolbar, grid_button);
   gtk_widget_class_bind_template_child (widget_class, BjbMainToolbar, search_button);
   gtk_widget_class_bind_template_child (widget_class, BjbMainToolbar, empty_button);
-  gtk_widget_class_bind_template_child (widget_class, BjbMainToolbar, style_buttons);
   gtk_widget_class_bind_template_child (widget_class, BjbMainToolbar, cancel_button);
   gtk_widget_class_bind_template_child (widget_class, BjbMainToolbar, select_button);
   gtk_widget_class_bind_template_child (widget_class, BjbMainToolbar, color_button);
@@ -817,7 +746,6 @@ bjb_main_toolbar_class_init (BjbMainToolbarClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, on_new_note_clicked);
   gtk_widget_class_bind_template_callback (widget_class, on_selection_mode_clicked);
   gtk_widget_class_bind_template_callback (widget_class, on_back_button_clicked);
-  gtk_widget_class_bind_template_callback (widget_class, on_view_mode_clicked);
   gtk_widget_class_bind_template_callback (widget_class, on_empty_clicked_callback);
   gtk_widget_class_bind_template_callback (widget_class, on_color_button_clicked);
 
diff --git a/src/bjb-main-view.c b/src/bjb-main-view.c
index 02a2e95..8c6328d 100644
--- a/src/bjb-main-view.c
+++ b/src/bjb-main-view.c
@@ -437,120 +437,6 @@ bjb_main_view_connect_signals (BjbMainView *self)
                               G_CALLBACK (on_drag_data_received), self);
 }
 
-static void
-__destroy_n_notify__ (gpointer data)
-{
-}
-
-
-
-static BijiItem *
-_get_item_for_tree_path (GtkTreeModel *tree_model,
-                         GtkTreeIter *iter,
-                         BjbMainView *self)
-{
-  BijiItem *retval;
-  gchar *uuid;
-
-
-  retval = NULL;
-  uuid = NULL;
-  gtk_tree_model_get (tree_model,
-                      iter,
-                      GD_MAIN_COLUMN_ID,
-                      &uuid,
-                      -1);
-
-
-  if (uuid != NULL)
-  {
-    retval = biji_manager_get_item_at_path (
-               bjb_window_base_get_manager (self->window), uuid);
-    g_free (uuid);
-  }
-
-  return retval;
-}
-
-static void
-render_where    (GtkTreeViewColumn *tree_column,
-                 GtkCellRenderer *cell,
-                 GtkTreeModel *tree_model,
-                 GtkTreeIter *iter,
-                 gpointer data)
-{
-  BijiItem *item;
-  const gchar *str;
-  BjbMainView *self;
-
-  self = data;
-  item = _get_item_for_tree_path (tree_model, iter, self);
-
-  if (item != NULL)
-  {
-    str = biji_item_get_place (item);
-    g_object_set (cell, "text", str, NULL);
-  }
-}
-
-
-
-static void
-render_date     (GtkTreeViewColumn *tree_column,
-                 GtkCellRenderer *cell,
-                 GtkTreeModel *tree_model,
-                 GtkTreeIter *iter,
-                 gpointer data)
-{
-  BijiItem *item;
-  g_autofree gchar *str = NULL;
-  BjbMainView *self;
-
-  self = data;
-  item = _get_item_for_tree_path (tree_model, iter, self);
-
-  if (item != NULL)
-  {
-    str = bjb_utils_get_human_time (biji_item_get_mtime (item));
-    g_object_set (cell, "text", str, NULL);
-  }
-}
-
-
-static void
-add_list_renderers (BjbMainView *self)
-{
-  GtkWidget *generic;
-  GtkCellRenderer *cell;
-
-  generic =  gd_main_view_get_generic_view (self->view);
-
-  /* Where Renderer */
-  cell = gd_styled_text_renderer_new ();
-  gd_styled_text_renderer_add_class (GD_STYLED_TEXT_RENDERER (cell), "dim-label");
-  gtk_cell_renderer_set_padding (cell, 16, 0);
-
-  gd_main_list_view_add_renderer (GD_MAIN_LIST_VIEW (generic),
-                                  cell,
-                                  render_where,
-                                  self,
-                                  __destroy_n_notify__);
-
-
-  /* Date renderer */
-  cell = gtk_cell_renderer_text_new ();
-  gtk_cell_renderer_set_padding (cell, 32, 0);
-
-  gd_main_list_view_add_renderer (GD_MAIN_LIST_VIEW (generic),
-                                  cell,
-                                  render_date,
-                                  self,
-                                  __destroy_n_notify__);
-
-}
-
-
-
 static void
 bjb_main_view_view_changed (BjbMainView *self)
 {
@@ -597,20 +483,13 @@ bjb_main_view_constructed(GObject *o)
   GtkAdjustment        *vadjustment;
   GtkWidget            *vscrollbar;
   GtkWidget            *button;
-  BjbSettings *settings;
-  GdMainViewType type;
 
   G_OBJECT_CLASS (bjb_main_view_parent_class)->constructed(G_OBJECT(o));
 
   self = BJB_MAIN_VIEW(o);
 
-  settings = bjb_app_get_settings (g_application_get_default ());
-  type = g_settings_get_enum (G_SETTINGS (settings), "view-type");
-
   gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_VERTICAL);
-  self->view = gd_main_view_new (type);
-  if (type == GD_MAIN_VIEW_LIST)
-    add_list_renderers (self);
+  self->view = gd_main_view_new (GD_MAIN_VIEW_ICON);
   g_object_add_weak_pointer (G_OBJECT (self->view), (gpointer*) &(self->view));
 
   /* Main view */
@@ -743,28 +622,3 @@ bjb_main_view_set_selection_mode (BjbMainView *self, gboolean mode)
   gd_main_view_set_selection_mode (self->view, mode);
 }
 
-GdMainViewType
-bjb_main_view_get_view_type (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 ViewType we return.
-   */
-  if (self->view == NULL) return GD_MAIN_VIEW_ICON;
-  return gd_main_view_get_view_type (self->view);
-}
-
-void
-bjb_main_view_set_view_type (BjbMainView *self, GdMainViewType type)
-{
-  BjbSettings *settings;
-
-  settings = bjb_app_get_settings(g_application_get_default());
-  g_settings_set_enum (G_SETTINGS (settings), "view-type", type);
-
-  gd_main_view_set_view_type (self->view, type);
-
-  if (type == GD_MAIN_VIEW_LIST)
-    add_list_renderers (self);
-}
-
diff --git a/src/bjb-main-view.h b/src/bjb-main-view.h
index f481654..fc61436 100644
--- a/src/bjb-main-view.h
+++ b/src/bjb-main-view.h
@@ -59,11 +59,6 @@ gboolean bjb_main_view_get_selection_mode (BjbMainView *view);
 
 void bjb_main_view_set_selection_mode (BjbMainView *view, gboolean mode);
 
-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);
 
 


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