[gnome-photos/wip/rishi/edit-preview: 7/9] edit-palette: Reset when entering the edit mode
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/edit-preview: 7/9] edit-palette: Reset when entering the edit mode
- Date: Tue, 24 Nov 2015 16:42:33 +0000 (UTC)
commit 5eb379e086126394a10960a5714a016ee83d1823
Author: Debarshi Ray <debarshir gnome org>
Date: Tue Nov 24 16:59:27 2015 +0100
edit-palette: Reset when entering the edit mode
... so that the EditTools don't carry forward any state from the
previous item that we might have been editing.
src/photos-edit-palette.c | 200 +++++++++++++++++++++++++--------------------
1 files changed, 110 insertions(+), 90 deletions(-)
---
diff --git a/src/photos-edit-palette.c b/src/photos-edit-palette.c
index bf001e8..3bebf1f 100644
--- a/src/photos-edit-palette.c
+++ b/src/photos-edit-palette.c
@@ -33,6 +33,7 @@
struct _PhotosEditPalette
{
GtkListBox parent_instance;
+ GIOExtensionPoint *extension_point;
GList *tools;
PhotosModeController *mode_cntrlr;
};
@@ -90,21 +91,120 @@ photos_edit_palette_hide_requested_second (PhotosEditPalette *self)
static void
-photos_edit_palette_window_mode_changed (PhotosEditPalette *self, PhotosWindowMode mode, PhotosWindowMode
old_mode)
+photos_edit_palette_reset (PhotosEditPalette *self)
{
- GtkListBoxRow *row;
- gint i;
+ GList *extensions;
+ GList *l;
+ GtkSizeGroup *size_group;
+
+ gtk_container_foreach (GTK_CONTAINER (self), (GtkCallback) gtk_widget_destroy, NULL);
+ g_list_free_full (self->tools, g_object_unref);
+ self->tools = NULL;
+
+ extensions = g_io_extension_point_get_extensions (self->extension_point);
+ extensions = g_list_copy (extensions);
+ extensions = g_list_sort (extensions, photos_edit_palette_extensions_sort_func);
+
+ size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
- for (i = 0; (row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (self), i)) != NULL; i++)
+ for (l = extensions; l != NULL; l = l->next)
{
- GtkRevealer *revealer;
+ GIOExtension *extension = (GIOExtension *) l->data;
+ GType type;
+ GtkWidget *grid0;
+ GtkWidget *grid1;
+ GtkWidget *image;
+ GtkWidget *label;
+ GtkWidget *revealer;
+ GtkWidget *row;
+ GtkWidget *tool_widget;
+ PhotosTool *tool;
+ const gchar *icon_name;
+ const gchar *name;
+ gchar *name_markup;
- gtk_list_box_row_set_activatable (row, TRUE);
- revealer = GTK_REVEALER (g_object_get_data (G_OBJECT (row), "edit-tool-details-revealer"));
- gtk_revealer_set_reveal_child (revealer, FALSE);
+ type = g_io_extension_get_type (extension);
+ tool = PHOTOS_TOOL (g_object_new (type, NULL));
+ self->tools = g_list_prepend (self->tools, g_object_ref (tool));
+
+ row = gtk_list_box_row_new ();
+ g_object_set_data_full (G_OBJECT (row), "edit-tool", g_object_ref (tool), g_object_unref);
+ gtk_container_add (GTK_CONTAINER (self), row);
+
+ grid0 = gtk_grid_new ();
+ gtk_widget_set_margin_bottom (grid0, 6);
+ gtk_widget_set_margin_start (grid0, 18);
+ gtk_widget_set_margin_end (grid0, 18);
+ gtk_widget_set_margin_top (grid0, 6);
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (grid0), GTK_ORIENTATION_VERTICAL);
+ gtk_container_add (GTK_CONTAINER (row), grid0);
+
+ grid1 = gtk_grid_new ();
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (grid1), GTK_ORIENTATION_HORIZONTAL);
+ gtk_grid_set_column_spacing (GTK_GRID (grid1), 12);
+ gtk_container_add (GTK_CONTAINER (grid0), grid1);
+
+ icon_name = photos_tool_get_icon_name (tool);
+ image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
+ gtk_container_add (GTK_CONTAINER (grid1), image);
+
+ name = photos_tool_get_name (tool);
+ label = gtk_label_new (NULL);
+ name_markup = g_strdup_printf ("<b>%s</b>", name);
+ gtk_label_set_markup (GTK_LABEL (label), name_markup);
+ gtk_container_add (GTK_CONTAINER (grid1), label);
+
+ revealer = gtk_revealer_new ();
+ gtk_revealer_set_transition_type (GTK_REVEALER (revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
+ g_object_set_data (G_OBJECT (row), "edit-tool-details-revealer", revealer);
+ gtk_container_add (GTK_CONTAINER (grid0), revealer);
+
+ tool_widget = photos_tool_get_widget (tool);
+ gtk_widget_set_margin_bottom (tool_widget, 12);
+ gtk_widget_set_margin_top (tool_widget, 12);
+ gtk_container_add (GTK_CONTAINER (revealer), tool_widget);
+ gtk_size_group_add_widget (size_group, tool_widget);
+
+ g_signal_connect_swapped (tool, "hide-requested", G_CALLBACK (photos_edit_palette_hide_requested),
row);
+ g_signal_connect_swapped (tool,
+ "hide-requested",
+ G_CALLBACK (photos_edit_palette_hide_requested_second),
+ self);
+ g_free (name_markup);
+ g_object_unref (tool);
}
- g_signal_emit (self, signals[TOOL_CHANGED], 0, NULL);
+ gtk_widget_show_all (GTK_WIDGET (self));
+ g_object_unref (size_group);
+ g_list_free (extensions);
+}
+
+
+static void
+photos_edit_palette_window_mode_changed (PhotosEditPalette *self, PhotosWindowMode mode, PhotosWindowMode
old_mode)
+{
+ if (old_mode == PHOTOS_WINDOW_MODE_EDIT)
+ {
+ GtkListBoxRow *row;
+ gint i;
+
+ g_return_if_fail (mode == PHOTOS_WINDOW_MODE_PREVIEW);
+
+ for (i = 0; (row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (self), i)) != NULL; i++)
+ {
+ GtkRevealer *revealer;
+
+ gtk_list_box_row_set_activatable (row, TRUE);
+ revealer = GTK_REVEALER (g_object_get_data (G_OBJECT (row), "edit-tool-details-revealer"));
+ gtk_revealer_set_reveal_child (revealer, FALSE);
+ }
+
+ g_signal_emit (self, signals[TOOL_CHANGED], 0, NULL);
+ }
+ else if (old_mode == PHOTOS_WINDOW_MODE_PREVIEW && mode == PHOTOS_WINDOW_MODE_EDIT)
+ {
+ photos_edit_palette_reset (self);
+ }
}
@@ -175,10 +275,6 @@ static void
photos_edit_palette_init (PhotosEditPalette *self)
{
GApplication *app;
- GIOExtensionPoint *extension_point;
- GList *extensions;
- GList *l;
- GtkSizeGroup *size_group;
PhotosSearchContextState *state;
app = g_application_get_default ();
@@ -191,79 +287,7 @@ photos_edit_palette_init (PhotosEditPalette *self)
NULL,
NULL);
- extension_point = g_io_extension_point_lookup (PHOTOS_TOOL_EXTENSION_POINT_NAME);
- extensions = g_io_extension_point_get_extensions (extension_point);
- extensions = g_list_copy (extensions);
- extensions = g_list_sort (extensions, photos_edit_palette_extensions_sort_func);
-
- size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
-
- for (l = extensions; l != NULL; l = l->next)
- {
- GIOExtension *extension = (GIOExtension *) l->data;
- GType type;
- GtkWidget *grid0;
- GtkWidget *grid1;
- GtkWidget *image;
- GtkWidget *label;
- GtkWidget *revealer;
- GtkWidget *row;
- GtkWidget *tool_widget;
- PhotosTool *tool;
- const gchar *icon_name;
- const gchar *name;
- gchar *name_markup;
-
- type = g_io_extension_get_type (extension);
- tool = PHOTOS_TOOL (g_object_new (type, NULL));
- self->tools = g_list_prepend (self->tools, g_object_ref (tool));
-
- row = gtk_list_box_row_new ();
- g_object_set_data_full (G_OBJECT (row), "edit-tool", g_object_ref (tool), g_object_unref);
- gtk_container_add (GTK_CONTAINER (self), row);
-
- grid0 = gtk_grid_new ();
- gtk_widget_set_margin_bottom (grid0, 6);
- gtk_widget_set_margin_start (grid0, 18);
- gtk_widget_set_margin_end (grid0, 18);
- gtk_widget_set_margin_top (grid0, 6);
- gtk_orientable_set_orientation (GTK_ORIENTABLE (grid0), GTK_ORIENTATION_VERTICAL);
- gtk_container_add (GTK_CONTAINER (row), grid0);
-
- grid1 = gtk_grid_new ();
- gtk_orientable_set_orientation (GTK_ORIENTABLE (grid1), GTK_ORIENTATION_HORIZONTAL);
- gtk_grid_set_column_spacing (GTK_GRID (grid1), 12);
- gtk_container_add (GTK_CONTAINER (grid0), grid1);
-
- icon_name = photos_tool_get_icon_name (tool);
- image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
- gtk_container_add (GTK_CONTAINER (grid1), image);
-
- name = photos_tool_get_name (tool);
- label = gtk_label_new (NULL);
- name_markup = g_strdup_printf ("<b>%s</b>", name);
- gtk_label_set_markup (GTK_LABEL (label), name_markup);
- gtk_container_add (GTK_CONTAINER (grid1), label);
-
- revealer = gtk_revealer_new ();
- gtk_revealer_set_transition_type (GTK_REVEALER (revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
- g_object_set_data (G_OBJECT (row), "edit-tool-details-revealer", revealer);
- gtk_container_add (GTK_CONTAINER (grid0), revealer);
-
- tool_widget = photos_tool_get_widget (tool);
- gtk_widget_set_margin_bottom (tool_widget, 12);
- gtk_widget_set_margin_top (tool_widget, 12);
- gtk_container_add (GTK_CONTAINER (revealer), tool_widget);
- gtk_size_group_add_widget (size_group, tool_widget);
-
- g_signal_connect_swapped (tool, "hide-requested", G_CALLBACK (photos_edit_palette_hide_requested),
row);
- g_signal_connect_swapped (tool,
- "hide-requested",
- G_CALLBACK (photos_edit_palette_hide_requested_second),
- self);
- g_free (name_markup);
- g_object_unref (tool);
- }
+ self->extension_point = g_io_extension_point_lookup (PHOTOS_TOOL_EXTENSION_POINT_NAME);
self->mode_cntrlr = g_object_ref (state->mode_cntrlr);
g_signal_connect_object (self->mode_cntrlr,
@@ -271,10 +295,6 @@ photos_edit_palette_init (PhotosEditPalette *self)
G_CALLBACK (photos_edit_palette_window_mode_changed),
self,
G_CONNECT_SWAPPED);
-
- gtk_widget_show_all (GTK_WIDGET (self));
- g_object_unref (size_group);
- g_list_free (extensions);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]