[gnome-notes] main-toolbar: Add Text Sizes Menu



commit 23776cf3023ed9b56dcb81d04ac1852d5fd212f4
Author: Isaque Galdino <igaldino gmail com>
Date:   Wed Jul 18 01:27:33 2018 -0300

    main-toolbar: Add Text Sizes Menu
    
    It was requested by our GNOME Design Team [1] to create a menu entry for
    users to select one out of three notes' text sizes.
    
    In this first commit, we have added the menu option and the related code
    to save user selection as an application setting.
    
    [1] https://gitlab.gnome.org/GNOME/gnome-notes/issues/30

 data/org.gnome.bijiben.gschema.xml | 10 ++++++++
 data/resources/main-toolbar.ui     | 46 ++++++++++++++++++++++++++++++++++++
 src/bjb-main-toolbar.c             | 48 +++++++++++++++++++++++++++++++++++++-
 src/bjb-settings.c                 |  5 ++++
 src/bjb-settings.h                 |  6 +++++
 5 files changed, 114 insertions(+), 1 deletion(-)
---
diff --git a/data/org.gnome.bijiben.gschema.xml b/data/org.gnome.bijiben.gschema.xml
index 501f1db..5fa8def 100644
--- a/data/org.gnome.bijiben.gschema.xml
+++ b/data/org.gnome.bijiben.gschema.xml
@@ -1,4 +1,9 @@
 <schemalist>
+  <enum id="org.gnome.bijiben.BjbTextSizeType">
+    <value nick="large" value="0"/>
+    <value nick="medium" value="1"/>
+    <value nick="small" value="2"/>
+  </enum>
   <schema path="/org/gnome/bijiben/" id="org.gnome.bijiben" gettext-domain="bijiben">
     <key type="s" name="font">
       <default>'Cantarell 14'</default>
@@ -39,5 +44,10 @@
       <description>Whether to show note items in icon view or list view.</description>
       <default>'icon'</default>
     </key>
+    <key name="text-size" enum="org.gnome.bijiben.BjbTextSizeType">
+      <summary>Text size used by note editor.</summary>
+      <description>There are three text sizes available: small, medium (default) and large.</description>
+      <default>'medium'</default>
+    </key>
   </schema>
 </schemalist>
diff --git a/data/resources/main-toolbar.ui b/data/resources/main-toolbar.ui
index 6ebcc0e..b342423 100644
--- a/data/resources/main-toolbar.ui
+++ b/data/resources/main-toolbar.ui
@@ -234,6 +234,52 @@
       </object>
     </child>
 
+    <child>
+      <object class="GtkMenuItem">
+        <property name="visible">True</property>
+        <property name="label" translatable="yes">_Text Sizes</property>
+        <property name="use_underline">True</property>
+
+        <child type="submenu">
+          <object class="GtkMenu">
+            <property name="visible">True</property>
+
+            <child>
+              <object class="GtkRadioMenuItem" id="large_item">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">_Large</property>
+                <property name="use_underline">True</property>
+                <property name="draw_as_radio">True</property>
+                <signal name="activate" handler="on_text_size_cb" swapped="yes"/>
+              </object>
+            </child>
+
+            <child>
+              <object class="GtkRadioMenuItem" id="medium_item">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">_Medium</property>
+                <property name="use_underline">True</property>
+                <property name="draw_as_radio">True</property>
+                <property name="group">large_item</property>
+                <signal name="activate" handler="on_text_size_cb" swapped="yes"/>
+              </object>
+            </child>
+
+            <child>
+              <object class="GtkRadioMenuItem" id="small_item">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">_Small</property>
+                <property name="use_underline">True</property>
+                <property name="draw_as_radio">True</property>
+                <property name="group">large_item</property>
+                <signal name="activate" handler="on_text_size_cb" swapped="yes"/>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+
     <child>
       <object class="GtkMenuItem" id="preferences_item">
         <property name="visible">1</property>
diff --git a/src/bjb-main-toolbar.c b/src/bjb-main-toolbar.c
index e787449..82edd18 100644
--- a/src/bjb-main-toolbar.c
+++ b/src/bjb-main-toolbar.c
@@ -69,6 +69,11 @@ struct _BjbMainToolbar
   GtkWidget *main_button;
   GtkWidget *menu_button;
 
+  /* Main menu items */
+  GtkWidget *large_item;
+  GtkWidget *medium_item;
+  GtkWidget *small_item;
+
   /* Menu items */
   GtkWidget *new_window_item;
   GtkWidget *undo_item;
@@ -124,6 +129,33 @@ on_view_trash_cb (BjbMainToolbar *self)
   bjb_controller_set_group (controller, BIJI_ARCHIVED_ITEMS);
 }
 
+static void
+on_text_size_cb (BjbMainToolbar *self,
+                 GtkWidget      *item)
+{
+  BjbSettings *settings = bjb_app_get_settings (g_application_get_default ());
+  BjbTextSizeType text_size = g_settings_get_enum (G_SETTINGS (settings), "text-size");
+  BjbTextSizeType new_text_size = text_size;
+
+  if (item == self->large_item)
+    {
+      new_text_size = BJB_TEXT_SIZE_LARGE;
+    }
+  else if (item == self->medium_item)
+    {
+      new_text_size = BJB_TEXT_SIZE_MEDIUM;
+    }
+  else if (item == self->small_item)
+    {
+      new_text_size = BJB_TEXT_SIZE_SMALL;
+    }
+
+  if (text_size != new_text_size)
+    {
+      g_settings_set_enum (G_SETTINGS (settings), "text-size", new_text_size);
+    }
+}
+
 static void
 on_preferences_cb (BjbMainToolbar *self)
 {
@@ -133,7 +165,6 @@ on_preferences_cb (BjbMainToolbar *self)
   show_bijiben_settings_window (g_list_nth_data (windows, 0));
 }
 
-
 static void
 on_help_cb (BjbMainToolbar *self)
 {
@@ -750,6 +781,9 @@ populate_main_toolbar(BjbMainToolbar *self)
 static void
 bjb_main_toolbar_setup_menu (BjbMainToolbar *self)
 {
+  BjbSettings *settings = bjb_app_get_settings (g_application_get_default ());
+  BjbTextSizeType text_size = g_settings_get_enum (G_SETTINGS (settings), "text-size");
+
   gtk_widget_add_accelerator (self->undo_item, "activate", self->accel, GDK_KEY_z,
                               GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
   gtk_widget_add_accelerator (self->redo_item, "activate", self->accel, GDK_KEY_z,
@@ -757,6 +791,11 @@ bjb_main_toolbar_setup_menu (BjbMainToolbar *self)
   gtk_widget_add_accelerator (self->trash_item, "activate", self->accel,
                               GDK_KEY_Delete, GDK_CONTROL_MASK,
                               GTK_ACCEL_VISIBLE);
+
+  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (self->large_item), text_size == BJB_TEXT_SIZE_LARGE);
+  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (self->medium_item), text_size == 
BJB_TEXT_SIZE_MEDIUM);
+  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (self->small_item), text_size == BJB_TEXT_SIZE_SMALL);
+
 }
 
 static void
@@ -895,6 +934,12 @@ bjb_main_toolbar_class_init (BjbMainToolbarClass *klass)
   gtk_widget_class_bind_template_child (widget_class, BjbMainToolbar, main_button);
   gtk_widget_class_bind_template_child (widget_class, BjbMainToolbar, menu_button);
 
+  /* Main menu items */
+  gtk_widget_class_bind_template_child (widget_class, BjbMainToolbar, large_item);
+  gtk_widget_class_bind_template_child (widget_class, BjbMainToolbar, medium_item);
+  gtk_widget_class_bind_template_child (widget_class, BjbMainToolbar, small_item);
+
+  /* Menu items */
   gtk_widget_class_bind_template_child (widget_class, BjbMainToolbar, new_window_item);
   gtk_widget_class_bind_template_child (widget_class, BjbMainToolbar, undo_item);
   gtk_widget_class_bind_template_child (widget_class, BjbMainToolbar, redo_item);
@@ -914,6 +959,7 @@ bjb_main_toolbar_class_init (BjbMainToolbarClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, on_preferences_cb);
   gtk_widget_class_bind_template_callback (widget_class, on_help_cb);
   gtk_widget_class_bind_template_callback (widget_class, on_about_cb);
+  gtk_widget_class_bind_template_callback (widget_class, on_text_size_cb);
 
   /* Menu items */
   gtk_widget_class_bind_template_callback (widget_class, on_detached_clicked_cb);
diff --git a/src/bjb-settings.c b/src/bjb-settings.c
index b37ac95..4707c49 100644
--- a/src/bjb-settings.c
+++ b/src/bjb-settings.c
@@ -269,6 +269,11 @@ bjb_settings_get_system_font            (BjbSettings *self)
                                 "document-font-name");
 }
 
+BjbTextSizeType
+bjb_settings_get_text_size              (BjbSettings *self)
+{
+  return g_settings_get_enum (G_SETTINGS (self), "text-size");
+}
 
 void
 show_bijiben_settings_window (GtkWidget *parent_window)
diff --git a/src/bjb-settings.h b/src/bjb-settings.h
index 2a08f26..d06503a 100644
--- a/src/bjb-settings.h
+++ b/src/bjb-settings.h
@@ -27,6 +27,11 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (BjbSettings, bjb_settings, BJB, SETTINGS, GSettings)
 
+typedef enum {
+  BJB_TEXT_SIZE_LARGE,
+  BJB_TEXT_SIZE_MEDIUM,
+  BJB_TEXT_SIZE_SMALL
+} BjbTextSizeType;
 
 BjbSettings      *bjb_settings_new                        (void);
 
@@ -49,6 +54,7 @@ const gchar      *bjb_settings_get_default_location       (BjbSettings *self);
 
 gchar            *bjb_settings_get_system_font            (BjbSettings *self);
 
+BjbTextSizeType   bjb_settings_get_text_size              (BjbSettings *self);
 
 void              show_bijiben_settings_window            (GtkWidget *parent_window);
 


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