COMPONENT: class FileBrowser
A simple file browser. Acts as the interface between the user and its components.
Updates the contents of the screen with the file contents that the user should see as well as UI and prompts surronding it.
void execute(char command, bool & done)
Executes the command that the user inputs, represented by a single character. The user can open a file, scroll through the contents of the file, open links, open previously opened files and exit the program.
Runs the browser. It obtains size parameters from the user and then enters the browser's primary loop.
Implementation note: Holds the lines of text in a Buffer object. The displaying of the buffer contents and the execution of the commands is delegated to the Buffer object.
COMPONENT: class Buffer
A buffer for a simple file browser. Holds the lines of text and executes commands on them. Displays the contents of the buffer. See program specification for details on commands.
(Compiler-generated.) Creates an empty buffer.
Opens the previously open file. Removes the current file from the history before going back.
void display() const
Displays the lines of text that the user is currently viewing.
const string & file_name() const
Returns the name of the file.
bool go(int link)
Goes to the specified link in the current file. This opens the new link file and adds it to the open history.
Returns the maximum number of links on the page. This is used by the file browser.
bool open(const string & file_name)
Executes the corresponding file viewer command on the buffer. If a file is currently open, it adds the previous file to the open history. Lines in the file are formatted. Paragraph tags(
) define bodies of text which are seperated by other bodies of text by a line. Break tags(
) become a newline in the viewer. Anchor tags() are links. This incorperates the split_line function as well. The method open returns true if successful, otherwise false.
void Buffer::split_line(string str)
Takes a copy of the line given to it, and then splits the line up into subtrings that are less than the maximum length. If a word is longer than the maximum length, it prints that word on a line on its own.
void set_maximum_length(int l)
void set_window_height(int h)
Implementation note: Stores each line of text as a string and all the lines in a vector, which should be formatted and ready to display without further processing. The links that are processed in the open command are stored as a pair in another vector. Also stores the index of the line currently displayed at the top of the window, as well as the name of the file and the window height. A utility function that handles the processing of lines that would be longer than the browser's set width into multible lines.