0

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?

chollida
  • 7,834
  • 11
  • 55
  • 85
  • Can you given more details of the runtime environment? A Gtk Message dialog is similar to any window. Hence there should not be any problem in copying the text. – Praveen S Jul 15 '10 at 04:16
  • @Praveen, can you provide any insight into what this "similar to any window" means? How does any window handle this? I ended up having to trap the keyboard up signal. – chollida Jul 16 '10 at 02:51
  • You can select and copy the text of a `GtkMessageDialog` by default, although you _can_ turn it off. That this is not working for you seems to indicate that something else is wrong. You should not have to use the keyboard signal to do this. What platform are you on? How are you displaying the message dialog? – ptomato Jul 16 '10 at 09:42

2 Answers2

1

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

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.

chollida
  • 7,834
  • 11
  • 55
  • 85