On 08/23/2012 02:45 PM, Rudra Banerjee wrote: > > Dear friends, > I am openning an existing file in textview from command line as: > > textview = gtk_text_view_new(); > gtk_container_add(GTK_CONTAINER(scrolledwindow), textview); > textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); > if (argc > 1 && argv[1] != NULL) { > char *flnm = argv[1]; > read_view(flnm); > } > > > where the read_view is defined as: > > static void read_view(char *inpfn) { > char *buffer; > stat(inpfn, &filestat); > textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); > buffer = (char *) malloc(filestat.st_size * sizeof (char)); > efile = fopen(inpfn, "r"); > fread(buffer, filestat.st_size, 1, efile); > gtk_text_buffer_set_text(textbuffer, buffer, filestat.st_size); > free(buffer); > } > > > I am writing in the file that is opened as: > > FILE *fop = fopen(filename, "a" ); > g_fprintf( fop, "@%s{%s,\n", strcombo, strkey ); > > where the fileopen is difined globally. > > whenever I am writing, it is saved, but to see the change, I have to > reopen the file(obviously).
instead of appending text to the file, you better append the text to the GtkTextBuffer, and then save the GtkTextBuffer to a file once in a while. if you need to append to the file (and not write the complete file once in a while) I would try to append both to the file and to the textbuffer, so you don't need to reload the entire file for every append. Olivier _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list