Question

With a windows error dialog I can use CTRL-C to copy the window text.

I would like to allow users to do the same thing with the message dialogs I am using in my GTK app.

Is there a way to allow a GTK MessageDialog class to handle the copy command?

Was it helpful?

Solution

What I ended up doing was to add a message handler to the dialog to trap the Keyboard up command.

When that was triggered I checked for the CTRL-C combo and put the text onto the clipboard there.

OTHER TIPS

There's a simpler way to do it. Call _set_lables_selectable() with the dialog, after gtk_message_dialog_new()

static void _set_label_selectable(gpointer data, gpointer user_data)
{
    GtkWidget *widget = GTK_WIDGET(data);

    if (GTK_IS_LABEL(widget))
    {
        gtk_label_set_selectable(GTK_LABEL(widget), TRUE);
    }
}

static void _set_lables_selectable(GtkWidget *dialog)
{
    GtkWidget *area = gtk_message_dialog_get_message_area(
        GTK_MESSAGE_DIALOG(dialog));
    GtkContainer *box = (GtkContainer *) area;

    GList *children = gtk_container_get_children(box);
    g_list_foreach(children, _set_label_selectable, NULL);
    g_list_free(children);
}

example

GtkWidget *dialog =  gtk_message_dialog_new(opgU_window,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_YES_NO,
"%s", mbuf);

_set_lables_selectable(dialog);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top