add persistence for collapsed / expanded folder trees
authorAlfons Hoogervorst <alfons@proteus.demon.nl>
Tue, 10 Jul 2001 16:14:23 +0000 (16:14 +0000)
committerAlfons Hoogervorst <alfons@proteus.demon.nl>
Tue, 10 Jul 2001 16:14:23 +0000 (16:14 +0000)
ChangeLog.claws
src/folder.c
src/folder.h
src/folderview.c

index 742f0da73cabb68255c73621a30792263deb8302..980e6973cc14b9def8a07e2b3f49bbe78c72e38a 100644 (file)
@@ -1,3 +1,11 @@
+2001-07-10 [alfons]
+
+       * folder.[ch]
+         folderview.c
+               make collapse state of folders and folder items persistent, i.e.
+               if you collapse a folder tree, the next time sylpheed-claws starts 
+               up the folder tree remains collapsed.  
+               
 2001-07-10 [christoph]
 
        * acconfig.h
@@ -33,7 +41,7 @@
 
        * src/prefs_common.[ch]
          src/compose.c
-               add experimental option "smart wrapping" which make the
+               add experimental option "smart wrapping" which makes the
                compose editor auto wrap.
                
                | TODO: the problem with the buggy cursor handling is caused |
index b1934073b92a9e4eebd8ac9859c38100a312ad55..ae93c2ff3e46f53ce4b6f4d50008e0ad7e1a6171 100644 (file)
@@ -153,6 +153,7 @@ FolderItem *folder_item_new(const gchar *name, const gchar *path)
        item->last_num = -1;
        item->no_sub = FALSE;
        item->no_select = FALSE;
+       item->collapsed = FALSE; /* default is open */
        item->parent = NULL;
        item->folder = NULL;
        item->data = NULL;
@@ -1050,7 +1051,7 @@ static gboolean folder_build_tree(GNode *node, gpointer data)
        const gchar *name = NULL;
        const gchar *path = NULL;
        PrefsAccount *account = NULL;
-       gboolean no_sub = FALSE, no_select = FALSE;
+       gboolean no_sub = FALSE, no_select = FALSE, collapsed = FALSE;
        gint mtime = 0, new = 0, unread = 0, total = 0;
 
        g_return_val_if_fail(node->data != NULL, FALSE);
@@ -1100,6 +1101,8 @@ static gboolean folder_build_tree(GNode *node, gpointer data)
                        no_sub = *attr->value == '1' ? TRUE : FALSE;
                else if (!strcmp(attr->name, "no_select"))
                        no_select = *attr->value == '1' ? TRUE : FALSE;
+               else if (!strcmp(attr->name, "collapsed"))
+                       collapsed = *attr->value == '1' ? TRUE : FALSE;
        }
 
        item = folder_item_new(name, path);
@@ -1111,6 +1114,7 @@ static gboolean folder_build_tree(GNode *node, gpointer data)
        item->total = total;
        item->no_sub = no_sub;
        item->no_select = no_select;
+       item->collapsed = collapsed;
        item->parent = FOLDER_ITEM(node->parent->data);
        item->folder = folder;
        switch (stype) {
@@ -1140,6 +1144,7 @@ static gboolean folder_read_folder_func(GNode *node, gpointer data)
        const gchar *name = NULL;
        const gchar *path = NULL;
        PrefsAccount *account = NULL;
+       gboolean collapsed = FALSE;
 
        if (g_node_depth(node) != 2) return FALSE;
        g_return_val_if_fail(node->data != NULL, FALSE);
@@ -1175,6 +1180,9 @@ static gboolean folder_read_folder_func(GNode *node, gpointer data)
                        if (!account) g_warning("account_id: %s not found\n",
                                                attr->value);
                }
+               else if (!strcmp(attr->name, "collapsed")) {
+                       collapsed = *(attr->value) == '1' ? 1 : 0;
+               }
        }
 
        folder = folder_new(type, name, path);
@@ -1182,14 +1190,23 @@ static gboolean folder_read_folder_func(GNode *node, gpointer data)
        folder->account = account;
        if (account && (type == F_IMAP || type == F_NEWS))
                account->folder = REMOTE_FOLDER(folder);
+               
        node->data = folder->node->data;
        g_node_destroy(folder->node);
        folder->node = node;
+
        folder_add(folder);
 
        g_node_traverse(node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
                        folder_build_tree, folder);
 
+       /* ALFONS_NOTE: after a folder_new() the folder system also created a 
+        * FolderItem for the folder (which makes insertion in the GtkCTree
+        * easier because it deals with FolderItems only). put the collapsed
+        * state for this Folder in its associated FolderItem */
+
+       FOLDER_ITEM((folder->node->data))->collapsed = collapsed; 
+
        return FALSE;
 }
 
@@ -1237,6 +1254,13 @@ static void folder_write_list_recursive(GNode *node, gpointer data)
                if (folder->account)
                        fprintf(fp, " account_id=\"%d\"",
                                folder->account->account_id);
+                               
+               /* ALFONS_NOTE: for each Folder structure, also a FolderItem is created;
+                * this is very clever, but undocumented. (it is clever because the
+                * folderview's GtkCTree only deals with FolderItems.) */
+               if (item->collapsed )
+                       fprintf(fp, " collapsed=\"1\"");
+               
        } else {
                fprintf(fp, "<folderitem type=\"%s\"",
                        folder_item_stype_str[item->stype]);
@@ -1257,6 +1281,8 @@ static void folder_write_list_recursive(GNode *node, gpointer data)
                        fputs(" no_sub=\"1\"", fp);
                if (item->no_select)
                        fputs(" no_select=\"1\"", fp);
+               if (item->collapsed) 
+                       fputs(" collapsed=\"1\"", fp);
                fprintf(fp,
                        " mtime=\"%ld\" new=\"%d\" unread=\"%d\" total=\"%d\"",
                        item->mtime, item->new, item->unread, item->total);
index 306d33ed5da184d9a2afdd5fafb5ac49f68e656e..deb19dee9e75040a58538444aea2f6a264fd1bba 100644 (file)
@@ -211,8 +211,10 @@ struct _FolderItem
 
        gint last_num;
 
-       gboolean no_sub;
-       gboolean no_select;
+       /* special flags */
+       guint no_sub    : 1; /* no childs allowed? */   
+       guint no_select : 1; /* not selectable?    */
+       guint collapsed : 1; /* collapsed item     */
 
        FolderItem *parent;
 
index d1b738ca45b74f573bf54308dfd026dfcc745474..7ad83cbf136bf14b8f270f3270ca5b4e125f7584 100644 (file)
@@ -976,8 +976,23 @@ static gboolean folderview_gnode_func(GtkCTree *ctree, guint depth,
 static void folderview_expand_func(GtkCTree *ctree, GtkCTreeNode *node,
                                   gpointer data)
 {
-       if (GTK_CTREE_ROW(node)->children)
-               gtk_ctree_expand(ctree, node);
+       /* NOTE: data should by FolderView pointer */
+       if (GTK_CTREE_ROW(node)->children) {
+               FolderItem *item = gtk_ctree_node_get_row_data(ctree, node);
+               FolderView *view = (FolderView *) data;
+               g_return_if_fail(item != NULL);
+               g_return_if_fail(view);
+               
+               if (!item->collapsed) {
+                       gtk_ctree_expand(ctree, node);
+               }
+               else {
+                       /* if it is collapsed we should update the node,
+                        * in case one of the children contains unread
+                        * messages or other visible state things */
+                       folderview_update_node(view, node);                      
+               }
+       }               
 }
 
 #define SET_SPECIAL_FOLDER(ctree, item) \
@@ -1358,12 +1373,20 @@ static void folderview_selected(GtkCTree *ctree, GtkCTreeNode *row,
 static void folderview_tree_expanded(GtkCTree *ctree, GtkCTreeNode *node,
                                     FolderView *folderview)
 {
+       FolderItem *item = gtk_ctree_node_get_row_data(ctree, node);
+
+       g_return_if_fail(item);
+       item->collapsed = FALSE;
        folderview_update_node(folderview, node);
 }
 
 static void folderview_tree_collapsed(GtkCTree *ctree, GtkCTreeNode *node,
                                      FolderView *folderview)
 {
+       FolderItem *item = gtk_ctree_node_get_row_data(ctree, node);
+
+       g_return_if_fail(item);
+       item->collapsed = TRUE;
        folderview_update_node(folderview, node);
 }