Changeset 5343:ba0d96408425

Show
Ignore:
Timestamp:
2008-01-15 01:49:41 (8 months ago)
Author:
Rocco Rutte <pdmef@…>
Branch:
HEAD
Message:

Make formatting of query menu configurable via $query_format (closes #170).

Files:
4 modified

Legend:

Unmodified
Added
Removed
  • UPDATING

    r5324 r5343  
    55  !: modified feature, -: deleted feature, +: new feature 
    66 
     7  + $query_format (customize external query menu) 
    78  ! inode sorting is always enabled 
    89  + $time_inc suppresses progress updates less than $time_inc 
  • globals.h

    r5293 r5343  
    112112WHERE char *PrintCmd; 
    113113WHERE char *QueryCmd; 
     114WHERE char *QueryFormat; 
    114115WHERE char *Realname; 
    115116WHERE char *SendCharset; 
  • init.h

    r5342 r5343  
    22702270  ** with the query string the user types.  See ``$query'' for more 
    22712271  ** information. 
     2272  */ 
     2273  { "query_format",     DT_STR, R_NONE, UL &QueryFormat, UL "%4c %t %-25.25a %-25.25n %?e?(%e)?" }, 
     2274  /* 
     2275  ** .pp 
     2276  ** This variable describes the format of the `query' menu. The 
     2277  ** following printf-style sequences are understood: 
     2278  ** .pp 
     2279  ** .dl 
     2280  ** .dt %a  .dd destination address 
     2281  ** .dt %c  .dd current entry number 
     2282  ** .dt %e  .dd extra information * 
     2283  ** .dt %n  .dd destination name 
     2284  ** .dt %t  .dd ``*'' if current entry is tagged, a space otherwise 
     2285  ** .dt %>X .dd right justify the rest of the string and pad with "X" 
     2286  ** .dt %|X .dd pad to the end of the line with "X" 
     2287  ** .dt %*X .dd soft-fill with character "X" as pad 
     2288  ** .de 
     2289  ** .pp 
     2290  ** For an explanation of `soft-fill', see the ``$$index_format'' documentation. 
     2291  ** .pp 
     2292  ** * = can be optionally printed if nonzero, see the ``$$status_format'' documentation. 
    22722293  */ 
    22732294  { "quit",             DT_QUAD, R_NONE, OPT_QUIT, M_YES }, 
  • query.c

    r5184 r5343  
    3333typedef struct query 
    3434{ 
     35  int num; 
    3536  ADDRESS *addr; 
    3637  char *name; 
     
    181182} 
    182183 
    183 /* This is the callback routine from mutt_menuLoop() which is used to generate 
    184  * a menu entry for the requested item number. 
    185  */ 
    186 #define QUERY_MIN_COLUMN_LENGHT 20 /* Must be < 70/2 */ 
     184static const char * query_format_str (char *dest, size_t destlen, size_t col, 
     185                                      char op, const char *src, 
     186                                      const char *fmt, const char *ifstring, 
     187                                      const char *elsestring, 
     188                                      unsigned long data, format_flag flags) 
     189{ 
     190  ENTRY *entry = (ENTRY *)data; 
     191  QUERY *query = entry->data; 
     192  char tmp[SHORT_STRING]; 
     193  char buf2[STRING] = ""; 
     194  int optional = (flags & M_FORMAT_OPTIONAL); 
     195 
     196  switch (op) 
     197  { 
     198  case 'a': 
     199    rfc822_write_address (buf2, sizeof (buf2), query->addr, 1); 
     200    snprintf (tmp, sizeof (tmp), "%%%ss", fmt); 
     201    snprintf (dest, destlen, tmp, buf2); 
     202    break; 
     203  case 'c': 
     204    snprintf (tmp, sizeof (tmp), "%%%sd", fmt); 
     205    snprintf (dest, destlen, tmp, query->num); 
     206    break; 
     207  case 'e': 
     208    if (!optional) 
     209    { 
     210      snprintf (tmp, sizeof (tmp), "%%%ss", fmt); 
     211      snprintf (dest, destlen, tmp, NONULL (query->other)); 
     212    } 
     213    else if (!query->other || !*query->other) 
     214      optional = 0; 
     215    break; 
     216  case 'n': 
     217    snprintf (tmp, sizeof (tmp), "%%%ss", fmt); 
     218    snprintf (dest, destlen, tmp, NONULL (query->name)); 
     219    break; 
     220  case 't': 
     221    snprintf (tmp, sizeof (tmp), "%%%sc", fmt); 
     222    snprintf (dest, destlen, tmp, entry->tagged ? '*' : ' '); 
     223    break; 
     224  default: 
     225    snprintf (tmp, sizeof (tmp), "%%%sc", fmt); 
     226    snprintf (dest, destlen, tmp, op); 
     227    break; 
     228  } 
     229 
     230  if (optional) 
     231    mutt_FormatString (dest, destlen, col, ifstring, query_format_str, data, 0); 
     232  else if (flags & M_FORMAT_OPTIONAL) 
     233    mutt_FormatString (dest, destlen, col, elsestring, query_format_str, data, 0); 
     234 
     235  return src; 
     236} 
     237 
    187238static void query_entry (char *s, size_t slen, MUTTMENU *m, int num) 
    188239{ 
    189   ENTRY *table = (ENTRY *) m->data; 
    190   char buf2[SHORT_STRING], buf[SHORT_STRING] = ""; 
    191  
    192   /* need a query format ... hard coded constants are not good */ 
    193   while (FirstColumn + SecondColumn > 70) 
    194   { 
    195     FirstColumn = FirstColumn * 3 / 4; 
    196     SecondColumn = SecondColumn * 3 / 4; 
    197     if (FirstColumn < QUERY_MIN_COLUMN_LENGHT) 
    198       FirstColumn = QUERY_MIN_COLUMN_LENGHT; 
    199     if (SecondColumn < QUERY_MIN_COLUMN_LENGHT) 
    200       SecondColumn = QUERY_MIN_COLUMN_LENGHT; 
    201   } 
    202  
    203   rfc822_write_address (buf, sizeof (buf), table[num].data->addr, 1); 
    204  
    205   mutt_format_string (buf2, sizeof (buf2), 
    206                       FirstColumn + 2, FirstColumn + 2, 
    207                       FMT_LEFT, ' ', table[num].data->name, 
    208                       mutt_strlen (table[num].data->name), 0); 
    209  
    210   snprintf (s, slen, " %c %3d %s %-*.*s %s",  
    211             table[num].tagged ? '*':' ', 
    212             num+1, 
    213             buf2, 
    214             SecondColumn+2, 
    215             SecondColumn+2, 
    216             buf, 
    217             NONULL (table[num].data->other)); 
     240  ENTRY *entry = &((ENTRY *) m->data)[num]; 
     241 
     242  entry->data->num = num; 
     243  mutt_FormatString (s, slen, 0, NONULL (QueryFormat), query_format_str, 
     244                     (unsigned long) entry, M_FORMAT_ARROWCURSOR); 
    218245} 
    219246