[Anjuta-list] Lookup and Textview problem



Before i can go deep into my project I have to resolve some basic problems: the first was grasp how to to use of the glib library in Anjuta. Thank to Johannes Schmid I'm able to resolve it.
Now i would like to open a source file and display in a GtkTextView widget.
To achieve this goal I open glade, set an open file menu item, a GtkTextView widget and a GtkFileChooser widget. I am able also to modify the automaticaly generated method named on_open1_activate in callbacks.c to display the file chooser.

Here is the code.

void
on_open1_activate         (GtkMenuItem     *menuitem,
                                       gpointer         user_data)
{
   GtkWidget *file_selector;
file_selector = create_filechooseropendialog();
   if (gtk_dialog_run (GTK_DIALOG (file_selector)) == GTK_RESPONSE_ACCEPT)
   {
        char *filename;
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (file_selector));
       open_file (menuitem,filename,user_data);
       g_free (filename);
   }
   gtk_widget_destroy (file_selector);
}


Now what I'm not able to do is to associate the text in the selected filename to the GtkTextView widget (named TextView1). To simplify the goal a write an open_file method in callbacks.c that simply try to insert some text in the widget. I see that in support.c there is a LookUp method to get a particulay widget, and the i try to write the method so:

void open_file                 (GtkMenuItem     *menuitem,
                                       char             *filename,
gpointer user_data) {
   GtkWidget *main_window, *textview;
   GtkTextBuffer *buffer;
main_window = lookup_widget (GTK_WIDGET (menuitem), "window1");
    textview = lookup_widget (main_window, "textview1");
    buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));
    gtk_text_buffer_set_text (buffer, "Hello, this is some text", -1);
}

It compile fine, but when I open a file obtained by clicking the open file menu item and then selecting it from the dialog, the TextView widget remain the same.

Any tip?

Thank you in advance for any advice.

ciao, Michele




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]