[bijiben] main-view: Remember active view type



commit 34591140e761f7b985856d71fd979c98559a3c53
Author: Jonathan Kang <jonathan121537 gmail com>
Date:   Tue Nov 21 17:03:52 2017 +0800

    main-view: Remember active view type
    
    Save the active view type and load it when bijiben starts, so
    the user is presented with the last visible state of Bijiben when
    he/she last used it.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=788272

 data/meson.build                   |   17 +++++++++++++++++
 data/org.gnome.bijiben.gschema.xml |    5 +++++
 src/bjb-main-view.c                |   16 +++++++++++++---
 3 files changed, 35 insertions(+), 3 deletions(-)
---
diff --git a/data/meson.build b/data/meson.build
index a8e45d1..adae5c7 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -86,6 +86,23 @@ install_data(
   install_dir: bijiben_pkgdatadir
 )
 
+# https://github.com/mesonbuild/meson/issues/1687
+custom_target('gsettings-enums',
+  input: '../subprojects/libgd/libgd/gd-main-view.h',
+  output: 'org.gnome.bijiben.enums.xml',
+  install: true,
+  install_dir: join_paths(bijiben_datadir, 'glib-2.0', 'schemas'),
+  capture: true,
+  command: ['glib-mkenums',
+    '--comments', '<!-- @comment@ -->',
+    '--fhead', '<schemalist>',
+    '--vhead', '  <@type@ id="org.gnome.bijiben.@EnumName@">',
+    '--vprod', '    <value nick="@valuenick@" value="@valuenum@"/>',
+    '--vtail', '  </@type@>',
+    '--ftail', '</schemalist>',
+    '@INPUT@'
+  ]
+)
 install_data(
   'org.gnome.bijiben.gschema.xml',
   install_dir: join_paths(bijiben_datadir, 'glib-2.0', 'schemas')
diff --git a/data/org.gnome.bijiben.gschema.xml b/data/org.gnome.bijiben.gschema.xml
index 4d674b3..78c3d7b 100644
--- a/data/org.gnome.bijiben.gschema.xml
+++ b/data/org.gnome.bijiben.gschema.xml
@@ -34,5 +34,10 @@
       <summary>Window position</summary>
       <description>Window position (x and y).</description>
     </key>
+    <key name="view-type" enum="org.gnome.bijiben.GdMainViewType">
+      <summary>How to show note items</summary>
+      <description>Whether show note items in icon view or list view.</description>
+      <default>'icon'</default>
+    </key>
   </schema>
 </schemalist>
diff --git a/src/bjb-main-view.c b/src/bjb-main-view.c
index aa07c6f..17fe6c7 100644
--- a/src/bjb-main-view.c
+++ b/src/bjb-main-view.c
@@ -32,8 +32,6 @@
 #include "bjb-selection-toolbar.h"
 #include "bjb-window-base.h"
 
-#define DEFAULT_VIEW GD_MAIN_VIEW_ICON
-
 enum
 {
   PROP_0,
@@ -643,13 +641,20 @@ 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 (DEFAULT_VIEW);
+  self->view = gd_main_view_new (type);
+  if (type == GD_MAIN_VIEW_LIST)
+    add_list_renderers (self);
   g_object_add_weak_pointer (G_OBJECT (self->view), (gpointer*) &(self->view));
 
   /* Main view */
@@ -796,6 +801,11 @@ bjb_main_view_get_view_type (BjbMainView *self)
 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)


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