[gnome-builder] colorpicker: add dialog to close changed palette
- From: Sébastien Lafargue <slafargue src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] colorpicker: add dialog to close changed palette
- Date: Tue, 26 Jul 2016 19:38:12 +0000 (UTC)
commit 6c1df91543ab36ce9a8c656116558dc99063d398
Author: Sebastien Lafargue <slafargue gnome org>
Date: Tue Jul 26 21:34:35 2016 +0200
colorpicker: add dialog to close changed palette
contrib/gstyle/gstyle-palette.c | 4 +-
.../gb-color-picker-prefs-palette-row.c | 43 ++++++-----
plugins/color-picker/gb-color-picker-prefs.c | 80 +++++++++++++++++++-
3 files changed, 105 insertions(+), 22 deletions(-)
---
diff --git a/contrib/gstyle/gstyle-palette.c b/contrib/gstyle/gstyle-palette.c
index b2c8c7f..98fa593 100644
--- a/contrib/gstyle/gstyle-palette.c
+++ b/contrib/gstyle/gstyle-palette.c
@@ -769,7 +769,9 @@ gstyle_palette_new_from_file (GFile *file,
if (tmp_error)
g_propagate_error (error, tmp_error);
- gstyle_palette_set_changed (palette, FALSE);
+ if (palette != NULL)
+ gstyle_palette_set_changed (palette, FALSE);
+
return palette;
}
diff --git a/plugins/color-picker/gb-color-picker-prefs-palette-row.c
b/plugins/color-picker/gb-color-picker-prefs-palette-row.c
index 1793854..0ba77e3 100644
--- a/plugins/color-picker/gb-color-picker-prefs-palette-row.c
+++ b/plugins/color-picker/gb-color-picker-prefs-palette-row.c
@@ -31,6 +31,7 @@ struct _GbColorPickerPrefsPaletteRow
GtkLabel *palette_name;
GtkImage *image;
GtkWidget *event_box;
+ GtkWidget *popover_menu;
gchar *palette_id;
gulong handler;
@@ -231,6 +232,7 @@ popover_button_rename_clicked_cb (GbColorPickerPrefsPaletteRow *self,
self->is_editing = TRUE;
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_IS_EDITING]);
+ gtk_widget_hide (self->popover_menu);
g_signal_emit_by_name (self, "edit");
}
@@ -248,6 +250,7 @@ popover_button_remove_clicked_cb (GbColorPickerPrefsPaletteRow *self,
id = g_variant_get_string (self->target, NULL);
g_signal_emit_by_name (self, "closed", id);
+ gtk_widget_hide (self->popover_menu);
}
static gboolean
@@ -255,32 +258,13 @@ event_box_button_pressed_cb (GbColorPickerPrefsPaletteRow *self,
GdkEventButton *event,
GtkEventBox *event_box)
{
- GtkWidget *popover;
- GtkBuilder *builder;
- GtkWidget *button_rename;
- GtkWidget *button_remove;
-
g_assert (GB_IS_COLOR_PICKER_PREFS_PALETTE_ROW (self));
g_assert (event != NULL);
g_assert (GTK_IS_EVENT_BOX (event_box));
if (event->type == GDK_BUTTON_PRESS && event->button == GDK_BUTTON_SECONDARY)
{
- builder = gtk_builder_new_from_resource
("/org/gnome/builder/plugins/color-picker-plugin/gtk/color-picker-palette-menu.ui");
- popover = GTK_WIDGET (gtk_builder_get_object (builder, "popover"));
- button_rename = GTK_WIDGET (gtk_builder_get_object (builder, "button_rename"));
- g_signal_connect_object (button_rename, "button-release-event",
- G_CALLBACK (popover_button_rename_clicked_cb), self, G_CONNECT_SWAPPED);
-
- button_remove = GTK_WIDGET (gtk_builder_get_object (builder, "button_remove"));
- g_signal_connect_object (button_remove, "button-release-event",
- G_CALLBACK (popover_button_remove_clicked_cb), self, G_CONNECT_SWAPPED);
-
- gtk_popover_set_relative_to (GTK_POPOVER (popover), GTK_WIDGET (self));
- g_signal_connect_swapped (popover, "closed", G_CALLBACK (contextual_popover_closed_cb), self);
- gtk_widget_show (popover);
- g_object_unref (builder);
-
+ gtk_widget_show (self->popover_menu);
return GDK_EVENT_STOP;
}
@@ -357,6 +341,7 @@ gb_color_picker_prefs_palette_row_finalize (GObject *object)
g_clear_pointer (&self->key, g_free);
g_clear_pointer (&self->target, g_variant_unref);
g_clear_pointer (&self->palette_id, g_free);
+ g_clear_object (&self->popover_menu);
G_OBJECT_CLASS (gb_color_picker_prefs_palette_row_parent_class)->finalize (object);
}
@@ -530,10 +515,28 @@ gb_color_picker_prefs_palette_row_class_init (GbColorPickerPrefsPaletteRowClass
static void
gb_color_picker_prefs_palette_row_init (GbColorPickerPrefsPaletteRow *self)
{
+ GtkBuilder *builder;
+ GtkWidget *button_rename;
+ GtkWidget *button_remove;
+
gtk_widget_init_template (GTK_WIDGET (self));
gtk_widget_add_events (self->event_box, GDK_KEY_PRESS_MASK);
g_signal_connect_swapped (self->event_box, "button-press-event",
G_CALLBACK (event_box_button_pressed_cb),
self);
+
+ builder = gtk_builder_new_from_resource
("/org/gnome/builder/plugins/color-picker-plugin/gtk/color-picker-palette-menu.ui");
+ self->popover_menu = GTK_WIDGET (g_object_ref_sink (gtk_builder_get_object (builder, "popover")));
+ button_rename = GTK_WIDGET (gtk_builder_get_object (builder, "button_rename"));
+ g_signal_connect_object (button_rename, "button-release-event",
+ G_CALLBACK (popover_button_rename_clicked_cb), self, G_CONNECT_SWAPPED);
+
+ button_remove = GTK_WIDGET (gtk_builder_get_object (builder, "button_remove"));
+ g_signal_connect_object (button_remove, "button-release-event",
+ G_CALLBACK (popover_button_remove_clicked_cb), self, G_CONNECT_SWAPPED);
+
+ gtk_popover_set_relative_to (GTK_POPOVER (self->popover_menu), GTK_WIDGET (self));
+
+ g_object_unref (builder);
}
diff --git a/plugins/color-picker/gb-color-picker-prefs.c b/plugins/color-picker/gb-color-picker-prefs.c
index fc64fcf..d74ca96 100644
--- a/plugins/color-picker/gb-color-picker-prefs.c
+++ b/plugins/color-picker/gb-color-picker-prefs.c
@@ -73,6 +73,39 @@ enum
static GParamSpec *properties [N_PROPS];
+static GtkDialog *
+create_palette_close_dialog (GbColorPickerPrefs *self,
+ GstylePalette *palette)
+{
+ GtkWindow *toplevel;
+ GtkDialog *dialog;
+ g_autofree gchar *text;
+ const gchar *palette_name;
+
+ g_assert (GB_IS_COLOR_PICKER_PREFS (self));
+ g_assert (GSTYLE_IS_PALETTE (palette));
+
+ toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self->panel)));
+ palette_name = gstyle_palette_get_name (palette);
+ text = g_strdup_printf ("Save changes to palette “%s” before closing ?", palette_name);
+ dialog = g_object_new (GTK_TYPE_MESSAGE_DIALOG,
+ "text", text,
+ "message-type", GTK_MESSAGE_QUESTION,
+ NULL);
+
+ gtk_dialog_add_buttons (dialog,
+ _("Close without Saving"), GTK_RESPONSE_CLOSE,
+ _("Cancel"), GTK_RESPONSE_CANCEL,
+ _("Save As…"), GTK_RESPONSE_YES,
+ NULL);
+
+ gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+ gtk_window_set_transient_for (GTK_WINDOW (dialog), toplevel);
+ gtk_window_set_attached_to (GTK_WINDOW (dialog), GTK_WIDGET (toplevel));
+
+ return dialog;
+}
+
GtkWidget *
gb_color_picker_prefs_get_page (GbColorPickerPrefs *self,
GstyleColorPanelPrefs prefs_type)
@@ -349,12 +382,57 @@ generate_palette_button_clicked_cb (GbColorPickerPrefs *self,
}
static void
+palette_close_dialog_cb (GbColorPickerPrefs *self,
+ gint response_id,
+ GtkDialog *dialog)
+{
+ GstylePalette *palette;
+ GtkWidget *save_dialog;
+
+ g_assert (GB_IS_COLOR_PICKER_PREFS (self));
+ g_assert (GTK_IS_DIALOG (dialog));
+
+ palette = g_object_get_data (G_OBJECT (dialog), "palette");
+ g_assert (GSTYLE_IS_PALETTE (palette));
+
+ if (response_id == GTK_RESPONSE_YES)
+ {
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+
+ save_dialog = create_file_save_dialog (self, palette);
+ g_signal_connect_object (save_dialog, "response", G_CALLBACK (palette_save_dialog_cb), self,
G_CONNECT_SWAPPED);
+ gtk_widget_show (save_dialog);
+
+ return;
+ }
+ else if (response_id == GTK_RESPONSE_CLOSE)
+ gstyle_palette_widget_remove (self->palette_widget, palette);
+
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
+static void
gb_color_picker_prefs_row_closed_cb (GbColorPickerPrefs *self,
const gchar *palette_id)
{
+ GstylePalette *palette;
+ GtkDialog *dialog;
+
g_assert (GB_IS_COLOR_PICKER_PREFS (self));
- gstyle_palette_widget_remove_by_id (self->palette_widget, palette_id);
+ if (NULL != (palette = gstyle_palette_widget_get_palette_by_id (self->palette_widget, palette_id)))
+ {
+ if (gstyle_palette_get_changed (palette))
+ {
+ dialog = create_palette_close_dialog (self, palette);
+ g_object_set_data (G_OBJECT (dialog), "palette", palette);
+ g_signal_connect_object (dialog, "response", G_CALLBACK (palette_close_dialog_cb), self,
G_CONNECT_SWAPPED);
+ gtk_widget_show (GTK_WIDGET (dialog));
+ }
+ else
+ gstyle_palette_widget_remove_by_id (self->palette_widget, palette_id);
+
+ }
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]