From 309fa84cb7439221c01f8526fcbc67b6004a95d1 Mon Sep 17 00:00:00 2001
From: Lukas Fleischer <calcurse@cryptocrack.de>
Date: Wed, 29 Jun 2011 19:26:29 +0200
Subject: Add key binding for pipe-item command

This removes the need of reading the whole data file and find matching
entries if we want to parse appointments in external programs.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
---
 src/calcurse.c |  7 +++++++
 src/calcurse.h |  1 +
 src/help.c     | 13 +++++++++++++
 src/keys.c     |  3 +++
 src/wins.c     | 16 +++++++++-------
 5 files changed, 33 insertions(+), 7 deletions(-)

(limited to 'src')

diff --git a/src/calcurse.c b/src/calcurse.c
index 662f185..0ae7e9a 100644
--- a/src/calcurse.c
+++ b/src/calcurse.c
@@ -368,6 +368,13 @@ main (int argc, char **argv)
           do_storage = 1;
           break;
 
+        case KEY_PIPE_ITEM:
+          if (wins_slctd () == APP && apoint_hilt () != 0)
+            day_pipe_item (&conf);
+          else if (wins_slctd () == TOD && todo_hilt () != 0)
+            todo_pipe_item ();
+          break;
+
         case KEY_RAISE_PRIORITY:
         case KEY_LOWER_PRIORITY:
           if (wins_slctd () == TOD && todo_hilt () != 0)
diff --git a/src/calcurse.h b/src/calcurse.h
index 95382e9..1443964 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -401,6 +401,7 @@ enum key {
   KEY_DEL_ITEM,
   KEY_EDIT_ITEM,
   KEY_VIEW_ITEM,
+  KEY_PIPE_ITEM,
   KEY_FLAG_ITEM,
   KEY_REPEAT_ITEM,
   KEY_EDIT_NOTE,
diff --git a/src/help.c b/src/help.c
index 3f4f7c7..7c43d44 100644
--- a/src/help.c
+++ b/src/help.c
@@ -56,6 +56,7 @@ typedef enum
   HELP_EXPORT,
   HELP_DISPLACEMENT,
   HELP_VIEW,
+  HELP_PIPE,
   HELP_TAB,
   HELP_GOTO,
   HELP_DELETE,
@@ -296,6 +297,10 @@ wanted_page (int ch)
       page = HELP_VIEW;
       break;
 
+    case KEY_PIPE_ITEM:
+      page = HELP_PIPE;
+      break;
+
     case KEY_RAISE_PRIORITY:
     case KEY_LOWER_PRIORITY:
       page = HELP_PRIORITY;
@@ -451,6 +456,14 @@ help_screen (void)
       "Calcurse screen."),
       keys_action_firstkey (KEY_VIEW_ITEM));
 
+  hscr[HELP_PIPE].title = _("Pipe\n");
+  (void)snprintf (hscr[HELP_PIPE].text, HELPTEXTSIZ,
+    _("Pipe the selected item to an external program.\n"
+      "\nPress the '%s' key to pipe the currently selected appointment or\n"
+      "todo entry to an external program.\n"
+      "\nYou will be driven back to calcurse as soon as the program exits.\n"),
+      keys_action_firstkey (KEY_PIPE_ITEM));
+
   hscr[HELP_TAB].title = _("Tab\n");
   (void)snprintf (hscr[HELP_TAB].text, HELPTEXTSIZ,
     _("Switch between panels.\n"
diff --git a/src/keys.c b/src/keys.c
index 6f3316f..1a46530 100644
--- a/src/keys.c
+++ b/src/keys.c
@@ -91,6 +91,7 @@ static struct keydef_s keydef[NBKEYS] = {
   {"del-item", "d D"},
   {"edit-item", "e E"},
   {"view-item", "v V"},
+  {"pipe-item", "|"},
   {"flag-item", "!"},
   {"repeat", "r R"},
   {"edit-note", "n N"},
@@ -567,6 +568,8 @@ keys_popup_info (enum key key)
     _("Flag the currently selected item as important.");
   info[KEY_REPEAT_ITEM] =
     _("Repeat an item");
+  info[KEY_PIPE_ITEM] =
+    _("Pipe the currently selected item to an external program.");
   info[KEY_EDIT_NOTE] =
     _("Attach (or edit if one exists) a note to the currently selected item");
   info[KEY_VIEW_NOTE] =
diff --git a/src/wins.c b/src/wins.c
index 2396a87..0e4b402 100644
--- a/src/wins.c
+++ b/src/wins.c
@@ -642,8 +642,8 @@ wins_launch_external (char *file, char *cmd)
 }
 
 #define NB_CAL_CMDS	27	/* number of commands while in cal view */
-#define NB_APP_CMDS	31	/* same thing while in appointment view */
-#define NB_TOD_CMDS	30	/* same thing while in todo view */
+#define NB_APP_CMDS	32	/* same thing while in appointment view */
+#define NB_TOD_CMDS	31	/* same thing while in todo view */
 #define TOTAL_CMDS	NB_CAL_CMDS + NB_APP_CMDS + NB_TOD_CMDS
 #define CMDS_PER_LINE	6	/* max number of commands per line */
 
@@ -695,6 +695,7 @@ wins_status_bar (void)
   struct binding del    = {_("Del Item"), KEY_DEL_ITEM};
   struct binding edit   = {_("Edit Itm"), KEY_EDIT_ITEM};
   struct binding view   = {_("View"),     KEY_VIEW_ITEM};
+  struct binding pipe   = {_("Pipe"),     KEY_PIPE_ITEM};
   struct binding flag   = {_("Flag Itm"), KEY_FLAG_ITEM};
   struct binding rept   = {_("Repeat"),   KEY_REPEAT_ITEM};
   struct binding enote  = {_("EditNote"), KEY_EDIT_NOTE};
@@ -709,13 +710,14 @@ wins_status_bar (void)
     &gnday, &gpday, &gnweek, &gpweek, &draw, &othr, &today, &conf, &othr,
     /* appointment keys */
     &help, &quit, &save, &chgvu, &import, &export, &add, &del, &edit, &view,
-    &draw, &othr, &rept, &flag, &enote, &vnote, &up, &down, &gnday, &gpday,
-    &gnweek, &gpweek, &togo, &othr, &today, &conf, &appt, &todo, &cut, &paste,
-    &othr,
+    &pipe, &othr, &draw, &rept, &flag, &enote, &vnote, &up, &down, &gnday,
+    &gpday, &gnweek, &gpweek, &othr, &togo, &today, &conf, &appt, &todo, &cut,
+    &paste, &othr,
     /* todo keys */
     &help, &quit, &save, &chgvu, &import, &export, &add, &del, &edit, &view,
-    &flag, &othr, &rprio, &lprio, &enote, &vnote, &up, &down, &gnday, &gpday,
-    &gnweek, &gpweek, &togo, &othr, &today, &conf, &appt, &todo, &draw, &othr
+    &pipe, &othr, &flag, &rprio, &lprio, &enote, &vnote, &up, &down, &gnday,
+    &gpday, &gnweek, &gpweek, &othr, &togo, &today, &conf, &appt, &todo, &draw,
+    &othr
   };
 
   /* Drawing the keybinding with attribute and label without. */
-- 
cgit v1.2.3-70-g09d2