Skip to content

Commit

Permalink
Help Browser: Implement history
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel authored and Vultraz committed Apr 16, 2017
1 parent d5b74a3 commit a8edca2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
26 changes: 26 additions & 0 deletions src/gui/dialogs/help_browser.cpp
Expand Up @@ -56,6 +56,12 @@ help_browser::help_browser()
void help_browser::pre_show(window& window)
{
tree_view& topic_tree = find_widget<tree_view>(&window, "topic_tree", false);
button& back_button = find_widget<button>(&window, "back", false);
button& next_button = find_widget<button>(&window, "next", false);
next_button.set_visible(widget::visibility::hidden);
back_button.set_visible(widget::visibility::hidden);
connect_signal_mouse_left_click(back_button, std::bind(&help_browser::on_history_navigate, this, std::ref(window), true));
connect_signal_mouse_left_click(next_button, std::bind(&help_browser::on_history_navigate, this, std::ref(window), false));

topic_tree.set_selection_change_callback(std::bind(&help_browser::on_topic_select, this, std::ref(window)));

Expand Down Expand Up @@ -218,9 +224,29 @@ void help_browser::on_topic_select(window& window)
window.invalidate_layout();
}

if(!history_.empty()) {
history_.erase(std::next(history_pos_), history_.end());
}
history_.push_back(topic_id);
history_pos_ = std::prev(history_.end());
find_widget<button>(&window, "back", false).set_visible(widget::visibility::visible);
find_widget<button>(&window, "next", false).set_visible(widget::visibility::hidden);

const unsigned topic_i = parsed_pages_.at(topic_id);
topic_pages.select_page(topic_i);
}

void help_browser::on_history_navigate(window& window, bool backwards) {
if(backwards) {
history_pos_--;
} else {
history_pos_++;
}
find_widget<button>(&window, "back", false).set_visible(history_pos_ == history_.begin() ? widget::visibility::hidden : widget::visibility::visible);
find_widget<button>(&window, "next", false).set_visible(history_pos_ == std::prev(history_.end()) ? widget::visibility::hidden : widget::visibility::visible);
const unsigned topic_i = parsed_pages_.at(*history_pos_);
find_widget<multi_page>(&window, "topic_text_pages", false).select_page(topic_i);
}

} // namespace dialogs
} // namespace gui2
11 changes: 9 additions & 2 deletions src/gui/dialogs/help_browser.hpp
Expand Up @@ -17,13 +17,16 @@

#include "gui/dialogs/modal_dialog.hpp"

#include "help/help_impl.hpp"

#include <map>
#include <list>

class config;
class CVideo;

namespace help {
struct section;
}

namespace gui2
{
class tree_view_node;
Expand All @@ -47,13 +50,17 @@ class help_browser : public modal_dialog

std::map<std::string, int> parsed_pages_;

std::list<std::string> history_;
std::list<std::string>::const_iterator history_pos_;

/** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const override;

/** Inherited from modal_dialog. */
virtual void pre_show(window& window) override;

void on_topic_select(window& window);
void on_history_navigate(window& window, bool backwards);

void add_topics_for_section(const help::section& parent_section, tree_view_node& parent_node);
tree_view_node& add_topic(const std::string& topic_id, const std::string& topic_title,
Expand Down

0 comments on commit a8edca2

Please sign in to comment.