Old stuff, Bookmarks

From Bluefish Wiki
Jump to: navigation, search

Bookmarks

bookmarks will be loaded and saved to an arraylist (see stringlist.c). This is a double linked list (GList *) with pointers to string arrays (gchar **).

To have the GUI work with them, we convert those arrays (gchar **) into a Tbmark struct. This struct will ahve a pointer to the array (gchar **) so on change it can directly change the array as well, without any need to look it up in the list.

For the GUI, we store everything in a Gtktreestore. The treestore will have a pointer to a string with the name, and it will also have a pointer to the Tbmark. When the user clicks in the Gtktreeview widget, we can get immediately a pointer to the Tbmark, and that has the Gtktextmark, so that is very easy, and very fast!

But now we have one problem: all normal windows do share the same bookmarks list. So it is probably the most logical to have them store the same Gtktreestore as well. But how do we switch to a project then?? The best way I guess is to have the project functions create/destroy the gtktreestore when they convert a window (Tbfwin) into a project window.

any other things?

Code bits

the global gtktreestore

   main_v->bookmarkstore

the treestore for a project

   Tproject project->bookmarkstore

every Tbfwin (this is a pointer to the global, or to the project treestore

   Tbfwin bfwin->bookmarkstore

The code does not need to know if the window is from a project or not, we simply use bfwin->bookmarkstore and bfwin->session->bmarks and we don't care if they are pointers to the global list or to a session list

The (Tdocument *) also will get an Gtktreeiter to the tree, this is the parent for all bookmarks for that file. This will also give us easy access when we close a document. We simply check if there is a ?GtkTreeIter (if not there are no bookmarks), and if so, we will get all Gtktreeiter children, and those children contain the Tbmark structs!!!

Global (non static) functions needed in bookmarks.c

/* this function will load the bookmarks
 * from bfwin->session->bmarks and parse
 * them into treestore bfwin->bookmarkstore
 *
 * this function should ALSO check all dcouments that are
 * opened (bfwin->documentlist) if they have bookmarks !!
 */
void bmark_reload(Tbfwin *bfwin);

/*
 * this function will simply call
 * gtk_tree_view_set_model() to connect the treeview
 * to the new treestore, used in unloading and
 * loading of projects
 */
void bmark_set_store(Tbfwin *bfwin);

/*
 * this function should create the global
 * main_v->bookmarkstore
 */
void bmark_init();

/*
 * this function will check is this document needs any bookmarks, and set the
 * doc->bmark_parent if needed
 */
void bmark_set_for_doc(Tdocument *doc);

/*
 * This function should convert all GtkTextMarks into
 * character offsets, and free doc->bmark_parent
 */
void bmark_clean_for_doc(Tdocument *doc);