Browse Source

Updated go and back fns

grissess
Sarah Inzerillo 4 years ago
parent
commit
9179a2e5ab
  1. 0
      source.sh
  2. 20
      src/Buffer.cpp
  3. 8
      src/Buffer.h
  4. 6
      src/FileBrowser.cpp
  5. 1
      test.txt

0
source.sh

20
src/Buffer.cpp

@ -79,33 +79,37 @@ bool Buffer::open(const string & new_file_name)
file_name_ = new_file_name;
ix_top_line_ = 0;
v_hist_.push_back(file_name);
v_hist_.push_back(file_name_);
curr_link_itr = v_hist_.end() - 1;
return true;
}
bool go(int & link)
bool Buffer::go(const int & link)
{
string f_name = v_links[link].first;
string f_name = v_links_[link-1].first;
if(!open(f_name))
return false;
else
v_hist_.push_back(f_name);
curr_link_itr = v_hist_.end() - 1;
{
// v_hist_.push_back(file_name_);
// curr_link_itr = v_hist_.end() - 1;
return true;
}
}
bool back()
bool Buffer::back()
{
if(v_hist_.empty())
return false;
v_hist_.erase(curr_link_itr);
if(v_hist_.size() == 0)
return false;
curr_link_itr = prev(curr_link_itr);
open(*current_link_itr);
open(*curr_link_itr);
return true;
}

8
src/Buffer.h

@ -18,7 +18,7 @@ public:
void move_to_next_page();
void move_to_previous_page();
int max_links();
bool go(int & link);
bool go(const int & link);
bool back();
bool open(const std::string & file_name);
void set_window_height(int h) { window_height_ = h; }
@ -27,7 +27,7 @@ private:
std::vector<std::string> v_lines_;
std::vector<std::pair<std::string, std::string>> v_links_;
std::vector<std::string> v_hist_;
auto curr_link_itr = v_hist_.end();
std::vector<std::string>::iterator curr_link_itr = v_hist_.end();
int ix_top_line_ = 0;
std::string file_name_;
int window_height_;
@ -47,9 +47,9 @@ inline void Buffer::move_to_previous_page()
ix_top_line_ = 0;
}
inline int Buffer::max::links()
inline int Buffer::max_links()
{
return v_links_.length();
return v_links_.size();
}
#endif

6
src/FileBrowser.cpp

@ -49,11 +49,11 @@ void FileBrowser::execute_command(char command, bool & done)
if (!ss) {
error_message_ = temp + " is not a valid link";
}
if (link < 1 || link > buffer_.max_links()) {
else if (link < 1 || link > buffer_.max_links()) {
error_message_ = "Could not open " + temp + " because the file is out of range";
}
if(!buffer_.go(link)){
error_message_ = "Could not open link " + link;
else if(!buffer_.go(link)){
error_message_ = "Could not open link " + temp;
}
break;
}

1
test.txt

@ -3,3 +3,4 @@
<p> This line has a link to the <a docs/specification.txt specification> file.
<p> This line is split into <p> two paragraph tags.
<p> This line contains some<br> problematic<p> tags.
<p> This has a link to sarahs <a sarahTest.txt anotherLink> file.
Loading…
Cancel
Save