GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Nov 25, 2014 1:52 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Textview/Buffer Problem...AHHH!
PostPosted: Mon Mar 03, 2008 2:03 am 
Offline
Familiar Face

Joined: Mon Feb 11, 2008 12:28 pm
Posts: 15
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:
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 :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 03, 2008 2:21 am 
Offline

Joined: Mon Mar 03, 2008 2:07 am
Posts: 2
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=]
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);
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 03, 2008 2:34 am 
Offline
Familiar Face

Joined: Mon Feb 11, 2008 12:28 pm
Posts: 15
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 :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group