[gnome-builder] color-picker: add palette menu and popover
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] color-picker: add palette menu and popover
- Date: Mon, 18 Jul 2016 00:22:08 +0000 (UTC)
commit 68ea98e5548a53227e2a19775a34232421fbd92f
Author: Sebastien Lafargue <slafargue gnome org>
Date: Sat Jul 16 00:00:10 2016 +0200
color-picker: add palette menu and popover
We now use the same menu and popover as for the
color widgets:
menu with rename and remove.
rename popover for the remove choice.
The old flat GtkEntry used for the name
and to edit it is removed.
The contextual menu is triggered by right click or
by the F2 key.
Please enter the commit message for your changes. Lines starting
.../gb-color-picker-prefs-palette-list.c | 13 --
.../gb-color-picker-prefs-palette-row.c | 171 ++++++++++----------
plugins/color-picker/gb-color-picker.gresource.xml | 1 +
.../color-picker/gtk/color-picker-palette-menu.ui | 25 +++
.../color-picker/gtk/color-picker-palette-row.ui | 22 +---
5 files changed, 116 insertions(+), 116 deletions(-)
---
diff --git a/plugins/color-picker/gb-color-picker-prefs-palette-list.c
b/plugins/color-picker/gb-color-picker-prefs-palette-list.c
index c2db381..6aca33b 100644
--- a/plugins/color-picker/gb-color-picker-prefs-palette-list.c
+++ b/plugins/color-picker/gb-color-picker-prefs-palette-list.c
@@ -110,19 +110,6 @@ gb_picker_prefs_palette_list_key_pressed_cb (GbColorPickerPrefsPaletteList *self
}
}
}
- else if (GTK_IS_ENTRY (focused_widget))
- {
- if (gtk_widget_is_ancestor (focused_widget, GTK_WIDGET (list_box)) &&
- is_editing &&
- event->keyval == GDK_KEY_Escape)
- {
- row_child = gtk_widget_get_ancestor (focused_widget, GTK_TYPE_LIST_BOX_ROW);
- if (row_child != NULL)
- gtk_widget_grab_focus (row_child);
- }
-
- return GDK_EVENT_STOP;
- }
return GDK_EVENT_PROPAGATE;
}
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 d26e236..004972b 100644
--- a/plugins/color-picker/gb-color-picker-prefs-palette-row.c
+++ b/plugins/color-picker/gb-color-picker-prefs-palette-row.c
@@ -17,8 +17,10 @@
*/
#include <gdk/gdk.h>
+#include "glib/gi18n.h"
#include <ide.h>
+#include "gstyle-rename-popover.h"
#include "gb-color-picker-prefs-palette-row.h"
@@ -26,12 +28,10 @@ struct _GbColorPickerPrefsPaletteRow
{
IdePreferencesBin parent_instance;
- GtkEntry *palette_name;
- GtkButton *button;
+ GtkLabel *palette_name;
GtkImage *image;
GtkWidget *event_box;
gchar *palette_id;
- gchar *backup_name;
gulong handler;
@@ -123,31 +123,64 @@ gb_color_picker_prefs_palette_row_activate (GbColorPickerPrefsPaletteRow *self)
}
static void
-gb_color_picker_prefs_palette_row_edit (GbColorPickerPrefsPaletteRow *self)
+gb_color_picker_prefs_palette_row_set_edit (GbColorPickerPrefsPaletteRow *self,
+ gboolean is_editing)
{
g_assert (GB_IS_COLOR_PICKER_PREFS_PALETTE_ROW (self));
- gtk_entry_grab_focus_without_selecting (self->palette_name);
- gtk_editable_set_position (GTK_EDITABLE (self->palette_name), -1);
+ if (is_editing && !self->is_editing)
+ g_signal_emit_by_name (self, "edit");
+
+ self->is_editing = is_editing;
}
static void
-gb_color_picker_prefs_palette_row_set_edit (GbColorPickerPrefsPaletteRow *self,
- gboolean is_editing)
+contextual_popover_closed_cb (GbColorPickerPrefsPaletteRow *self,
+ GtkWidget *popover)
+{
+ g_assert (GB_IS_COLOR_PICKER_PREFS_PALETTE_ROW (self));
+ g_assert (GTK_IS_WIDGET (popover));
+
+ gtk_widget_destroy (popover);
+
+ gb_color_picker_prefs_palette_row_set_edit (self, FALSE);
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_IS_EDITING]);
+}
+
+static void
+rename_popover_entry_renamed_cb (GbColorPickerPrefsPaletteRow *self,
+ const gchar *name)
{
- GtkWidget *parent;
+ const gchar *id;
g_assert (GB_IS_COLOR_PICKER_PREFS_PALETTE_ROW (self));
- if (is_editing)
- g_signal_emit_by_name (self, "edit");
- else
- {
- parent = gtk_widget_get_parent (GTK_WIDGET (self));
- gtk_widget_grab_focus (parent);
- }
+ gtk_label_set_text (self->palette_name, name);
+ id = g_variant_get_string (self->target, NULL);
+ g_signal_emit_by_name (self, "name-changed",
+ id,
+ gtk_label_get_text (self->palette_name));
+}
- self->is_editing = is_editing;
+static void
+gb_color_picker_prefs_palette_row_edit (GbColorPickerPrefsPaletteRow *self)
+{
+ GtkWidget *popover;
+ const gchar *name;
+
+ g_assert (GB_IS_COLOR_PICKER_PREFS_PALETTE_ROW (self));
+
+ name = gtk_label_get_text (self->palette_name);
+ popover = g_object_new (GSTYLE_TYPE_RENAME_POPOVER,
+ "label", _("Palette name"),
+ "name", name,
+ "message", _("Enter a new name for the palette"),
+ 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
@@ -187,40 +220,32 @@ gb_color_picker_prefs_palette_row_disconnect (IdePreferencesBin *bin,
}
static void
-gb_color_picker_prefs_list_row_button_clicked_cb (GbColorPickerPrefsPaletteRow *self,
- GtkButton *button)
+popover_button_rename_clicked_cb (GbColorPickerPrefsPaletteRow *self,
+ GdkEvent *event,
+ GtkButton *button)
{
- const gchar *id;
-
g_assert (GB_IS_COLOR_PICKER_PREFS_PALETTE_ROW (self));
g_assert (GTK_IS_BUTTON (button));
- id = g_variant_get_string (self->target, NULL);
- g_signal_emit_by_name (self, "closed", id);
+ self->is_editing = TRUE;
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_IS_EDITING]);
+
+ g_signal_emit_by_name (self, "edit");
}
-static gboolean
-palette_name_activate_cb (GbColorPickerPrefsPaletteRow *self,
- GtkEntry *palette_name)
+static void
+popover_button_remove_clicked_cb (GbColorPickerPrefsPaletteRow *self,
+ GdkEvent *event,
+ GtkButton *button)
{
- GtkWidget *parent;
const gchar *id;
g_assert (GB_IS_COLOR_PICKER_PREFS_PALETTE_ROW (self));
- g_assert (GTK_IS_ENTRY (palette_name));
+ g_assert (event != NULL);
+ g_assert (GTK_IS_BUTTON (button));
- g_clear_pointer (&self->backup_name, g_free);
- self->backup_name = g_strdup (gtk_entry_get_text (self->palette_name));
id = g_variant_get_string (self->target, NULL);
- g_signal_emit_by_name (self, "name-changed",
- id,
- self->backup_name );
-
- parent = gtk_widget_get_parent (GTK_WIDGET (self));
- g_assert (GTK_IS_LIST_BOX_ROW (parent));
- gtk_widget_grab_focus (GTK_WIDGET (parent));
-
- return GDK_EVENT_STOP;
+ g_signal_emit_by_name (self, "closed", id);
}
static gboolean
@@ -228,44 +253,36 @@ 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)
{
- g_signal_emit_by_name (self, "edit");
- return GDK_EVENT_STOP;
- }
+ 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);
- return GDK_EVENT_PROPAGATE;
-}
+ 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);
-static void
-palette_name_has_focus_cb (GbColorPickerPrefsPaletteRow *self,
- GParamSpec *pspec,
- GtkEntry *palette_name)
-{
- g_assert (GB_IS_COLOR_PICKER_PREFS_PALETTE_ROW (self));
- g_assert (pspec != NULL);
- g_assert (GTK_IS_ENTRY (palette_name));
-
- self->is_editing = gtk_widget_has_focus (GTK_WIDGET (self->palette_name));
- g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_IS_EDITING]);
+ 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);
- if (!self->is_editing)
- {
- if (g_strcmp0 (self->backup_name, gtk_entry_get_text (self->palette_name)) != 0)
- {
- gtk_entry_set_text (self->palette_name, self->backup_name);
- g_clear_pointer (&self->backup_name, g_free);
- }
- }
- else
- {
- g_clear_pointer (&self->backup_name, g_free);
- self->backup_name = g_strdup (gtk_entry_get_text (self->palette_name));
+ return GDK_EVENT_STOP;
}
+
+ return GDK_EVENT_PROPAGATE;
}
static void
@@ -278,16 +295,16 @@ gb_color_picker_prefs_palette_row_set_palette_name (GbColorPickerPrefsPaletteRow
if (ide_str_empty0 (new_text))
{
- gtk_entry_set_text (self->palette_name, "No name");
+ gtk_label_set_text (self->palette_name, "No name");
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_PALETTE_NAME]);
return;
}
- text = gtk_entry_get_text (self->palette_name);
+ text = gtk_label_get_text (self->palette_name);
if (g_strcmp0 (text, new_text) != 0)
{
- gtk_entry_set_text (self->palette_name, new_text);
+ gtk_label_set_text (self->palette_name, new_text);
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_PALETTE_NAME]);
}
}
@@ -309,7 +326,6 @@ 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_pointer (&self->backup_name, g_free);
G_OBJECT_CLASS (gb_color_picker_prefs_palette_row_parent_class)->finalize (object);
}
@@ -337,7 +353,7 @@ gb_color_picker_prefs_palette_row_get_property (GObject *object,
break;
case PROP_PALETTE_NAME:
- g_value_set_string (value, gtk_entry_get_text (self->palette_name));
+ g_value_set_string (value, gtk_label_get_text (self->palette_name));
break;
default:
@@ -461,7 +477,6 @@ gb_color_picker_prefs_palette_row_class_init (GbColorPickerPrefsPaletteRowClass
gtk_widget_class_bind_template_child (widget_class, GbColorPickerPrefsPaletteRow, image);
gtk_widget_class_bind_template_child (widget_class, GbColorPickerPrefsPaletteRow, event_box);
gtk_widget_class_bind_template_child (widget_class, GbColorPickerPrefsPaletteRow, palette_name);
- gtk_widget_class_bind_template_child (widget_class, GbColorPickerPrefsPaletteRow, button);
}
static void
@@ -473,14 +488,4 @@ gb_color_picker_prefs_palette_row_init (GbColorPickerPrefsPaletteRow *self)
g_signal_connect_swapped (self->event_box, "button-press-event",
G_CALLBACK (event_box_button_pressed_cb),
self);
-
- g_signal_connect_swapped (self->palette_name, "activate",
- G_CALLBACK (palette_name_activate_cb),
- self);
-
- g_signal_connect_swapped (self->palette_name, "notify::has-focus",
- G_CALLBACK (palette_name_has_focus_cb),
- self);
-
- g_signal_connect_swapped (self->button, "clicked", G_CALLBACK
(gb_color_picker_prefs_list_row_button_clicked_cb), self);
}
diff --git a/plugins/color-picker/gb-color-picker.gresource.xml
b/plugins/color-picker/gb-color-picker.gresource.xml
index a4aff9b..32bd79a 100644
--- a/plugins/color-picker/gb-color-picker.gresource.xml
+++ b/plugins/color-picker/gb-color-picker.gresource.xml
@@ -10,6 +10,7 @@
<file>gtk/color-picker-prefs-palette-list.ui</file>
<file>gtk/color-picker-preview.ui</file>
<file>gtk/color-picker-palette-row.ui</file>
+ <file>gtk/color-picker-palette-menu.ui</file>
<file>gtk/menus.ui</file>
<file>data/basic.xml</file>
diff --git a/plugins/color-picker/gtk/color-picker-palette-menu.ui
b/plugins/color-picker/gtk/color-picker-palette-menu.ui
new file mode 100644
index 0000000..3b6e1b6
--- /dev/null
+++ b/plugins/color-picker/gtk/color-picker-palette-menu.ui
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <requires lib="gtk+" version="3.20"/>
+ <object class="GtkPopoverMenu" id="popover">
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="margin">3</property>
+ <child>
+ <object class="GtkModelButton" id="button_rename">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Rename</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton" id="button_remove">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Remove</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/plugins/color-picker/gtk/color-picker-palette-row.ui
b/plugins/color-picker/gtk/color-picker-palette-row.ui
index f29f37a..7b44d1a 100644
--- a/plugins/color-picker/gtk/color-picker-palette-row.ui
+++ b/plugins/color-picker/gtk/color-picker-palette-row.ui
@@ -17,12 +17,11 @@
<property name="spacing">6</property>
<property name="visible">true</property>
<child>
- <object class="GtkEntry" id="palette_name">
+ <object class="GtkLabel" id="palette_name">
<property name="visible">true</property>
- <property name="activates-default">false</property>
+ <property name="ellipsize">end</property>
<property name="hexpand">true</property>
<property name="xalign">0.0</property>
- <property name="placeholder-text" translatable="yes">No name</property>
<style>
<class name="flat"/>
</style>
@@ -39,23 +38,6 @@
</child>
</object>
</child>
- <child>
- <object class="GtkButton" id="button">
- <property name="visible">true</property>
- <property name="hexpand">true</property>
- <property name="halign">end</property>
- <style>
- <class name="flat"/>
- </style>
- <child>
- <object class="GtkImage">
- <property name="icon-name">window-close-symbolic</property>
- <property name="visible">true</property>
- <property name="valign">center</property>
- </object>
- </child>
- </object>
- </child>
</object>
</child>
</template>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]