From 5d30ead071fc7f5f38e439824e97aa5d9ccea67a Mon Sep 17 00:00:00 2001 From: Mirko Lindner Date: Sun, 24 Jan 2010 14:54:33 +0100 Subject: [PATCH] start implemting back and forward in history Signed-off-by: Mirko Lindner --- src/main_window.cc | 5 ++++ src/vido.cc | 71 +++++++++++++++++++++++++++++++++++----------- src/vido.hh | 3 +- 3 files changed, 61 insertions(+), 18 deletions(-) diff --git a/src/main_window.cc b/src/main_window.cc index 4d77dda..3030a66 100644 --- a/src/main_window.cc +++ b/src/main_window.cc @@ -39,6 +39,7 @@ main_window::main_window() bool main_window::actions(int key) { static int key_b = 98; + static int key_f = 102; static int key_h = 104; static int key_q = 113; static int key_r = 114; @@ -63,6 +64,10 @@ bool main_window::actions(int key) GoToTop(); }else if(key == key_h){ show_history(); + }else if(key == key_f){ + history_jump(1); + }else if(key == key_b){ + history_jump(-1); }else{ log_debug("key pressed: " << key); } diff --git a/src/vido.cc b/src/vido.cc index 6ff2e1a..29c7933 100644 --- a/src/vido.cc +++ b/src/vido.cc @@ -48,7 +48,8 @@ main_window *window; Gtk::Widget *html; GtkWidget *html_wg; std::vector < std::pair< std::string, std::string > > history; - +unsigned int position = 0; +bool historyCall = false; // // // misc functions // get zimFile, if not already opened, open file @@ -75,17 +76,29 @@ void show_message(std::string title, std::string txt) // fill gtkhtml widget with new content //TODO prepend "top" anchor on html void fill_gtkhtml(std::string& html, std::string url, std::string title){ - log_debug("fill gtkhtml called"); + log_debug("fill gtkhtml called with " << url << " and " << title); std::string ccontent; ccontent = "" + html; gtk_html_flush(GTK_HTML(html_wg)); gtk_html_load_from_string(GTK_HTML(html_wg), ccontent.c_str(), -1); if ((url != "") && title != ""){ - log_debug("adding " << title << " to history"); - history.push_back( std::make_pair( url, title ) ); - if (history.size() == 11){ - history.erase(history.begin()); + if (position == 0){ + log_debug("adding " << title << " to history"); + history.push_back( std::make_pair( url, title ) ); + if (history.size() == 11){ + history.erase(history.begin()); + } + }else{ + if (!historyCall){ + log_debug("clearing history"); + std::vector < std::pair< std::string, std::string > >::iterator iterator = history.begin(); + for (int m=0; m < position; m++){ + history.erase(iterator+m); + } + }else{ + historyCall = false; + } } } @@ -97,13 +110,17 @@ void show_history() std::string res, url, title; res += "