GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Textview/Buffer Problem...AHHH!

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
angel face
Familiar Face


Joined: 11 Feb 2008
Posts: 15

PostPosted: Mon Mar 03, 2008 2:03 am    Post subject: Textview/Buffer Problem...AHHH! Reply with quote

Hey guys.

I have a problem which is really bugging me! its one of those small annoying things i cant seem to get working!!! grrrrrr!!!

anyway, here it goes....

i have a textview and associated text buffer.
bacially i want to save what is in the textview to a file, which i have working.
now i am adding some error handeling which is....

if there is nothing in the textview (i.e its empty) then generate a message
to the users telling them there is nothing to save.

okay...here is a snipet of my code....


Code: (Plaintext)
1
2
3
4
5
6

if (widget->buffer2 != NULL) 
     infile = fopen("/Desktop/file.txt", "a+");
else
    gtk_text_buffer_set_text (widget->buffer3, "No text to save", -1);   



please somebody put me out of my misery!!!!

thanks a mill :)
Back to top
JBullard



Joined: 03 Mar 2008
Posts: 2

PostPosted: Mon Mar 03, 2008 2:21 am    Post subject: Reply with quote

This may help. Its a snippet from a project I'm working on.
I use the sprintf function to write something to a string called errmessage.
Then insert the string into the GtkTextBuffer.
Then set the buffer into the text view.
It works for me.

Code: (Plaintext)
1
2
3
4
5
6
7
8

gchar errmessage[100];
GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (user_data));
       
sprintf(errmessage,"\nThe file %s was not written.\n",filename);
gtk_text_buffer_insert_at_cursor (buffer, errmessage, -1);
gtk_text_view_set_buffer (GTK_TEXT_VIEW (user_data),buffer);
Back to top
angel face
Familiar Face


Joined: 11 Feb 2008
Posts: 15

PostPosted: Mon Mar 03, 2008 2:34 am    Post subject: Reply with quote

Hey guys.

Its okay, i figured something out.
I just used the get_char_count() function to count how many chars are
in the textview and then said that if count is greater that zero (i.e if there is text in the textview) then save to the file otherwise generate the error.

i cant believe i didnt think of something so simple sooner.

Im pretty new to GTK, Im self learning for a project, so any feedback on why the other way didnt work would be much appreciated :)

Thanks :)
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP