Skip to content
This repository has been archived by the owner on Oct 10, 2019. It is now read-only.

Commit

Permalink
make search phrase stand out in article view.
Browse files Browse the repository at this point in the history
  • Loading branch information
akrennmair committed Feb 9, 2009
1 parent 0249e5e commit a815e04
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -21,6 +21,7 @@ Changes for newsbeuter:
Extended "set" commandline command to toggle boolean variables and reset configuration variables of all types to their default.
Added ability to configure local files as feeds.
Added a "random-unread" key to go to a random unread article.
When opening articles from a search result dialog, make search phrase stand out in article view.

1.3 (2008-12-06):
Changed some internal data structures to smart pointers (stability improvement).
Expand Down
6 changes: 3 additions & 3 deletions TODO
Expand Up @@ -7,10 +7,7 @@ TODO:
- implement internal alias mechanism to allow transition of renamed config commands.
- improve logging of which feeds are broken.
- persist search and command history to text files.
- make last search phrase stand out in article view.
- make search phrase stand out in help (just like article view instead of limit) - configurable? combine both limit and standout?
- add license to -V output
- rename -v to something else to avoid confusion


DONE:
Expand Down Expand Up @@ -146,3 +143,6 @@ DONE:
- fix W3CDTF parser
- make boolean config variables toggable via commandline and resettable to default
- backtick evaluation in configuration
- add license to -V output
- rename -v to something else to avoid confusion
- make last search phrase stand out in article view.
2 changes: 2 additions & 0 deletions include/itemview_formaction.h
Expand Up @@ -18,6 +18,7 @@ class itemview_formaction : public formaction {
virtual void init();
inline void set_guid(const std::string& guid_) { guid = guid_; }
inline void set_feed(std::tr1::shared_ptr<rss_feed> fd) { feed = fd; }
void set_highlightphrase(const std::string& text);
keymap_hint_entry * get_keymap_hint();
virtual void handle_cmdline(const std::string& cmd);

Expand All @@ -35,6 +36,7 @@ class itemview_formaction : public formaction {
private:
virtual void process_operation(operation op, bool automatic = false, std::vector<std::string> * args = NULL);
void set_head(const std::string& s);
void highlight_text(const std::string& searchphrase);

void render_source(std::vector<std::string>& lines, std::string desc, unsigned int width);

Expand Down
2 changes: 1 addition & 1 deletion include/view.h
Expand Up @@ -51,7 +51,7 @@ namespace newsbeuter {

void push_itemlist(unsigned int pos);
void push_itemlist(std::tr1::shared_ptr<rss_feed> feed);
void push_itemview(std::tr1::shared_ptr<rss_feed> f, const std::string& guid);
void push_itemview(std::tr1::shared_ptr<rss_feed> f, const std::string& guid, const std::string& searchphrase = "");
void push_help();
void push_urlview(const std::vector<linkpair>& links);
void push_searchresult(std::tr1::shared_ptr<rss_feed> feed, const std::string& phrase = "");
Expand Down
4 changes: 2 additions & 2 deletions src/itemlist_formaction.cpp
Expand Up @@ -44,7 +44,7 @@ void itemlist_formaction::process_operation(operation op, bool automatic, std::v
if (itemposname.length() > 0) {
visible_items[itempos].first->set_unread(false); // set article as read
old_itempos = itempos;
v->push_itemview(feed, visible_items[itempos].first->guid());
v->push_itemview(feed, visible_items[itempos].first->guid(), show_searchresult ? searchphrase : "");
do_redraw = true;
} else {
v->show_error(_("No item selected!")); // should not happen
Expand Down Expand Up @@ -433,7 +433,7 @@ void itemlist_formaction::qna_end_editflags() {
}

void itemlist_formaction::qna_start_search() {
std::string searchphrase = qna_responses[0];
searchphrase = qna_responses[0];
if (searchphrase.length() == 0)
return;

Expand Down
12 changes: 10 additions & 2 deletions src/itemview_formaction.cpp
Expand Up @@ -520,6 +520,10 @@ std::string itemview_formaction::title() {
return utils::strprintf(_("Article - %s"), item->title().c_str());
}

void itemview_formaction::set_highlightphrase(const std::string& text) {
highlight_text(text);
}

void itemview_formaction::do_search() {
std::string searchphrase = qna_responses[0];
if (searchphrase.length() == 0)
Expand All @@ -529,6 +533,10 @@ void itemview_formaction::do_search() {

LOG(LOG_DEBUG, "itemview_formaction::do_search: searchphrase = %s", searchphrase.c_str());

highlight_text(searchphrase);
}

void itemview_formaction::highlight_text(const std::string& searchphrase) {
std::vector<std::string> params;
params.push_back("article");
params.push_back(searchphrase);
Expand All @@ -539,14 +547,14 @@ void itemview_formaction::do_search() {
try {
rxman->handle_action("highlight", params);

LOG(LOG_DEBUG, "itemview_formaction::do_search: configuration manipulation was successful");
LOG(LOG_DEBUG, "itemview_formaction::highlight_text: configuration manipulation was successful");

set_regexmanager(rxman);

in_search = true;
do_redraw = true;
} catch (const confighandlerexception& e) {
LOG(LOG_ERROR, "itemview_formaction::do_search: handle_action failed, error = %s", e.what());
LOG(LOG_ERROR, "itemview_formaction::highlight_text: handle_action failed, error = %s", e.what());
v->show_error(_("Error: invalid regular expression!"));
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/view.cpp
Expand Up @@ -412,7 +412,7 @@ void view::push_itemlist(unsigned int pos) {
}
}

void view::push_itemview(std::tr1::shared_ptr<rss_feed> f, const std::string& guid) {
void view::push_itemview(std::tr1::shared_ptr<rss_feed> f, const std::string& guid, const std::string& searchphrase) {
std::string pager;
if ((pager = cfg->get_configvalue("pager")) == "internal") {
std::tr1::shared_ptr<itemlist_formaction> itemlist = std::tr1::dynamic_pointer_cast<itemlist_formaction, formaction>(get_current_formaction());
Expand All @@ -423,6 +423,8 @@ void view::push_itemview(std::tr1::shared_ptr<rss_feed> f, const std::string& gu
itemview->set_feed(f);
itemview->set_guid(guid);
itemview->set_parent_formaction(get_current_formaction());
if (searchphrase.length() > 0)
itemview->set_highlightphrase(searchphrase);
apply_colors(itemview);
itemview->init();
formaction_stack.push_back(itemview);
Expand Down

0 comments on commit a815e04

Please sign in to comment.