[gnome-notes] window-base: change the style of radio icon in notebooks popover



commit c19264533cfd379556aaf511faea95f302789d5d
Author: Jonathan Kang <jonathankang gnome org>
Date:   Thu Feb 4 15:54:49 2021 +0800

    window-base: change the style of radio icon in notebooks popover
    
    Change the style of radio icons in the notebooks selection popover based
    on the design.

 data/resources/bjb-window-base.ui | 12 +++++--
 data/resources/style.css          | 17 +++++++++
 src/bjb-window-base.c             | 73 +++++++++++++++++++++------------------
 3 files changed, 67 insertions(+), 35 deletions(-)
---
diff --git a/data/resources/bjb-window-base.ui b/data/resources/bjb-window-base.ui
index d174497..1e3fe9a 100644
--- a/data/resources/bjb-window-base.ui
+++ b/data/resources/bjb-window-base.ui
@@ -280,7 +280,11 @@
           <object class="GtkModelButton">
             <property name="visible">True</property>
             <property name="text" translatable="yes">All Notes</property>
-            <property name="action-name">win.show-all-notes</property>
+            <property name="action-name">win.show-notebook</property>
+            <property name="action-target">'ALL NOTES'</property>
+            <style>
+              <class name="modelbutton"/>
+            </style>
           </object>
         </child>
 
@@ -323,7 +327,11 @@
           <object class="GtkModelButton">
             <property name="visible">True</property>
             <property name="text" translatable="yes">Trash</property>
-            <property name="action-name">win.show-trash</property>
+            <property name="action-name">win.show-notebook</property>
+            <property name="action-target">'TRASH'</property>
+            <style>
+              <class name="modelbutton"/>
+            </style>
           </object>
         </child>
       </object>
diff --git a/data/resources/style.css b/data/resources/style.css
index 5a54db9..47cb555 100644
--- a/data/resources/style.css
+++ b/data/resources/style.css
@@ -10,3 +10,20 @@ row:last-child {
        border-bottom: none;
 }
 
+.modelbutton radio:checked {
+    background-color: transparent;
+    background-image: none;
+    border: none;
+    border-radius: 0px;
+    box-shadow: none;
+    color: @theme_selected_bg_color;
+    -gtk-icon-source: -gtk-icontheme("object-select-symbolic");
+}
+
+.modelbutton radio:not(checked) {
+    background-color: transparent;
+    background-image: none;
+    border: none;
+    border-radius: 0px;
+    box-shadow: none;
+}
diff --git a/src/bjb-window-base.c b/src/bjb-window-base.c
index 8291cc5..b217d98 100644
--- a/src/bjb-window-base.c
+++ b/src/bjb-window-base.c
@@ -425,12 +425,8 @@ on_email_cb (GSimpleAction *action,
 }
 
 static void
-on_show_all_notes_cb (GSimpleAction *action,
-                      GVariant      *parameter,
-                      gpointer       user_data)
+show_all_notes (BjbWindowBase *self)
 {
-  BjbWindowBase *self = BJB_WINDOW_BASE (user_data);
-
   clear_text_in_search_entry (self);
 
   /* Going back from a notebook. */
@@ -441,9 +437,18 @@ on_show_all_notes_cb (GSimpleAction *action,
   gtk_label_set_text (GTK_LABEL (self->filter_label), _("All Notes"));
 }
 
+static void
+show_trash (BjbWindowBase *self)
+{
+  clear_text_in_search_entry (self);
+
+  bjb_controller_set_group (self->controller, BIJI_ARCHIVED_ITEMS);
+  gtk_label_set_text (GTK_LABEL (self->filter_label), _("Trash"));
+}
+
 static void
 on_show_notebook_cb (GSimpleAction *action,
-                     GVariant      *parameter,
+                     GVariant      *variant,
                      gpointer       user_data)
 {
   const char *note_uuid;
@@ -454,27 +459,23 @@ on_show_notebook_cb (GSimpleAction *action,
 
   clear_text_in_search_entry (self);
 
-  note_uuid = g_variant_get_string (parameter, NULL);
-  manager = bjb_window_base_get_manager (GTK_WIDGET (self));
-  notebook = biji_manager_get_item_at_path (manager, note_uuid);
-  bjb_controller_set_notebook (self->controller, BIJI_NOTEBOOK (notebook));
-
-  /* Update headerbar title. */
-  title = biji_item_get_title (notebook);
-  gtk_label_set_text (GTK_LABEL (self->filter_label), title);
-}
-
-static void
-on_show_trash_cb (GSimpleAction *action,
-                  GVariant      *parameter,
-                  gpointer       user_data)
-{
-  BjbWindowBase *self = BJB_WINDOW_BASE (user_data);
+  note_uuid = g_variant_get_string (variant, NULL);
+  if (g_strcmp0 (note_uuid, "ALL NOTES") == 0)
+    show_all_notes (self);
+  else if (g_strcmp0 (note_uuid, "TRASH") == 0)
+    show_trash (self);
+  else
+  {
+    manager = bjb_window_base_get_manager (GTK_WIDGET (self));
+    notebook = biji_manager_get_item_at_path (manager, note_uuid);
+    bjb_controller_set_notebook (self->controller, BIJI_NOTEBOOK (notebook));
 
-  clear_text_in_search_entry (self);
+    /* Update headerbar title. */
+    title = biji_item_get_title (notebook);
+    gtk_label_set_text (GTK_LABEL (self->filter_label), title);
+  }
 
-  bjb_controller_set_group (self->controller, BIJI_ARCHIVED_ITEMS);
-  gtk_label_set_text (GTK_LABEL (self->filter_label), _("Trash"));
+  g_simple_action_set_state (action, variant);
 }
 
 static void
@@ -507,6 +508,14 @@ on_close (GSimpleAction *action,
   gtk_window_close (GTK_WINDOW (window));
 }
 
+static void
+on_action_radio (GSimpleAction *action,
+                 GVariant      *variant,
+                 gpointer       user_data)
+{
+  g_action_change_state (G_ACTION (action), variant);
+}
+
 static void
 bjb_window_base_save_geometry (BjbWindowBase *self)
 {
@@ -562,22 +571,22 @@ append_notebook (BijiItem      *notebook,
   const char *note_uuid;
   const char *title;
   GVariant *variant;
+  GtkStyleContext *context;
   GtkWidget *button;
-  GtkWidget *label;
 
   note_uuid = biji_item_get_uuid (notebook);
   variant = g_variant_new_string (note_uuid);
 
+  title = biji_item_get_title (notebook);
   button = gtk_model_button_new ();
   g_object_set (button,
                 "action-name", "win.show-notebook",
                 "action-target", variant,
+                "text", title,
                 NULL);
 
-  title = biji_item_get_title (notebook);
-  gtk_button_set_label (GTK_BUTTON (button), title);
-  label = gtk_bin_get_child (GTK_BIN (button));
-  gtk_label_set_xalign (GTK_LABEL (label), 0);
+  context = gtk_widget_get_style_context (button);
+  gtk_style_context_add_class (context, "modelbutton");
 
   gtk_widget_show (button);
   gtk_box_pack_start (GTK_BOX (self->notebooks_box), button, TRUE, TRUE, 0);
@@ -615,9 +624,7 @@ static GActionEntry win_entries[] = {
   { "redo", on_redo_cb, NULL, NULL, NULL },
   { "view-notebooks", on_view_notebooks_cb, NULL, NULL, NULL },
   { "email", on_email_cb, NULL, NULL, NULL },
-  { "show-all-notes", on_show_all_notes_cb, NULL, NULL, NULL },
-  { "show-notebook", on_show_notebook_cb, "s", NULL, NULL },
-  { "show-trash", on_show_trash_cb, NULL, NULL, NULL },
+  { "show-notebook", on_action_radio, "s", "'ALL NOTES'", on_show_notebook_cb },
   { "trash", on_trash_cb, NULL, NULL, NULL },
   { "close", on_close },
 };


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