Help Browser: Implement history

This commit is contained in:
Celtic Minstrel 2017-04-10 14:08:09 -04:00
parent ec5cdb4fe4
commit f421a74864
2 changed files with 35 additions and 0 deletions

View file

@ -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)));
@ -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

View file

@ -17,9 +17,14 @@
#include "gui/dialogs/modal_dialog.hpp"
#include "help/help_impl.hpp"
#include <map>
#include <list>
class config;
namespace help {
struct section;
}
namespace gui2
{
class tree_view_node;
@ -40,6 +45,9 @@ private:
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;
@ -47,6 +55,7 @@ private:
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,