GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Mon Sep 01, 2014 7:36 am

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Edit entry in file from treeview entry
PostPosted: Tue Oct 16, 2012 2:21 pm 
Offline
GTK+ Guru

Joined: Sun Jul 08, 2012 3:14 pm
Posts: 107
Location: Coventry, UK
This is actually a repost, as previous post did not got any attention.
Dear friends,
I have another query.
As the treeview is loaded from a file, in my program, new entries can also be entered. It writes to the Treeview, as well as in a file using:

Code:
strAuth = gtk_entry_get_text(GTK_ENTRY(e->entryAuth));

/*Entering the data in Treeview */
  gtk_list_store_append(store, &siter);
  gtk_list_store_set(store, &siter,
                      COL_BIB_KEY, strkey,
                      COL_BIB_TYPE, strcombo,
                      COL_BIB_NAME, strAuth,
                      COL_BIB_YEAR, strYear,
                      COL_BIB_PUB, strTitle,
                      -1);
/*Entering the data in file */
if( strlen(strEditor)!=0)
    g_fprintf( fop, "\tEditor=\"%s\",\n", strAuth);
...etc...


Now, my question is, can this two entry be linked such that if I delete an entry from treeview, it will also delete the entry from file(fop). Or for doing this, I have to regex the complete file(fop)?
I can change the writing to file using hash table as well, but can I link the treeview entry with the entry in table?
Please reply.


Top
 Profile  
 
 Post subject: Re: Edit entry in file from treeview entry
PostPosted: Tue Oct 16, 2012 3:21 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hi.

Usually you don't associate changes in GUI directly to changes in file. You load your file into your internal data structure, then modify/update it as you see fit and store changes back to file (usually overwriting the old one).

You can achieve what you want by using memory mapped files, but in your case, this is really not needed, since storing bibliography can be safely done at the end of editing or at regular intervals.

Cheers,
Tadej


Top
 Profile  
 
 Post subject: Re: Edit entry in file from treeview entry
PostPosted: Tue Oct 16, 2012 4:19 pm 
Offline
GTK+ Guru

Joined: Sun Jul 08, 2012 3:14 pm
Posts: 107
Location: Coventry, UK
Ok,
I am obeying your advice.


Top
 Profile  
 
 Post subject: Re: Edit entry in file from treeview entry
PostPosted: Tue Oct 16, 2012 10:36 pm 
Offline
GTK+ Guru

Joined: Sun Jul 08, 2012 3:14 pm
Posts: 107
Location: Coventry, UK
oops, I read you wrong!
As you rightly said, storing bibliography can be done at regular interval, that means to me, I should not write to file at each step, for each entry created, right?


Top
 Profile  
 
 Post subject: Re: Edit entry in file from treeview entry
PostPosted: Thu Oct 18, 2012 12:43 am 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
right. Have a look at the source code for some text editing programs to get an example.
If you save at each step then a user can easily destroy his/her work quite easily.
If you want to do a real thorough job you might want to save each edit as a diff in temporary memory. At regular intervals autosave by merging the diffs to create a temporary file. This allows the user to be able to undo/redo actions as well as having both the original and a backup in the event of something going wrong with the system.


Top
 Profile  
 
 Post subject: Re: Edit entry in file from treeview entry
PostPosted: Thu Oct 18, 2012 1:03 pm 
Offline
GTK+ Guru

Joined: Sun Jul 08, 2012 3:14 pm
Posts: 107
Location: Coventry, UK
Paul,
I checked, probably I have to deal with gtksourceview, isn't it?

Also, as par tadej's advice, I am trying to open the file using mapped file, but i think examples on this is very little.
Can anybody kindly direct me where i can find some working example?


Top
 Profile  
 
 Post subject: Re: Edit entry in file from treeview entry
PostPosted: Thu Oct 18, 2012 10:06 pm 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
GtkSourceView is a good option. You don't have to though. You could write your code entirely yourself; building up on what you have already done. Or there's also a middle ground as GtkSourceView is under LGPL2 you can fork it and trim it down to what you need. The fact, however, that GtkSourceView is in most repositories makes it an attractive option.
Re: mapped files, I haven't any experience with them but if its working examples your after the usual process I do is do a search on the command; ignore all the glib/gtk documentation sites (you'll then find either bug reports or diffs); search for where the source code of the project associated with a particular diff/bug report is. Keep in mind with working examples that though they may be working it doesn't mean they work well (particularly in terms of memory leaks).


Top
 Profile  
 
 Post subject: Re: Edit entry in file from treeview entry
PostPosted: Sun Oct 21, 2012 10:00 pm 
Offline
GTK+ Guru

Joined: Sun Jul 08, 2012 3:14 pm
Posts: 107
Location: Coventry, UK
I tried to find out how g_mapped_file works and failed.
If someone has used it, can he guide me a bit?


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 3 guests


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