[gnome-todo/wip/lists] storage-popover: create list



commit 80cd7948ac314415444deee910b1c9266184edc3
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Jun 12 20:41:08 2015 -0300

    storage-popover: create list

 data/ui/storage-popover.ui |    2 +
 src/gtd-storage-popover.c  |   62 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 0 deletions(-)
---
diff --git a/data/ui/storage-popover.ui b/data/ui/storage-popover.ui
index a0c80cf..15d1371 100644
--- a/data/ui/storage-popover.ui
+++ b/data/ui/storage-popover.ui
@@ -25,6 +25,7 @@
                 <property name="sensitive">False</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
+                <signal name="clicked" handler="gtd_storage_popover__action_button_clicked" 
object="GtdStoragePopover" swapped="yes" />
                 <style>
                   <class name="suggested-action"/>
                 </style>
@@ -40,6 +41,7 @@
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
+                <signal name="clicked" handler="gtd_storage_popover__action_button_clicked" 
object="GtdStoragePopover" swapped="yes" />
               </object>
               <packing>
                 <property name="left_attach">0</property>
diff --git a/src/gtd-storage-popover.c b/src/gtd-storage-popover.c
index ff24655..a443745 100644
--- a/src/gtd-storage-popover.c
+++ b/src/gtd-storage-popover.c
@@ -28,6 +28,7 @@ typedef struct
   GtkWidget            *change_location_button;
   GtkWidget            *location_provider_image;
   GtkWidget            *new_list_create_button;
+  GtkWidget            *new_list_name_entry;
   GtkWidget            *stack;
   GtkWidget            *storage_selector;
 
@@ -51,6 +52,65 @@ enum {
 };
 
 static void
+clear_and_hide (GtdStoragePopover *popover)
+{
+  GtdStoragePopoverPrivate *priv;
+  GList *locations;
+  GList *l;
+
+  g_return_if_fail (GTD_IS_STORAGE_POPOVER (popover));
+
+  priv = popover->priv;
+
+  /* Select the default source again */
+  locations = gtd_manager_get_storage_locations (priv->manager);
+
+  for (l = locations; l != NULL; l = l->next)
+    {
+      if (gtd_storage_get_is_default (l->data))
+        {
+          gtd_storage_selector_set_selected_storage (GTD_STORAGE_SELECTOR (priv->storage_selector), l->data);
+          break;
+        }
+    }
+
+  g_list_free (locations);
+
+  /* By clearing the text, Create button will get insensitive */
+  gtk_entry_set_text (GTK_ENTRY (priv->new_list_name_entry), "");
+
+  /* Hide the popover at last */
+  gtk_widget_hide (GTK_WIDGET (popover));
+}
+
+static void
+gtd_storage_popover__action_button_clicked (GtdStoragePopover *popover,
+                                            GtkWidget         *button)
+{
+  GtdStoragePopoverPrivate *priv;
+
+  g_return_if_fail (GTD_IS_STORAGE_POPOVER (popover));
+
+  priv = popover->priv;
+
+  if (button == priv->new_list_create_button)
+    {
+      GtdTaskList *task_list;
+      const gchar *name;
+      GtdStorage *storage;
+
+      storage = gtd_storage_selector_get_selected_storage (GTD_STORAGE_SELECTOR (priv->storage_selector));
+      name = gtk_entry_get_text (GTK_ENTRY (priv->new_list_name_entry));
+
+      task_list = gtd_storage_create_task_list (storage, name);
+
+      gtd_manager_save_task_list (priv->manager, task_list);
+    }
+
+  clear_and_hide (popover);
+}
+
+static void
 gtd_storage_popover__text_changed_cb (GtdStoragePopover *popover,
                                       GParamSpec        *spec,
                                       GtkEntry          *entry)
@@ -207,9 +267,11 @@ gtd_storage_popover_class_init (GtdStoragePopoverClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, GtdStoragePopover, change_location_button);
   gtk_widget_class_bind_template_child_private (widget_class, GtdStoragePopover, location_provider_image);
   gtk_widget_class_bind_template_child_private (widget_class, GtdStoragePopover, new_list_create_button);
+  gtk_widget_class_bind_template_child_private (widget_class, GtdStoragePopover, new_list_name_entry);
   gtk_widget_class_bind_template_child_private (widget_class, GtdStoragePopover, stack);
   gtk_widget_class_bind_template_child_private (widget_class, GtdStoragePopover, storage_selector);
 
+  gtk_widget_class_bind_template_callback (widget_class, gtd_storage_popover__action_button_clicked);
   gtk_widget_class_bind_template_callback (widget_class, gtd_storage_popover__change_location_clicked);
   gtk_widget_class_bind_template_callback (widget_class, gtd_storage_popover__storage_selected);
   gtk_widget_class_bind_template_callback (widget_class, gtd_storage_popover__text_changed_cb);


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