开发者

Copying the text from a GTK MessageDialog

开发者 https://www.devze.com 2023-01-07 08:46 出处:网络
With a windows error dialog I can use CTRL-C to copy the window text. I开发者_JAVA技巧 would like to allow users to do the same thing with the message dialogs I am using in my GTK app.

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

I开发者_JAVA技巧 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?


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);


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号