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.

85 lines
3.2 KiB

4 years ago
  1. # File Browser
  3. ### COMPONENT: class FileBrowser
  4. A simple file browser. Acts as the interface between the user and its components.
  5. #### Public method:
  6. * void display()
  7. Updates the contents of the screen with the file contents that the user should see as well as UI and prompts surronding it.
  8. * void execute(char command, bool & done)
  9. 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.
  10. * void run()
  11. Runs the browser. It obtains size parameters from the user and then enters the browser's primary loop.
  12. **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.
  13. Collaborator: Buffer.
  14. ### COMPONENT: class Buffer
  15. 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.
  16. #### Public methods:
  17. * Buffer()
  18. (Compiler-generated.) Creates an empty buffer.
  19. * back()
  20. Opens the previously open file. Removes the current file from the history before going back.
  21. * void display() const
  22. Displays the lines of text that the user is currently viewing.
  23. * const string & file_name() const
  24. Returns the name of the file.
  25. * bool go(int link)
  26. Goes to the specified link in the current file. This opens the new link file and adds it to the open history.
  27. * void max_links()
  28. Returns the maximum number of links on the page. This is used by the file browser.
  29. * void move_to_next_page()
  30. Self-explanatory.
  31. * void move_to_previous_page()
  32. Self-explanatory.
  33. * bool open(const string & file_name)
  34. 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(<p>) define bodies of text which are seperated by other bodies of text by a line. Break tags(<br>) become a newline in the viewer. Anchor tags(<a>) are links. This incorperates the split_line function as well. The method open returns true if successful, otherwise false.
  35. * void Buffer::split_line(string str)
  36. 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.
  37. * void set_maximum_length(int l)
  38. Self-explanatory.
  39. * void set_window_height(int h)
  40. Self-explanatory.
  41. **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.