[gnome-todo/wip/selection-mode] window: allow renaming task lists
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-todo/wip/selection-mode] window: allow renaming task lists
- Date: Sun, 23 Aug 2015 01:36:52 +0000 (UTC)
commit 4a3bcf97f2fec6f0daedb78fae69a2c2c5287d93
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Sat Aug 22 22:36:33 2015 -0300
window: allow renaming task lists
data/ui/window.ui | 57 +++++++++++++++++++++++++
src/gtd-task-list-item.c | 2 +
src/gtd-window.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 161 insertions(+), 0 deletions(-)
---
diff --git a/data/ui/window.ui b/data/ui/window.ui
index d296523..22c41d6 100644
--- a/data/ui/window.ui
+++ b/data/ui/window.ui
@@ -145,6 +145,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="sensitive">False</property>
+ <signal name="clicked" handler="gtd_window__rename_button_clicked"
object="GtdWindow" swapped="yes" />
</object>
<packing>
<property name="position">1</property>
@@ -307,4 +308,60 @@
</object>
</child>
</template>
+ <object class="GtkPopover" id="rename_popover">
+ <property name="can_focus">False</property>
+ <property name="border_width">12</property>
+ <child>
+ <object class="GtkGrid" id="grid">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="row_spacing">12</property>
+ <property name="column_spacing">12</property>
+ <child>
+ <object class="GtkLabel" id="label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Name of the task list</property>
+ <property name="xalign">0</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ <property name="width">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="rename_entry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <signal name="notify::text" handler="gtd_window__rename_entry_text_changed" object="GtdWindow"
swapped="no" />
+ <signal name="activate" handler="gtd_window__rename_task_list" object="GtdWindow" swapped="yes"
/>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="save_rename_button">
+ <property name="label" translatable="yes">Rename</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked" handler="gtd_window__rename_task_list" object="GtdWindow" swapped="yes" />
+ <style>
+ <class name="suggested-action"/>
+ </style>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
</interface>
diff --git a/src/gtd-task-list-item.c b/src/gtd-task-list-item.c
index 03786c0..7de2570 100644
--- a/src/gtd-task-list-item.c
+++ b/src/gtd-task-list-item.c
@@ -437,6 +437,8 @@ gtd_task_list_item_set_property (GObject *object,
}
}
+//static void
+
static void
gtd_task_list_item_class_init (GtdTaskListItemClass *klass)
{
diff --git a/src/gtd-window.c b/src/gtd-window.c
index b2216c4..98edee7 100644
--- a/src/gtd-window.c
+++ b/src/gtd-window.c
@@ -55,6 +55,11 @@ typedef struct
GtdTaskListView *today_list_view;
GtdTaskListView *list_view;
+ /* rename popover */
+ GtkWidget *rename_entry;
+ GtkWidget *rename_popover;
+ GtkWidget *save_rename_button;
+
/* mode */
GtdWindowMode mode;
@@ -89,6 +94,34 @@ enum {
LAST_PROP
};
+static GtdTaskListItem*
+get_selected_list (GtdWindow *window)
+{
+ GtdWindowPrivate *priv;
+ GtdTaskListItem *item;
+ GList *children;
+ GList *l;
+
+ priv = window->priv;
+ item = NULL;
+
+ /* Retrieve the only selected task list */
+ children = gtk_container_get_children (GTK_CONTAINER (priv->lists_flowbox));
+
+ for (l = children; l != NULL; l = l->next)
+ {
+ if (gtd_task_list_item_get_selected (l->data))
+ {
+ item = l->data;
+ break;
+ }
+ }
+
+ g_list_free (children);
+
+ return item;
+}
+
static void
gtd_window__remove_button_clicked (GtdWindow *window)
{
@@ -155,6 +188,69 @@ gtd_window__remove_button_clicked (GtdWindow *window)
}
static void
+gtd_window__rename_button_clicked (GtdWindow *window)
+{
+ GtdWindowPrivate *priv;
+ GtdTaskListItem *item;
+
+ priv = window->priv;
+ item = get_selected_list (window);
+
+ if (item)
+ {
+ GtdTaskList *list;
+
+ list = gtd_task_list_item_get_list (item);
+
+ gtk_popover_set_relative_to (GTK_POPOVER (priv->rename_popover), GTK_WIDGET (item));
+ gtk_entry_set_text (GTK_ENTRY (priv->rename_entry), gtd_task_list_get_name (list));
+ gtk_widget_show (priv->rename_popover);
+
+ gtk_widget_grab_focus (priv->rename_entry);
+ }
+}
+
+static void
+gtd_window__rename_entry_text_changed (GObject *object,
+ GParamSpec *pspec,
+ GtdWindow *window)
+{
+ gtk_widget_set_sensitive (window->priv->save_rename_button,
+ gtk_entry_get_text_length (GTK_ENTRY (object)) > 0);
+}
+
+static void
+gtd_window__rename_task_list (GtdWindow *window)
+{
+ GtdWindowPrivate *priv;
+ GtdTaskListItem *item;
+
+ priv = window->priv;
+
+ /*
+ * If the save_rename_button is insensitive, the list name is
+ * empty and cannot be saved.
+ */
+ if (!gtk_widget_get_sensitive (priv->save_rename_button))
+ return;
+
+ item = get_selected_list (window);
+
+ if (item)
+ {
+ GtdTaskList *list;
+
+ list = gtd_task_list_item_get_list (item);
+
+ gtd_task_list_set_name (list, gtk_entry_get_text (GTK_ENTRY (priv->rename_entry)));
+ gtk_flow_box_invalidate_sort (GTK_FLOW_BOX (priv->lists_flowbox));
+ gtd_window_set_mode (window, GTD_WINDOW_MODE_NORMAL);
+
+ gtk_widget_hide (priv->rename_popover);
+ }
+}
+
+static void
gtd_window__stack_visible_child_cb (GtdWindow *window)
{
GtdWindowPrivate *priv;
@@ -721,6 +817,9 @@ gtd_window_class_init (GtdWindowClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, GtdWindow, notification_widget);
gtk_widget_class_bind_template_child_private (widget_class, GtdWindow, remove_button);
gtk_widget_class_bind_template_child_private (widget_class, GtdWindow, rename_button);
+ gtk_widget_class_bind_template_child_private (widget_class, GtdWindow, rename_entry);
+ gtk_widget_class_bind_template_child_private (widget_class, GtdWindow, rename_popover);
+ gtk_widget_class_bind_template_child_private (widget_class, GtdWindow, save_rename_button);
gtk_widget_class_bind_template_child_private (widget_class, GtdWindow, scheduled_list_view);
gtk_widget_class_bind_template_child_private (widget_class, GtdWindow, stack);
gtk_widget_class_bind_template_child_private (widget_class, GtdWindow, search_bar);
@@ -737,6 +836,9 @@ gtd_window_class_init (GtdWindowClass *klass)
gtk_widget_class_bind_template_callback (widget_class, gtd_window__list_selected);
gtk_widget_class_bind_template_callback (widget_class, gtd_window__on_key_press_event);
gtk_widget_class_bind_template_callback (widget_class, gtd_window__remove_button_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, gtd_window__rename_button_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, gtd_window__rename_entry_text_changed);
+ gtk_widget_class_bind_template_callback (widget_class, gtd_window__rename_task_list);
gtk_widget_class_bind_template_callback (widget_class, gtd_window__select_button_toggled);
gtk_widget_class_bind_template_callback (widget_class, gtd_window__stack_visible_child_cb);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]