[recipes/inline-editing] More refactoring work
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes/inline-editing] More refactoring work
- Date: Thu, 20 Apr 2017 02:55:07 +0000 (UTC)
commit 1ecac7088a2a6d8a71d451bea29045d97aa6942c
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Apr 19 20:50:37 2017 -0400
More refactoring work
Hook up list removal, and make it so that there can be only
one active row in all the lists.
src/gr-edit-page.c | 95 +++++++++++++++++++++++++++---------------
src/gr-edit-page.ui | 2 +-
src/gr-ingredients-viewer.c | 71 ++++++++++++++++++++++++++++---
src/gr-ingredients-viewer.ui | 1 +
4 files changed, 127 insertions(+), 42 deletions(-)
---
diff --git a/src/gr-edit-page.c b/src/gr-edit-page.c
index f1d8d9e..bfa7653 100644
--- a/src/gr-edit-page.c
+++ b/src/gr-edit-page.c
@@ -168,7 +168,7 @@ dismiss_error (GrEditPage *page)
static void add_image_cb (GrEditPage *page);
static void set_unsaved (GrEditPage *page);
-static void add_list2 (GtkButton *button, GrEditPage *page);
+static void add_list2 (GrEditPage *page);
static void
populate_image_flowbox (GrEditPage *page)
@@ -1558,7 +1558,7 @@ gr_edit_page_get_property (GObject *object,
static void
set_unsaved (GrEditPage *page)
{
- g_object_set (G_OBJECT (page),"unsaved", TRUE, NULL);
+ g_object_set (G_OBJECT (page), "unsaved", TRUE, NULL);
}
static void
@@ -1943,6 +1943,63 @@ update_segments (GrEditPage *page)
}
static void
+remove_list2 (GrIngredientsViewer *viewer, GrEditPage *page)
+{
+ gtk_widget_destroy (GTK_WIDGET (viewer));
+}
+
+static void
+active_changed (GrIngredientsViewer *viewer,
+ GParamSpec *pspec,
+ GrEditPage *page)
+{
+ gboolean active;
+ GList *children, *l;
+
+ g_object_get (viewer, "active", &active, NULL);
+
+ if (!active)
+ return;
+
+ children = gtk_container_get_children (GTK_CONTAINER (page->ingredients_box2));
+ for (l = children; l; l = l->next) {
+ GrIngredientsViewer *list = l->data;
+ if (list != viewer)
+ g_object_set (list, "active", FALSE, NULL);
+ }
+ g_list_free (children);
+}
+
+static void
+add_list_full (GrEditPage *page,
+ const char *title,
+ const char *ingredients,
+ gboolean editable_title)
+{
+ GtkWidget *list;
+
+ list = g_object_new (GR_TYPE_INGREDIENTS_VIEWER,
+ "title", title,
+ "ingredients", ingredients,
+ "editable-title", editable_title,
+ "editable", TRUE,
+ NULL);
+
+ g_signal_connect_swapped (list, "notify::title", G_CALLBACK (set_unsaved), page);
+ g_signal_connect_swapped (list, "notify::ingredients", G_CALLBACK (set_unsaved), page);
+ g_signal_connect (list, "notify::active", G_CALLBACK (active_changed), page);
+ g_signal_connect (list, "delete", G_CALLBACK (remove_list2), page);
+
+ gtk_container_add (GTK_CONTAINER (page->ingredients_box2), list);
+}
+
+static void
+add_list2 (GrEditPage *page)
+{
+ add_list_full (page, "", "", TRUE);
+}
+
+static void
populate_ingredients (GrEditPage *page,
const char *text)
{
@@ -1997,15 +2054,7 @@ populate_ingredients (GrEditPage *page,
container_remove_all (GTK_CONTAINER (page->ingredients_box2));
if (strcmp (text, "") == 0) {
- GtkWidget *list;
-
- list = g_object_new (GR_TYPE_INGREDIENTS_VIEWER,
- "title", "",
- "editable-title", FALSE,
- "editable", TRUE,
- "ingredients", "",
- NULL);
- gtk_container_add (GTK_CONTAINER (page->ingredients_box2), list);
+ add_list_full (page, "", "", FALSE);
}
else {
g_autoptr(GrIngredientsList) ingredients = NULL;
@@ -2017,34 +2066,12 @@ populate_ingredients (GrEditPage *page,
segs = gr_ingredients_list_get_segments (ingredients);
editable_title = g_strv_length (segs) > 1;
for (j = 0; segs[j]; j++) {
- GtkWidget *list;
-
- list = g_object_new (GR_TYPE_INGREDIENTS_VIEWER,
- "title", segs[j],
- "editable-title", editable_title,
- "editable", TRUE,
- "ingredients", text,
- NULL);
- gtk_container_add (GTK_CONTAINER (page->ingredients_box2), list);
+ add_list_full (page, segs[j], text, editable_title);
}
}
}
static void
-add_list2 (GtkButton *button, GrEditPage *page)
-{
- GtkWidget *list;
-
- list = g_object_new (GR_TYPE_INGREDIENTS_VIEWER,
- "title", "",
- "editable-title", TRUE,
- "editable", TRUE,
- "ingredients", "",
- NULL);
- gtk_container_add (GTK_CONTAINER (page->ingredients_box2), list);
-}
-
-static void
scroll_up (GrEditPage *page)
{
GtkAdjustment *adj;
diff --git a/src/gr-edit-page.ui b/src/gr-edit-page.ui
index cc63282..a349687 100644
--- a/src/gr-edit-page.ui
+++ b/src/gr-edit-page.ui
@@ -253,7 +253,7 @@
<property name="visible">1</property>
<property name="margin-top">20</property>
<property name="label" translatable="yes">Add List</property>
- <signal name="clicked" handler="add_list2"/>
+ <signal name="clicked" handler="add_list2" swapped="yes"/>
</object>
</child>
</object>
diff --git a/src/gr-ingredients-viewer.c b/src/gr-ingredients-viewer.c
index 618aef0..3419442 100644
--- a/src/gr-ingredients-viewer.c
+++ b/src/gr-ingredients-viewer.c
@@ -59,9 +59,17 @@ enum {
PROP_TITLE,
PROP_EDITABLE_TITLE,
PROP_EDITABLE,
+ PROP_ACTIVE,
PROP_INGREDIENTS
};
+enum {
+ DELETE,
+ N_SIGNALS
+};
+
+static int signals[N_SIGNALS] = { 0, };
+
static void
gr_ingredients_viewer_finalize (GObject *object)
{
@@ -79,12 +87,20 @@ static void
set_active_row (GrIngredientsViewer *viewer,
GtkWidget *row)
{
- if (viewer->active_row)
+ gboolean was_active = FALSE;
+ gboolean active = FALSE;
+
+ if (viewer->active_row) {
g_object_set (viewer->active_row, "active", FALSE, NULL);
+ was_active = TRUE;
+ }
viewer->active_row = row;
- if (viewer->active_row)
+ if (viewer->active_row) {
g_object_set (viewer->active_row, "active", TRUE, NULL);
- // TODO: notify a property so other lists can unset theirs
+ active = TRUE;
+ }
+ if (active != was_active)
+ g_object_notify (G_OBJECT (viewer), "active");
}
static void
@@ -99,9 +115,13 @@ selected_rows_changed (GtkListBox *list,
static void
title_changed (GtkEntry *entry,
+ GParamSpec *pspec,
GrIngredientsViewer *viewer)
{
- // TODO mark page as unsaved
+ g_free (viewer->title);
+ viewer->title = g_strdup (gtk_entry_get_text (entry));
+
+ g_object_notify (G_OBJECT (viewer), "title");
}
static void
@@ -132,6 +152,10 @@ gr_ingredients_viewer_get_property (GObject *object,
g_value_set_string (value, self->ingredients);
break;
+ case PROP_ACTIVE:
+ g_value_set_boolean (value, self->active_row != NULL);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -142,7 +166,7 @@ delete_row (GrIngredientsViewerRow *row,
GrIngredientsViewer *viewer)
{
gtk_widget_destroy (GTK_WIDGET (row));
- // TODO: mark page unsaved
+ g_object_notify (G_OBJECT (viewer), "ingredients");
}
static void
@@ -163,7 +187,7 @@ move_row (GrIngredientsViewerRow *row,
g_object_unref (row);
gtk_list_box_select_row (GTK_LIST_BOX (list), GTK_LIST_BOX_ROW (row));
- // TODO: mark page unsaved
+ g_object_notify (G_OBJECT (viewer), "ingredients");
}
static void
@@ -183,7 +207,14 @@ add_row (GtkButton *button,
g_signal_connect (row, "move", G_CALLBACK (move_row), viewer);
gtk_container_add (GTK_CONTAINER (viewer->list), row);
- // TODO mark page as unsaved
+ g_object_notify (G_OBJECT (viewer), "ingredients");
+}
+
+static void
+remove_list (GtkButton *button,
+ GrIngredientsViewer *viewer)
+{
+ g_signal_emit (viewer, signals[DELETE], 0);
}
static void
@@ -248,6 +279,14 @@ gr_ingredients_viewer_set_editable (GrIngredientsViewer *viewer,
}
static void
+gr_ingredients_viewer_set_active (GrIngredientsViewer *viewer,
+ gboolean active)
+{
+ if (!active)
+ gtk_list_box_unselect_all (GTK_LIST_BOX (viewer->list));
+}
+
+static void
gr_ingredients_viewer_set_property (GObject *object,
guint prop_id,
const GValue *value,
@@ -274,6 +313,10 @@ gr_ingredients_viewer_set_property (GObject *object,
gr_ingredients_viewer_set_editable (self, g_value_get_boolean (value));
break;
+ case PROP_ACTIVE:
+ gr_ingredients_viewer_set_active (self, g_value_get_boolean (value));
+ break;
+
case PROP_INGREDIENTS:
gr_ingredients_viewer_set_ingredients (self, g_value_get_string (value));
break;
@@ -324,6 +367,11 @@ gr_ingredients_viewer_class_init (GrIngredientsViewerClass *klass)
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_EDITABLE, pspec);
+ pspec = g_param_spec_boolean ("active", NULL, NULL,
+ FALSE,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_ACTIVE, pspec);
+
pspec = g_param_spec_string ("title", NULL, NULL,
NULL,
G_PARAM_READWRITE);
@@ -334,6 +382,14 @@ gr_ingredients_viewer_class_init (GrIngredientsViewerClass *klass)
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_INGREDIENTS, pspec);
+ signals[DELETE] = g_signal_new ("delete",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ 0,
+ NULL, NULL,
+ NULL,
+ G_TYPE_NONE, 0);
+
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/Recipes/gr-ingredients-viewer.ui");
gtk_widget_class_bind_template_child (widget_class, GrIngredientsViewer, title_stack);
gtk_widget_class_bind_template_child (widget_class, GrIngredientsViewer, title_entry);
@@ -344,4 +400,5 @@ gr_ingredients_viewer_class_init (GrIngredientsViewerClass *klass)
gtk_widget_class_bind_template_callback (widget_class, title_changed);
gtk_widget_class_bind_template_callback (widget_class, selected_rows_changed);
gtk_widget_class_bind_template_callback (widget_class, add_row);
+ gtk_widget_class_bind_template_callback (widget_class, remove_list);
}
diff --git a/src/gr-ingredients-viewer.ui b/src/gr-ingredients-viewer.ui
index dcb5bf6..60cb69e 100644
--- a/src/gr-ingredients-viewer.ui
+++ b/src/gr-ingredients-viewer.ui
@@ -41,6 +41,7 @@
<object class="GtkButton">
<property name="visible">1</property>
<property name="label" translatable="yes">Remove</property>
+ <signal name="clicked" handler="remove_list"/>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]