[gnome-builder/wip/slaf/colorpicker] gstyle-color-widget: add remove and rename actions



commit 43e7ad3f805165a071d6c0e02eeeb334fcb83508
Author: Sebastien Lafargue <slafargue gnome org>
Date:   Fri Jul 15 23:03:19 2016 +0200

    gstyle-color-widget: add remove and rename actions
    
    The rename action make use of the
    GstyleRenamePopover class.

 contrib/gstyle/Makefile.am                   |    2 +
 contrib/gstyle/gstyle-color-widget-actions.c |  114 ++++++++++++++++++++++++++
 contrib/gstyle/gstyle-color-widget-actions.h |   32 +++++++
 contrib/gstyle/gstyle-color-widget.c         |    3 +
 4 files changed, 151 insertions(+), 0 deletions(-)
---
diff --git a/contrib/gstyle/Makefile.am b/contrib/gstyle/Makefile.am
index 7b19a2b..c7a8f5d 100644
--- a/contrib/gstyle/Makefile.am
+++ b/contrib/gstyle/Makefile.am
@@ -24,6 +24,7 @@ headers_DATA =                        \
        gstyle-color-predefined.h     \
        gstyle-color-scale.h          \
        gstyle-color-widget.h         \
+       gstyle-color-widget-actions.h \
        gstyle-colorlexer.h           \
        gstyle-css-provider.h         \
        gstyle-eyedropper.h           \
@@ -53,6 +54,7 @@ libgstyle_private_la_SOURCES =        \
        gstyle-color-plane.c          \
        gstyle-color-scale.c          \
        gstyle-color-widget.c         \
+       gstyle-color-widget-actions.c \
        gstyle-colorlexer.c           \
        gstyle-css-provider.c         \
        gstyle-eyedropper.c           \
diff --git a/contrib/gstyle/gstyle-color-widget-actions.c b/contrib/gstyle/gstyle-color-widget-actions.c
new file mode 100644
index 0000000..88590bf
--- /dev/null
+++ b/contrib/gstyle/gstyle-color-widget-actions.c
@@ -0,0 +1,114 @@
+/* gstyle-color-widget-actions.c
+ *
+ * Copyright (C) 2016 Sebastien Lafargue <slafargue gnome org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define G_LOG_DOMAIN "gstyle-color-widget"
+
+#include <glib/gi18n.h>
+#include "gstyle-rename-popover.h"
+#include "gstyle-palette-widget.h"
+
+#include "gstyle-color-widget-actions.h"
+
+static void
+contextual_popover_closed_cb (GstyleColorWidget *self,
+                              GtkWidget         *popover)
+{
+  g_assert (GSTYLE_IS_COLOR_WIDGET (self));
+  g_assert (GTK_IS_WIDGET (popover));
+
+  gtk_widget_destroy (popover);
+}
+
+static void
+rename_popover_entry_renamed_cb (GstyleColorWidget *self,
+                                 const gchar       *name)
+{
+  GstyleColor *color;
+
+  g_assert (GSTYLE_IS_COLOR_WIDGET (self));
+
+  color = gstyle_color_widget_get_color (self);
+  gstyle_color_set_name (color, name);
+}
+
+static void
+gstyle_color_widget_actions_rename (GSimpleAction *action,
+                                    GVariant      *variant,
+                                    gpointer       user_data)
+{
+  GstyleColorWidget *self = (GstyleColorWidget *)user_data;
+  GtkWidget *popover;
+  GstyleColor *color;
+  const gchar *name;
+
+  g_assert (GSTYLE_IS_COLOR_WIDGET (self));
+  g_assert (G_IS_SIMPLE_ACTION (action));
+
+  color = gstyle_color_widget_get_color (self);
+  name = gstyle_color_get_name (color);
+
+  popover = g_object_new (GSTYLE_TYPE_RENAME_POPOVER,
+                          "label", _("Color name"),
+                          "name", name,
+                          "message", _("Enter a new name for the color"),
+                          NULL);
+
+  gtk_popover_set_relative_to (GTK_POPOVER (popover), GTK_WIDGET (self));
+  g_signal_connect_swapped (popover, "closed", G_CALLBACK (contextual_popover_closed_cb), self);
+  g_signal_connect_swapped (popover, "renamed", G_CALLBACK (rename_popover_entry_renamed_cb), self);
+  gtk_widget_show (popover);
+}
+
+static void
+gstyle_color_widget_actions_remove (GSimpleAction *action,
+                                    GVariant      *variant,
+                                    gpointer       user_data)
+{
+  GstyleColorWidget *self = (GstyleColorWidget *)user_data;
+  GtkWidget *ancestor;
+  GstylePalette *selected_palette;
+  GstyleColor *color;
+
+  g_assert (GSTYLE_IS_COLOR_WIDGET (self));
+  g_assert (G_IS_SIMPLE_ACTION (action));
+
+  ancestor = gtk_widget_get_ancestor (GTK_WIDGET (self), GSTYLE_TYPE_PALETTE_WIDGET);
+  if (ancestor != NULL)
+    {
+      color = gstyle_color_widget_get_color (self);
+      selected_palette = gstyle_palette_widget_get_selected_palette (GSTYLE_PALETTE_WIDGET (ancestor));
+      if (selected_palette != NULL && color != NULL)
+        gstyle_palette_remove (selected_palette, color);
+    }
+}
+
+static GActionEntry actions[] = {
+  { "rename", gstyle_color_widget_actions_rename },
+  { "remove", gstyle_color_widget_actions_remove }
+};
+
+void
+gstyle_color_widget_actions_init (GstyleColorWidget *self)
+{
+  g_autoptr (GSimpleActionGroup) action_group = NULL;
+
+  action_group = g_simple_action_group_new ();
+  g_action_map_add_action_entries (G_ACTION_MAP (action_group), actions,
+                                   G_N_ELEMENTS (actions), self);
+  gtk_widget_insert_action_group (GTK_WIDGET (self), "gstyle-color-widget-menu", G_ACTION_GROUP 
(action_group));
+}
diff --git a/contrib/gstyle/gstyle-color-widget-actions.h b/contrib/gstyle/gstyle-color-widget-actions.h
new file mode 100644
index 0000000..6221324
--- /dev/null
+++ b/contrib/gstyle/gstyle-color-widget-actions.h
@@ -0,0 +1,32 @@
+/* gstyle-color-widget-actions.h
+ *
+ * Copyright (C) 2016 Sebastien Lafargue <slafargue gnome org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GSTYLE_COLOR_WIDGET_ACTIONS_H
+#define GSTYLE_COLOR_WIDGET_ACTIONS_H
+
+#include <glib.h>
+
+#include "gstyle-color-widget.h"
+
+G_BEGIN_DECLS
+
+void gstyle_color_widget_actions_init   (GstyleColorWidget *self);
+
+G_END_DECLS
+
+#endif /* GSTYLE_COLOR_WIDGET_ACTIONS_H */
diff --git a/contrib/gstyle/gstyle-color-widget.c b/contrib/gstyle/gstyle-color-widget.c
index 2d530f8..0eb4816 100644
--- a/contrib/gstyle/gstyle-color-widget.c
+++ b/contrib/gstyle/gstyle-color-widget.c
@@ -22,6 +22,7 @@
 #include <string.h>
 #include <gdk/gdk.h>
 
+#include "gstyle-color-widget-actions.h"
 #include "gstyle-css-provider.h"
 #include "gstyle-palette-widget.h"
 #include "gstyle-private.h"
@@ -1273,6 +1274,8 @@ gstyle_color_widget_init (GstyleColorWidget *self)
   self->drag_gesture = gtk_gesture_drag_new (GTK_WIDGET (self));
   g_signal_connect (self->drag_gesture, "drag-update",
                     G_CALLBACK (gstyle_color_widget_drag_gesture_update), self);
+
+  gstyle_color_widget_actions_init (self);
 }
 
 GType


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