You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
2.6 KiB
113 lines
2.6 KiB
// FileBrowser.cpp
|
|
|
|
#include "FileBrowser.h"
|
|
|
|
using namespace std;
|
|
|
|
void FileBrowser::display()
|
|
{
|
|
const string long_separator(50, '-');
|
|
const string short_separator(8, '-');
|
|
|
|
//system("cls || clear");
|
|
|
|
if (!error_message_.empty()) {
|
|
cout << "ERROR: " + error_message_ << endl;
|
|
error_message_.clear();
|
|
}
|
|
|
|
string file_name = buffer_.file_name();
|
|
if (file_name.empty())
|
|
cout << "<no file opened>\n";
|
|
else
|
|
cout << file_name << endl;
|
|
cout << long_separator << endl;
|
|
|
|
auto lines = buffer_.get_lines();
|
|
delete[] lines;
|
|
buffer_.display();
|
|
cout << long_separator << endl;
|
|
cout << " next previous open\n";
|
|
cout << " go back quit\n";
|
|
cout << short_separator << endl;
|
|
}
|
|
|
|
void FileBrowser::execute_command(char command, bool & done)
|
|
{
|
|
switch (command) {
|
|
/*case 'b': {
|
|
buffer_.back();
|
|
break;
|
|
}
|
|
case 'g': {
|
|
stringstream ss;
|
|
string temp;
|
|
int link;
|
|
cout << "go to link: ";
|
|
getline(cin, temp);
|
|
ss.str(temp);
|
|
ss >> link;
|
|
if (!ss) {
|
|
error_message_ = "Could not open " + temp;
|
|
}
|
|
if (link < 1 || link > buffer_.max_links()) {
|
|
error_message_ = "Could not open " + temp + " because the file is out of range";
|
|
}
|
|
buffer_.go(link);
|
|
break;
|
|
}*/
|
|
case 'n': {
|
|
buffer_.move_to_next_page();
|
|
break;
|
|
}
|
|
|
|
case 'o': {
|
|
cout << "file name: ";
|
|
string file_name;
|
|
getline(cin, file_name);
|
|
if (!buffer_.open(file_name))
|
|
error_message_ = "Could not open " + file_name;
|
|
break;
|
|
}
|
|
|
|
case 'p': {
|
|
buffer_.move_to_previous_page();
|
|
break;
|
|
}
|
|
|
|
case 'q': {
|
|
done = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void FileBrowser::run()
|
|
{
|
|
cout << "Window height? ";
|
|
cin >> window_height_;
|
|
cin.get(); // '\n'
|
|
cout << '\n';
|
|
buffer_.set_window_height(window_height_);
|
|
|
|
cout << "Maximum length? ";
|
|
cin >> maximum_length_;
|
|
cin.get(); // '\n'
|
|
cout << '\n';
|
|
|
|
bool done = false;
|
|
while (!done) {
|
|
display();
|
|
|
|
cout << "command: ";
|
|
char command;
|
|
cin >> command;
|
|
cin.get(); // '\n'
|
|
|
|
execute_command(command, done);
|
|
|
|
cout << endl;
|
|
}
|
|
}
|
|
|
|
|