Andreas Krennmair:
authorak1 <ak1@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Tue, 22 Feb 2005 20:27:39 +0000 (20:27 +0000)
committerak1 <ak1@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Tue, 22 Feb 2005 20:27:39 +0000 (20:27 +0000)
added "shorten hierarchy" option.

git-svn-id: svn://svn.berlios.de/mutt-ng/trunk@74 e385b8ad-14ed-0310-8656-cc95a2468c6d

ChangeLog.mutt-ng
init.h
mutt.h
sidebar.c

index a97e69b..c3c4800 100644 (file)
@@ -3,6 +3,7 @@ Changes specific to mutt-ng:
 2005-02-22:
   * Merged mutt changes
   * Sidebar now honors the imap_home_namespace
 2005-02-22:
   * Merged mutt changes
   * Sidebar now honors the imap_home_namespace
+  * Added "shorten hierarchy" option
 
 2005-02-21:
   * Merged past mutt changes
 
 2005-02-21:
   * Merged past mutt changes
diff --git a/init.h b/init.h
index fa7a047..c9be17e 100644 (file)
--- a/init.h
+++ b/init.h
@@ -2667,6 +2667,12 @@ struct option_t MuttVars[] = {
   ** When \fIset\fP, info about unsubscribed newsgroups will be saved into
   ** ``newsrc'' file and into cache.
   */
   ** When \fIset\fP, info about unsubscribed newsgroups will be saved into
   ** ``newsrc'' file and into cache.
   */
+  { "shorten_hierarchy", DT_BOOL, R_NONE, OPTSHORTENHIERARCHY, 0 },
+  /*
+  ** .pp
+  ** When \fIset\fP, the "hierarchy" of the sidebar entries will be shortened,
+  ** e.g. de.alt.sysadmin.recovery becomes d.a.s.recovery.
+  */
   { "show_new_news",  DT_BOOL, R_NONE, OPTSHOWNEWNEWS, 1 },
   /*
   ** .pp
   { "show_new_news",  DT_BOOL, R_NONE, OPTSHOWNEWNEWS, 1 },
   /*
   ** .pp
diff --git a/mutt.h b/mutt.h
index c320c8a..bdf9110 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -558,6 +558,7 @@ enum
   OPTNEWSSEND,         /* (pseudo) used to change behavior when posting */
   OPTNEWSCACHE,                /* (pseudo) used to indicate if news cache exist */
 #endif
   OPTNEWSSEND,         /* (pseudo) used to change behavior when posting */
   OPTNEWSCACHE,                /* (pseudo) used to indicate if news cache exist */
 #endif
+  OPTSHORTENHIERARCHY, /* set when to shorten "hierarchies" in the sidebar */
 
   OPTMAX
 };
 
   OPTMAX
 };
index 49555d5..e1bec5d 100644 (file)
--- a/sidebar.c
+++ b/sidebar.c
@@ -77,6 +77,36 @@ void calc_boundaries (int menu)
        }
 }
 
        }
 }
 
+static char * shortened_hierarchy(char * box) {
+  int dots = 0;
+  char * last_dot;
+  int i,j;
+  char * new_box;
+  for (i=0;i<strlen(box);++i)
+    if (box[i] == '.') ++dots;
+  last_dot = strrchr(box,'.');
+  if (last_dot) {
+    ++last_dot;
+    new_box = safe_malloc(strlen(last_dot)+2*dots+1);
+    new_box[0] = box[0];
+    for (i=1,j=1;i<strlen(box);++i) {
+      if (box[i] == '.') {
+        new_box[j++] = '.';
+        new_box[j] = 0;
+        if (&box[i+1] != last_dot) {
+          new_box[j++] = box[i+1];
+          new_box[j] = 0;
+        } else {
+          strcat(&new_box[j],last_dot);
+          break;
+        }
+      }
+    }
+    return new_box;
+  }
+  return safe_strdup(box);
+}
+
 char *make_sidebar_entry(char *box, int size, int new)
 {
        static char *entry = 0;
 char *make_sidebar_entry(char *box, int size, int new)
 {
        static char *entry = 0;
@@ -94,6 +124,9 @@ char *make_sidebar_entry(char *box, int size, int new)
     }
   }
 #endif
     }
   }
 #endif
+  if (option(OPTSHORTENHIERARCHY)) {
+    box = shortened_hierarchy(box);
+  }
        i = strlen(box);
        strncpy( entry, box, i < SidebarWidth ? i :SidebarWidth );
 
        i = strlen(box);
        strncpy( entry, box, i < SidebarWidth ? i :SidebarWidth );
 
@@ -103,6 +136,9 @@ char *make_sidebar_entry(char *box, int size, int new)
                        "% d(%d)", size, new);
        else
                sprintf( entry + SidebarWidth - 3 - quick_log10(size), "% d", size);
                        "% d(%d)", size, new);
        else
                sprintf( entry + SidebarWidth - 3 - quick_log10(size), "% d", size);
+  if (option(OPTSHORTENHIERARCHY)) {
+    free(box);
+  }
        return entry;
 }
 
        return entry;
 }