[gnome-todo] task-row: improve button behavior



commit 4be83ac2b53e6fd10b88b8cf3f587b083b890b50
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sun Oct 15 14:53:02 2017 -0200

    task-row: improve button behavior
    
    This makes the button always visible, and also makes
    the icon of the button rotate when the row is activated.
    
    Looks very nice.

 data/theme/Adwaita.css |    6 ++----
 data/ui/task-row.ui    |   27 +++++++++------------------
 src/gtd-task-row.c     |   23 +++++++++++++++++++----
 3 files changed, 30 insertions(+), 26 deletions(-)
---
diff --git a/data/theme/Adwaita.css b/data/theme/Adwaita.css
index 90076d2..3e6d724 100644
--- a/data/theme/Adwaita.css
+++ b/data/theme/Adwaita.css
@@ -81,10 +81,8 @@ taskrow.priority-hight:dir(rtl)  { border-right: solid 6px #cc0000; padding-righ
 
 taskrow.complete label { text-decoration-line: line-through; }
 
-taskrow entry.title {
-    font-size: 1.1rem;
-    font-weight: bold;
-}
+taskrow .close-button.active > image { transition: 200ms cubic-bezier(0.25, 0.46, 0.45, 0.94); 
-gtk-icon-transform: rotate(-0.5turn); }
+taskrow .close-button > image { transition: 200ms cubic-bezier(0.25, 0.46, 0.45, 0.94); -gtk-icon-transform: 
rotate(0turn); }
 
 /* dnd row */
 dndrow {
diff --git a/data/ui/task-row.ui b/data/ui/task-row.ui
index c1ecbd7..d190c20 100644
--- a/data/ui/task-row.ui
+++ b/data/ui/task-row.ui
@@ -157,28 +157,19 @@
 
                 <!-- Close button -->
                 <child>
-                  <object class="GtkRevealer" id="close_button_revealer">
+                  <object class="GtkButton" id="toggle_button">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
-                    <property name="receives_default">False</property>
-                    <property name="transition_type">slide-left</property>
-                    <property name="transition_duration" bind-source="edit_panel_revealer" 
bind-property="transition_duration" bind-flags="default|sync-create" />
-                    <property name="reveal-child" bind-source="edit_panel_revealer" 
bind-property="reveal-child" bind-flags="default" />
+                    <signal name="clicked" handler="toggle_active_cb" object="GtdTaskRow" swapped="no"/>
+                    <style>
+                      <class name="flat" />
+                      <class name="close-button" />
+                    </style>
                     <child>
-                      <object class="GtkButton" id="close_button">
+                      <object class="GtkImage">
                         <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <signal name="clicked" handler="edit_finished_cb" object="GtdTaskRow" swapped="no"/>
-                        <style>
-                          <class name="flat" />
-                        </style>
-                        <child>
-                          <object class="GtkImage">
-                            <property name="visible">True</property>
-                            <property name="can-focus">False</property>
-                            <property name="icon-name">pan-up-symbolic</property>
-                          </object>
-                        </child>
+                        <property name="can-focus">False</property>
+                        <property name="icon-name">pan-down-symbolic</property>
                       </object>
                     </child>
                   </object>
diff --git a/src/gtd-task-row.c b/src/gtd-task-row.c
index 1b908c2..8bbae34 100644
--- a/src/gtd-task-row.c
+++ b/src/gtd-task-row.c
@@ -38,6 +38,7 @@ struct _GtdTaskRow
   GtkWidget          *edit_panel;
   GtkWidget          *edit_panel_revealer;
   GtkWidget          *title_entry;
+  GtkWidget          *toggle_button;
   GtkWidget          *stack;
 
   /* task widgets */
@@ -150,11 +151,13 @@ get_dnd_icon (GtdTaskRow *self)
  */
 
 static void
-edit_finished_cb (GtkWidget  *button,
+toggle_active_cb (GtkWidget  *button,
                   GtdTaskRow *self)
 {
-  gtd_manager_update_task (gtd_manager_get_default (), self->task);
-  gtd_task_row_set_active (self, FALSE);
+  if (self->active)
+    gtd_manager_update_task (gtd_manager_get_default (), self->task);
+
+  gtd_task_row_set_active (self, !self->active);
 }
 
 static void
@@ -624,17 +627,18 @@ gtd_task_row_class_init (GtdTaskRowClass *klass)
   gtk_widget_class_bind_template_child (widget_class, GtdTaskRow, task_list_label);
   gtk_widget_class_bind_template_child (widget_class, GtdTaskRow, title_label);
   gtk_widget_class_bind_template_child (widget_class, GtdTaskRow, title_entry);
+  gtk_widget_class_bind_template_child (widget_class, GtdTaskRow, toggle_button);
 
   gtk_widget_class_bind_template_callback (widget_class, button_press_event);
   gtk_widget_class_bind_template_callback (widget_class, complete_check_toggled_cb);
   gtk_widget_class_bind_template_callback (widget_class, drag_begin_cb);
   gtk_widget_class_bind_template_callback (widget_class, drag_failed_cb);
-  gtk_widget_class_bind_template_callback (widget_class, edit_finished_cb);
   gtk_widget_class_bind_template_callback (widget_class, mouse_out_event_cb);
   gtk_widget_class_bind_template_callback (widget_class, mouse_out_dnd_event_cb);
   gtk_widget_class_bind_template_callback (widget_class, mouse_over_event_cb);
   gtk_widget_class_bind_template_callback (widget_class, mouse_over_dnd_event_cb);
   gtk_widget_class_bind_template_callback (widget_class, remove_task_cb);
+  gtk_widget_class_bind_template_callback (widget_class, toggle_active_cb);
 
   gtk_widget_class_set_css_name (widget_class, "taskrow");
 }
@@ -872,6 +876,8 @@ void
 gtd_task_row_set_active (GtdTaskRow *self,
                          gboolean    active)
 {
+  GtkStyleContext *context;
+
   g_return_if_fail (GTD_IS_TASK_ROW (self));
 
   if (self->active == active)
@@ -879,6 +885,15 @@ gtd_task_row_set_active (GtdTaskRow *self,
 
   self->active = active;
 
+  /* Update the arrow icon */
+  context = gtk_widget_get_style_context (self->toggle_button);
+
+  if (active)
+    gtk_style_context_add_class (context, "active");
+  else
+    gtk_style_context_remove_class (context, "active");
+
+  /* And the listbox */
   gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (self), !active);
   gtk_widget_set_can_focus (GTK_WIDGET (self), !active);
 


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