Permalink
Browse files

Implement tag editing in search view

  • Loading branch information...
wereHamster committed Mar 26, 2012
1 parent c945edc commit f76b34cd03b161c3d98242225c70f18a946c3782
Showing with 90 additions and 0 deletions.
  1. +9 −0 src/message.cc
  2. +1 −0 src/message.hh
  3. +64 −0 src/search_view.cc
  4. +3 −0 src/search_view.hh
  5. +11 −0 src/thread.cc
  6. +2 −0 src/thread.hh
View
@@ -79,3 +79,12 @@ void Message::addTag(std::string tag)
{
notmuch_message_add_tag(_message, tag.c_str());
}
+
+void Message::addTagRecursive(std::string tag)
+{
+ notmuch_message_add_tag(_message, tag.c_str());
+
+ for (Message m : replies) {
+ m.addTagRecursive(tag);
+ }
+}
View
@@ -90,6 +90,7 @@ class Message
~Message();
void addTag(std::string tag);
+ void addTagRecursive(std::string tag);
void removeTag(std::string tag);
void removeTagRecursive(std::string tag);
View
@@ -32,6 +32,7 @@
#include "ncurses.hh"
#include "notmuch.hh"
#include "status_bar.hh"
+#include "line_editor.hh"
const int newestDateWidth = 13;
const int messageCountWidth = 8;
@@ -52,6 +53,9 @@ SearchView::SearchView(const std::string & search, const View::Geometry & geomet
addHandledSequence("a", std::bind(&SearchView::archiveSelectedThread, this));
+ addHandledSequence("+", std::bind(&SearchView::addTags, this));
+ addHandledSequence("-", std::bind(&SearchView::removeTags, this));
+
std::unique_lock<std::mutex> lock(_mutex);
while (_threads.size() < getmaxy(_window) && _collecting)
_condition.wait_for(lock, conditionWaitTime);
@@ -316,5 +320,65 @@ void SearchView::collectThreads()
_condition.notify_one();
}
+void SearchView::addTags()
+{
+ std::lock_guard<std::mutex> lock(_mutex);
+
+ if (_selectedIndex < _threads.size())
+ {
+ Thread & thread = _threads.at(_selectedIndex);
+
+ try
+ {
+ std::string tags = StatusBar::instance().prompt("Tags: ", "tags");
+
+ if (!tags.empty()) {
+ std::stringstream ss(tags);
+ std::string s;
+
+ while (std::getline(ss, s, ' ')) {
+ thread.addTag(s);
+ }
+
+ next();
+ update();
+ }
+ }
+ catch (const AbortInputException&)
+ {
+ }
+ }
+}
+
+void SearchView::removeTags()
+{
+ std::lock_guard<std::mutex> lock(_mutex);
+
+ if (_selectedIndex < _threads.size())
+ {
+ Thread & thread = _threads.at(_selectedIndex);
+
+ try
+ {
+ std::string tags = StatusBar::instance().prompt("Tags: ", "tags");
+
+ if (!tags.empty()) {
+ std::stringstream ss(tags);
+ std::string s;
+
+ while (std::getline(ss, s, ' ')) {
+ thread.removeTag(s);
+ }
+
+ next();
+ update();
+ }
+ }
+ catch (const AbortInputException&)
+ {
+ }
+ }
+}
+
// vim: fdm=syntax fo=croql et sw=4 sts=4 ts=8
View
@@ -43,6 +43,9 @@ class SearchView : public LineBrowserView
void openSelectedThread();
void archiveSelectedThread();
+ void addTags();
+ void removeTags();
+
protected:
virtual int lineCount() const;
View
@@ -60,6 +60,17 @@ void Thread::topLevelMessages(std::vector<Message> & messages)
}
}
+void Thread::addTag(std::string tag)
+{
+ tags.insert(tag);
+
+ std::vector<Message> messages;
+ topLevelMessages(messages);
+
+ for (Message m : messages) {
+ m.addTagRecursive(tag);
+ }
+}
void Thread::removeTag(std::string tag)
{
View
@@ -28,6 +28,8 @@ class Thread
void topLevelMessages(std::vector<Message> & messages);
+
+ void addTag(std::string tag);
void removeTag(std::string tag);

0 comments on commit f76b34c

Please sign in to comment.