Re: display a file from file selection dialog

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

 



Niow Kim Chwee ha scritto lo scorso 22/10/2004 3.35:
hello,

  thanks for replying.

  i still have a problem.. how do i select a file from file selection dialog, and display it in the textview widget i created inside a window using glade?

  my current approach is to scan the file string using gtk_file_selection_get_file, but i get stuck here.. what should i do next?

  thanks in advance

regards


You can try this:

  if (gtk_dialog_run (GTK_DIALOG (dlg)) == GTK_RESPONSE_ACCEPT) {
    /* gets file path and name as a (gchar *)
     */
    gFile_in = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dlg));
    /* opens a GIOChannel for input
     */
    input    = g_io_channel_new_file (gFile_in, "r", NULL);
    /* gets file content in a buffer of type (gchar *)
     */
    g_io_channel_read_to_end (input, & buffer, NULL, NULL);
    /* closes the GIOChannel
     */
    g_io_channel_shutdown (input, FALSE, NULL);
    g_io_channel_unref (input);

    /* gets a pointer to the text buffer associated
     * with an existing textview
     */
    text_buf  = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
    /* puts the buffer into the text buffer
     */
    gtk_text_buffer_set_text (text_buf, buffer, -1);

    /* deallocates memory
     */
    g_free (buffer);
  }
  gtk_widget_destroy (dlg);

HTH

Carlo

_______________________________________________

gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux