gui::file_menu Class Reference

A widget where the user may navigate through directories and choose a file. More...

#include <file_menu.hpp>

Inheritance diagram for gui::file_menu:

Inheritance graph
[legend]
Collaboration diagram for gui::file_menu:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 file_menu (CVideo &disp, std::string start_file="")
 Initialize the file menu.
std::string get_choice () const
 Return the chosen file.
int delete_chosen_file ()
std::string get_directory () const
std::string add_path (const std::string path, const std::string to_add) const
 Return path with to_add added, using a path delimiter between them.
std::string strip_last_delim (const std::string path) const
 Return the string with the last path delimiter removed, if one was there.
bool is_directory (const std::string &fname) const
void change_directory (const std::string path)
bool make_directory (const std::string &subdir_name)

Static Public Attributes

static const char path_delim

Protected Member Functions

void handle_event (const SDL_Event &event)

Private Member Functions

std::string get_path (const std::string file_or_dir) const
 If file_or_dir is a file, return the directory the file is in, if it is a directory, return the directory name.
std::string get_path_up (const std::string path, const unsigned levels=1) const
 Return the path that is the specified number of levels up from the path.
bool is_root (const std::string path) const
 Return true if the path is the root of the filesystem.
void display_current_files ()
 Show the files in the current directory.
void update_file_lists ()
 Updated the locally maintained lists of files and directories in the current directory.
void entry_selected (const unsigned entry)
 Set the textbox to reflect the selected file.

Private Attributes

std::string current_dir_
std::string chosen_file_
std::vector< std::string > files_in_current_dir_
std::vector< std::string > dirs_in_current_dir_
int last_selection_


Detailed Description

A widget where the user may navigate through directories and choose a file.

Definition at line 25 of file file_menu.hpp.


Constructor & Destructor Documentation

gui::file_menu::file_menu ( CVideo disp,
std::string  start_file = "" 
)

Initialize the file menu.

start_file is the file that will be selected initially. The current directory will be the one the file is in.

Definition at line 42 of file file_menu.cpp.

References chosen_file_, current_dir_, file_exists(), is_directory(), path_delim, and update_file_lists().


Member Function Documentation

std::string gui::file_menu::get_choice (  )  const

Return the chosen file.

Definition at line 175 of file file_menu.cpp.

References chosen_file_.

Referenced by dialogs::file_dialog::action().

int gui::file_menu::delete_chosen_file (  ) 

Definition at line 91 of file file_menu.cpp.

References chosen_file_, current_dir_, last_selection_, and update_file_lists().

Referenced by dialogs::file_dialog::action().

std::string gui::file_menu::get_directory (  )  const [inline]

std::string gui::file_menu::add_path ( const std::string  path,
const std::string  to_add 
) const

Return path with to_add added, using a path delimiter between them.

Definition at line 233 of file file_menu.cpp.

References get_path_up(), path_delim, and strip_last_delim().

Referenced by entry_selected(), make_directory(), and dialogs::file_dialog::unformat_filename().

std::string gui::file_menu::strip_last_delim ( const std::string  path  )  const

Return the string with the last path delimiter removed, if one was there.

Definition at line 217 of file file_menu.cpp.

References path_delim.

Referenced by add_path(), dialogs::file_dialog::format_dirname(), and get_path_up().

bool gui::file_menu::is_directory ( const std::string &  fname  )  const

void gui::file_menu::change_directory ( const std::string  path  ) 

bool gui::file_menu::make_directory ( const std::string &  subdir_name  ) 

void gui::file_menu::handle_event ( const SDL_Event &  event  )  [protected, virtual]

Reimplemented from gui::menu.

Definition at line 117 of file file_menu.cpp.

References entry_selected(), map_editor::handle_event(), last_selection_, and gui::menu::selection().

std::string gui::file_menu::get_path ( const std::string  file_or_dir  )  const [private]

If file_or_dir is a file, return the directory the file is in, if it is a directory, return the directory name.

If no path delimiters could be found, return the unchanged argument.

Definition at line 180 of file file_menu.cpp.

References is_directory(), and path_delim.

Referenced by get_path_up().

std::string gui::file_menu::get_path_up ( const std::string  path,
const unsigned  levels = 1 
) const [private]

Return the path that is the specified number of levels up from the path.

If the movement could not proceed due to being at the root or having an invalid argument, return the path that the movement ended on.

Definition at line 191 of file file_menu.cpp.

References get_path(), is_root(), path_delim, and strip_last_delim().

Referenced by add_path(), and change_directory().

bool gui::file_menu::is_root ( const std::string  path  )  const [private]

Return true if the path is the root of the filesystem.

Definition at line 225 of file file_menu.cpp.

References path_delim.

Referenced by change_directory(), display_current_files(), entry_selected(), and get_path_up().

void gui::file_menu::display_current_files (  )  [private]

void gui::file_menu::update_file_lists (  )  [private]

Updated the locally maintained lists of files and directories in the current directory.

Definition at line 258 of file file_menu.cpp.

References current_dir_, dirs_in_current_dir_, display_current_files(), FILE_NAME_ONLY, files_in_current_dir_, and get_files_in_dir().

Referenced by change_directory(), delete_chosen_file(), file_menu(), and make_directory().

void gui::file_menu::entry_selected ( const unsigned  entry  )  [private]

Set the textbox to reflect the selected file.

Definition at line 125 of file file_menu.cpp.

References add_path(), chosen_file_, current_dir_, dirs_in_current_dir_, files_in_current_dir_, and is_root().

Referenced by handle_event().


Member Data Documentation

const char gui::file_menu::path_delim [static]

std::string gui::file_menu::current_dir_ [private]

std::string gui::file_menu::chosen_file_ [private]

std::vector<std::string> gui::file_menu::files_in_current_dir_ [private]

Definition at line 86 of file file_menu.hpp.

Referenced by display_current_files(), entry_selected(), and update_file_lists().

std::vector<std::string> gui::file_menu::dirs_in_current_dir_ [private]

Definition at line 86 of file file_menu.hpp.

Referenced by display_current_files(), entry_selected(), and update_file_lists().

Definition at line 87 of file file_menu.hpp.

Referenced by change_directory(), delete_chosen_file(), handle_event(), and make_directory().


The documentation for this class was generated from the following files:

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs