Browse Source

ALl done i promise

stew
Sarah Inzerillo 4 years ago
parent
commit
e60d1cfbe5
  1. 33
      src/Buffer.cpp
  2. 2
      src/Buffer.h
  3. 2
      src/FileBrowser.cpp

33
src/Buffer.cpp

@ -49,7 +49,6 @@ vector<string> Buffer::split_line(string str) {
//Check if the string part can still be chopped
if (str_part.length() != str.length()) {
str_part = str.substr(0, total_pos);
cout << str_part << endl;
str = str.substr(total_pos + 1, str.length());
v.push_back(str_part);
}
@ -79,12 +78,13 @@ size_t Buffer::get_tag_(const string & line)
return p_tag;
}
bool Buffer::open(const string & new_file_name)
bool Buffer::open(const string & new_file_name, bool add_to_hist_)
{
std::ifstream file(new_file_name);
if (!file)
return false;
v_links_.clear();
v_lines_.clear();
//Note: the vector is cleared only after we know the file
//opened successfully.
@ -163,39 +163,38 @@ bool Buffer::open(const string & new_file_name)
ix_top_line_ = 0;
file_name_ = new_file_name;
if(add_to_hist_ == 1){
v_hist_.push_back(file_name_);
curr_link_itr = v_hist_.end() - 1;
if(add_to_hist_){
v_hist_.push_back(file_name_);
curr_link_itr = v_hist_.end() - 1;
}
return true;
}
bool Buffer::go(int link)
{
string f_name = v_links_[link-1].first;
v_links_.clear();
add_to_hist_ = 1;
if(!open(f_name))
return false;
else
{
if(open(f_name))
return true;
}
else
return false;
}
bool Buffer::back()
{
if(v_hist_.empty())
if(v_hist_.size() <= 1)
return false;
curr_link_itr = curr_link_itr - 1;
v_hist_.erase(curr_link_itr + 1);
if(v_hist_.empty())
return false;
open(*curr_link_itr, false);
add_to_hist_ = 0;
open(*curr_link_itr);
// for(string x : v_hist_)
// cout << x << ' ';
// cin.get();
return true;
}

2
src/Buffer.h

@ -20,7 +20,7 @@ public:
long max_links() {return v_links_.size(); };
void move_to_next_page();
void move_to_previous_page();
bool open(const std::string & file_name);
bool open(const std::string & file_name, bool add_to_hist_ = true);
void set_maximum_length(int l) { maximum_length_ = l; }
void set_window_height(int h) { window_height_ = h; }

2
src/FileBrowser.cpp

@ -35,7 +35,7 @@ void FileBrowser::execute_command(char command, bool & done)
switch (command) {
case 'b': {
if(!buffer_.back())
error_message_ = "No pervious links to open";
error_message_ = "No previous links to open";
break;
}

Loading…
Cancel
Save