]> mj.ucw.cz Git - checkmail.git/commitdiff
Mailboxes can be assigned hotkeys.
authorMartin Mares <mj@ucw.cz>
Mon, 25 Jun 2007 19:51:59 +0000 (21:51 +0200)
committerMartin Mares <mj@ucw.cz>
Mon, 25 Jun 2007 19:51:59 +0000 (21:51 +0200)
cm.c

diff --git a/cm.c b/cm.c
index a3bba1853305c46e21b595475157a6ec37ff5b0a..0b7fbf17072e0dc04acae97df4dd53e25245e226 100644 (file)
--- a/cm.c
+++ b/cm.c
@@ -39,6 +39,7 @@ struct options {
   int show_flagged;
   int sender_personal;
   int sender_mbox;
+  int hotkey;
 };
 
 struct option_node {
@@ -121,6 +122,7 @@ init_options(struct options *o)
   o->show_flagged = -1;
   o->sender_personal = -1;
   o->sender_mbox = -1;
+  o->hotkey = -1;
 }
 
 static void
@@ -141,6 +143,7 @@ setup_options(struct mbox *b)
        MERGE(show_flagged);
        MERGE(sender_personal);
        MERGE(sender_mbox);
+       MERGE(hotkey);
       }
 }
 
@@ -549,7 +552,9 @@ redraw_line(int i)
       int hi = b->o.highlight;
 
       attrset(attrs[cc][hi][M_IDLE]);
-      if (cc)
+      if (b->o.hotkey)
+       printw("%c ", b->o.hotkey);
+      else if (cc)
        printw("> ");
       else
        printw("  ");
@@ -781,6 +786,20 @@ next_active(int since, int step)
     move_cursor(besti);
 }
 
+static void
+mbox_run(struct mbox *b)
+{
+  char cmd[strlen(run_cmd) + strlen(b->path) + 16];
+  sprintf(cmd, run_cmd, b->path);
+  term_cleanup();
+  system(cmd);
+  term_init();
+  redraw_all();
+  refresh();
+  b->force_refresh = 1;
+  scan_and_redraw();
+}
+
 #define STR2(c) #c
 #define STR(c) STR2(c)
 
@@ -808,6 +827,7 @@ m\t\t\tShow mailbox name of the sender\n\
 p\t\t\tShow personal info (full name) of the sender\n\
 s\t\t\tShow message snippets\n\
 t\t\t\tHighlight the entry\n\
+!<key>\t\t\tSet hot key\n\
 \n\
 CheckMail " STR(VERSION) ", (c) " STR(YEAR) " Martin Mares <mj@ucw.cz>\n\
 It can be freely distributed and used according to the GNU GPL v2.\n\
@@ -837,6 +857,8 @@ parse_options(char *c)
   while (x = *c++)
     if (x >= '0' && x <= '9')
       o->priority = x - '0';
+    else if (x == '!' && *c)
+      o->hotkey = *c++;
     else
       {
        int value = !!islower(x);
@@ -916,6 +938,7 @@ main(int argc, char **argv)
   next_active(0, 1);
 
   int should_exit = 0;
+restart:
   while (!should_exit)
     {
       time_t now = time(NULL);
@@ -927,6 +950,14 @@ main(int argc, char **argv)
          remains *= 10;
          halfdelay((remains > 255) ? 255 : remains);
          int ch = getch();
+         for (int i=0; i<num_mboxes; i++)
+           if (ch == mbox_array[i]->o.hotkey)
+             {
+               if (i < cursor_max)
+                 cursor_at = i;
+               mbox_run(mbox_array[i]);
+               goto restart;
+             }
          switch (ch)
            {
            case 'q':
@@ -959,18 +990,7 @@ main(int argc, char **argv)
            case '\r':
            case '\n':
              if (cursor_at < cursor_max)
-               {
-                 struct mbox *b = mbox_array[cursor_at];
-                 char cmd[strlen(run_cmd) + strlen(b->path) + 16];
-                 sprintf(cmd, run_cmd, b->path);
-                 term_cleanup();
-                 system(cmd);
-                 term_init();
-                 redraw_all();
-                 refresh();
-                 b->force_refresh = 1;
-                 scan_and_redraw();
-               }
+               mbox_run(mbox_array[cursor_at]);
              break;
            case 'l' & 0x1f:
              clearok(stdscr, TRUE);