From 8be6c589daa70910d6a4574f5a34fce0e8263376 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 14 Sep 2014 15:55:22 -0400 Subject: [PATCH] Hooks - Implemented new interface. Testing time. --- src/Hooks.cpp | 50 ++++++++++++++------------------------------------ 1 file changed, 14 insertions(+), 36 deletions(-) diff --git a/src/Hooks.cpp b/src/Hooks.cpp index 3c3478ab3..0d3d0acbc 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -94,10 +94,11 @@ bool Hooks::enable (bool value) // void Hooks::onLaunch () { - context.timer_hooks.start (); if (! _enabled) return; + context.timer_hooks.start (); + std::vector matchingScripts = scripts ("on-launch"); std::vector ::iterator i; for (i = matchingScripts.begin (); i != matchingScripts.end (); ++i) @@ -151,10 +152,11 @@ void Hooks::onLaunch () // void Hooks::onExit () { - context.timer_hooks.start (); if (! _enabled) return; + context.timer_hooks.start (); + std::vector matchingScripts = scripts ("on-exit"); std::vector ::iterator i; for (i = matchingScripts.begin (); i != matchingScripts.end (); ++i) @@ -199,16 +201,16 @@ void Hooks::onExit () // void Hooks::onAdd (std::vector & changes) { -/* - context.timer_hooks.start (); if (! _enabled) return; + context.timer_hooks.start (); + std::vector matchingScripts = scripts ("on-add"); std::vector ::iterator i; for (i = matchingScripts.begin (); i != matchingScripts.end (); ++i) { - std::string input = after.composeJSON () + "\n"; + std::string input = changes[0].composeJSON () + "\n"; std::string output; std::vector args; int status = execute (*i, args, input, output); @@ -219,22 +221,11 @@ void Hooks::onAdd (std::vector & changes) if (status == 0) { - bool first = true; + changes.clear (); for (line = lines.begin (); line != lines.end (); ++line) { if (line->length () && (*line)[0] == '{') - { - Task newTask (*line); - - // TODO Not sure if this first/!first thing is good. - if (first) - { - after = newTask; - first = false; - } - else - context.tdb2.add (newTask); - } + changes.push_back (Task (*line)); else context.footnote (*line); } @@ -250,7 +241,6 @@ void Hooks::onAdd (std::vector & changes) } context.timer_hooks.stop (); -*/ } //////////////////////////////////////////////////////////////////////////////// @@ -270,16 +260,16 @@ void Hooks::onAdd (std::vector & changes) // void Hooks::onModify (const Task& before, std::vector & changes) { -/* - context.timer_hooks.start (); if (! _enabled) return; + context.timer_hooks.start (); + std::vector matchingScripts = scripts ("on-modify"); std::vector ::iterator i; for (i = matchingScripts.begin (); i != matchingScripts.end (); ++i) { - std::string afterJSON = after.composeJSON (); + std::string afterJSON = changes[0].composeJSON (); std::string input = before.composeJSON () + "\n" + afterJSON @@ -294,22 +284,11 @@ void Hooks::onModify (const Task& before, std::vector & changes) if (status == 0) { - bool first = true; + changes.clear (); for (line = lines.begin (); line != lines.end (); ++line) { if (line->length () && (*line)[0] == '{') - { - Task newTask (*line); - - // TODO Not sure if this first/!first thing is good. - if (first) - { - after = newTask; - first = false; - } - else - context.tdb2.modify (newTask); - } + changes.push_back (Task (*line)); else context.footnote (*line); } @@ -325,7 +304,6 @@ void Hooks::onModify (const Task& before, std::vector & changes) } context.timer_hooks.stop (); -*/ } ////////////////////////////////////////////////////////////////////////////////