Add Ctrl-C shortcut to copy colors to the selection clipboard

Fixes #43.
parent 2df3a195
......@@ -100,6 +100,7 @@ gcolor3_application_init_accelerators (GtkApplication *application)
* Enter the action name followed by the accelerator strings
* and terminate the entry with a NULL-string.*/
static const gchar *const accelmap[] = {
"win.copy", "<Ctrl>c", NULL,
"win.save", "<Ctrl>s", NULL,
"win.delete", "<Shift>Delete", NULL,
"win.change-page", "F9", NULL,
......
......@@ -75,6 +75,15 @@ hex_value (GdkColor *color) {
color->blue / 256);
}
static void
set_color_in_clipboard (const gchar *color)
{
GtkClipboard *clipboard;
clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
gtk_clipboard_set_text (clipboard, color, -1);
}
static GdkPixbuf *
create_pixbuf_from_xpm (const gchar *hex)
{
......@@ -103,6 +112,27 @@ create_pixbuf_from_xpm (const gchar *hex)
return gdk_pixbuf_new_from_xpm_data ((gchar const **) xpm);
}
static void
gcolor3_window_action_copy (UNUSED GSimpleAction *action,
UNUSED GVariant *parameter,
gpointer user_data)
{
Gcolor3WindowPrivate *priv;
GtkTreeIter iter;
GtkTreeModel *model;
gchar *hex;
priv = gcolor3_window_get_instance_private (GCOLOR3_WINDOW (user_data));
if (!gtk_tree_selection_get_selected (priv->selection, &model, &iter)) {
return;
}
gtk_tree_model_get (model, &iter, COLOR_VALUE, &hex, -1);
set_color_in_clipboard (hex);
g_free (hex);
}
static void
gcolor3_window_action_save (UNUSED GSimpleAction *action,
UNUSED GVariant *parameter,
......@@ -170,6 +200,7 @@ gcolor3_window_action_change_page (UNUSED GSimpleAction *action,
}
static const GActionEntry window_actions[] = {
{ "copy", gcolor3_window_action_copy, NULL, NULL, NULL },
{ "save", gcolor3_window_action_save, NULL, NULL, NULL },
{ "delete", gcolor3_window_action_delete, NULL, NULL, NULL },
{ "change-page", gcolor3_window_action_change_page, NULL, NULL, NULL },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment