The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
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

Public Member Functions

 file_menu (CVideo &disp, std::string start_file="")
 Initialize the file menu. More...
 
std::string get_choice () const
 Return the chosen file. More...
 
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. More...
 
std::string strip_last_delim (const std::string &path) const
 Return the string with the last path delimiter removed, if one was there. More...
 
bool is_directory (const std::string &fname) const
 
void change_directory (const std::string &path)
 
bool make_directory (const std::string &subdir_name)
 
void select_file (const std::string &begin_of_filename)
 Selects file (type-a-head search) More...
 
bool type_a_head () const
 
void reset_type_a_head ()
 
- Public Member Functions inherited from gui::menu
 menu (CVideo &video, const std::vector< std::string > &items, bool click_selects=false, int max_height=-1, int max_width=-1, const sorter *sorter_obj=nullptr, style *menu_style=nullptr, const bool auto_join=true)
 
 ~menu ()
 Default implementation, but defined out-of-line for efficiency reasons. More...
 
int selection () const
 
void move_selection (size_t id)
 
void move_selection_keeping_viewport (size_t id)
 
void reset_selection ()
 
const itemget_item (int index) const
 
const itemget_selected_item () const
 
void change_item (int pos1, int pos2, const std::string &str)
 
virtual void erase_item (size_t index)
 
void set_heading (const std::vector< std::string > &heading)
 
virtual void set_items (const std::vector< std::string > &items, bool strip_spaces=true, bool keep_viewport=false)
 Set new items to show and redraw/recalculate everything. More...
 
void set_max_height (const int new_max_height)
 Set a new max height for this menu. More...
 
void set_max_width (const int new_max_width)
 
int get_max_height ()
 
int get_max_width ()
 
size_t number_of_items () const
 
int process ()
 
bool double_clicked ()
 
void set_click_selects (bool value)
 
void set_numeric_keypress_selection (bool value)
 
void scroll (unsigned int pos)
 
void set_sorter (sorter *s)
 
void sort_by (int column)
 
int get_sort_by ()
 
bool get_sort_reversed ()
 
- Public Member Functions inherited from gui::scrollarea
 scrollarea (CVideo &video, bool auto_join=true)
 Create a zone with automatic handling of scrollbar. More...
 
virtual void hide (bool value=true)
 
- Public Member Functions inherited from gui::widget
SDL_Rect const & location () const
 
virtual void set_location (SDL_Rect const &rect)
 
void set_location (int x, int y)
 
void set_width (int w)
 
void set_height (int h)
 
void set_measurements (int w, int h)
 
int width () const
 
int height () const
 
bool focus (const SDL_Event *event)
 
void set_focus (bool focus)
 
bool hidden () const
 
virtual void enable (bool new_val=true)
 
bool enabled () const
 
void set_clip_rect (const SDL_Rect &rect)
 
void set_volatile (bool val=true)
 
void set_dirty (bool dirty=true)
 
bool dirty () const
 
const std::stringid () const
 
void set_id (const std::string &id)
 
void set_help_string (const std::string &str)
 
void set_tooltip_string (const std::string &str)
 
virtual void process_tooltip_string (int mousex, int mousey)
 
- Public Member Functions inherited from events::sdl_handler
virtual void join ()
 
virtual void join (context &c)
 
virtual void join_same (sdl_handler *parent)
 
virtual void leave ()
 
virtual void join_global ()
 
virtual void leave_global ()
 

Static Public Attributes

static const char path_delim
 
- Static Public Attributes inherited from gui::menu
static styledefault_style = menu::bluebg_style
 
static style simple_style
 
static imgsel_style bluebg_style
 

Protected Member Functions

void handle_event (const SDL_Event &event)
 
- Protected Member Functions inherited from gui::menu
bool item_ends_with_image (const std::string &item) const
 
void set_inner_location (const SDL_Rect &rect)
 
bool requires_event_focus (const SDL_Event *event=nullptr) const
 
const std::vector< int > & column_widths () const
 
virtual void draw_row (const size_t row_index, const SDL_Rect &rect, ROW_TYPE type)
 
int hit (int x, int y) const
 
std::pair< int, inthit_cell (int x, int y) const
 
int hit_column (int x) const
 
int hit_heading (int x, int y) const
 
void invalidate_row (size_t id)
 
void invalidate_row_pos (size_t pos)
 
void invalidate_heading ()
 
- Protected Member Functions inherited from gui::scrollarea
virtual sdl_handler_vector handler_members ()
 
virtual void update_location (SDL_Rect const &rect)
 
virtual void process_event ()
 
SDL_Rect inner_location () const
 
unsigned scrollbar_width () const
 
unsigned get_position () const
 
unsigned get_max_position () const
 
void set_position (unsigned pos)
 
void adjust_position (unsigned pos)
 
void move_position (int dep)
 
void set_shown_size (unsigned h)
 
void set_full_size (unsigned h)
 
void set_scroll_rate (unsigned r)
 
bool has_scrollbar () const
 
- Protected Member Functions inherited from gui::widget
 widget (widget const &o)
 
 widget (CVideo &video, const bool auto_join=true)
 
virtual ~widget ()
 
void bg_register (SDL_Rect const &rect)
 
void bg_restore () const
 
void bg_restore (SDL_Rect const &rect) const
 
void bg_update ()
 
void bg_cancel ()
 
CVideovideo () const
 
const SDL_Rect * clip_rect () const
 
virtual sdl_handler_vector member_handlers ()
 
virtual void handle_window_event (SDL_Event const &event)
 
bool mouse_locked () const
 
void aquire_mouse_lock ()
 
void free_mouse_lock ()
 
- Protected Member Functions inherited from events::sdl_handler
 sdl_handler (const bool auto_join=true)
 
virtual ~sdl_handler ()
 

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. More...
 
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. More...
 
bool is_root (const std::string &path) const
 Return true if the path is the root of the filesystem. More...
 
void display_current_files ()
 Show the files in the current directory. More...
 
void update_file_lists ()
 Updated the locally maintained lists of files and directories in the current directory. More...
 
void entry_selected (const unsigned entry)
 Set the textbox to reflect the selected file. More...
 

Private Attributes

std::string current_dir_
 
std::string chosen_file_
 
std::vector< std::stringfiles_in_current_dir_
 
std::vector< std::stringdirs_in_current_dir_
 
int last_selection_
 
int type_a_head_
 

Additional Inherited Members

- Public Types inherited from gui::menu
enum  ROW_TYPE { NORMAL_ROW, SELECTED_ROW, HEADING_ROW }
 
- Protected Attributes inherited from gui::menu
stylestyle_
 
bool silent_
 
- Protected Attributes inherited from gui::widget
bool focus_
 

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 52 of file file_menu.cpp.

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

Member Function Documentation

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 244 of file file_menu.cpp.

References get_path_up(), path_delim, gui::path_up(), and strip_last_delim().

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

void gui::file_menu::change_directory ( const std::string path)
int gui::file_menu::delete_chosen_file ( )
void gui::file_menu::display_current_files ( )
private
void gui::file_menu::entry_selected ( const unsigned  entry)
private

Set the textbox to reflect the selected file.

Definition at line 141 of file file_menu.cpp.

References add_path(), chosen_file_, current_dir_, dirs_in_current_dir_, files_in_current_dir_, is_root(), gui::path_up(), and game_config::images::selected.

Referenced by handle_event(), and reset_type_a_head().

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

Return the chosen file.

Definition at line 191 of file file_menu.cpp.

References chosen_file_.

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

std::string gui::file_menu::get_directory ( ) const
inline
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 196 of file file_menu.cpp.

References filesystem::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 207 of file file_menu.cpp.

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

Referenced by add_path(), and change_directory().

void gui::file_menu::handle_event ( const SDL_Event &  event)
protectedvirtual
bool gui::file_menu::is_directory ( const std::string fname) const
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 240 of file file_menu.cpp.

References path_delim.

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

bool gui::file_menu::make_directory ( const std::string subdir_name)
void gui::file_menu::reset_type_a_head ( )

Definition at line 285 of file file_menu.cpp.

References entry_selected(), last_selection_, and type_a_head_.

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

void gui::file_menu::select_file ( const std::string begin_of_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 232 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::type_a_head ( ) const

Definition at line 280 of file file_menu.cpp.

References gui::menu::selection(), and type_a_head_.

Referenced by dialogs::file_dialog::action(), and handle_event().

void gui::file_menu::update_file_lists ( )
private

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

Definition at line 317 of file file_menu.cpp.

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

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

Member Data Documentation

std::string gui::file_menu::chosen_file_
private
std::string gui::file_menu::current_dir_
private
std::vector<std::string> gui::file_menu::dirs_in_current_dir_
private
std::vector<std::string> gui::file_menu::files_in_current_dir_
private
int gui::file_menu::last_selection_
private
const char gui::file_menu::path_delim
static
int gui::file_menu::type_a_head_
private

Definition at line 96 of file file_menu.hpp.

Referenced by handle_event(), reset_type_a_head(), select_file(), and type_a_head().


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